1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.resolution;
20
21 import java.util.Collections;
22 import java.util.List;
23
24 import org.eclipse.aether.RepositoryException;
25 import org.eclipse.aether.repository.LocalArtifactResult;
26 import org.eclipse.aether.transfer.ArtifactFilteredOutException;
27 import org.eclipse.aether.transfer.ArtifactNotFoundException;
28 import org.eclipse.aether.transfer.RepositoryOfflineException;
29
30
31
32
33 public class ArtifactResolutionException extends RepositoryException {
34
35 private final transient List<ArtifactResult> results;
36
37
38
39
40
41
42 public ArtifactResolutionException(List<ArtifactResult> results) {
43 super(getMessage(results), getCause(results));
44 this.results = (results != null) ? results : Collections.<ArtifactResult>emptyList();
45 }
46
47
48
49
50
51
52
53 public ArtifactResolutionException(List<ArtifactResult> results, String message) {
54 super(message, getCause(results));
55 this.results = (results != null) ? results : Collections.<ArtifactResult>emptyList();
56 }
57
58
59
60
61
62
63
64
65 public ArtifactResolutionException(List<ArtifactResult> results, String message, Throwable cause) {
66 super(message, cause);
67 this.results = (results != null) ? results : Collections.<ArtifactResult>emptyList();
68 }
69
70
71
72
73
74
75
76 public List<ArtifactResult> getResults() {
77 return results;
78 }
79
80
81
82
83
84
85
86 public ArtifactResult getResult() {
87 return (results != null && !results.isEmpty()) ? results.get(0) : null;
88 }
89
90 private static String getMessage(List<? extends ArtifactResult> results) {
91 StringBuilder buffer = new StringBuilder(256);
92
93 buffer.append("The following artifacts could not be resolved: ");
94
95 String sep = "";
96 for (ArtifactResult result : results) {
97 if (!result.isResolved()) {
98 buffer.append(sep);
99 buffer.append(result.getRequest().getArtifact());
100 LocalArtifactResult localResult = result.getLocalArtifactResult();
101 if (localResult != null) {
102 buffer.append(" (");
103 if (localResult.getFile() != null) {
104 buffer.append("present");
105 if (!localResult.isAvailable()) {
106 buffer.append(", but unavailable");
107 }
108 } else {
109 buffer.append("absent");
110 }
111 buffer.append(")");
112 }
113 sep = ", ";
114 }
115 }
116
117 Throwable cause = getCause(results);
118 if (cause != null) {
119 buffer.append(": ").append(cause.getMessage());
120 }
121
122 return buffer.toString();
123 }
124
125 private static Throwable getCause(List<? extends ArtifactResult> results) {
126 for (ArtifactResult result : results) {
127 if (!result.isResolved()) {
128 Throwable notFound = null, offline = null;
129 for (Throwable t : result.getExceptions()) {
130 if (t instanceof ArtifactNotFoundException) {
131 if (notFound == null || notFound instanceof ArtifactFilteredOutException) {
132 notFound = t;
133 }
134 if (offline == null && t.getCause() instanceof RepositoryOfflineException) {
135 offline = t;
136 }
137 } else {
138 return t;
139 }
140 }
141 if (offline != null) {
142 return offline;
143 }
144 if (notFound != null) {
145 return notFound;
146 }
147 }
148 }
149 return null;
150 }
151 }