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   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
35   */
36  public class PluginManagerException extends Exception {
37  
38      private final String pluginGroupId;
39  
40      private final String pluginArtifactId;
41  
42      private final String pluginVersion;
43  
44      private String goal;
45  
46      private MavenProject project;
47  
48      protected PluginManagerException(Plugin plugin, String message, MavenProject project, Throwable cause) {
49          super(message, cause);
50  
51          this.project = project;
52          pluginGroupId = plugin.getGroupId();
53          pluginArtifactId = plugin.getArtifactId();
54          pluginVersion = plugin.getVersion();
55      }
56  
57      public PluginManagerException(Plugin plugin, String message, Throwable cause) {
58          super(message, cause);
59  
60          pluginGroupId = plugin.getGroupId();
61          pluginArtifactId = plugin.getArtifactId();
62          pluginVersion = plugin.getVersion();
63      }
64  
65      protected PluginManagerException(MojoDescriptor mojoDescriptor, String message, Throwable cause) {
66          super(message, cause);
67          pluginGroupId = mojoDescriptor.getPluginDescriptor().getGroupId();
68          pluginArtifactId = mojoDescriptor.getPluginDescriptor().getArtifactId();
69          pluginVersion = mojoDescriptor.getPluginDescriptor().getVersion();
70          goal = mojoDescriptor.getGoal();
71      }
72  
73      protected PluginManagerException(MojoDescriptor mojoDescriptor, MavenProject project, String message) {
74          super(message);
75          this.project = project;
76          pluginGroupId = mojoDescriptor.getPluginDescriptor().getGroupId();
77          pluginArtifactId = mojoDescriptor.getPluginDescriptor().getArtifactId();
78          pluginVersion = mojoDescriptor.getPluginDescriptor().getVersion();
79          goal = mojoDescriptor.getGoal();
80      }
81  
82      protected PluginManagerException(
83              MojoDescriptor mojoDescriptor, MavenProject project, String message, Throwable cause) {
84          super(message, cause);
85          this.project = project;
86          pluginGroupId = mojoDescriptor.getPluginDescriptor().getGroupId();
87          pluginArtifactId = mojoDescriptor.getPluginDescriptor().getArtifactId();
88          pluginVersion = mojoDescriptor.getPluginDescriptor().getVersion();
89          goal = mojoDescriptor.getGoal();
90      }
91  
92      public PluginManagerException(Plugin plugin, InvalidVersionSpecificationException cause) {
93          super(cause);
94  
95          pluginGroupId = plugin.getGroupId();
96          pluginArtifactId = plugin.getArtifactId();
97          pluginVersion = plugin.getVersion();
98      }
99  
100     public PluginManagerException(Plugin plugin, String message, PlexusConfigurationException cause) {
101         super(message, cause);
102 
103         pluginGroupId = plugin.getGroupId();
104         pluginArtifactId = plugin.getArtifactId();
105         pluginVersion = plugin.getVersion();
106     }
107 
108     public PluginManagerException(Plugin plugin, String message, ComponentRepositoryException cause) {
109         super(message, cause);
110 
111         pluginGroupId = plugin.getGroupId();
112         pluginArtifactId = plugin.getArtifactId();
113         pluginVersion = plugin.getVersion();
114     }
115 
116     public PluginManagerException(
117             MojoDescriptor mojoDescriptor, MavenProject project, String message, NoSuchRealmException cause) {
118         super(message, cause);
119 
120         this.project = project;
121         pluginGroupId = mojoDescriptor.getPluginDescriptor().getGroupId();
122         pluginArtifactId = mojoDescriptor.getPluginDescriptor().getArtifactId();
123         pluginVersion = mojoDescriptor.getPluginDescriptor().getVersion();
124         goal = mojoDescriptor.getGoal();
125     }
126 
127     public PluginManagerException(
128             MojoDescriptor mojoDescriptor, String message, MavenProject project, PlexusContainerException cause) {
129         super(message, cause);
130 
131         this.project = project;
132 
133         PluginDescriptor pd = mojoDescriptor.getPluginDescriptor();
134         pluginGroupId = pd.getGroupId();
135         pluginArtifactId = pd.getArtifactId();
136         pluginVersion = pd.getVersion();
137 
138         goal = mojoDescriptor.getGoal();
139     }
140 
141     public PluginManagerException(Plugin plugin, String message, PlexusContainerException cause) {
142         super(message, cause);
143 
144         pluginGroupId = plugin.getGroupId();
145         pluginArtifactId = plugin.getArtifactId();
146         pluginVersion = plugin.getVersion();
147     }
148 
149     public PluginManagerException(Plugin plugin, String message, MavenProject project) {
150         super(message);
151 
152         pluginGroupId = plugin.getGroupId();
153         pluginArtifactId = plugin.getArtifactId();
154         pluginVersion = plugin.getVersion();
155         this.project = project;
156     }
157 
158     public String getPluginGroupId() {
159         return pluginGroupId;
160     }
161 
162     public String getPluginArtifactId() {
163         return pluginArtifactId;
164     }
165 
166     public String getPluginVersion() {
167         return pluginVersion;
168     }
169 
170     public String getGoal() {
171         return goal;
172     }
173 
174     public MavenProject getProject() {
175         return project;
176     }
177 }