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  import static java.util.Objects.requireNonNull;
25  
26  import org.eclipse.aether.RepositorySystem;
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(org.eclipse.aether.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          this.request = requireNonNull( request, "dependency request cannot be null" );
56          root = request.getRoot();
57          cycles = Collections.emptyList();
58          collectExceptions = Collections.emptyList();
59          artifactResults = Collections.emptyList();
60      }
61  
62      /**
63       * Gets the resolution request that was made.
64       * 
65       * @return The resolution request, never {@code null}.
66       */
67      public DependencyRequest getRequest()
68      {
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      {
80          return root;
81      }
82  
83      /**
84       * Sets the root node of the resolved dependency graph.
85       * 
86       * @param root The root node of the resolved dependency graph, may be {@code null}.
87       * @return This result for chaining, never {@code null}.
88       */
89      public DependencyResult setRoot( DependencyNode root )
90      {
91          this.root = root;
92          return this;
93      }
94  
95      /**
96       * Gets the dependency cycles that were encountered while building the dependency graph. Note that dependency cycles
97       * will only be reported here if the underlying request was created from a
98       * {@link org.eclipse.aether.collection.CollectRequest CollectRequest}. If the underlying {@link DependencyRequest}
99       * was created from an existing dependency graph, information about cycles will not be available in this result.
100      * 
101      * @return The dependency cycles in the (raw) graph, never {@code null}.
102      */
103     public List<DependencyCycle> getCycles()
104     {
105         return cycles;
106     }
107 
108     /**
109      * Records the specified dependency cycles while building the dependency graph.
110      * 
111      * @param cycles The dependency cycles to record, may be {@code null}.
112      * @return This result for chaining, never {@code null}.
113      */
114     public DependencyResult setCycles( List<DependencyCycle> cycles )
115     {
116         if ( cycles == null )
117         {
118             this.cycles = Collections.emptyList();
119         }
120         else
121         {
122             this.cycles = cycles;
123         }
124         return this;
125     }
126 
127     /**
128      * Gets the exceptions that occurred while building the dependency graph.
129      * 
130      * @return The exceptions that occurred, never {@code null}.
131      */
132     public List<Exception> getCollectExceptions()
133     {
134         return collectExceptions;
135     }
136 
137     /**
138      * Records the specified exceptions while building the dependency graph.
139      * 
140      * @param exceptions The exceptions to record, may be {@code null}.
141      * @return This result for chaining, never {@code null}.
142      */
143     public DependencyResult setCollectExceptions( List<Exception> exceptions )
144     {
145         if ( exceptions == null )
146         {
147             this.collectExceptions = Collections.emptyList();
148         }
149         else
150         {
151             this.collectExceptions = exceptions;
152         }
153         return this;
154     }
155 
156     /**
157      * Gets the resolution results for the dependency artifacts that matched {@link DependencyRequest#getFilter()}.
158      * 
159      * @return The resolution results for the dependency artifacts, never {@code null}.
160      */
161     public List<ArtifactResult> getArtifactResults()
162     {
163         return artifactResults;
164     }
165 
166     /**
167      * Sets the resolution results for the artifacts that matched {@link DependencyRequest#getFilter()}.
168      * 
169      * @param results The resolution results for the artifacts, may be {@code null}.
170      * @return This result for chaining, never {@code null}.
171      */
172     public DependencyResult setArtifactResults( List<ArtifactResult> results )
173     {
174         if ( results == null )
175         {
176             this.artifactResults = Collections.emptyList();
177         }
178         else
179         {
180             this.artifactResults = results;
181         }
182         return this;
183     }
184 
185     @Override
186     public String toString()
187     {
188         return String.valueOf( artifactResults );
189     }
190 
191 }