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 import org.eclipse.aether.repository.LocalRepository;
23 import org.eclipse.aether.repository.RemoteRepository;
24
25
26
27
28 public class PluginVersionResolutionException extends Exception {
29 private final String groupId;
30
31 private final String artifactId;
32
33 private final String baseMessage;
34
35 public PluginVersionResolutionException(String groupId, String artifactId, String baseMessage, Throwable cause) {
36 super("Error resolving version for plugin '" + groupId + ":" + artifactId + "': " + baseMessage, cause);
37
38 this.groupId = groupId;
39 this.artifactId = artifactId;
40 this.baseMessage = baseMessage;
41 }
42
43 public PluginVersionResolutionException(String groupId, String artifactId, String baseMessage) {
44 super("Error resolving version for plugin '" + groupId + ":" + artifactId + "': " + baseMessage);
45
46 this.groupId = groupId;
47 this.artifactId = artifactId;
48 this.baseMessage = baseMessage;
49 }
50
51 public PluginVersionResolutionException(
52 String groupId,
53 String artifactId,
54 LocalRepository localRepository,
55 List<RemoteRepository> remoteRepositories,
56 String baseMessage) {
57 super("Error resolving version for plugin '" + groupId + ":" + artifactId + "' from the repositories "
58 + format(localRepository, remoteRepositories) + ": " + baseMessage);
59
60 this.groupId = groupId;
61 this.artifactId = artifactId;
62 this.baseMessage = baseMessage;
63 }
64
65 public String getGroupId() {
66 return groupId;
67 }
68
69 public String getArtifactId() {
70 return artifactId;
71 }
72
73 public String getBaseMessage() {
74 return baseMessage;
75 }
76
77 private static String format(LocalRepository localRepository, List<RemoteRepository> remoteRepositories) {
78 StringBuilder repos = new StringBuilder("[");
79
80 if (localRepository != null) {
81 repos.append(localRepository.getId())
82 .append(" (")
83 .append(localRepository.getBasedir())
84 .append(")");
85 }
86
87 if (remoteRepositories != null && !remoteRepositories.isEmpty()) {
88 for (RemoteRepository repository : remoteRepositories) {
89 repos.append(", ");
90
91 if (repository != null) {
92 repos.append(repository.getId())
93 .append(" (")
94 .append(repository.getUrl())
95 .append(")");
96 }
97 }
98 }
99
100 repos.append("]");
101
102 return repos.toString();
103 }
104 }