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          StringBuilder repos = new StringBuilder("[");
80  
81          if (localRepository != null) {
82              repos.append(localRepository.getId())
83                      .append(" (")
84                      .append(localRepository.getBasedir())
85                      .append(")");
86          }
87  
88          if (remoteRepositories != null && !remoteRepositories.isEmpty()) {
89              for (RemoteRepository repository : remoteRepositories) {
90                  repos.append(", ");
91  
92                  if (repository != null) {
93                      repos.append(repository.getId())
94                              .append(" (")
95                              .append(repository.getUrl())
96                              .append(")");
97                  }
98              }
99          }
100 
101         repos.append("]");
102 
103         return repos.toString();
104     }
105 }