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.sonatype.aether.repository.LocalRepository;
25 import org.sonatype.aether.repository.RemoteRepository;
26
27 public class PluginVersionResolutionException
28 extends Exception
29 {
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 {
38 super( "Error resolving version for plugin \'" + groupId + ":" + artifactId + "\': " + baseMessage, cause );
39
40 this.groupId = groupId;
41 this.artifactId = artifactId;
42 this.baseMessage = baseMessage;
43 }
44
45 public PluginVersionResolutionException( String groupId, String artifactId, String baseMessage )
46 {
47 super( "Error resolving version for plugin \'" + groupId + ":" + artifactId + "\': " + baseMessage );
48
49 this.groupId = groupId;
50 this.artifactId = artifactId;
51 this.baseMessage = baseMessage;
52 }
53
54 public PluginVersionResolutionException( String groupId, String artifactId, LocalRepository localRepository,
55 List<RemoteRepository> remoteRepositories, String baseMessage )
56 {
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 {
67 return groupId;
68 }
69
70 public String getArtifactId()
71 {
72 return artifactId;
73 }
74
75 public String getBaseMessage()
76 {
77 return baseMessage;
78 }
79
80 private static String format( LocalRepository localRepository, List<RemoteRepository> remoteRepositories )
81 {
82 String repos = "[";
83
84 if ( localRepository != null )
85 {
86 repos += localRepository.getId() + " (" + localRepository.getBasedir() + ")";
87 }
88
89 if ( remoteRepositories != null && !remoteRepositories.isEmpty() )
90 {
91 for ( RemoteRepository repository : remoteRepositories )
92 {
93 repos += ", ";
94
95 if ( repository != null )
96 {
97 repos += repository.getId() + " (" + repository.getUrl() + ")";
98 }
99 }
100 }
101
102 repos += "]";
103
104 return repos;
105 }
106
107 }