View Javadoc
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  import static java.util.Objects.requireNonNull;
26  
27  import org.eclipse.aether.RepositorySystem;
28  import org.eclipse.aether.RepositorySystemSession;
29  import org.eclipse.aether.repository.ArtifactRepository;
30  
31  /**
32   * The result of a version resolution request.
33   * 
34   * @see RepositorySystem#resolveVersion(RepositorySystemSession, VersionRequest)
35   */
36  public final class VersionResult
37  {
38  
39      private final VersionRequest request;
40  
41      private List<Exception> exceptions;
42  
43      private String version;
44  
45      private ArtifactRepository repository;
46  
47      /**
48       * Creates a new result for the specified request.
49       *
50       * @param request The resolution request, must not be {@code null}.
51       */
52      public VersionResult( VersionRequest request )
53      {
54          this.request = requireNonNull( request, "version request cannot be null" );
55          exceptions = Collections.emptyList();
56      }
57  
58      /**
59       * Gets the resolution request that was made.
60       *
61       * @return The resolution request, never {@code null}.
62       */
63      public VersionRequest getRequest()
64      {
65          return request;
66      }
67  
68      /**
69       * Gets the exceptions that occurred while resolving the version.
70       * 
71       * @return The exceptions that occurred, never {@code null}.
72       */
73      public List<Exception> getExceptions()
74      {
75          return exceptions;
76      }
77  
78      /**
79       * Records the specified exception while resolving the version.
80       * 
81       * @param exception The exception to record, may be {@code null}.
82       * @return This result for chaining, never {@code null}.
83       */
84      public VersionResult addException( Exception exception )
85      {
86          if ( exception != null )
87          {
88              if ( exceptions.isEmpty() )
89              {
90                  exceptions = new ArrayList<Exception>();
91              }
92              exceptions.add( exception );
93          }
94          return this;
95      }
96  
97      /**
98       * Gets the resolved version.
99       * 
100      * @return The resolved version or {@code null} if the resolution failed.
101      */
102     public String getVersion()
103     {
104         return version;
105     }
106 
107     /**
108      * Sets the resolved version.
109      * 
110      * @param version The resolved version, may be {@code null}.
111      * @return This result for chaining, never {@code null}.
112      */
113     public VersionResult setVersion( String version )
114     {
115         this.version = version;
116         return this;
117     }
118 
119     /**
120      * Gets the repository from which the version was eventually resolved.
121      * 
122      * @return The repository from which the version was resolved or {@code null} if unknown.
123      */
124     public ArtifactRepository getRepository()
125     {
126         return repository;
127     }
128 
129     /**
130      * Sets the repository from which the version was resolved.
131      * 
132      * @param repository The repository from which the version was resolved, may be {@code null}.
133      * @return This result for chaining, never {@code null}.
134      */
135     public VersionResult setRepository( ArtifactRepository repository )
136     {
137         this.repository = repository;
138         return this;
139     }
140 
141     @Override
142     public String toString()
143     {
144         return getVersion() + " @ " + getRepository();
145     }
146 
147 }