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
9 * Sonatype, Inc. - initial API and implementation
10 *******************************************************************************/
11 package org
.eclipse
.aether
.resolution
;
13 import java
.util
.ArrayList
;
14 import java
.util
.Collection
;
15 import java
.util
.Collections
;
16 import java
.util
.List
;
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
;
27 * The result from reading an artifact descriptor.
29 * @see RepositorySystem#readArtifactDescriptor(RepositorySystemSession, ArtifactDescriptorRequest)
31 public final class ArtifactDescriptorResult
34 private final ArtifactDescriptorRequest request
;
36 private List
<Exception
> exceptions
;
38 private List
<Artifact
> relocations
;
40 private Collection
<Artifact
> aliases
;
42 private Artifact artifact
;
44 private ArtifactRepository repository
;
46 private List
<Dependency
> dependencies
;
48 private List
<Dependency
> managedDependencies
;
50 private List
<RemoteRepository
> repositories
;
52 private Map
<String
, Object
> properties
;
55 * Creates a new result for the specified request.
57 * @param request The descriptor request, must not be {@code null}.
59 public ArtifactDescriptorResult( ArtifactDescriptorRequest request
)
61 if ( request
== null )
63 throw new IllegalArgumentException( "artifact descriptor request has not been specified" );
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();
76 * Gets the descriptor request that was made.
78 * @return The descriptor request, never {@code null}.
80 public ArtifactDescriptorRequest
getRequest()
86 * Gets the exceptions that occurred while reading the artifact descriptor.
88 * @return The exceptions that occurred, never {@code null}.
90 public List
<Exception
> getExceptions()
96 * Sets the exceptions that occurred while reading the artifact descriptor.
98 * @param exceptions The exceptions that occurred, may be {@code null}.
99 * @return This result for chaining, never {@code null}.
101 public ArtifactDescriptorResult
setExceptions( List
<Exception
> exceptions
)
103 if ( exceptions
== null )
105 this.exceptions
= Collections
.emptyList();
109 this.exceptions
= exceptions
;
115 * Records the specified exception while reading the artifact descriptor.
117 * @param exception The exception to record, may be {@code null}.
118 * @return This result for chaining, never {@code null}.
120 public ArtifactDescriptorResult
addException( Exception exception
)
122 if ( exception
!= null )
124 if ( exceptions
.isEmpty() )
126 exceptions
= new ArrayList
<Exception
>();
128 exceptions
.add( exception
);
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()}.
137 * @return The relocations that were processed, never {@code null}.
139 public List
<Artifact
> getRelocations()
145 * Sets the relocations that were processed to read the artifact descriptor.
147 * @param relocations The relocations that were processed, may be {@code null}.
148 * @return This result for chaining, never {@code null}.
150 public ArtifactDescriptorResult
setRelocations( List
<Artifact
> relocations
)
152 if ( relocations
== null )
154 this.relocations
= Collections
.emptyList();
158 this.relocations
= relocations
;
164 * Records the specified relocation hop while locating the artifact descriptor.
166 * @param artifact The artifact that got relocated, may be {@code null}.
167 * @return This result for chaining, never {@code null}.
169 public ArtifactDescriptorResult
addRelocation( Artifact artifact
)
171 if ( artifact
!= null )
173 if ( relocations
.isEmpty() )
175 relocations
= new ArrayList
<Artifact
>();
177 relocations
.add( artifact
);
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.
187 * @return The aliases of the artifact, never {@code null}.
189 public Collection
<Artifact
> getAliases()
195 * Sets the aliases of the artifact.
197 * @param aliases The aliases of the artifact, may be {@code null}.
198 * @return This result for chaining, never {@code null}.
200 public ArtifactDescriptorResult
setAliases( Collection
<Artifact
> aliases
)
202 if ( aliases
== null )
204 this.aliases
= Collections
.emptyList();
208 this.aliases
= aliases
;
214 * Records the specified alias.
216 * @param alias The alias for the artifact, may be {@code null}.
217 * @return This result for chaining, never {@code null}.
219 public ArtifactDescriptorResult
addAlias( Artifact alias
)
223 if ( aliases
.isEmpty() )
225 aliases
= new ArrayList
<Artifact
>();
227 aliases
.add( alias
);
233 * Gets the artifact whose descriptor was read. This can be a different artifact than originally requested in case
234 * relocations were encountered.
236 * @return The artifact after following any relocations, never {@code null}.
238 public Artifact
getArtifact()
244 * Sets the artifact whose descriptor was read.
246 * @param artifact The artifact whose descriptor was read, may be {@code null}.
247 * @return This result for chaining, never {@code null}.
249 public ArtifactDescriptorResult
setArtifact( Artifact artifact
)
251 this.artifact
= artifact
;
256 * Gets the repository from which the descriptor was eventually resolved.
258 * @return The repository from which the descriptor was resolved or {@code null} if unknown.
260 public ArtifactRepository
getRepository()
266 * Sets the repository from which the descriptor was resolved.
268 * @param repository The repository from which the descriptor was resolved, may be {@code null}.
269 * @return This result for chaining, never {@code null}.
271 public ArtifactDescriptorResult
setRepository( ArtifactRepository repository
)
273 this.repository
= repository
;
278 * Gets the list of direct dependencies of the artifact.
280 * @return The list of direct dependencies, never {@code null}
282 public List
<Dependency
> getDependencies()
288 * Sets the list of direct dependencies of the artifact.
290 * @param dependencies The list of direct dependencies, may be {@code null}
291 * @return This result for chaining, never {@code null}.
293 public ArtifactDescriptorResult
setDependencies( List
<Dependency
> dependencies
)
295 if ( dependencies
== null )
297 this.dependencies
= Collections
.emptyList();
301 this.dependencies
= dependencies
;
307 * Adds the specified direct dependency.
309 * @param dependency The direct dependency to add, may be {@code null}.
310 * @return This result for chaining, never {@code null}.
312 public ArtifactDescriptorResult
addDependency( Dependency dependency
)
314 if ( dependency
!= null )
316 if ( dependencies
.isEmpty() )
318 dependencies
= new ArrayList
<Dependency
>();
320 dependencies
.add( dependency
);
326 * Gets the dependency management information.
328 * @return The dependency management information.
330 public List
<Dependency
> getManagedDependencies()
332 return managedDependencies
;
336 * Sets the dependency management information.
338 * @param dependencies The dependency management information, may be {@code null}.
339 * @return This result for chaining, never {@code null}.
341 public ArtifactDescriptorResult
setManagedDependencies( List
<Dependency
> dependencies
)
343 if ( dependencies
== null )
345 this.managedDependencies
= Collections
.emptyList();
349 this.managedDependencies
= dependencies
;
355 * Adds the specified managed dependency.
357 * @param dependency The managed dependency to add, may be {@code null}.
358 * @return This result for chaining, never {@code null}.
360 public ArtifactDescriptorResult
addManagedDependency( Dependency dependency
)
362 if ( dependency
!= null )
364 if ( managedDependencies
.isEmpty() )
366 managedDependencies
= new ArrayList
<Dependency
>();
368 managedDependencies
.add( dependency
);
374 * Gets the remote repositories listed in the artifact descriptor.
376 * @return The remote repositories listed in the artifact descriptor, never {@code null}.
378 public List
<RemoteRepository
> getRepositories()
384 * Sets the remote repositories listed in the artifact descriptor.
386 * @param repositories The remote repositories listed in the artifact descriptor, may be {@code null}.
387 * @return This result for chaining, never {@code null}.
389 public ArtifactDescriptorResult
setRepositories( List
<RemoteRepository
> repositories
)
391 if ( repositories
== null )
393 this.repositories
= Collections
.emptyList();
397 this.repositories
= repositories
;
403 * Adds the specified remote repository.
405 * @param repository The remote repository to add, may be {@code null}.
406 * @return This result for chaining, never {@code null}.
408 public ArtifactDescriptorResult
addRepository( RemoteRepository repository
)
410 if ( repository
!= null )
412 if ( repositories
.isEmpty() )
414 repositories
= new ArrayList
<RemoteRepository
>();
416 repositories
.add( repository
);
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.
425 * @return The additional information about the artifact, never {@code null}.
427 public Map
<String
, Object
> getProperties()
433 * Sets any additional information about the artifact in form of key-value pairs.
435 * @param properties The additional information about the artifact, may be {@code null}.
436 * @return This result for chaining, never {@code null}.
438 public ArtifactDescriptorResult
setProperties( Map
<String
, Object
> properties
)
440 if ( properties
== null )
442 this.properties
= Collections
.emptyMap();
446 this.properties
= properties
;
452 public String
toString()
454 return getArtifact() + " -> " + getDependencies();