1 package org.apache.maven.repository;
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.Collections;
24 import java.util.LinkedHashSet;
25 import java.util.List;
26 import java.util.Set;
27
28 import org.apache.maven.artifact.Artifact;
29 import org.apache.maven.artifact.repository.ArtifactRepository;
30 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
31 import org.apache.maven.artifact.resolver.CyclicDependencyException;
32 import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
33
34
35
36
37
38
39
40 public class MetadataResolutionResult
41 {
42 private Artifact originatingArtifact;
43
44 private List<Artifact> missingArtifacts;
45
46
47
48 private List<Exception> exceptions;
49
50 private List<Exception> versionRangeViolations;
51
52 private List<ArtifactResolutionException> metadataResolutionExceptions;
53
54 private List<CyclicDependencyException> circularDependencyExceptions;
55
56 private List<ArtifactResolutionException> errorArtifactExceptions;
57
58
59
60 private List<ArtifactRepository> repositories;
61
62 private Set<Artifact> requestedArtifacts;
63
64 private Set<Artifact> artifacts;
65
66 private MetadataGraph dirtyTree;
67
68 private MetadataGraph resolvedTree;
69
70 private MetadataGraph resolvedGraph;
71
72 public Artifact getOriginatingArtifact()
73 {
74 return originatingArtifact;
75 }
76
77 public MetadataResolutionResult ListOriginatingArtifact( final Artifact originatingArtifact )
78 {
79 this.originatingArtifact = originatingArtifact;
80
81 return this;
82 }
83
84 public void addArtifact( Artifact artifact )
85 {
86 if ( artifacts == null )
87 {
88 artifacts = new LinkedHashSet<Artifact>();
89 }
90
91 artifacts.add( artifact );
92 }
93
94 public Set<Artifact> getArtifacts()
95 {
96 return artifacts;
97 }
98
99 public void addRequestedArtifact( Artifact artifact )
100 {
101 if ( requestedArtifacts == null )
102 {
103 requestedArtifacts = new LinkedHashSet<Artifact>();
104 }
105
106 requestedArtifacts.add( artifact );
107 }
108
109 public Set<Artifact> getRequestedArtifacts()
110 {
111 return requestedArtifacts;
112 }
113
114 public boolean hasMissingArtifacts()
115 {
116 return missingArtifacts != null && !missingArtifacts.isEmpty();
117 }
118
119 public List<Artifact> getMissingArtifacts()
120 {
121 return missingArtifacts == null ? Collections.<Artifact> emptyList() : missingArtifacts;
122 }
123
124 public MetadataResolutionResult addMissingArtifact( Artifact artifact )
125 {
126 missingArtifacts = initList( missingArtifacts );
127
128 missingArtifacts.add( artifact );
129
130 return this;
131 }
132
133 public MetadataResolutionResult setUnresolvedArtifacts( final List<Artifact> unresolvedArtifacts )
134 {
135 this.missingArtifacts = unresolvedArtifacts;
136
137 return this;
138 }
139
140
141
142
143
144 public boolean hasExceptions()
145 {
146 return exceptions != null && !exceptions.isEmpty();
147 }
148
149 public List<Exception> getExceptions()
150 {
151 return exceptions == null ? Collections.<Exception> emptyList() : exceptions;
152 }
153
154
155
156
157
158 public boolean hasVersionRangeViolations()
159 {
160 return versionRangeViolations != null;
161 }
162
163
164
165
166
167
168 public MetadataResolutionResult addVersionRangeViolation( Exception e )
169 {
170 versionRangeViolations = initList( versionRangeViolations );
171
172 versionRangeViolations.add( e );
173
174 exceptions = initList( exceptions );
175
176 exceptions.add( e );
177
178 return this;
179 }
180
181 public OverConstrainedVersionException getVersionRangeViolation( int i )
182 {
183 return (OverConstrainedVersionException) versionRangeViolations.get( i );
184 }
185
186 public List<Exception> getVersionRangeViolations()
187 {
188 return versionRangeViolations == null ? Collections.<Exception> emptyList() : versionRangeViolations;
189 }
190
191
192
193
194
195 public boolean hasMetadataResolutionExceptions()
196 {
197 return metadataResolutionExceptions != null;
198 }
199
200 public MetadataResolutionResult addMetadataResolutionException( ArtifactResolutionException e )
201 {
202 metadataResolutionExceptions = initList( metadataResolutionExceptions );
203
204 metadataResolutionExceptions.add( e );
205
206 exceptions = initList( exceptions );
207
208 exceptions.add( e );
209
210 return this;
211 }
212
213 public ArtifactResolutionException getMetadataResolutionException( int i )
214 {
215 return metadataResolutionExceptions.get( i );
216 }
217
218 public List<ArtifactResolutionException> getMetadataResolutionExceptions()
219 {
220 return metadataResolutionExceptions == null ? Collections.<ArtifactResolutionException> emptyList()
221 : metadataResolutionExceptions;
222 }
223
224
225
226
227
228 public boolean hasErrorArtifactExceptions()
229 {
230 return errorArtifactExceptions != null;
231 }
232
233 public MetadataResolutionResult addError( Exception e )
234 {
235 if ( exceptions == null )
236 {
237 initList( exceptions );
238 }
239
240 exceptions.add( e );
241
242 return this;
243 }
244
245 public List<ArtifactResolutionException> getErrorArtifactExceptions()
246 {
247 if ( errorArtifactExceptions == null )
248 {
249 return Collections.emptyList();
250 }
251
252 return errorArtifactExceptions;
253 }
254
255
256
257
258
259 public boolean hasCircularDependencyExceptions()
260 {
261 return circularDependencyExceptions != null;
262 }
263
264 public MetadataResolutionResult addCircularDependencyException( CyclicDependencyException e )
265 {
266 circularDependencyExceptions = initList( circularDependencyExceptions );
267
268 circularDependencyExceptions.add( e );
269
270 exceptions = initList( exceptions );
271
272 exceptions.add( e );
273
274 return this;
275 }
276
277 public CyclicDependencyException getCircularDependencyException( int i )
278 {
279 return circularDependencyExceptions.get( i );
280 }
281
282 public List<CyclicDependencyException> getCircularDependencyExceptions()
283 {
284 if ( circularDependencyExceptions == null )
285 {
286 return Collections.emptyList();
287 }
288
289 return circularDependencyExceptions;
290 }
291
292
293
294
295
296 public List<ArtifactRepository> getRepositories()
297 {
298 if ( repositories == null )
299 {
300 return Collections.emptyList();
301 }
302
303 return repositories;
304 }
305
306 public MetadataResolutionResult setRepositories( final List<ArtifactRepository> repositories )
307 {
308 this.repositories = repositories;
309
310 return this;
311 }
312
313
314
315
316
317 private <T> List<T> initList( final List<T> l )
318 {
319 if ( l == null )
320 {
321 return new ArrayList<T>();
322 }
323 return l;
324 }
325
326 public String toString()
327 {
328 StringBuilder sb = new StringBuilder();
329
330 if ( artifacts != null )
331 {
332 int i = 1;
333 sb.append( "---------" ).append( "\n" );
334 sb.append( artifacts.size() ).append( "\n" );
335 for ( Artifact a : artifacts )
336 {
337 sb.append( i ).append( " " ).append( a ).append( "\n" );
338 i++;
339 }
340 sb.append( "---------" ).append( "\n" );
341 }
342
343 return sb.toString();
344 }
345
346 public MetadataGraph getResolvedTree()
347 {
348 return resolvedTree;
349 }
350
351 public void setResolvedTree( MetadataGraph resolvedTree )
352 {
353 this.resolvedTree = resolvedTree;
354 }
355
356 }