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