PR: MNG-122

exception clean up phase 2

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@320675 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-10-13 06:50:22 +00:00
parent 5de6418c69
commit 1901992586
15 changed files with 228 additions and 148 deletions

View File

@ -32,6 +32,7 @@ import org.apache.maven.artifact.resolver.filter.TypeArtifactFilter;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Repository;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.artifact.MavenMetadataSource;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
@ -172,6 +173,10 @@ public class DependenciesTask
// TODO: improve handling
throw new BuildException( "Unable to locate artifact", e );
}
catch ( InvalidDependencyVersionException e )
{
throw new BuildException( e.getMessage(), e );
}
if ( pathId != null && getProject().getReference( pathId ) != null )
{

View File

@ -23,7 +23,7 @@ package org.apache.maven;
* @version $Id$
*/
public class BuildFailureException
extends Throwable
extends Exception
{
public BuildFailureException( String message )
{

View File

@ -196,6 +196,10 @@ public class DefaultMaven
{
return dispatchErrorResponse( dispatcher, event, request.getBaseDirectory(), e );
}
catch ( BuildFailureException e )
{
return dispatchErrorResponse( dispatcher, event, request.getBaseDirectory(), e );
}
ReactorManager rm;
try
@ -409,7 +413,7 @@ public class DefaultMaven
private List collectProjects( List files, ArtifactRepository localRepository, boolean recursive, Settings settings,
ProfileManager globalProfileManager, boolean isRoot )
throws ArtifactResolutionException, ProjectBuildingException, ProfileActivationException,
MavenExecutionException
MavenExecutionException, BuildFailureException
{
List projects = new ArrayList( files.size() );
@ -435,17 +439,10 @@ public class DefaultMaven
if ( project.getPrerequisites() != null && project.getPrerequisites().getMaven() != null )
{
DefaultArtifactVersion version = new DefaultArtifactVersion( project.getPrerequisites().getMaven() );
try
if ( runtimeInformation.getApplicationVersion().compareTo( version ) < 0 )
{
if ( runtimeInformation.getApplicationVersion().compareTo( version ) < 0 )
{
throw new ProjectBuildingException( project.getId(), "Unable to build project '" +
project.getFile() + "; it requires Maven version " + version.toString() );
}
}
catch ( IOException e )
{
throw new MavenExecutionException( "Unable to get Maven application version", e );
throw new BuildFailureException( "Unable to build project '" + project.getFile() +
"; it requires Maven version " + version.toString() );
}
}

View File

@ -18,10 +18,12 @@ package org.apache.maven.execution;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.codehaus.plexus.util.IOUtil;
import java.io.InputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
@ -31,30 +33,41 @@ import java.util.Properties;
* @version $Id$
*/
public class DefaultRuntimeInformation
implements RuntimeInformation
implements RuntimeInformation, Initializable
{
private ArtifactVersion applicationVersion;
public ArtifactVersion getApplicationVersion()
throws IOException
{
if ( applicationVersion == null )
{
InputStream resourceAsStream = null;
try
{
Properties properties = new Properties();
resourceAsStream = getClass().getClassLoader().getResourceAsStream(
"META-INF/maven/org.apache.maven/maven-core/pom.properties" );
properties.load( resourceAsStream );
applicationVersion = new DefaultArtifactVersion( properties.getProperty( "version" ) );
}
finally
{
IOUtil.close( resourceAsStream );
}
}
return applicationVersion;
}
public void initialize()
throws InitializationException
{
InputStream resourceAsStream = null;
try
{
Properties properties = new Properties();
resourceAsStream = getClass().getClassLoader().getResourceAsStream(
"META-INF/maven/org.apache.maven/maven-core/pom.properties" );
properties.load( resourceAsStream );
String property = properties.getProperty( "version" );
if ( property == null )
{
throw new InitializationException( "maven-core properties did not include the version" );
}
applicationVersion = new DefaultArtifactVersion( property );
}
catch ( IOException e )
{
throw new InitializationException( "Unable to read properties file from maven-core", e );
}
finally
{
IOUtil.close( resourceAsStream );
}
}
}

View File

@ -18,8 +18,6 @@ package org.apache.maven.execution;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import java.io.IOException;
/**
* Describes runtime information about the application.
*
@ -28,6 +26,5 @@ import java.io.IOException;
*/
public interface RuntimeInformation
{
ArtifactVersion getApplicationVersion()
throws IOException;
ArtifactVersion getApplicationVersion();
}

View File

@ -35,9 +35,11 @@ import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.ReportSet;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.MavenEvents;
import org.apache.maven.plugin.InvalidPluginException;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.PluginConfigurationException;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.plugin.PluginManagerException;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
@ -46,6 +48,7 @@ import org.apache.maven.plugin.lifecycle.Execution;
import org.apache.maven.plugin.lifecycle.Phase;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.reporting.MavenReport;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.PlexusContainerException;
@ -368,6 +371,13 @@ public class DefaultLifecycleExecutor
// TODO: should be dispatchFailure?
dispatcher.dispatchError( event, target, e );
handleExecutionFailure( rm, project, e, task, buildStartTime );
}
catch ( InvalidDependencyVersionException e )
{
// TODO: should be dispatchFailure?
dispatcher.dispatchError( event, target, e );
handleExecutionFailure( rm, project, e, task, buildStartTime );
}
}
@ -516,7 +526,7 @@ public class DefaultLifecycleExecutor
private void executeGoal( String task, MavenSession session, MavenProject project, MavenExecutionResponse response )
throws LifecycleExecutionException, ArtifactNotFoundException, MojoExecutionException,
ArtifactResolutionException, MojoFailureException
ArtifactResolutionException, MojoFailureException, InvalidDependencyVersionException
{
if ( getPhaseToLifecycleMap().containsKey( task ) )
{
@ -535,7 +545,7 @@ public class DefaultLifecycleExecutor
private void executeGoalWithLifecycle( String task, MavenSession session, Map lifecycleMappings,
MavenProject project, MavenExecutionResponse response, Lifecycle lifecycle )
throws ArtifactResolutionException, LifecycleExecutionException, MojoExecutionException, MojoFailureException,
ArtifactNotFoundException
ArtifactNotFoundException, InvalidDependencyVersionException
{
List goals = processGoalChain( task, lifecycleMappings, lifecycle );
@ -552,7 +562,7 @@ public class DefaultLifecycleExecutor
private void executeStandaloneGoal( String task, MavenSession session, MavenProject project,
MavenExecutionResponse response )
throws ArtifactResolutionException, LifecycleExecutionException, MojoExecutionException, MojoFailureException,
ArtifactNotFoundException
ArtifactNotFoundException, InvalidDependencyVersionException
{
// guaranteed to come from the CLI and not be part of a phase
MojoDescriptor mojoDescriptor = getMojoDescriptor( task, session, project, task, true );
@ -561,7 +571,7 @@ public class DefaultLifecycleExecutor
private void executeGoals( List goals, MavenSession session, MavenProject project, MavenExecutionResponse response )
throws LifecycleExecutionException, MojoExecutionException, ArtifactResolutionException, MojoFailureException,
ArtifactNotFoundException
ArtifactNotFoundException, InvalidDependencyVersionException
{
for ( Iterator i = goals.iterator(); i.hasNext(); )
{
@ -598,8 +608,8 @@ public class DefaultLifecycleExecutor
}
catch ( PluginManagerException e )
{
throw new LifecycleExecutionException(
"Internal error in the plugin manager executing goal '" + mojoDescriptor.getId(), e );
throw new LifecycleExecutionException( "Internal error in the plugin manager executing goal '" +
mojoDescriptor.getId() + "': " + e.getMessage(), e );
}
}
}
@ -724,6 +734,11 @@ public class DefaultLifecycleExecutor
}
}
catch ( PluginManagerException e )
{
throw new LifecycleExecutionException(
"Error getting reports from the plugin '" + reportPlugin.getKey() + "': " + e.getMessage(), e );
}
catch ( PluginConfigurationException e )
{
throw new LifecycleExecutionException(
"Error getting reports from the plugin '" + reportPlugin.getKey() + "'", e );
@ -736,7 +751,7 @@ public class DefaultLifecycleExecutor
private void forkLifecycle( MojoDescriptor mojoDescriptor, MavenSession session, MavenProject project,
MavenExecutionResponse response )
throws LifecycleExecutionException, MojoExecutionException, ArtifactResolutionException, MojoFailureException,
ArtifactNotFoundException
ArtifactNotFoundException, InvalidDependencyVersionException
{
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
getLogger().info( "Preparing " + pluginDescriptor.getGoalPrefix() + ":" + mojoDescriptor.getGoal() );
@ -767,7 +782,7 @@ public class DefaultLifecycleExecutor
private void forkProjectLifecycle( MojoDescriptor mojoDescriptor, MavenSession session, MavenProject project,
MavenExecutionResponse response )
throws ArtifactResolutionException, LifecycleExecutionException, MojoExecutionException, MojoFailureException,
ArtifactNotFoundException
ArtifactNotFoundException, InvalidDependencyVersionException
{
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
@ -1015,7 +1030,9 @@ public class DefaultLifecycleExecutor
ArtifactRepository localRepository )
throws ArtifactResolutionException, ArtifactNotFoundException, LifecycleExecutionException
{
for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext(); )
Object pluginComponent = null;
for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext() && pluginComponent == null; )
{
Plugin plugin = (Plugin) i.next();
@ -1026,7 +1043,7 @@ public class DefaultLifecycleExecutor
// TODO: if moved to the plugin manager we already have the descriptor from above and so do can lookup the container directly
try
{
return pluginManager.getPluginComponent( plugin, role, roleHint );
pluginComponent = pluginManager.getPluginComponent( plugin, role, roleHint );
}
catch ( ComponentLookupException e )
{
@ -1035,11 +1052,11 @@ public class DefaultLifecycleExecutor
catch ( PluginManagerException e )
{
throw new LifecycleExecutionException(
"Error getting extensions from the plugin '" + plugin.getKey() + "'", e );
"Error getting extensions from the plugin '" + plugin.getKey() + "': " + e.getMessage(), e );
}
}
}
return null;
return pluginComponent;
}
/**
@ -1070,7 +1087,8 @@ public class DefaultLifecycleExecutor
}
catch ( PluginManagerException e )
{
throw new LifecycleExecutionException( "Error looking up available components from a plugin", e );
throw new LifecycleExecutionException( "Error looking up available components from plugin '" +
plugin.getKey() + "': " + e.getMessage(), e );
}
// shudder...
@ -1140,7 +1158,8 @@ public class DefaultLifecycleExecutor
}
catch ( PluginManagerException e )
{
throw new LifecycleExecutionException( "Internal error in the plugin manager", e );
throw new LifecycleExecutionException(
"Internal error in the plugin manager getting plugin '" + plugin.getKey() + "': " + e.getMessage(), e );
}
catch ( PluginVersionResolutionException e )
{
@ -1150,6 +1169,10 @@ public class DefaultLifecycleExecutor
{
throw new LifecycleExecutionException( "Error resolving plugin version", e );
}
catch ( InvalidPluginException e )
{
throw new LifecycleExecutionException( "Error resolving plugin version", e );
}
return pluginDescriptor;
}
@ -1163,7 +1186,8 @@ public class DefaultLifecycleExecutor
}
catch ( PluginManagerException e )
{
throw new LifecycleExecutionException( "Internal error in the plugin manager", e );
throw new LifecycleExecutionException(
"Internal error in the plugin manager getting report '" + plugin.getKey() + "': " + e.getMessage(), e );
}
catch ( PluginVersionResolutionException e )
{
@ -1173,6 +1197,10 @@ public class DefaultLifecycleExecutor
{
throw new LifecycleExecutionException( "Error resolving plugin version", e );
}
catch ( InvalidPluginException e )
{
throw new LifecycleExecutionException( "Error resolving plugin version", e );
}
return pluginDescriptor;
}
@ -1293,15 +1321,7 @@ public class DefaultLifecycleExecutor
// 2. look in the repository via search groups
if ( pluginDescriptor == null )
{
try
{
plugin = pluginManager.getPluginDefinitionForPrefix( prefix, session, project );
}
catch ( PluginManagerException e )
{
throw new LifecycleExecutionException(
"Cannot resolve plugin-prefix: \'" + prefix + "\' from plugin mappings metadata.", e );
}
plugin = pluginManager.getPluginDefinitionForPrefix( prefix, session, project );
}
else
{

View File

@ -49,6 +49,7 @@ import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.artifact.MavenMetadataSource;
import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.reporting.MavenReport;
@ -74,7 +75,6 @@ import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
@ -136,7 +136,6 @@ public class DefaultPluginManager
}
public Plugin getPluginDefinitionForPrefix( String prefix, MavenSession session, MavenProject project )
throws PluginManagerException
{
// TODO: since this is only used in the lifecycle executor, maybe it should be moved there? There is no other
// use for the mapping manager in here
@ -147,8 +146,8 @@ public class DefaultPluginManager
public PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings,
ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException,
ArtifactNotFoundException, InvalidVersionSpecificationException
throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException
{
// TODO: this should be possibly outside
// All version-resolution logic has been moved to DefaultPluginVersionManager.
@ -164,8 +163,8 @@ public class DefaultPluginManager
private PluginDescriptor verifyVersionedPlugin( Plugin plugin, MavenProject project,
ArtifactRepository localRepository )
throws PluginVersionResolutionException, PluginManagerException, ArtifactNotFoundException,
ArtifactResolutionException, InvalidVersionSpecificationException
throws PluginVersionResolutionException, ArtifactNotFoundException, ArtifactResolutionException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException
{
// TODO: this might result in an artifact "RELEASE" being resolved continuously
// FIXME: need to find out how a plugin gets marked as 'installed'
@ -239,7 +238,7 @@ public class DefaultPluginManager
* manager which executes before the plugin is instantiated
*/
private void checkRequiredMavenVersion( Plugin plugin, ArtifactRepository localRepository, List remoteRepositories )
throws PluginVersionResolutionException, PluginManagerException
throws PluginVersionResolutionException
{
try
{
@ -264,15 +263,11 @@ public class DefaultPluginManager
throw new PluginVersionResolutionException( plugin.getGroupId(), plugin.getArtifactId(),
"Unable to build project for plugin", e );
}
catch ( IOException e )
{
throw new PluginManagerException( "Unable to determine Maven version for comparison", e );
}
}
protected void addPlugin( Plugin plugin, Artifact pluginArtifact, MavenProject project,
ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginManagerException, ArtifactNotFoundException
throws PluginManagerException, InvalidPluginException
{
PlexusContainer child;
try
@ -284,7 +279,8 @@ public class DefaultPluginManager
}
catch ( PlexusContainerException e )
{
throw new PluginManagerException( "Failed to create plugin container for plugin '" + plugin + "'", e );
throw new PluginManagerException(
"Failed to create plugin container for plugin '" + plugin + "': " + e.getMessage(), e );
}
// this plugin's descriptor should have been discovered in the child creation, so we should be able to
@ -305,9 +301,9 @@ public class DefaultPluginManager
addedPlugin.setIntroducedDependencyArtifacts( artifacts );
}
catch ( ProjectBuildingException e )
catch ( InvalidDependencyVersionException e )
{
throw new PluginManagerException( "Error getting plugin dependencies", e );
throw new InvalidPluginException( "Plugin '" + plugin + "' is invalid: " + e.getMessage(), e );
}
}
@ -316,8 +312,8 @@ public class DefaultPluginManager
// ----------------------------------------------------------------------
public void executeMojo( MavenProject project, MojoExecution mojoExecution, MavenSession session )
throws ArtifactResolutionException, PluginManagerException, MojoExecutionException, MojoFailureException,
ArtifactNotFoundException
throws ArtifactResolutionException, MojoExecutionException, MojoFailureException, ArtifactNotFoundException,
InvalidDependencyVersionException, PluginManagerException
{
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
@ -352,16 +348,8 @@ public class DefaultPluginManager
for ( Iterator i = projects.iterator(); i.hasNext(); )
{
MavenProject p = (MavenProject) i.next();
try
{
resolveTransitiveDependencies( session, artifactResolver,
mojoDescriptor.isDependencyResolutionRequired(), artifactFactory,
p );
}
catch ( ProjectBuildingException e )
{
throw new PluginManagerException( e.getMessage(), e );
}
resolveTransitiveDependencies( session, artifactResolver,
mojoDescriptor.isDependencyResolutionRequired(), artifactFactory, p );
}
downloadDependencies( project, session, artifactResolver );
@ -393,10 +381,6 @@ public class DefaultPluginManager
String msg = "Error configuring plugin for execution of '" + goalName + "'.";
throw new MojoExecutionException( msg, e );
}
catch ( ComponentLookupException e )
{
throw new MojoExecutionException( "Error looking up mojo: " + goalName, e );
}
// Event monitoring.
String event = MavenEvents.MOJO_EXECUTION;
@ -456,7 +440,7 @@ public class DefaultPluginManager
}
public MavenReport getReport( MavenProject project, MojoExecution mojoExecution, MavenSession session )
throws PluginManagerException, ArtifactNotFoundException
throws ArtifactNotFoundException, PluginConfigurationException, PluginManagerException
{
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
PluginDescriptor descriptor = mojoDescriptor.getPluginDescriptor();
@ -467,25 +451,12 @@ public class DefaultPluginManager
dom = Xpp3Dom.mergeXpp3Dom( dom, mojoExecution.getConfiguration() );
}
MavenReport reportMojo;
try
{
reportMojo = (MavenReport) getConfiguredMojo( session, dom, project, true, mojoExecution );
}
catch ( ComponentLookupException e )
{
throw new PluginManagerException( "Error looking up report: ", e );
}
catch ( PluginConfigurationException e )
{
throw new PluginManagerException( "Error configuring report: ", e );
}
return reportMojo;
return (MavenReport) getConfiguredMojo( session, dom, project, true, mojoExecution );
}
public PluginDescriptor verifyReportPlugin( ReportPlugin reportPlugin, MavenProject project, MavenSession session )
throws PluginVersionResolutionException, ArtifactResolutionException, PluginManagerException,
ArtifactNotFoundException, InvalidVersionSpecificationException
throws PluginVersionResolutionException, ArtifactResolutionException, ArtifactNotFoundException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException
{
String version = reportPlugin.getVersion();
@ -516,7 +487,7 @@ public class DefaultPluginManager
if ( pluginContainer == null )
{
throw new PluginManagerException( "Cannot find PlexusContainer for plugin: " + pluginKey );
throw new PluginManagerException( "Cannot find Plexus container for plugin: " + pluginKey );
}
return pluginContainer;
@ -524,7 +495,7 @@ public class DefaultPluginManager
private Mojo getConfiguredMojo( MavenSession session, Xpp3Dom dom, MavenProject project, boolean report,
MojoExecution mojoExecution )
throws ComponentLookupException, PluginConfigurationException, PluginManagerException, ArtifactNotFoundException
throws PluginConfigurationException, ArtifactNotFoundException, PluginManagerException
{
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
@ -537,11 +508,20 @@ public class DefaultPluginManager
// dependencies, and add them to the container.
ensurePluginContainerIsComplete( pluginDescriptor, pluginContainer, project, session );
Mojo plugin = (Mojo) pluginContainer.lookup( Mojo.ROLE, mojoDescriptor.getRoleHint() );
if ( report && !( plugin instanceof MavenReport ) )
Mojo plugin;
try
{
// TODO: the mojoDescriptor should actually capture this information so we don't get this far
return null;
plugin = (Mojo) pluginContainer.lookup( Mojo.ROLE, mojoDescriptor.getRoleHint() );
if ( report && !( plugin instanceof MavenReport ) )
{
// TODO: the mojoDescriptor should actually capture this information so we don't get this far
return null;
}
}
catch ( ComponentLookupException e )
{
throw new PluginManagerException( "Unable to find the mojo '" + mojoDescriptor.getRoleHint() +
"' in the plugin '" + pluginDescriptor.getPluginLookupKey() + "'", e );
}
if ( plugin instanceof ContextEnabled )
@ -1155,7 +1135,7 @@ public class DefaultPluginManager
private void resolveTransitiveDependencies( MavenSession context, ArtifactResolver artifactResolver, String scope,
ArtifactFactory artifactFactory, MavenProject project )
throws ArtifactResolutionException, ArtifactNotFoundException, ProjectBuildingException
throws ArtifactResolutionException, ArtifactNotFoundException, InvalidDependencyVersionException
{
ArtifactFilter filter = new ScopeArtifactFilter( scope );
@ -1197,7 +1177,7 @@ public class DefaultPluginManager
}
public Object getPluginComponent( Plugin plugin, String role, String roleHint )
throws ComponentLookupException, PluginManagerException
throws PluginManagerException, ComponentLookupException
{
PluginDescriptor pluginDescriptor = pluginCollector.getPluginDescriptor( plugin );

View File

@ -0,0 +1,32 @@
package org.apache.maven.plugin;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Thrown when a plugin is not internally consistent.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public class InvalidPluginException
extends Exception
{
public InvalidPluginException( String message, Exception e )
{
super( message, e );
}
}

View File

@ -26,6 +26,7 @@ import org.apache.maven.model.ReportPlugin;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.reporting.MavenReport;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
@ -41,28 +42,27 @@ public interface PluginManager
String ROLE = PluginManager.class.getName();
void executeMojo( MavenProject project, MojoExecution execution, MavenSession session )
throws MojoExecutionException, PluginManagerException, ArtifactResolutionException, MojoFailureException,
ArtifactNotFoundException;
throws MojoExecutionException, ArtifactResolutionException, MojoFailureException, ArtifactNotFoundException,
InvalidDependencyVersionException, PluginManagerException;
MavenReport getReport( MavenProject project, MojoExecution mojoExecution, MavenSession session )
throws PluginManagerException, ArtifactNotFoundException;
throws ArtifactNotFoundException, PluginConfigurationException, PluginManagerException;
PluginDescriptor getPluginDescriptorForPrefix( String prefix );
Plugin getPluginDefinitionForPrefix( String prefix, MavenSession session, MavenProject project )
throws PluginManagerException;
Plugin getPluginDefinitionForPrefix( String prefix, MavenSession session, MavenProject project );
PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings,
ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException,
ArtifactNotFoundException, InvalidVersionSpecificationException;
throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException;
PluginDescriptor verifyReportPlugin( ReportPlugin reportPlugin, MavenProject project, MavenSession session )
throws PluginVersionResolutionException, ArtifactResolutionException, PluginManagerException,
ArtifactNotFoundException, InvalidVersionSpecificationException;
throws PluginVersionResolutionException, ArtifactResolutionException, ArtifactNotFoundException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException;
Object getPluginComponent( Plugin plugin, String role, String roleHint )
throws ComponentLookupException, PluginManagerException;
throws PluginManagerException, ComponentLookupException;
Map getPluginComponents( Plugin plugin, String role )
throws ComponentLookupException, PluginManagerException;

View File

@ -696,11 +696,6 @@ public class DefaultPluginVersionManager
throw new PluginVersionResolutionException( groupId, artifactId,
"Unable to build resolve plugin project information", e );
}
catch ( IOException e )
{
throw new PluginVersionResolutionException( groupId, artifactId,
"Unable to determine Maven version for comparison", e );
}
return version;
}

View File

@ -23,6 +23,7 @@ import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.InvalidPluginException;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.PluginManager;
@ -276,15 +277,7 @@ public class DescribeMojo
if ( descriptor == null )
{
try
{
forLookup = pluginManager.getPluginDefinitionForPrefix( pi.prefix, session, project );
}
catch ( PluginManagerException e )
{
throw new MojoExecutionException(
"Cannot resolve plugin-prefix: \'" + pi.prefix + "\' from plugin mappings metadata.", e );
}
forLookup = pluginManager.getPluginDefinitionForPrefix( pi.prefix, session, project );
}
}
else if ( pi.groupId != null && pi.artifactId != null )
@ -336,6 +329,11 @@ public class DescribeMojo
throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId +
"\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e );
}
catch ( InvalidPluginException e )
{
throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId +
"\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e );
}
}
return descriptor;

