View Javadoc
1   package org.eclipse.aether.collection;
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.graph.DependencyCycle;
29  import org.eclipse.aether.graph.DependencyNode;
30  
31  /**
32   * The result of a dependency collection request.
33   * 
34   * @see RepositorySystem#collectDependencies(RepositorySystemSession, CollectRequest)
35   */
36  public final class CollectResult
37  {
38  
39      private final CollectRequest request;
40  
41      private List<Exception> exceptions;
42  
43      private List<DependencyCycle> cycles;
44  
45      private DependencyNode root;
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 CollectResult( CollectRequest request )
53      {
54          if ( request == null )
55          {
56              throw new IllegalArgumentException( "dependency collection request has not been specified" );
57          }
58          this.request = request;
59          exceptions = Collections.emptyList();
60          cycles = Collections.emptyList();
61      }
62  
63      /**
64       * Gets the collection request that was made.
65       * 
66       * @return The collection request, never {@code null}.
67       */
68      public CollectRequest getRequest()
69      {
70          return request;
71      }
72  
73      /**
74       * Gets the exceptions that occurred while building the dependency graph.
75       * 
76       * @return The exceptions that occurred, never {@code null}.
77       */
78      public List<Exception> getExceptions()
79      {
80          return exceptions;
81      }
82  
83      /**
84       * Records the specified exception while building the dependency graph.
85       * 
86       * @param exception The exception to record, may be {@code null}.
87       * @return This result for chaining, never {@code null}.
88       */
89      public CollectResult addException( Exception exception )
90      {
91          if ( exception != null )
92          {
93              if ( exceptions.isEmpty() )
94              {
95                  exceptions = new ArrayList<Exception>();
96              }
97              exceptions.add( exception );
98          }
99          return this;
100     }
101 
102     /**
103      * Gets the dependency cycles that were encountered while building the dependency graph.
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 cycle.
114      * 
115      * @param cycle The dependency cycle to record, may be {@code null}.
116      * @return This result for chaining, never {@code null}.
117      */
118     public CollectResult addCycle( DependencyCycle cycle )
119     {
120         if ( cycle != null )
121         {
122             if ( cycles.isEmpty() )
123             {
124                 cycles = new ArrayList<DependencyCycle>();
125             }
126             cycles.add( cycle );
127         }
128         return this;
129     }
130 
131     /**
132      * Gets the root node of the dependency graph.
133      * 
134      * @return The root node of the dependency graph or {@code null} if none.
135      */
136     public DependencyNode getRoot()
137     {
138         return root;
139     }
140 
141     /**
142      * Sets the root node of the dependency graph.
143      * 
144      * @param root The root node of the dependency graph, may be {@code null}.
145      * @return This result for chaining, never {@code null}.
146      */
147     public CollectResult setRoot( DependencyNode root )
148     {
149         this.root = root;
150         return this;
151     }
152 
153     @Override
154     public String toString()
155     {
156         return String.valueOf( getRoot() );
157     }
158 
159 }