1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  package org.apache.maven.artifact.resolver;
20  
21  import java.util.ArrayList;
22  import java.util.Collections;
23  import java.util.LinkedHashSet;
24  import java.util.List;
25  import java.util.Set;
26  
27  import org.apache.maven.artifact.Artifact;
28  import org.apache.maven.artifact.repository.ArtifactRepository;
29  import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  @Deprecated
47  public class ArtifactResolutionResult {
48      private static final String LS = System.lineSeparator();
49  
50      private Artifact originatingArtifact;
51  
52      private List<Artifact> missingArtifacts;
53  
54      
55  
56      private List<Exception> exceptions;
57  
58      private List<Exception> versionRangeViolations;
59  
60      private List<ArtifactResolutionException> metadataResolutionExceptions;
61  
62      private List<CyclicDependencyException> circularDependencyExceptions;
63  
64      private List<ArtifactResolutionException> errorArtifactExceptions;
65  
66      
67  
68      private List<ArtifactRepository> repositories;
69  
70      private Set<Artifact> artifacts;
71  
72      private Set<ResolutionNode> resolutionNodes;
73  
74      public Artifact getOriginatingArtifact() {
75          return originatingArtifact;
76      }
77  
78      public ArtifactResolutionResult setOriginatingArtifact(final Artifact originatingArtifact) {
79          this.originatingArtifact = originatingArtifact;
80  
81          return this;
82      }
83  
84      public void addArtifact(Artifact artifact) {
85          if (artifacts == null) {
86              artifacts = new LinkedHashSet<>();
87          }
88  
89          artifacts.add(artifact);
90      }
91  
92      public Set<Artifact> getArtifacts() {
93          if (artifacts == null) {
94              artifacts = new LinkedHashSet<>();
95          }
96  
97          return artifacts;
98      }
99  
100     public void setArtifacts(Set<Artifact> artifacts) {
101         this.artifacts = artifacts;
102     }
103 
104     public Set<ResolutionNode> getArtifactResolutionNodes() {
105         if (resolutionNodes == null) {
106             resolutionNodes = new LinkedHashSet<>();
107         }
108 
109         return resolutionNodes;
110     }
111 
112     public void setArtifactResolutionNodes(Set<ResolutionNode> resolutionNodes) {
113         this.resolutionNodes = resolutionNodes;
114     }
115 
116     public boolean hasMissingArtifacts() {
117         return missingArtifacts != null && !missingArtifacts.isEmpty();
118     }
119 
120     public List<Artifact> getMissingArtifacts() {
121         return missingArtifacts == null ? Collections.emptyList() : Collections.unmodifiableList(missingArtifacts);
122     }
123 
124     public ArtifactResolutionResult addMissingArtifact(Artifact artifact) {
125         missingArtifacts = initList(missingArtifacts);
126 
127         missingArtifacts.add(artifact);
128 
129         return this;
130     }
131 
132     public ArtifactResolutionResult setUnresolvedArtifacts(final List<Artifact> unresolvedArtifacts) {
133         this.missingArtifacts = unresolvedArtifacts;
134 
135         return this;
136     }
137 
138     public boolean isSuccess() {
139         return !(hasMissingArtifacts() || hasExceptions());
140     }
141 
142     
143     
144     
145 
146     public boolean hasExceptions() {
147         return exceptions != null && !exceptions.isEmpty();
148     }
149 
150     public List<Exception> getExceptions() {
151         return exceptions == null ? Collections.emptyList() : Collections.unmodifiableList(exceptions);
152     }
153 
154     
155     
156     
157 
158     public boolean hasVersionRangeViolations() {
159         return versionRangeViolations != null;
160     }
161 
162     
163 
164 
165 
166 
167 
168 
169 
170     public ArtifactResolutionResult addVersionRangeViolation(Exception e) {
171         versionRangeViolations = initList(versionRangeViolations);
172 
173         versionRangeViolations.add(e);
174 
175         exceptions = initList(exceptions);
176 
177         exceptions.add(e);
178 
179         return this;
180     }
181 
182     public OverConstrainedVersionException getVersionRangeViolation(int i) {
183         return (OverConstrainedVersionException) versionRangeViolations.get(i);
184     }
185 
186     public List<Exception> getVersionRangeViolations() {
187         return versionRangeViolations == null
188                 ? Collections.emptyList()
189                 : Collections.unmodifiableList(versionRangeViolations);
190     }
191 
192     
193     
194     
195 
196     public boolean hasMetadataResolutionExceptions() {
197         return metadataResolutionExceptions != null;
198     }
199 
200     public ArtifactResolutionResult addMetadataResolutionException(ArtifactResolutionException e) {
201         metadataResolutionExceptions = initList(metadataResolutionExceptions);
202 
203         metadataResolutionExceptions.add(e);
204 
205         exceptions = initList(exceptions);
206 
207         exceptions.add(e);
208 
209         return this;
210     }
211 
212     public ArtifactResolutionException getMetadataResolutionException(int i) {
213         return metadataResolutionExceptions.get(i);
214     }
215 
216     public List<ArtifactResolutionException> getMetadataResolutionExceptions() {
217         return metadataResolutionExceptions == null
218                 ? Collections.emptyList()
219                 : Collections.unmodifiableList(metadataResolutionExceptions);
220     }
221 
222     
223     
224     
225 
226     public boolean hasErrorArtifactExceptions() {
227         return errorArtifactExceptions != null;
228     }
229 
230     public ArtifactResolutionResult addErrorArtifactException(ArtifactResolutionException e) {
231         errorArtifactExceptions = initList(errorArtifactExceptions);
232 
233         errorArtifactExceptions.add(e);
234 
235         exceptions = initList(exceptions);
236 
237         exceptions.add(e);
238 
239         return this;
240     }
241 
242     public List<ArtifactResolutionException> getErrorArtifactExceptions() {
243         if (errorArtifactExceptions == null) {
244             return Collections.emptyList();
245         }
246 
247         return Collections.unmodifiableList(errorArtifactExceptions);
248     }
249 
250     
251     
252     
253 
254     public boolean hasCircularDependencyExceptions() {
255         return circularDependencyExceptions != null;
256     }
257 
258     public ArtifactResolutionResult addCircularDependencyException(CyclicDependencyException e) {
259         circularDependencyExceptions = initList(circularDependencyExceptions);
260 
261         circularDependencyExceptions.add(e);
262 
263         exceptions = initList(exceptions);
264 
265         exceptions.add(e);
266 
267         return this;
268     }
269 
270     public CyclicDependencyException getCircularDependencyException(int i) {
271         return circularDependencyExceptions.get(i);
272     }
273 
274     public List<CyclicDependencyException> getCircularDependencyExceptions() {
275         if (circularDependencyExceptions == null) {
276             return Collections.emptyList();
277         }
278 
279         return Collections.unmodifiableList(circularDependencyExceptions);
280     }
281 
282     
283     
284     
285 
286     public List<ArtifactRepository> getRepositories() {
287         if (repositories == null) {
288             return Collections.emptyList();
289         }
290 
291         return Collections.unmodifiableList(repositories);
292     }
293 
294     public ArtifactResolutionResult setRepositories(final List<ArtifactRepository> repositories) {
295         this.repositories = repositories;
296 
297         return this;
298     }
299 
300     
301     
302     
303 
304     private <T> List<T> initList(final List<T> l) {
305         if (l == null) {
306             return new ArrayList<>();
307         }
308         return l;
309     }
310 
311     public String toString() {
312         StringBuilder sb = new StringBuilder();
313 
314         if (artifacts != null) {
315             int i = 1;
316             sb.append("---------").append(LS);
317             sb.append(artifacts.size()).append(LS);
318             for (Artifact a : artifacts) {
319                 sb.append(i).append(' ').append(a).append(LS);
320                 i++;
321             }
322             sb.append("---------");
323         }
324 
325         return sb.toString();
326     }
327 }