This project has retired. For details please refer to its
Attic page.
LegacyConverterArtifactConsumer xref
1 package org.apache.archiva.converter.legacy;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.archiva.common.filelock.FileLockManager;
23 import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
24 import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
25 import org.apache.archiva.configuration.FileTypes;
26 import org.apache.archiva.consumers.AbstractMonitoredConsumer;
27 import org.apache.archiva.consumers.ConsumerException;
28 import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
29 import org.apache.archiva.converter.artifact.ArtifactConversionException;
30 import org.apache.archiva.converter.artifact.ArtifactConverter;
31 import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider;
32 import org.apache.archiva.model.ArtifactReference;
33 import org.apache.archiva.repository.LayoutException;
34 import org.apache.archiva.repository.ManagedRepository;
35 import org.apache.archiva.repository.ManagedRepositoryContent;
36 import org.apache.archiva.repository.content.maven2.ManagedDefaultRepositoryContent;
37 import org.apache.maven.artifact.Artifact;
38 import org.apache.maven.artifact.factory.ArtifactFactory;
39 import org.apache.maven.artifact.repository.ArtifactRepository;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
42 import org.springframework.context.annotation.Scope;
43 import org.springframework.stereotype.Service;
44
45 import javax.inject.Inject;
46 import javax.inject.Named;
47 import java.util.ArrayList;
48 import java.util.Date;
49 import java.util.List;
50
51
52
53
54
55
56
57 @Service( "knownRepositoryContentConsumer#artifact-legacy-to-default-converter" )
58 @Scope( "prototype" )
59 public class LegacyConverterArtifactConsumer
60 extends AbstractMonitoredConsumer
61 implements KnownRepositoryContentConsumer
62 {
63 private Logger log = LoggerFactory.getLogger( LegacyConverterArtifactConsumer.class );
64
65 @Inject
66 @Named("artifactConverter#legacy-to-default")
67 private ArtifactConverter artifactConverter;
68
69 @Inject
70 private List<? extends ArtifactMappingProvider> artifactMappingProviders;
71
72 @Inject
73 private FileTypes fileTypes;
74
75 @Inject
76 private FileLockManager fileLockManager;
77
78 private ArtifactFactory artifactFactory;
79
80 private ManagedRepositoryContent managedRepository;
81
82 private ArtifactRepository destinationRepository;
83
84 private List<String> includes;
85
86 private List<String> excludes;
87
88 @Inject
89 public LegacyConverterArtifactConsumer( PlexusSisuBridge plexusSisuBridge )
90 throws PlexusSisuBridgeException
91 {
92 includes = new ArrayList<>( 3 );
93 includes.add( "**/*.jar" );
94 includes.add( "**/*.ear" );
95 includes.add( "**/*.war" );
96 artifactFactory = plexusSisuBridge.lookup( ArtifactFactory.class );
97 }
98
99 @Override
100 public void beginScan( ManagedRepository repository, Date whenGathered )
101 throws ConsumerException
102 {
103 this.managedRepository = new ManagedDefaultRepositoryContent(repository, artifactMappingProviders, fileTypes, fileLockManager);
104 }
105
106 @Override
107 public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo )
108 throws ConsumerException
109 {
110 beginScan( repository, whenGathered );
111 }
112
113 @Override
114 public void completeScan()
115 {
116
117 }
118
119 @Override
120 public void completeScan( boolean executeOnEntireRepo )
121 {
122 completeScan();
123 }
124
125 @Override
126 public List<String> getExcludes()
127 {
128 return excludes;
129 }
130
131 @Override
132 public List<String> getIncludes()
133 {
134 return includes;
135 }
136
137 @Override
138 public void processFile( String path )
139 throws ConsumerException
140 {
141 try
142 {
143 ArtifactReference reference = managedRepository.toArtifactReference( path );
144 Artifact artifact = artifactFactory.createArtifact( reference.getGroupId(), reference.getArtifactId(),
145 reference.getVersion(), reference.getClassifier(),
146 reference.getType() );
147 artifactConverter.convert( artifact, destinationRepository );
148 }
149 catch ( LayoutException e )
150 {
151 log.warn( "Unable to convert artifact: {} : {}",path , e.getMessage(), e );
152 }
153 catch ( ArtifactConversionException e )
154 {
155 log.warn( "Unable to convert artifact: {} : {}",path , e.getMessage(), e );
156 }
157 }
158
159 @Override
160 public void processFile( String path, boolean executeOnEntireRepo )
161 throws Exception
162 {
163 processFile( path );
164 }
165
166 @Override
167 public String getDescription()
168 {
169 return "Legacy Artifact to Default Artifact Converter";
170 }
171
172 @Override
173 public String getId()
174 {
175 return "artifact-legacy-to-default-converter";
176 }
177
178 public void setExcludes( List<String> excludes )
179 {
180 this.excludes = excludes;
181 }
182
183 public void setIncludes( List<String> includes )
184 {
185 this.includes = includes;
186 }
187
188 public ArtifactRepository getDestinationRepository()
189 {
190 return destinationRepository;
191 }
192
193 public void setDestinationRepository( ArtifactRepository destinationRepository )
194 {
195 this.destinationRepository = destinationRepository;
196 }
197 }