]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.repo/src/org/eclipse/aether/resolution/ArtifactDescriptorResult.java
Merge branch 'master' of https://github.com/argeo/argeo-slc.git
[gpl/argeo-slc.git] / org.argeo.slc.repo / src / org / eclipse / aether / resolution / ArtifactDescriptorResult.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2012 Sonatype, Inc.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Sonatype, Inc. - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.aether.resolution;
12
13 import java.util.ArrayList;
14 import java.util.Collection;
15 import java.util.Collections;
16 import java.util.List;
17 import java.util.Map;
18
19 import org.eclipse.aether.RepositorySystem;
20 import org.eclipse.aether.RepositorySystemSession;
21 import org.eclipse.aether.artifact.Artifact;
22 import org.eclipse.aether.graph.Dependency;
23 import org.eclipse.aether.repository.ArtifactRepository;
24 import org.eclipse.aether.repository.RemoteRepository;
25
26 /**
27 * The result from reading an artifact descriptor.
28 *
29 * @see RepositorySystem#readArtifactDescriptor(RepositorySystemSession, ArtifactDescriptorRequest)
30 */
31 public final class ArtifactDescriptorResult
32 {
33
34 private final ArtifactDescriptorRequest request;
35
36 private List<Exception> exceptions;
37
38 private List<Artifact> relocations;
39
40 private Collection<Artifact> aliases;
41
42 private Artifact artifact;
43
44 private ArtifactRepository repository;
45
46 private List<Dependency> dependencies;
47
48 private List<Dependency> managedDependencies;
49
50 private List<RemoteRepository> repositories;
51
52 private Map<String, Object> properties;
53
54 /**
55 * Creates a new result for the specified request.
56 *
57 * @param request The descriptor request, must not be {@code null}.
58 */
59 public ArtifactDescriptorResult( ArtifactDescriptorRequest request )
60 {
61 if ( request == null )
62 {
63 throw new IllegalArgumentException( "artifact descriptor request has not been specified" );
64 }
65 this.request = request;
66 artifact = request.getArtifact();
67 exceptions = Collections.emptyList();
68 relocations = Collections.emptyList();
69 aliases = Collections.emptyList();
70 dependencies = managedDependencies = Collections.emptyList();
71 repositories = Collections.emptyList();
72 properties = Collections.emptyMap();
73 }
74
75 /**
76 * Gets the descriptor request that was made.
77 *
78 * @return The descriptor request, never {@code null}.
79 */
80 public ArtifactDescriptorRequest getRequest()
81 {
82 return request;
83 }
84
85 /**
86 * Gets the exceptions that occurred while reading the artifact descriptor.
87 *
88 * @return The exceptions that occurred, never {@code null}.
89 */
90 public List<Exception> getExceptions()
91 {
92 return exceptions;
93 }
94
95 /**
96 * Sets the exceptions that occurred while reading the artifact descriptor.
97 *
98 * @param exceptions The exceptions that occurred, may be {@code null}.
99 * @return This result for chaining, never {@code null}.
100 */
101 public ArtifactDescriptorResult setExceptions( List<Exception> exceptions )
102 {
103 if ( exceptions == null )
104 {
105 this.exceptions = Collections.emptyList();
106 }
107 else
108 {
109 this.exceptions = exceptions;
110 }
111 return this;
112 }
113
114 /**
115 * Records the specified exception while reading the artifact descriptor.
116 *
117 * @param exception The exception to record, may be {@code null}.
118 * @return This result for chaining, never {@code null}.
119 */
120 public ArtifactDescriptorResult addException( Exception exception )
121 {
122 if ( exception != null )
123 {
124 if ( exceptions.isEmpty() )
125 {
126 exceptions = new ArrayList<Exception>();
127 }
128 exceptions.add( exception );
129 }
130 return this;
131 }
132
133 /**
134 * Gets the relocations that were processed to read the artifact descriptor. The returned list denotes the hops that
135 * lead to the final artifact coordinates as given by {@link #getArtifact()}.
136 *
137 * @return The relocations that were processed, never {@code null}.
138 */
139 public List<Artifact> getRelocations()
140 {
141 return relocations;
142 }
143
144 /**
145 * Sets the relocations that were processed to read the artifact descriptor.
146 *
147 * @param relocations The relocations that were processed, may be {@code null}.
148 * @return This result for chaining, never {@code null}.
149 */
150 public ArtifactDescriptorResult setRelocations( List<Artifact> relocations )
151 {
152 if ( relocations == null )
153 {
154 this.relocations = Collections.emptyList();
155 }
156 else
157 {
158 this.relocations = relocations;
159 }
160 return this;
161 }
162
163 /**
164 * Records the specified relocation hop while locating the artifact descriptor.
165 *
166 * @param artifact The artifact that got relocated, may be {@code null}.
167 * @return This result for chaining, never {@code null}.
168 */
169 public ArtifactDescriptorResult addRelocation( Artifact artifact )
170 {
171 if ( artifact != null )
172 {
173 if ( relocations.isEmpty() )
174 {
175 relocations = new ArrayList<Artifact>();
176 }
177 relocations.add( artifact );
178 }
179 return this;
180 }
181
182 /**
183 * Gets the known aliases for this artifact. An alias denotes a different artifact with (almost) the same contents
184 * and can be used to mark a patched rebuild of some other artifact as such, thereby allowing conflict resolution to
185 * consider the patched and the original artifact as a conflict.
186 *
187 * @return The aliases of the artifact, never {@code null}.
188 */
189 public Collection<Artifact> getAliases()
190 {
191 return aliases;
192 }
193
194 /**
195 * Sets the aliases of the artifact.
196 *
197 * @param aliases The aliases of the artifact, may be {@code null}.
198 * @return This result for chaining, never {@code null}.
199 */
200 public ArtifactDescriptorResult setAliases( Collection<Artifact> aliases )
201 {
202 if ( aliases == null )
203 {
204 this.aliases = Collections.emptyList();
205 }
206 else
207 {
208 this.aliases = aliases;
209 }
210 return this;
211 }
212
213 /**
214 * Records the specified alias.
215 *
216 * @param alias The alias for the artifact, may be {@code null}.
217 * @return This result for chaining, never {@code null}.
218 */
219 public ArtifactDescriptorResult addAlias( Artifact alias )
220 {
221 if ( alias != null )
222 {
223 if ( aliases.isEmpty() )
224 {
225 aliases = new ArrayList<Artifact>();
226 }
227 aliases.add( alias );
228 }
229 return this;
230 }
231
232 /**
233 * Gets the artifact whose descriptor was read. This can be a different artifact than originally requested in case
234 * relocations were encountered.
235 *
236 * @return The artifact after following any relocations, never {@code null}.
237 */
238 public Artifact getArtifact()
239 {
240 return artifact;
241 }
242
243 /**
244 * Sets the artifact whose descriptor was read.
245 *
246 * @param artifact The artifact whose descriptor was read, may be {@code null}.
247 * @return This result for chaining, never {@code null}.
248 */
249 public ArtifactDescriptorResult setArtifact( Artifact artifact )
250 {
251 this.artifact = artifact;
252 return this;
253 }
254
255 /**
256 * Gets the repository from which the descriptor was eventually resolved.
257 *
258 * @return The repository from which the descriptor was resolved or {@code null} if unknown.
259 */
260 public ArtifactRepository getRepository()
261 {
262 return repository;
263 }
264
265 /**
266 * Sets the repository from which the descriptor was resolved.
267 *
268 * @param repository The repository from which the descriptor was resolved, may be {@code null}.
269 * @return This result for chaining, never {@code null}.
270 */
271 public ArtifactDescriptorResult setRepository( ArtifactRepository repository )
272 {
273 this.repository = repository;
274 return this;
275 }
276
277 /**
278 * Gets the list of direct dependencies of the artifact.
279 *
280 * @return The list of direct dependencies, never {@code null}
281 */
282 public List<Dependency> getDependencies()
283 {
284 return dependencies;
285 }
286
287 /**
288 * Sets the list of direct dependencies of the artifact.
289 *
290 * @param dependencies The list of direct dependencies, may be {@code null}
291 * @return This result for chaining, never {@code null}.
292 */
293 public ArtifactDescriptorResult setDependencies( List<Dependency> dependencies )
294 {
295 if ( dependencies == null )
296 {
297 this.dependencies = Collections.emptyList();
298 }
299 else
300 {
301 this.dependencies = dependencies;
302 }
303 return this;
304 }
305
306 /**
307 * Adds the specified direct dependency.
308 *
309 * @param dependency The direct dependency to add, may be {@code null}.
310 * @return This result for chaining, never {@code null}.
311 */
312 public ArtifactDescriptorResult addDependency( Dependency dependency )
313 {
314 if ( dependency != null )
315 {
316 if ( dependencies.isEmpty() )
317 {
318 dependencies = new ArrayList<Dependency>();
319 }
320 dependencies.add( dependency );
321 }
322 return this;
323 }
324
325 /**
326 * Gets the dependency management information.
327 *
328 * @return The dependency management information.
329 */
330 public List<Dependency> getManagedDependencies()
331 {
332 return managedDependencies;
333 }
334
335 /**
336 * Sets the dependency management information.
337 *
338 * @param dependencies The dependency management information, may be {@code null}.
339 * @return This result for chaining, never {@code null}.
340 */
341 public ArtifactDescriptorResult setManagedDependencies( List<Dependency> dependencies )
342 {
343 if ( dependencies == null )
344 {
345 this.managedDependencies = Collections.emptyList();
346 }
347 else
348 {
349 this.managedDependencies = dependencies;
350 }
351 return this;
352 }
353
354 /**
355 * Adds the specified managed dependency.
356 *
357 * @param dependency The managed dependency to add, may be {@code null}.
358 * @return This result for chaining, never {@code null}.
359 */
360 public ArtifactDescriptorResult addManagedDependency( Dependency dependency )
361 {
362 if ( dependency != null )
363 {
364 if ( managedDependencies.isEmpty() )
365 {
366 managedDependencies = new ArrayList<Dependency>();
367 }
368 managedDependencies.add( dependency );
369 }
370 return this;
371 }
372
373 /**
374 * Gets the remote repositories listed in the artifact descriptor.
375 *
376 * @return The remote repositories listed in the artifact descriptor, never {@code null}.
377 */
378 public List<RemoteRepository> getRepositories()
379 {
380 return repositories;
381 }
382
383 /**
384 * Sets the remote repositories listed in the artifact descriptor.
385 *
386 * @param repositories The remote repositories listed in the artifact descriptor, may be {@code null}.
387 * @return This result for chaining, never {@code null}.
388 */
389 public ArtifactDescriptorResult setRepositories( List<RemoteRepository> repositories )
390 {
391 if ( repositories == null )
392 {
393 this.repositories = Collections.emptyList();
394 }
395 else
396 {
397 this.repositories = repositories;
398 }
399 return this;
400 }
401
402 /**
403 * Adds the specified remote repository.
404 *
405 * @param repository The remote repository to add, may be {@code null}.
406 * @return This result for chaining, never {@code null}.
407 */
408 public ArtifactDescriptorResult addRepository( RemoteRepository repository )
409 {
410 if ( repository != null )
411 {
412 if ( repositories.isEmpty() )
413 {
414 repositories = new ArrayList<RemoteRepository>();
415 }
416 repositories.add( repository );
417 }
418 return this;
419 }
420
421 /**
422 * Gets any additional information about the artifact in form of key-value pairs. <em>Note:</em> Regardless of their
423 * actual type, all property values must be treated as being read-only.
424 *
425 * @return The additional information about the artifact, never {@code null}.
426 */
427 public Map<String, Object> getProperties()
428 {
429 return properties;
430 }
431
432 /**
433 * Sets any additional information about the artifact in form of key-value pairs.
434 *
435 * @param properties The additional information about the artifact, may be {@code null}.
436 * @return This result for chaining, never {@code null}.
437 */
438 public ArtifactDescriptorResult setProperties( Map<String, Object> properties )
439 {
440 if ( properties == null )
441 {
442 this.properties = Collections.emptyMap();
443 }
444 else
445 {
446 this.properties = properties;
447 }
448 return this;
449 }
450
451 @Override
452 public String toString()
453 {
454 return getArtifact() + " -> " + getDependencies();
455 }
456
457 }