View File

@ -51,6 +51,7 @@ import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.profiles.ProfilesConversionUtils;
import org.apache.maven.profiles.ProfilesRoot;
import org.apache.maven.profiles.activation.ProfileActivationException;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.inheritance.ModelInheritanceAssembler;
import org.apache.maven.project.injection.ModelDefaultsInjector;
import org.apache.maven.project.injection.ProfileInjector;
@ -191,7 +192,16 @@ public class DefaultMavenProjectBuilder
ensureMetadataSourceIsInitialized();
project.setDependencyArtifacts( project.createArtifacts( artifactFactory, null, null ) );
try
{
project.setDependencyArtifacts( project.createArtifacts( artifactFactory, null, null ) );
}
catch ( InvalidDependencyVersionException e )
{
throw new ProjectBuildingException( projectId,
"Unable to build project due to an invalid dependency version: " +
e.getMessage(), e );
}
if ( transferListener != null )
{

View File

@ -45,6 +45,7 @@ import org.apache.maven.model.Resource;
import org.apache.maven.model.Scm;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.project.artifact.ActiveProjectArtifact;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.artifact.MavenMetadataSource;
import org.apache.maven.project.overlay.BuildOverlay;
import org.codehaus.plexus.util.xml.Xpp3Dom;
@ -1405,7 +1406,7 @@ public class MavenProject
*/
public Set createArtifacts( ArtifactFactory artifactFactory, String inheritedScope,
ArtifactFilter dependencyFilter )
throws ProjectBuildingException
throws InvalidDependencyVersionException
{
return MavenMetadataSource.createArtifacts( artifactFactory, getDependencies(), inheritedScope,
dependencyFilter, this );

View File

@ -0,0 +1,32 @@
package org.apache.maven.project.artifact;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Thrown if a dependency has an invalid version.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public class InvalidDependencyVersionException
extends Exception
{
public InvalidDependencyVersionException( String message, Exception cause )
{
super( message, cause );
}
}

View File

@ -17,7 +17,6 @@ package org.apache.maven.project.artifact;
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
@ -206,6 +205,10 @@ public class MavenMetadataSource
{
throw new ArtifactMetadataRetrievalException( "Unable to read the metadata file", e );
}
catch ( InvalidDependencyVersionException e )
{
throw new ArtifactMetadataRetrievalException( "Unable to read the metadata file", e );
}
}
private List aggregateRepositoryLists( List remoteRepositories, List remoteArtifactRepositories )
@ -259,7 +262,7 @@ public class MavenMetadataSource
*/
public static Set createArtifacts( ArtifactFactory artifactFactory, List dependencies, String inheritedScope,
ArtifactFilter dependencyFilter, MavenProject project )
throws ProjectBuildingException
throws InvalidDependencyVersionException
{
Set projectArtifacts = new HashSet( dependencies.size() );
@ -283,10 +286,7 @@ public class MavenMetadataSource
}
catch ( InvalidVersionSpecificationException e )
{
String projectId = project != null ? ArtifactUtils.versionlessKey( project.getGroupId(),
project.getArtifactId() )
: "unknown";
throw new ProjectBuildingException( projectId, "Unable to parse version '" + d.getVersion() +
throw new InvalidDependencyVersionException( "Unable to parse version '" + d.getVersion() +
"' for dependency '" + d.getManagementKey() + "': " + e.getMessage(), e );
}
Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(),