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<>();
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<>();
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 exceptions = initList( exceptions );
236
237 exceptions.add( e );
238
239 return this;
240 }
241
242 public List<ArtifactResolutionException> getErrorArtifactExceptions()
243 {
244 if ( errorArtifactExceptions == null )
245 {
246 return Collections.emptyList();
247 }
248
249 return errorArtifactExceptions;
250 }
251
252
253
254
255
256 public boolean hasCircularDependencyExceptions()
257 {
258 return circularDependencyExceptions != null;
259 }
260
261 public MetadataResolutionResult addCircularDependencyException( CyclicDependencyException e )
262 {
263 circularDependencyExceptions = initList( circularDependencyExceptions );
264
265 circularDependencyExceptions.add( e );
266
267 exceptions = initList( exceptions );
268
269 exceptions.add( e );
270
271 return this;
272 }
273
274 public CyclicDependencyException getCircularDependencyException( int i )
275 {
276 return circularDependencyExceptions.get( i );
277 }
278
279 public List<CyclicDependencyException> getCircularDependencyExceptions()
280 {
281 if ( circularDependencyExceptions == null )
282 {
283 return Collections.emptyList();
284 }
285
286 return circularDependencyExceptions;
287 }
288
289
290
291
292
293 public List<ArtifactRepository> getRepositories()
294 {
295 if ( repositories == null )
296 {
297 return Collections.emptyList();
298 }
299
300 return repositories;
301 }
302
303 public MetadataResolutionResult setRepositories( final List<ArtifactRepository> repositories )
304 {
305 this.repositories = repositories;
306
307 return this;
308 }
309
310
311
312
313
314 private <T> List<T> initList( final List<T> l )
315 {
316 if ( l == null )
317 {
318 return new ArrayList<>();
319 }
320 return l;
321 }
322
323 public String toString()
324 {
325 if ( artifacts == null )
326 return "";
327
328 StringBuilder sb = new StringBuilder( 256 );
329 int i = 1;
330 sb.append( "---------\n" );
331 sb.append( artifacts.size() ).append( '\n' );
332 for ( Artifact a : artifacts )
333 {
334 sb.append( i ).append( ' ' ).append( a ).append( '\n' );
335 i++;
336 }
337 sb.append( "---------\n" );
338 return sb.toString();
339 }
340
341 public MetadataGraph getResolvedTree()
342 {
343 return resolvedTree;
344 }
345
346 public void setResolvedTree( MetadataGraph resolvedTree )
347 {
348 this.resolvedTree = resolvedTree;
349 }
350
351 }