View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.eclipse.aether.resolution;
20  
21  import java.util.Collections;
22  import java.util.List;
23  
24  import org.eclipse.aether.RepositorySystem;
25  import org.eclipse.aether.graph.DependencyCycle;
26  import org.eclipse.aether.graph.DependencyNode;
27  
28  import static java.util.Objects.requireNonNull;
29  
30  /**
31   * The result of a dependency resolution request.
32   *
33   * @see RepositorySystem#resolveDependencies(org.eclipse.aether.RepositorySystemSession, DependencyRequest)
34   */
35  public final class DependencyResult {
36  
37      private final DependencyRequest request;
38  
39      private DependencyNode root;
40  
41      private List<DependencyCycle> cycles;
42  
43      private List<Exception> collectExceptions;
44  
45      private List<DependencyNode> dependencyNodeResults;
46  
47      private List<ArtifactResult> artifactResults;
48  
49      /**
50       * Creates a new result for the specified request.
51       *
52       * @param request The resolution request, must not be {@code null}.
53       */
54      public DependencyResult(DependencyRequest request) {
55          this.request = requireNonNull(request, "dependency request cannot be null");
56          root = request.getRoot();
57          cycles = Collections.emptyList();
58          collectExceptions = Collections.emptyList();
59          this.dependencyNodeResults = Collections.emptyList();
60          artifactResults = Collections.emptyList();
61      }
62  
63      /**
64       * Gets the resolution request that was made.
65       *
66       * @return The resolution request, never {@code null}.
67       */
68      public DependencyRequest getRequest() {
69          return request;
70      }
71  
72      /**
73       * Gets the root node of the resolved dependency graph. Note that this dependency graph might be
74       * incomplete/unfinished in case of {@link #getCollectExceptions()} indicating errors during its calculation.
75       *
76       * @return The root node of the resolved dependency graph or {@code null} if none.
77       */
78      public DependencyNode getRoot() {
79          return root;
80      }
81  
82      /**
83       * Sets the root node of the resolved dependency graph.
84       *
85       * @param root The root node of the resolved dependency graph, may be {@code null}.
86       * @return This result for chaining, never {@code null}.
87       */
88      public DependencyResult setRoot(DependencyNode root) {
89          this.root = root;
90          return this;
91      }
92  
93      /**
94       * Gets the dependency cycles that were encountered while building the dependency graph. Note that dependency cycles
95       * will only be reported here if the underlying request was created from a
96       * {@link org.eclipse.aether.collection.CollectRequest CollectRequest}. If the underlying {@link DependencyRequest}
97       * was created from an existing dependency graph, information about cycles will not be available in this result.
98       *
99       * @return The dependency cycles in the (raw) graph, never {@code null}.
100      */
101     public List<DependencyCycle> getCycles() {
102         return cycles;
103     }
104 
105     /**
106      * Records the specified dependency cycles while building the dependency graph.
107      *
108      * @param cycles The dependency cycles to record, may be {@code null}.
109      * @return This result for chaining, never {@code null}.
110      */
111     public DependencyResult setCycles(List<DependencyCycle> cycles) {
112         if (cycles == null) {
113             this.cycles = Collections.emptyList();
114         } else {
115             this.cycles = cycles;
116         }
117         return this;
118     }
119 
120     /**
121      * Gets the exceptions that occurred while building the dependency graph.
122      *
123      * @return The exceptions that occurred, never {@code null}.
124      */
125     public List<Exception> getCollectExceptions() {
126         return collectExceptions;
127     }
128 
129     /**
130      * Records the specified exceptions while building the dependency graph.
131      *
132      * @param exceptions The exceptions to record, may be {@code null}.
133      * @return This result for chaining, never {@code null}.
134      */
135     public DependencyResult setCollectExceptions(List<Exception> exceptions) {
136         if (exceptions == null) {
137             this.collectExceptions = Collections.emptyList();
138         } else {
139             this.collectExceptions = exceptions;
140         }
141         return this;
142     }
143 
144     /**
145      * Gets the resolution results for the dependency nodes that matched {@link DependencyRequest#getFilter()}.
146      *
147      * @return The resolution results for the dependency nodes, never {@code null}.
148      * @since TBD
149      */
150     public List<DependencyNode> getDependencyNodeResults() {
151         return dependencyNodeResults;
152     }
153 
154     /**
155      * Sets the resolution results for the dependency nodes that matched {@link DependencyRequest#getFilter()}.
156      *
157      * @param results The resolution results for the dependency nodes, may be {@code null}.
158      * @return This result for chaining, never {@code null}.
159      * @since TBD
160      */
161     public DependencyResult setDependencyNodeResults(List<DependencyNode> results) {
162         if (results == null) {
163             this.dependencyNodeResults = Collections.emptyList();
164         } else {
165             this.dependencyNodeResults = results;
166         }
167         return this;
168     }
169 
170     /**
171      * Gets the resolution results for the dependency artifacts that matched {@link DependencyRequest#getFilter()}.
172      *
173      * @return The resolution results for the dependency artifacts, never {@code null}.
174      */
175     public List<ArtifactResult> getArtifactResults() {
176         return artifactResults;
177     }
178 
179     /**
180      * Sets the resolution results for the artifacts that matched {@link DependencyRequest#getFilter()}.
181      *
182      * @param results The resolution results for the artifacts, may be {@code null}.
183      * @return This result for chaining, never {@code null}.
184      */
185     public DependencyResult setArtifactResults(List<ArtifactResult> results) {
186         if (results == null) {
187             this.artifactResults = Collections.emptyList();
188         } else {
189             this.artifactResults = results;
190         }
191         return this;
192     }
193 
194     @Override
195     public String toString() {
196         return String.valueOf(artifactResults);
197     }
198 }