1 package org.eclipse.aether.resolution;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.List;
25
26 import org.eclipse.aether.RepositorySystem;
27 import org.eclipse.aether.RepositorySystemSession;
28 import org.eclipse.aether.repository.ArtifactRepository;
29
30 /**
31 * The result of a version resolution request.
32 *
33 * @see RepositorySystem#resolveVersion(RepositorySystemSession, VersionRequest)
34 */
35 public final class VersionResult
36 {
37
38 private final VersionRequest request;
39
40 private List<Exception> exceptions;
41
42 private String version;
43
44 private ArtifactRepository repository;
45
46 /**
47 * Creates a new result for the specified request.
48 *
49 * @param request The resolution request, must not be {@code null}.
50 */
51 public VersionResult( VersionRequest request )
52 {
53 if ( request == null )
54 {
55 throw new IllegalArgumentException( "version request has not been specified" );
56 }
57 this.request = request;
58 exceptions = Collections.emptyList();
59 }
60
61 /**
62 * Gets the resolution request that was made.
63 *
64 * @return The resolution request, never {@code null}.
65 */
66 public VersionRequest getRequest()
67 {
68 return request;
69 }
70
71 /**
72 * Gets the exceptions that occurred while resolving the version.
73 *
74 * @return The exceptions that occurred, never {@code null}.
75 */
76 public List<Exception> getExceptions()
77 {
78 return exceptions;
79 }
80
81 /**
82 * Records the specified exception while resolving the version.
83 *
84 * @param exception The exception to record, may be {@code null}.
85 * @return This result for chaining, never {@code null}.
86 */
87 public VersionResult addException( Exception exception )
88 {
89 if ( exception != null )
90 {
91 if ( exceptions.isEmpty() )
92 {
93 exceptions = new ArrayList<Exception>();
94 }
95 exceptions.add( exception );
96 }
97 return this;
98 }
99
100 /**
101 * Gets the resolved version.
102 *
103 * @return The resolved version or {@code null} if the resolution failed.
104 */
105 public String getVersion()
106 {
107 return version;
108 }
109
110 /**
111 * Sets the resolved version.
112 *
113 * @param version The resolved version, may be {@code null}.
114 * @return This result for chaining, never {@code null}.
115 */
116 public VersionResult setVersion( String version )
117 {
118 this.version = version;
119 return this;
120 }
121
122 /**
123 * Gets the repository from which the version was eventually resolved.
124 *
125 * @return The repository from which the version was resolved or {@code null} if unknown.
126 */
127 public ArtifactRepository getRepository()
128 {
129 return repository;
130 }
131
132 /**
133 * Sets the repository from which the version was resolved.
134 *
135 * @param repository The repository from which the version was resolved, may be {@code null}.
136 * @return This result for chaining, never {@code null}.
137 */
138 public VersionResult setRepository( ArtifactRepository repository )
139 {
140 this.repository = repository;
141 return this;
142 }
143
144 @Override
145 public String toString()
146 {
147 return getVersion() + " @ " + getRepository();
148 }
149
150 }