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