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
.Collections
;
15 import java
.util
.List
;
17 import org
.eclipse
.aether
.RepositorySystem
;
18 import org
.eclipse
.aether
.RepositorySystemSession
;
19 import org
.eclipse
.aether
.repository
.ArtifactRepository
;
22 * The result of a version resolution request.
24 * @see RepositorySystem#resolveVersion(RepositorySystemSession, VersionRequest)
26 public final class VersionResult
29 private final VersionRequest request
;
31 private List
<Exception
> exceptions
;
33 private String version
;
35 private ArtifactRepository repository
;
38 * Creates a new result for the specified request.
40 * @param request The resolution request, must not be {@code null}.
42 public VersionResult( VersionRequest request
)
44 if ( request
== null )
46 throw new IllegalArgumentException( "version request has not been specified" );
48 this.request
= request
;
49 exceptions
= Collections
.emptyList();
53 * Gets the resolution request that was made.
55 * @return The resolution request, never {@code null}.
57 public VersionRequest
getRequest()
63 * Gets the exceptions that occurred while resolving the version.
65 * @return The exceptions that occurred, never {@code null}.
67 public List
<Exception
> getExceptions()
73 * Records the specified exception while resolving the version.
75 * @param exception The exception to record, may be {@code null}.
76 * @return This result for chaining, never {@code null}.
78 public VersionResult
addException( Exception exception
)
80 if ( exception
!= null )
82 if ( exceptions
.isEmpty() )
84 exceptions
= new ArrayList
<Exception
>();
86 exceptions
.add( exception
);
92 * Gets the resolved version.
94 * @return The resolved version or {@code null} if the resolution failed.
96 public String
getVersion()
102 * Sets the resolved version.
104 * @param version The resolved version, may be {@code null}.
105 * @return This result for chaining, never {@code null}.
107 public VersionResult
setVersion( String version
)
109 this.version
= version
;
114 * Gets the repository from which the version was eventually resolved.
116 * @return The repository from which the version was resolved or {@code null} if unknown.
118 public ArtifactRepository
getRepository()
124 * Sets the repository from which the version was resolved.
126 * @param repository The repository from which the version was resolved, may be {@code null}.
127 * @return This result for chaining, never {@code null}.
129 public VersionResult
setRepository( ArtifactRepository repository
)
131 this.repository
= repository
;
136 public String
toString()
138 return getVersion() + " @ " + getRepository();