View Javadoc
1   package org.apache.maven.plugin.version;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.List;
23  
24  import org.eclipse.aether.repository.LocalRepository;
25  import org.eclipse.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 }