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