You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LegacyConverterArtifactConsumer.java 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. package org.apache.archiva.converter.legacy;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import org.apache.archiva.admin.model.beans.ManagedRepository;
  21. import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
  22. import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
  23. import org.apache.archiva.consumers.AbstractMonitoredConsumer;
  24. import org.apache.archiva.consumers.ConsumerException;
  25. import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
  26. import org.apache.archiva.converter.artifact.ArtifactConversionException;
  27. import org.apache.archiva.converter.artifact.ArtifactConverter;
  28. import org.apache.archiva.model.ArtifactReference;
  29. import org.apache.archiva.repository.ManagedRepositoryContent;
  30. import org.apache.archiva.repository.content.maven2.ManagedDefaultRepositoryContent;
  31. import org.apache.archiva.repository.layout.LayoutException;
  32. import org.apache.maven.artifact.Artifact;
  33. import org.apache.maven.artifact.factory.ArtifactFactory;
  34. import org.apache.maven.artifact.repository.ArtifactRepository;
  35. import org.slf4j.Logger;
  36. import org.slf4j.LoggerFactory;
  37. import org.springframework.context.annotation.Scope;
  38. import org.springframework.stereotype.Service;
  39. import javax.inject.Inject;
  40. import java.util.ArrayList;
  41. import java.util.Date;
  42. import java.util.List;
  43. /**
  44. * LegacyConverterArtifactConsumer - convert artifacts as they are found
  45. * into the destination repository.
  46. *
  47. *
  48. */
  49. @Service( "knownRepositoryContentConsumer#artifact-legacy-to-default-converter" )
  50. @Scope( "prototype" )
  51. public class LegacyConverterArtifactConsumer
  52. extends AbstractMonitoredConsumer
  53. implements KnownRepositoryContentConsumer
  54. {
  55. private Logger log = LoggerFactory.getLogger( LegacyConverterArtifactConsumer.class );
  56. /**
  57. *
  58. */
  59. @Inject
  60. private ArtifactConverter artifactConverter;
  61. /**
  62. *
  63. */
  64. private ArtifactFactory artifactFactory;
  65. private ManagedRepositoryContent managedRepository;
  66. private ArtifactRepository destinationRepository;
  67. private List<String> includes;
  68. private List<String> excludes;
  69. @Inject
  70. public LegacyConverterArtifactConsumer( PlexusSisuBridge plexusSisuBridge )
  71. throws PlexusSisuBridgeException
  72. {
  73. includes = new ArrayList<>( 3 );
  74. includes.add( "**/*.jar" );
  75. includes.add( "**/*.ear" );
  76. includes.add( "**/*.war" );
  77. artifactFactory = plexusSisuBridge.lookup( ArtifactFactory.class );
  78. }
  79. public void beginScan( ManagedRepository repository, Date whenGathered )
  80. throws ConsumerException
  81. {
  82. this.managedRepository = new ManagedDefaultRepositoryContent();
  83. this.managedRepository.setRepository( repository );
  84. }
  85. public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo )
  86. throws ConsumerException
  87. {
  88. beginScan( repository, whenGathered );
  89. }
  90. public void completeScan()
  91. {
  92. // no op
  93. }
  94. public void completeScan( boolean executeOnEntireRepo )
  95. {
  96. completeScan();
  97. }
  98. public List<String> getExcludes()
  99. {
  100. return excludes;
  101. }
  102. public List<String> getIncludes()
  103. {
  104. return includes;
  105. }
  106. public void processFile( String path )
  107. throws ConsumerException
  108. {
  109. try
  110. {
  111. ArtifactReference reference = managedRepository.toArtifactReference( path );
  112. Artifact artifact = artifactFactory.createArtifact( reference.getGroupId(), reference.getArtifactId(),
  113. reference.getVersion(), reference.getClassifier(),
  114. reference.getType() );
  115. artifactConverter.convert( artifact, destinationRepository );
  116. }
  117. catch ( LayoutException e )
  118. {
  119. log.warn( "Unable to convert artifact: {} : {}",path , e.getMessage(), e );
  120. }
  121. catch ( ArtifactConversionException e )
  122. {
  123. log.warn( "Unable to convert artifact: {} : {}",path , e.getMessage(), e );
  124. }
  125. }
  126. public void processFile( String path, boolean executeOnEntireRepo )
  127. throws Exception
  128. {
  129. processFile( path );
  130. }
  131. public String getDescription()
  132. {
  133. return "Legacy Artifact to Default Artifact Converter";
  134. }
  135. public String getId()
  136. {
  137. return "artifact-legacy-to-default-converter";
  138. }
  139. public boolean isPermanent()
  140. {
  141. return false;
  142. }
  143. public void setExcludes( List<String> excludes )
  144. {
  145. this.excludes = excludes;
  146. }
  147. public void setIncludes( List<String> includes )
  148. {
  149. this.includes = includes;
  150. }
  151. public ArtifactRepository getDestinationRepository()
  152. {
  153. return destinationRepository;
  154. }
  155. public void setDestinationRepository( ArtifactRepository destinationRepository )
  156. {
  157. this.destinationRepository = destinationRepository;
  158. }
  159. }