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