1 | |
package org.apache.maven.artifact.resolver; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import org.apache.maven.artifact.Artifact; |
23 | |
import org.apache.maven.artifact.repository.ArtifactRepository; |
24 | |
|
25 | |
import java.util.HashSet; |
26 | |
import java.util.Iterator; |
27 | |
import java.util.List; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
public class AbstractArtifactResolutionException |
36 | |
extends Exception |
37 | |
{ |
38 | |
private String groupId; |
39 | |
|
40 | |
private String artifactId; |
41 | |
|
42 | |
private String version; |
43 | |
|
44 | |
private String type; |
45 | |
|
46 | |
private String classifier; |
47 | |
|
48 | |
private Artifact artifact; |
49 | |
|
50 | |
private List remoteRepositories; |
51 | |
|
52 | |
private final String originalMessage; |
53 | |
|
54 | |
private final String path; |
55 | |
|
56 | 0 | static final String LS = System.getProperty( "line.separator" ); |
57 | |
|
58 | |
protected AbstractArtifactResolutionException( String message, String groupId, String artifactId, String version, |
59 | |
String type, String classifier, List remoteRepositories, List path ) |
60 | |
{ |
61 | 0 | this( message, groupId, artifactId, version, type, classifier, remoteRepositories, path, null ); |
62 | 0 | } |
63 | |
|
64 | |
protected AbstractArtifactResolutionException( String message, String groupId, String artifactId, String version, |
65 | |
String type, String classifier, List remoteRepositories, List path, Throwable t ) |
66 | |
{ |
67 | 0 | super( constructMessageBase( message, groupId, artifactId, version, type, remoteRepositories, path ), t ); |
68 | |
|
69 | 0 | this.originalMessage = message; |
70 | 0 | this.groupId = groupId; |
71 | 0 | this.artifactId = artifactId; |
72 | 0 | this.type = type; |
73 | 0 | this.classifier = classifier; |
74 | 0 | this.version = version; |
75 | 0 | this.remoteRepositories = remoteRepositories; |
76 | 0 | this.path = constructArtifactPath( path, "" ); |
77 | 0 | } |
78 | |
|
79 | |
protected AbstractArtifactResolutionException( String message, Artifact artifact ) |
80 | |
{ |
81 | 0 | this( message, artifact, null ); |
82 | 0 | } |
83 | |
|
84 | |
protected AbstractArtifactResolutionException( String message, Artifact artifact, List remoteRepositories ) |
85 | |
{ |
86 | 0 | this( message, artifact, remoteRepositories, null ); |
87 | 0 | } |
88 | |
|
89 | |
protected AbstractArtifactResolutionException( String message, Artifact artifact, List remoteRepositories, |
90 | |
Throwable t ) |
91 | |
{ |
92 | 0 | this( message, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), |
93 | |
artifact.getClassifier(),remoteRepositories, artifact.getDependencyTrail(), t ); |
94 | 0 | this.artifact = artifact; |
95 | 0 | } |
96 | |
|
97 | |
public Artifact getArtifact() |
98 | |
{ |
99 | 0 | return artifact; |
100 | |
} |
101 | |
|
102 | |
public String getGroupId() |
103 | |
{ |
104 | 0 | return groupId; |
105 | |
} |
106 | |
|
107 | |
public String getArtifactId() |
108 | |
{ |
109 | 0 | return artifactId; |
110 | |
} |
111 | |
|
112 | |
public String getVersion() |
113 | |
{ |
114 | 0 | return version; |
115 | |
} |
116 | |
|
117 | |
public String getType() |
118 | |
{ |
119 | 0 | return type; |
120 | |
} |
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
public String getClassifier() |
126 | |
{ |
127 | 0 | return this.classifier; |
128 | |
} |
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
public String getPath() |
134 | |
{ |
135 | 0 | return this.path; |
136 | |
} |
137 | |
|
138 | |
public List getRemoteRepositories() |
139 | |
{ |
140 | 0 | return remoteRepositories; |
141 | |
} |
142 | |
|
143 | |
public String getOriginalMessage() |
144 | |
{ |
145 | 0 | return originalMessage; |
146 | |
} |
147 | |
|
148 | |
protected static String constructArtifactPath( List path, String indentation ) |
149 | |
{ |
150 | 0 | StringBuffer sb = new StringBuffer(); |
151 | |
|
152 | 0 | if ( path != null ) |
153 | |
{ |
154 | 0 | sb.append( LS ); |
155 | 0 | sb.append( indentation ); |
156 | 0 | sb.append( "Path to dependency: " ); |
157 | 0 | sb.append( LS ); |
158 | 0 | int num = 1; |
159 | 0 | for ( Iterator i = path.iterator(); i.hasNext(); num++ ) |
160 | |
{ |
161 | 0 | sb.append( indentation ); |
162 | 0 | sb.append( "\t" ); |
163 | 0 | sb.append( num ); |
164 | 0 | sb.append( ") " ); |
165 | 0 | sb.append( i.next() ); |
166 | 0 | sb.append( LS ); |
167 | |
} |
168 | |
} |
169 | |
|
170 | 0 | return sb.toString(); |
171 | |
} |
172 | |
|
173 | |
private static String constructMessageBase( String message, String groupId, String artifactId, String version, |
174 | |
String type, List remoteRepositories, List path ) |
175 | |
{ |
176 | 0 | StringBuffer sb = new StringBuffer(); |
177 | |
|
178 | 0 | sb.append( message ); |
179 | 0 | sb.append( LS ); |
180 | 0 | sb.append( " " + groupId + ":" + artifactId + ":" + type + ":" + version ); |
181 | 0 | sb.append( LS ); |
182 | 0 | if ( remoteRepositories != null && !remoteRepositories.isEmpty() ) |
183 | |
{ |
184 | 0 | sb.append( LS ); |
185 | 0 | sb.append( "from the specified remote repositories:" ); |
186 | 0 | sb.append( LS + " " ); |
187 | |
|
188 | 0 | for ( Iterator i = new HashSet( remoteRepositories ).iterator(); i.hasNext(); ) |
189 | |
{ |
190 | 0 | ArtifactRepository remoteRepository = (ArtifactRepository) i.next(); |
191 | |
|
192 | 0 | sb.append( remoteRepository.getId() ); |
193 | 0 | sb.append( " (" ); |
194 | 0 | sb.append( remoteRepository.getUrl() ); |
195 | 0 | sb.append( ")" ); |
196 | 0 | if ( i.hasNext() ) |
197 | |
{ |
198 | 0 | sb.append( ",\n " ); |
199 | |
} |
200 | 0 | } |
201 | |
} |
202 | |
|
203 | 0 | sb.append( LS ); |
204 | 0 | sb.append( constructArtifactPath( path, "" ) ); |
205 | 0 | sb.append( LS ); |
206 | 0 | return sb.toString(); |
207 | |
} |
208 | |
|
209 | |
protected static String constructMissingArtifactMessage( String message, String indentation, String groupId, String artifactId, String version, |
210 | |
String type, String classifier, String downloadUrl, List path ) |
211 | |
{ |
212 | 0 | StringBuffer sb = new StringBuffer( message ); |
213 | |
|
214 | 0 | if ( !"pom".equals( type ) ) |
215 | |
{ |
216 | 0 | if ( downloadUrl != null ) |
217 | |
{ |
218 | 0 | sb.append( LS ); |
219 | 0 | sb.append( LS ); |
220 | 0 | sb.append( indentation ); |
221 | 0 | sb.append( "Try downloading the file manually from: " ); |
222 | 0 | sb.append( LS ); |
223 | 0 | sb.append( indentation ); |
224 | 0 | sb.append( " " ); |
225 | 0 | sb.append( downloadUrl ); |
226 | |
} |
227 | |
else |
228 | |
{ |
229 | 0 | sb.append( LS ); |
230 | 0 | sb.append( LS ); |
231 | 0 | sb.append( indentation ); |
232 | 0 | sb.append( "Try downloading the file manually from the project website." ); |
233 | |
} |
234 | |
|
235 | 0 | sb.append( LS ); |
236 | 0 | sb.append( LS ); |
237 | 0 | sb.append( indentation ); |
238 | 0 | sb.append( "Then, install it using the command: " ); |
239 | 0 | sb.append( LS ); |
240 | 0 | sb.append( indentation ); |
241 | 0 | sb.append( " mvn install:install-file -DgroupId=" ); |
242 | 0 | sb.append( groupId ); |
243 | 0 | sb.append( " -DartifactId=" ); |
244 | 0 | sb.append( artifactId ); |
245 | 0 | sb.append( " -Dversion=" ); |
246 | 0 | sb.append( version ); |
247 | |
|
248 | |
|
249 | 0 | if (classifier !=null && !classifier.equals( "" )) |
250 | |
{ |
251 | 0 | sb.append( " -Dclassifier=" ); |
252 | 0 | sb.append( classifier ); |
253 | |
} |
254 | 0 | sb.append( " -Dpackaging=" ); |
255 | 0 | sb.append( type ); |
256 | 0 | sb.append( " -Dfile=/path/to/file" ); |
257 | 0 | sb.append( LS ); |
258 | |
|
259 | |
|
260 | |
|
261 | 0 | sb.append( LS ); |
262 | 0 | sb.append( indentation ); |
263 | 0 | sb.append( "Alternatively, if you host your own repository you can deploy the file there: " ); |
264 | 0 | sb.append( LS ); |
265 | 0 | sb.append( indentation ); |
266 | 0 | sb.append( " mvn deploy:deploy-file -DgroupId=" ); |
267 | 0 | sb.append( groupId ); |
268 | 0 | sb.append( " -DartifactId=" ); |
269 | 0 | sb.append( artifactId ); |
270 | 0 | sb.append( " -Dversion=" ); |
271 | 0 | sb.append( version ); |
272 | |
|
273 | |
|
274 | 0 | if (classifier !=null && !classifier.equals( "" )) |
275 | |
{ |
276 | 0 | sb.append( " -Dclassifier=" ); |
277 | 0 | sb.append( classifier ); |
278 | |
} |
279 | 0 | sb.append( " -Dpackaging=" ); |
280 | 0 | sb.append( type ); |
281 | 0 | sb.append( " -Dfile=/path/to/file" ); |
282 | 0 | sb.append( " -Durl=[url] -DrepositoryId=[id]" ); |
283 | 0 | sb.append( LS ); |
284 | |
|
285 | |
} |
286 | |
|
287 | 0 | sb.append( constructArtifactPath( path, indentation ) ); |
288 | 0 | sb.append( LS ); |
289 | |
|
290 | 0 | return sb.toString(); |
291 | |
} |
292 | |
|
293 | |
public String getArtifactPath() |
294 | |
{ |
295 | 0 | return path; |
296 | |
} |
297 | |
} |