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  /**
28   * PluginVersionResolutionException
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 }