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 javax.inject.Named;
22 import javax.inject.Singleton;
23
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.List;
27
28
29
30 @Named
31 @Singleton
32 @Deprecated
33 public class DefaultResolutionErrorHandler implements ResolutionErrorHandler {
34
35 public void throwErrors(ArtifactResolutionRequest request, ArtifactResolutionResult result)
36 throws ArtifactResolutionException {
37
38
39 if (result.hasMetadataResolutionExceptions()) {
40 throw result.getMetadataResolutionException(0);
41 }
42
43
44
45
46
47 if (result.hasCircularDependencyExceptions()) {
48 throw result.getCircularDependencyException(0);
49 }
50
51
52
53 if (result.hasVersionRangeViolations()) {
54 throw result.getVersionRangeViolation(0);
55 }
56
57
58
59 if (result.hasErrorArtifactExceptions()) {
60 throw result.getErrorArtifactExceptions().get(0);
61 }
62
63 if (result.hasMissingArtifacts()) {
64 throw new MultipleArtifactsNotFoundException(
65 request.getArtifact(),
66 toList(result.getArtifacts()),
67 result.getMissingArtifacts(),
68 request.getRemoteRepositories());
69 }
70
71
72 if (result.hasExceptions()) {
73 throw new ArtifactResolutionException(
74 "Unknown error during artifact resolution, " + request + ", " + result.getExceptions(),
75 request.getArtifact(),
76 request.getRemoteRepositories());
77 }
78 }
79
80 private static <T> List<T> toList(Collection<T> items) {
81 return (items != null) ? new ArrayList<>(items) : null;
82 }
83 }