View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugin;
20  
21  import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
22  import org.apache.maven.model.Plugin;
23  import org.apache.maven.plugin.descriptor.MojoDescriptor;
24  import org.apache.maven.plugin.descriptor.PluginDescriptor;
25  import org.apache.maven.project.MavenProject;
26  import org.codehaus.plexus.PlexusContainerException;
27  import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
28  import org.codehaus.plexus.component.repository.exception.ComponentRepositoryException;
29  import org.codehaus.plexus.configuration.PlexusConfigurationException;
30  
31  /**
32   * Exception in the plugin manager.
33   *
34   */
35  public class PluginManagerException extends Exception {
36  
37      private final String pluginGroupId;
38  
39      private final String pluginArtifactId;
40  
41      private final String pluginVersion;
42  
43      private String goal;
44  
45      private MavenProject project;
46  
47      protected PluginManagerException(Plugin plugin, String message, MavenProject project, Throwable cause) {
48          super(message, cause);
49  
50          this.project = project;
51          pluginGroupId = plugin.getGroupId();
52          pluginArtifactId = plugin.getArtifactId();
53          pluginVersion = plugin.getVersion();
54      }
55  
56      public PluginManagerException(Plugin plugin, String message, Throwable cause) {
57          super(message, cause);
58  
59          pluginGroupId = plugin.getGroupId();
60          pluginArtifactId = plugin.getArtifactId();
61          pluginVersion = plugin.getVersion();
62      }
63  
64      protected PluginManagerException(MojoDescriptor mojoDescriptor, String message, Throwable cause) {
65          super(message, cause);
66          pluginGroupId = mojoDescriptor.getPluginDescriptor().getGroupId();
67          pluginArtifactId = mojoDescriptor.getPluginDescriptor().getArtifactId();
68          pluginVersion = mojoDescriptor.getPluginDescriptor().getVersion();
69          goal = mojoDescriptor.getGoal();
70      }
71  
72      protected PluginManagerException(MojoDescriptor mojoDescriptor, MavenProject project, String message) {
73          super(message);
74          this.project = project;
75          pluginGroupId = mojoDescriptor.getPluginDescriptor().getGroupId();
76          pluginArtifactId = mojoDescriptor.getPluginDescriptor().getArtifactId();
77          pluginVersion = mojoDescriptor.getPluginDescriptor().getVersion();
78          goal = mojoDescriptor.getGoal();
79      }
80  
81      protected PluginManagerException(
82              MojoDescriptor mojoDescriptor, MavenProject project, String message, Throwable cause) {
83          super(message, cause);
84          this.project = project;
85          pluginGroupId = mojoDescriptor.getPluginDescriptor().getGroupId();
86          pluginArtifactId = mojoDescriptor.getPluginDescriptor().getArtifactId();
87          pluginVersion = mojoDescriptor.getPluginDescriptor().getVersion();
88          goal = mojoDescriptor.getGoal();
89      }
90  
91      public PluginManagerException(Plugin plugin, InvalidVersionSpecificationException cause) {
92          super(cause);
93  
94          pluginGroupId = plugin.getGroupId();
95          pluginArtifactId = plugin.getArtifactId();
96          pluginVersion = plugin.getVersion();
97      }
98  
99      public PluginManagerException(Plugin plugin, String message, PlexusConfigurationException cause) {
100         super(message, cause);
101 
102         pluginGroupId = plugin.getGroupId();
103         pluginArtifactId = plugin.getArtifactId();
104         pluginVersion = plugin.getVersion();
105     }
106 
107     public PluginManagerException(Plugin plugin, String message, ComponentRepositoryException cause) {
108         super(message, cause);
109 
110         pluginGroupId = plugin.getGroupId();
111         pluginArtifactId = plugin.getArtifactId();
112         pluginVersion = plugin.getVersion();
113     }
114 
115     public PluginManagerException(
116             MojoDescriptor mojoDescriptor, MavenProject project, String message, NoSuchRealmException cause) {
117         super(message, cause);
118 
119         this.project = project;
120         pluginGroupId = mojoDescriptor.getPluginDescriptor().getGroupId();
121         pluginArtifactId = mojoDescriptor.getPluginDescriptor().getArtifactId();
122         pluginVersion = mojoDescriptor.getPluginDescriptor().getVersion();
123         goal = mojoDescriptor.getGoal();
124     }
125 
126     public PluginManagerException(
127             MojoDescriptor mojoDescriptor, String message, MavenProject project, PlexusContainerException cause) {
128         super(message, cause);
129 
130         this.project = project;
131 
132         PluginDescriptor pd = mojoDescriptor.getPluginDescriptor();
133         pluginGroupId = pd.getGroupId();
134         pluginArtifactId = pd.getArtifactId();
135         pluginVersion = pd.getVersion();
136 
137         goal = mojoDescriptor.getGoal();
138     }
139 
140     public PluginManagerException(Plugin plugin, String message, PlexusContainerException cause) {
141         super(message, cause);
142 
143         pluginGroupId = plugin.getGroupId();
144         pluginArtifactId = plugin.getArtifactId();
145         pluginVersion = plugin.getVersion();
146     }
147 
148     public PluginManagerException(Plugin plugin, String message, MavenProject project) {
149         super(message);
150 
151         pluginGroupId = plugin.getGroupId();
152         pluginArtifactId = plugin.getArtifactId();
153         pluginVersion = plugin.getVersion();
154         this.project = project;
155     }
156 
157     public String getPluginGroupId() {
158         return pluginGroupId;
159     }
160 
161     public String getPluginArtifactId() {
162         return pluginArtifactId;
163     }
164 
165     public String getPluginVersion() {
166         return pluginVersion;
167     }
168 
169     public String getGoal() {
170         return goal;
171     }
172 
173     public MavenProject getProject() {
174         return project;
175     }
176 }