Working on cleaning up exceptions and reporting (these changes are from before the break I took to work on memory profiling in maven and plexus).

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@593294 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2007-11-08 20:33:27 +00:00
parent f1973980a5
commit 08947e7efb
8 changed files with 213 additions and 82 deletions

View File

@ -36,7 +36,6 @@ import org.apache.maven.lifecycle.plan.BuildPlanner;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.MavenEvents;
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;
@ -539,13 +538,6 @@ public class DefaultLifecycleExecutor
project,
e );
}
catch ( MojoExecutionException e )
{
throw new LifecycleExecutionException(
e.getMessage(),
project,
e );
}
catch ( PluginConfigurationException e )
{
throw new LifecycleExecutionException(

View File

@ -4,7 +4,6 @@ import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.plugin.InvalidPluginException;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.PluginConfigurationException;
import org.apache.maven.plugin.PluginManagerException;
import org.apache.maven.plugin.PluginNotFoundException;
@ -13,7 +12,6 @@ import org.apache.maven.plugin.version.PluginVersionNotFoundException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.codehaus.plexus.PlexusContainerException;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@ -119,13 +117,6 @@ public class LifecycleExecutionException
this.project = project;
}
public LifecycleExecutionException( String message, MavenProject project,
MojoExecutionException cause )
{
super( message, cause );
this.project = project;
}
public LifecycleExecutionException( String message, MavenProject project,
PluginConfigurationException cause )
{
@ -140,14 +131,6 @@ public class LifecycleExecutionException
this.project = project;
}
public LifecycleExecutionException( String message,
MavenProject project,
PlexusContainerException cause )
{
super( message, cause );
this.project = project;
}
public MavenProject getProject()
{
return project;

View File

@ -485,7 +485,7 @@ public class DefaultPluginManager
public void executeMojo( MavenProject project,
MojoExecution mojoExecution,
MavenSession session )
throws ArtifactResolutionException, MojoExecutionException, MojoFailureException,
throws ArtifactResolutionException, MojoFailureException,
ArtifactNotFoundException, InvalidDependencyVersionException, PluginManagerException,
PluginConfigurationException
{
@ -495,7 +495,7 @@ public class DefaultPluginManager
// anything that wants to execute a mojo.
if ( mojoDescriptor.isProjectRequired() && !session.isUsingPOMsFromFilesystem() )
{
throw new MojoExecutionException(
throw new PluginExecutionException( mojoExecution, project,
"Cannot execute mojo: "
+ mojoDescriptor.getGoal()
+ ". It requires a project with an existing pom.xml, but the build is not using one." );
@ -504,7 +504,7 @@ public class DefaultPluginManager
if ( mojoDescriptor.isOnlineRequired() && session.getSettings().isOffline() )
{
// TODO: Should we error out, or simply warn and skip??
throw new MojoExecutionException(
throw new PluginExecutionException( mojoExecution, project,
"Mojo: "
+ mojoDescriptor.getGoal()
+ " requires online mode for execution. Maven is currently offline." );
@ -537,7 +537,7 @@ public class DefaultPluginManager
String goalName = mojoDescriptor.getFullGoalName();
Mojo mojo;
Mojo mojo = null;
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
@ -597,7 +597,7 @@ public class DefaultPluginManager
{
session.getEventDispatcher().dispatchError( event, goalExecId, e );
throw e;
throw new PluginExecutionException( mojoExecution, project, e );
}
catch ( MojoFailureException e )
{
@ -607,6 +607,18 @@ public class DefaultPluginManager
}
finally
{
if ( mojo != null )
{
try
{
container.release( mojo );
}
catch ( ComponentLifecycleException e )
{
getLogger().debug( "Error releasing mojo for: " + goalExecId, e );
}
}
pluginDescriptor.setClassRealm( null );
pluginDescriptor.setArtifacts( null );
@ -686,8 +698,7 @@ public class DefaultPluginManager
MavenProject project,
boolean report,
MojoExecution mojoExecution )
throws PluginConfigurationException, ArtifactNotFoundException, PluginManagerException,
ArtifactResolutionException
throws PluginConfigurationException, PluginManagerException
{
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();

View File

@ -0,0 +1,32 @@
package org.apache.maven.plugin;
import org.apache.maven.project.MavenProject;
public class PluginExecutionException
extends PluginManagerException
{
private final MojoExecution mojoExecution;
public PluginExecutionException( MojoExecution mojoExecution,
MavenProject project,
String message )
{
super( mojoExecution.getMojoDescriptor(), project, message );
this.mojoExecution = mojoExecution;
}
public PluginExecutionException( MojoExecution mojoExecution,
MavenProject project,
MojoExecutionException cause )
{
super( mojoExecution.getMojoDescriptor(), project, "Mojo execution failed.", cause );
this.mojoExecution = mojoExecution;
}
public MojoExecution getMojoExecution()
{
return mojoExecution;
}
}

View File

@ -42,7 +42,7 @@ public interface PluginManager
void executeMojo( MavenProject project,
MojoExecution execution,
MavenSession session )
throws MojoExecutionException, ArtifactResolutionException, MojoFailureException, ArtifactNotFoundException,
throws ArtifactResolutionException, MojoFailureException, ArtifactNotFoundException,
InvalidDependencyVersionException, PluginManagerException, PluginConfigurationException;
MavenReport getReport( MavenProject project,

View File

@ -7,14 +7,10 @@ import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.PlexusContainerException;
import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;
import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.component.repository.exception.ComponentRepositoryException;
import org.codehaus.plexus.configuration.PlexusConfigurationException;
import java.net.MalformedURLException;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@ -55,9 +51,9 @@ public class PluginManagerException
private MavenProject project;
protected PluginManagerException( Plugin plugin,
String message,
MavenProject project,
PlexusContainerException cause )
String message,
MavenProject project,
Throwable cause )
{
super( message, cause );
@ -67,8 +63,9 @@ public class PluginManagerException
pluginVersion = plugin.getVersion();
}
protected PluginManagerException( Plugin plugin, String message,
NoSuchRealmException cause )
protected PluginManagerException( Plugin plugin,
String message,
Throwable cause )
{
super( message, cause );
@ -78,8 +75,8 @@ public class PluginManagerException
}
protected PluginManagerException( MojoDescriptor mojoDescriptor,
String message,
ComponentLookupException cause )
String message,
Throwable cause )
{
super( message, cause );
pluginGroupId = mojoDescriptor.getPluginDescriptor().getGroupId();
@ -88,6 +85,31 @@ public class PluginManagerException
goal = mojoDescriptor.getGoal();
}
protected PluginManagerException( MojoDescriptor mojoDescriptor,
MavenProject project,
String message )
{
super( message );
this.project = project;
pluginGroupId = mojoDescriptor.getPluginDescriptor().getGroupId();
pluginArtifactId = mojoDescriptor.getPluginDescriptor().getArtifactId();
pluginVersion = mojoDescriptor.getPluginDescriptor().getVersion();
goal = mojoDescriptor.getGoal();
}
protected PluginManagerException( MojoDescriptor mojoDescriptor,
MavenProject project,
String message,
Throwable cause )
{
super( message, cause );
this.project = project;
pluginGroupId = mojoDescriptor.getPluginDescriptor().getGroupId();
pluginArtifactId = mojoDescriptor.getPluginDescriptor().getArtifactId();
pluginVersion = mojoDescriptor.getPluginDescriptor().getVersion();
goal = mojoDescriptor.getGoal();
}
public PluginManagerException( Plugin plugin,
InvalidVersionSpecificationException cause )
{
@ -98,28 +120,6 @@ public class PluginManagerException
pluginVersion = plugin.getVersion();
}
protected PluginManagerException( Plugin plugin,
String message,
DuplicateRealmException cause )
{
super( message, cause );
pluginGroupId = plugin.getGroupId();
pluginArtifactId = plugin.getArtifactId();
pluginVersion = plugin.getVersion();
}
protected PluginManagerException( Plugin plugin,
String message,
MalformedURLException cause )
{
super( message, cause );
pluginGroupId = plugin.getGroupId();
pluginArtifactId = plugin.getArtifactId();
pluginVersion = plugin.getVersion();
}
public PluginManagerException( Plugin plugin,
String message,
PlexusConfigurationException cause )

View File

@ -19,9 +19,12 @@ import org.apache.maven.extension.ExtensionScanningException;
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.lifecycle.MojoBindingUtils;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.PluginNotFoundException;
import org.apache.maven.plugin.loader.PluginLoaderException;
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.profiles.activation.ProfileActivationException;
import org.apache.maven.project.DuplicateProjectException;
import org.apache.maven.project.InvalidProjectModelException;
@ -407,44 +410,154 @@ public final class CLIReportingUtils
// =====================================================================
//
// LifecycleExecutionException(String, MavenProject, PluginNotFoundException)
// LifecycleExecutionException(String, MavenProject, InvalidDependencyVersionException)
// LifecycleExecutionException(String, MavenProject, InvalidVersionSpecificationException)
// LifecycleExecutionException(String, MavenProject, ArtifactNotFoundException)
// LifecycleExecutionException(String, MavenProject, ArtifactResolutionException)
// LifecycleExecutionException(String, MavenProject, PluginVersionNotFoundException)
// LifecycleExecutionException(String, MavenProject, PluginVersionResolutionException)
//
// =====================================================================
// Cases left to cover:
// =====================================================================
//
// LifecycleExecutionException(String, MavenProject, ArtifactNotFoundException)
// LifecycleExecutionException(String, MavenProject, ArtifactResolutionException)
// LifecycleExecutionException(String, MavenProject, InvalidDependencyVersionException)
// LifecycleExecutionException(String, MavenProject, InvalidPluginException)
// LifecycleExecutionException(String, MavenProject, InvalidVersionSpecificationException)
// LifecycleExecutionException(String, MavenProject, LifecycleException)
// LifecycleExecutionException(String, MavenProject, MojoExecutionException)
// LifecycleExecutionException(String, MavenProject, PlexusContainerException)
// LifecycleExecutionException(String, MavenProject, PluginConfigurationException)
// LifecycleExecutionException(String, MavenProject, PluginLoaderException)
// LifecycleExecutionException(String, MavenProject, PluginManagerException)
// LifecycleExecutionException(String, MavenProject, PluginVersionNotFoundException)
// LifecycleExecutionException(String, MavenProject, PluginVersionResolutionException)
// ...this includes PluginExecutionException, which wraps MojoExecutionException
// with MojoExecution and MavenProject context info.
boolean result = false;
Throwable cause = e.getCause();
if ( cause != null )
{
if ( cause instanceof PluginNotFoundException )
{
// Plugin plugin = ( (PluginNotFoundException) cause ).getPlugin();
Plugin plugin = ( (PluginNotFoundException) cause ).getPlugin();
ArtifactNotFoundException artifactException = (ArtifactNotFoundException) ( (PluginNotFoundException) cause ).getCause();
writer.write( NEWLINE );
writer.write( "Maven cannot find a plugin required by your build:" );
writer.write( NEWLINE );
writer.write( "Group-Id: " );
writer.write( plugin.getGroupId() );
writer.write( NEWLINE );
writer.write( "Artifact-Id: " );
writer.write( plugin.getArtifactId() );
writer.write( NEWLINE );
writer.write( "Version: " );
writer.write( plugin.getVersion() );
writer.write( NEWLINE );
writer.write( NEWLINE );
handleGenericException( artifactException, showStackTraces, writer );
return true;
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "NOTE: If the above Group-Id or Artifact-Id are incorrect," );
writer.write( NEWLINE );
writer.write( "check that the corresponding <plugin/> section in your POM is correct." );
writer.write( NEWLINE );
writer.write( "If you specified this plugin directly using something like 'javadoc:javadoc'," );
writer.write( NEWLINE );
writer.write( "check that the <pluginGroups/> section in your $HOME/.m2/settings.xml contains the" );
writer.write( NEWLINE );
writer.write( "proper groupId for the plugin you are trying to use (each groupId goes in a separate" );
writer.write( NEWLINE );
writer.write( "<pluginGroup/> element within the <pluginGroups/> section." );
writer.write( NEWLINE );
result = true;
}
else if ( cause instanceof ProjectBuildingException )
{
result = handleProjectBuildingException( (ProjectBuildingException) cause, showStackTraces, writer );
}
else if ( cause instanceof ArtifactNotFoundException )
{
writer.write( NEWLINE );
writer.write( "One or more project dependency artifacts are missing." );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Reason: " );
writer.write( cause.getMessage() );
writer.write( NEWLINE );
result = true;
}
else if ( cause instanceof ArtifactNotFoundException )
{
writer.write( NEWLINE );
writer.write( "Maven encountered an error while resolving one or more project dependency artifacts." );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Reason: " );
writer.write( cause.getMessage() );
writer.write( NEWLINE );
result = true;
}
else if ( cause instanceof PluginVersionNotFoundException )
{
writer.write( NEWLINE );
writer.write( "Cannot find a valid version for plugin: " );
writer.write( NEWLINE );
writer.write( "Group-Id: " );
writer.write( ((PluginVersionNotFoundException)cause).getGroupId() );
writer.write( NEWLINE );
writer.write( "Artifact-Id: " );
writer.write( ((PluginVersionNotFoundException)cause).getArtifactId() );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Reason: " );
writer.write( cause.getMessage() );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Please ensure that your proxy information is specified correctly in $HOME/.m2/settings.xml." );
writer.write( NEWLINE );
result = true;
}
else if ( cause instanceof PluginVersionResolutionException )
{
writer.write( NEWLINE );
writer.write( "Maven encountered an error while trying to resolve a valid version for plugin: " );
writer.write( NEWLINE );
writer.write( "Group-Id: " );
writer.write( ((PluginVersionNotFoundException)cause).getGroupId() );
writer.write( NEWLINE );
writer.write( "Artifact-Id: " );
writer.write( ((PluginVersionNotFoundException)cause).getArtifactId() );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Reason: " );
writer.write( cause.getMessage() );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Please ensure that your proxy information is specified correctly in $HOME/.m2/settings.xml." );
writer.write( NEWLINE );
result = true;
}
}
return false;
MavenProject project = e.getProject();
writer.write( NEWLINE );
writer.write( "While building project with id: " );
writer.write( project.getId() );
writer.write( NEWLINE );
if ( project.getFile() != null )
{
writer.write( "Project File: " );
writer.write( project.getFile().getAbsolutePath() );
}
writer.write( NEWLINE );
return result;
}
private static boolean handleProjectBuildingException( ProjectBuildingException e,
@ -637,7 +750,7 @@ public final class CLIReportingUtils
}
writer.write( NEWLINE );
writer.write( "Project Id: " );
writer.write( "Failing project's id: " );
writer.write( e.getProjectId() );
writer.write( NEWLINE );
if ( e.getPomFile() == null )

View File

@ -1,15 +1,15 @@
package org.apache.maven.lifecycle;
public class LifecycleException
public abstract class LifecycleException
extends Exception
{
public LifecycleException( String message, Throwable cause )
protected LifecycleException( String message, Throwable cause )
{
super( message, cause );
}
public LifecycleException( String message )
protected LifecycleException( String message )
{
super( message );
}