001    package org.apache.maven.plugin;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *  http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
023    import org.apache.maven.model.Plugin;
024    import org.apache.maven.plugin.descriptor.MojoDescriptor;
025    import org.apache.maven.plugin.descriptor.PluginDescriptor;
026    import org.apache.maven.project.MavenProject;
027    import org.codehaus.plexus.PlexusContainerException;
028    import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
029    import org.codehaus.plexus.component.repository.exception.ComponentRepositoryException;
030    import org.codehaus.plexus.configuration.PlexusConfigurationException;
031    
032    /**
033     * Exception in the plugin manager.
034     *
035     * @author <a href="mailto:brett@apache.org">Brett Porter</a>
036     */
037    public class PluginManagerException
038        extends Exception
039    {
040    
041        private final String pluginGroupId;
042    
043        private final String pluginArtifactId;
044    
045        private final String pluginVersion;
046    
047        private String goal;
048    
049        private MavenProject project;
050    
051        protected PluginManagerException( Plugin plugin, String message, MavenProject project, Throwable cause )
052        {
053            super( message, cause );
054    
055            this.project = project;
056            pluginGroupId = plugin.getGroupId();
057            pluginArtifactId = plugin.getArtifactId();
058            pluginVersion = plugin.getVersion();
059        }
060    
061        public PluginManagerException( Plugin plugin, String message, Throwable cause )
062        {
063            super( message, cause );
064    
065            pluginGroupId = plugin.getGroupId();
066            pluginArtifactId = plugin.getArtifactId();
067            pluginVersion = plugin.getVersion();
068        }
069    
070        protected PluginManagerException( MojoDescriptor mojoDescriptor, String message, Throwable cause )
071        {
072            super( message, cause );
073            pluginGroupId = mojoDescriptor.getPluginDescriptor().getGroupId();
074            pluginArtifactId = mojoDescriptor.getPluginDescriptor().getArtifactId();
075            pluginVersion = mojoDescriptor.getPluginDescriptor().getVersion();
076            goal = mojoDescriptor.getGoal();
077        }
078    
079        protected PluginManagerException( MojoDescriptor mojoDescriptor, MavenProject project, String message )
080        {
081            super( message );
082            this.project = project;
083            pluginGroupId = mojoDescriptor.getPluginDescriptor().getGroupId();
084            pluginArtifactId = mojoDescriptor.getPluginDescriptor().getArtifactId();
085            pluginVersion = mojoDescriptor.getPluginDescriptor().getVersion();
086            goal = mojoDescriptor.getGoal();
087        }
088    
089        protected PluginManagerException( MojoDescriptor mojoDescriptor, MavenProject project, String message,
090                                          Throwable cause )
091        {
092            super( message, cause );
093            this.project = project;
094            pluginGroupId = mojoDescriptor.getPluginDescriptor().getGroupId();
095            pluginArtifactId = mojoDescriptor.getPluginDescriptor().getArtifactId();
096            pluginVersion = mojoDescriptor.getPluginDescriptor().getVersion();
097            goal = mojoDescriptor.getGoal();
098        }
099    
100        public PluginManagerException( Plugin plugin, InvalidVersionSpecificationException cause )
101        {
102            super( cause );
103    
104            pluginGroupId = plugin.getGroupId();
105            pluginArtifactId = plugin.getArtifactId();
106            pluginVersion = plugin.getVersion();
107        }
108    
109        public PluginManagerException( Plugin plugin, String message, PlexusConfigurationException cause )
110        {
111            super( message, cause );
112    
113            pluginGroupId = plugin.getGroupId();
114            pluginArtifactId = plugin.getArtifactId();
115            pluginVersion = plugin.getVersion();
116        }
117    
118        public PluginManagerException( Plugin plugin, String message, ComponentRepositoryException cause )
119        {
120            super( message, cause );
121    
122            pluginGroupId = plugin.getGroupId();
123            pluginArtifactId = plugin.getArtifactId();
124            pluginVersion = plugin.getVersion();
125        }
126    
127        public PluginManagerException( MojoDescriptor mojoDescriptor, MavenProject project, String message,
128                                       NoSuchRealmException cause )
129        {
130            super( message, cause );
131    
132            this.project = project;
133            pluginGroupId = mojoDescriptor.getPluginDescriptor().getGroupId();
134            pluginArtifactId = mojoDescriptor.getPluginDescriptor().getArtifactId();
135            pluginVersion = mojoDescriptor.getPluginDescriptor().getVersion();
136            goal = mojoDescriptor.getGoal();
137        }
138    
139        public PluginManagerException( MojoDescriptor mojoDescriptor, String message, MavenProject project,
140                                       PlexusContainerException cause )
141        {
142            super( message, cause );
143    
144            this.project = project;
145    
146            PluginDescriptor pd = mojoDescriptor.getPluginDescriptor();
147            pluginGroupId = pd.getGroupId();
148            pluginArtifactId = pd.getArtifactId();
149            pluginVersion = pd.getVersion();
150    
151            goal = mojoDescriptor.getGoal();
152        }
153    
154        public PluginManagerException( Plugin plugin, String message, PlexusContainerException cause )
155        {
156            super( message, cause );
157    
158            pluginGroupId = plugin.getGroupId();
159            pluginArtifactId = plugin.getArtifactId();
160            pluginVersion = plugin.getVersion();
161        }
162    
163        public PluginManagerException( Plugin plugin, String message, MavenProject project )
164        {
165            super( message );
166    
167            pluginGroupId = plugin.getGroupId();
168            pluginArtifactId = plugin.getArtifactId();
169            pluginVersion = plugin.getVersion();
170            this.project = project;
171        }
172    
173        public String getPluginGroupId()
174        {
175            return pluginGroupId;
176        }
177    
178        public String getPluginArtifactId()
179        {
180            return pluginArtifactId;
181        }
182    
183        public String getPluginVersion()
184        {
185            return pluginVersion;
186        }
187    
188        public String getGoal()
189        {
190            return goal;
191        }
192    
193        public MavenProject getProject()
194        {
195            return project;
196        }
197    }