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 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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.common.filelock.FileLockManager;
  21. import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
  22. import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
  23. import org.apache.archiva.configuration.FileTypes;
  24. import org.apache.archiva.consumers.AbstractMonitoredConsumer;
  25. import org.apache.archiva.consumers.ConsumerException;
  26. import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
  27. import org.apache.archiva.converter.artifact.ArtifactConversionException;
  28. import org.apache.archiva.converter.artifact.ArtifactConverter;
  29. import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider;
  30. import org.apache.archiva.model.ArtifactReference;
  31. import org.apache.archiva.repository.LayoutException;
  32. import org.apache.archiva.repository.ManagedRepository;
  33. import org.apache.archiva.repository.ManagedRepositoryContent;
  34. import org.apache.archiva.repository.content.maven2.ManagedDefaultRepositoryContent;
  35. import org.apache.maven.artifact.Artifact;
  36. import org.apache.maven.artifact.factory.ArtifactFactory;
  37. import org.apache.maven.artifact.repository.ArtifactRepository;
  38. import org.slf4j.Logger;
  39. import org.slf4j.LoggerFactory;
  40. import org.springframework.context.annotation.Scope;
  41. import org.springframework.stereotype.Service;
  42. import javax.inject.Inject;
  43. import javax.inject.Named;
  44. import java.util.ArrayList;
  45. import java.util.Date;
  46. import java.util.List;
  47. /**
  48. * LegacyConverterArtifactConsumer - convert artifacts as they are found
  49. * into the destination repository.
  50. *
  51. *
  52. */
  53. @Service( "knownRepositoryContentConsumer#artifact-legacy-to-default-converter" )
  54. @Scope( "prototype" )
  55. public class LegacyConverterArtifactConsumer
  56. extends AbstractMonitoredConsumer
  57. implements KnownRepositoryContentConsumer
  58. {
  59. private Logger log = LoggerFactory.getLogger( LegacyConverterArtifactConsumer.class );
  60. @Inject
  61. @Named("artifactConverter#legacy-to-default")
  62. private ArtifactConverter artifactConverter;
  63. @Inject
  64. private List<? extends ArtifactMappingProvider> artifactMappingProviders;
  65. @Inject
  66. private FileTypes fileTypes;
  67. @Inject
  68. private FileLockManager fileLockManager;
  69. private ArtifactFactory artifactFactory;
  70. private ManagedRepositoryContent managedRepository;
  71. private ArtifactRepository destinationRepository;
  72. private List<String> includes;
  73. private List<String> excludes;
  74. @Inject
  75. public LegacyConverterArtifactConsumer( PlexusSisuBridge plexusSisuBridge )
  76. throws PlexusSisuBridgeException
  77. {
  78. includes = new ArrayList<>( 3 );
  79. includes.add( "**/*.jar" );
  80. includes.add( "**/*.ear" );
  81. includes.add( "**/*.war" );
  82. artifactFactory = plexusSisuBridge.lookup( ArtifactFactory.class );
  83. }
  84. @Override
  85. public void beginScan( ManagedRepository repository, Date whenGathered )
  86. throws ConsumerException
  87. {
  88. this.managedRepository = new ManagedDefaultRepositoryContent(repository, artifactMappingProviders, fileTypes, fileLockManager);
  89. }
  90. @Override
  91. public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo )
  92. throws ConsumerException
  93. {
  94. beginScan( repository, whenGathered );
  95. }
  96. @Override
  97. public void completeScan()
  98. {
  99. // no op
  100. }
  101. @Override
  102. public void completeScan( boolean executeOnEntireRepo )
  103. {
  104. completeScan();
  105. }
  106. @Override
  107. public List<String> getExcludes()
  108. {
  109. return excludes;
  110. }
  111. @Override
  112. public List<String> getIncludes()
  113. {
  114. return includes;
  115. }
  116. @Override
  117. public void processFile( String path )
  118. throws ConsumerException
  119. {
  120. try
  121. {
  122. ArtifactReference reference = managedRepository.toArtifactReference( path );
  123. Artifact artifact = artifactFactory.createArtifact( reference.getGroupId(), reference.getArtifactId(),
  124. reference.getVersion(), reference.getClassifier(),
  125. reference.getType() );
  126. artifactConverter.convert( artifact, destinationRepository );
  127. }
  128. catch ( LayoutException e )
  129. {
  130. log.warn( "Unable to convert artifact: {} : {}",path , e.getMessage(), e );
  131. }
  132. catch ( ArtifactConversionException e )
  133. {
  134. log.warn( "Unable to convert artifact: {} : {}",path , e.getMessage(), e );
  135. }
  136. }
  137. @Override
  138. public void processFile( String path, boolean executeOnEntireRepo )
  139. throws Exception
  140. {
  141. processFile( path );
  142. }
  143. @Override
  144. public String getDescription()
  145. {
  146. return "Legacy Artifact to Default Artifact Converter";
  147. }
  148. @Override
  149. public String getId()
  150. {
  151. return "artifact-legacy-to-default-converter";
  152. }
  153. public void setExcludes( List<String> excludes )
  154. {
  155. this.excludes = excludes;
  156. }
  157. public void setIncludes( List<String> includes )
  158. {
  159. this.includes = includes;
  160. }
  161. public ArtifactRepository getDestinationRepository()
  162. {
  163. return destinationRepository;
  164. }
  165. public void setDestinationRepository( ArtifactRepository destinationRepository )
  166. {
  167. this.destinationRepository = destinationRepository;
  168. }
  169. }