1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugin.version;
20
21 import java.util.List;
22
23 import org.eclipse.aether.repository.LocalRepository;
24 import org.eclipse.aether.repository.RemoteRepository;
25
26
27
28
29 public class PluginVersionResolutionException extends Exception {
30 private final String groupId;
31
32 private final String artifactId;
33
34 private final String baseMessage;
35
36 public PluginVersionResolutionException(String groupId, String artifactId, String baseMessage, Throwable cause) {
37 super("Error resolving version for plugin \'" + groupId + ":" + artifactId + "\': " + baseMessage, cause);
38
39 this.groupId = groupId;
40 this.artifactId = artifactId;
41 this.baseMessage = baseMessage;
42 }
43
44 public PluginVersionResolutionException(String groupId, String artifactId, String baseMessage) {
45 super("Error resolving version for plugin \'" + groupId + ":" + artifactId + "\': " + baseMessage);
46
47 this.groupId = groupId;
48 this.artifactId = artifactId;
49 this.baseMessage = baseMessage;
50 }
51
52 public PluginVersionResolutionException(
53 String groupId,
54 String artifactId,
55 LocalRepository localRepository,
56 List<RemoteRepository> remoteRepositories,
57 String baseMessage) {
58 super("Error resolving version for plugin \'" + groupId + ":" + artifactId + "\' from the repositories "
59 + format(localRepository, remoteRepositories) + ": " + baseMessage);
60
61 this.groupId = groupId;
62 this.artifactId = artifactId;
63 this.baseMessage = baseMessage;
64 }
65
66 public String getGroupId() {
67 return groupId;
68 }
69
70 public String getArtifactId() {
71 return artifactId;
72 }
73
74 public String getBaseMessage() {
75 return baseMessage;
76 }
77
78 private static String format(LocalRepository localRepository, List<RemoteRepository> remoteRepositories) {
79 String repos = "[";
80
81 if (localRepository != null) {
82 repos += localRepository.getId() + " (" + localRepository.getBasedir() + ")";
83 }
84
85 if (remoteRepositories != null && !remoteRepositories.isEmpty()) {
86 for (RemoteRepository repository : remoteRepositories) {
87 repos += ", ";
88
89 if (repository != null) {
90 repos += repository.getId() + " (" + repository.getUrl() + ")";
91 }
92 }
93 }
94
95 repos += "]";
96
97 return repos;
98 }
99 }