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