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.Collections;
23  import java.util.List;
24  
25  import org.eclipse.aether.RepositorySystem;
26  import org.eclipse.aether.RepositorySystemSession;
27  import org.eclipse.aether.graph.DependencyCycle;
28  import org.eclipse.aether.graph.DependencyNode;
29  
30  /**
31   * The result of a dependency resolution request.
32   * 
33   * @see RepositorySystem#resolveDependencies(RepositorySystemSession, DependencyRequest)
34   */
35  public final class DependencyResult
36  {
37  
38      private final DependencyRequest request;
39  
40      private DependencyNode root;
41  
42      private List<DependencyCycle> cycles;
43  
44      private List<Exception> collectExceptions;
45  
46      private List<ArtifactResult> artifactResults;
47  
48      /**
49       * Creates a new result for the specified request.
50       * 
51       * @param request The resolution request, must not be {@code null}.
52       */
53      public DependencyResult( DependencyRequest request )
54      {
55          if ( request == null )
56          {
57              throw new IllegalArgumentException( "dependency request has not been specified" );
58          }
59          this.request = request;
60          root = request.getRoot();
61          cycles = Collections.emptyList();
62          collectExceptions = Collections.emptyList();
63          artifactResults = Collections.emptyList();
64      }
65  
66      /**
67       * Gets the resolution request that was made.
68       * 
69       * @return The resolution request, never {@code null}.
70       */
71      public DependencyRequest getRequest()
72      {
73          return request;
74      }
75  
76      /**
77       * Gets the root node of the resolved dependency graph. Note that this dependency graph might be
78       * incomplete/unfinished in case of {@link #getCollectExceptions()} indicating errors during its calculation.
79       * 
80       * @return The root node of the resolved dependency graph or {@code null} if none.
81       */
82      public DependencyNode getRoot()
83      {
84          return root;
85      }
86  
87      /**
88       * Sets the root node of the resolved dependency graph.
89       * 
90       * @param root The root node of the resolved dependency graph, may be {@code null}.
91       * @return This result for chaining, never {@code null}.
92       */
93      public DependencyResult setRoot( DependencyNode root )
94      {
95          this.root = root;
96          return this;
97      }
98  
99      /**
100      * Gets the dependency cycles that were encountered while building the dependency graph. Note that dependency cycles
101      * will only be reported here if the underlying request was created from a
102      * {@link org.eclipse.aether.collection.CollectRequest CollectRequest}. If the underlying {@link DependencyRequest}
103      * was created from an existing dependency graph, information about cycles will not be available in this result.
104      * 
105      * @return The dependency cycles in the (raw) graph, never {@code null}.
106      */
107     public List<DependencyCycle> getCycles()
108     {
109         return cycles;
110     }
111 
112     /**
113      * Records the specified dependency cycles while building the dependency graph.
114      * 
115      * @param cycles The dependency cycles to record, may be {@code null}.
116      * @return This result for chaining, never {@code null}.
117      */
118     public DependencyResult setCycles( List<DependencyCycle> cycles )
119     {
120         if ( cycles == null )
121         {
122             this.cycles = Collections.emptyList();
123         }
124         else
125         {
126             this.cycles = cycles;
127         }
128         return this;
129     }
130 
131     /**
132      * Gets the exceptions that occurred while building the dependency graph.
133      * 
134      * @return The exceptions that occurred, never {@code null}.
135      */
136     public List<Exception> getCollectExceptions()
137     {
138         return collectExceptions;
139     }
140 
141     /**
142      * Records the specified exceptions while building the dependency graph.
143      * 
144      * @param exceptions The exceptions to record, may be {@code null}.
145      * @return This result for chaining, never {@code null}.
146      */
147     public DependencyResult setCollectExceptions( List<Exception> exceptions )
148     {
149         if ( exceptions == null )
150         {
151             this.collectExceptions = Collections.emptyList();
152         }
153         else
154         {
155             this.collectExceptions = exceptions;
156         }
157         return this;
158     }
159 
160     /**
161      * Gets the resolution results for the dependency artifacts that matched {@link DependencyRequest#getFilter()}.
162      * 
163      * @return The resolution results for the dependency artifacts, never {@code null}.
164      */
165     public List<ArtifactResult> getArtifactResults()
166     {
167         return artifactResults;
168     }
169 
170     /**
171      * Sets the resolution results for the artifacts that matched {@link DependencyRequest#getFilter()}.
172      * 
173      * @param results The resolution results for the artifacts, may be {@code null}.
174      * @return This result for chaining, never {@code null}.
175      */
176     public DependencyResult setArtifactResults( List<ArtifactResult> results )
177     {
178         if ( results == null )
179         {
180             this.artifactResults = Collections.emptyList();
181         }
182         else
183         {
184             this.artifactResults = results;
185         }
186         return this;
187     }
188 
189     @Override
190     public String toString()
191     {
192         return String.valueOf( artifactResults );
193     }
194 
195 }