Author: jdcasey Date: Thu Nov 8 12:33:27 2007 New Revision: 593294 URL: http://svn.apache.org/viewvc?rev=593294&view=rev Log: 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).
Added: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginExecutionException.java (with props) Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutionException.java maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginManagerException.java maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java maven/components/trunk/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/LifecycleException.java Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java?rev=593294&r1=593293&r2=593294&view=diff ============================================================================== --- maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java (original) +++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java Thu Nov 8 12:33:27 2007 @@ -36,7 +36,6 @@ 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; @@ -533,13 +532,6 @@ e ); } catch ( ArtifactResolutionException e ) - { - throw new LifecycleExecutionException( - e.getMessage(), - project, - e ); - } - catch ( MojoExecutionException e ) { throw new LifecycleExecutionException( e.getMessage(), Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutionException.java URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutionException.java?rev=593294&r1=593293&r2=593294&view=diff ============================================================================== --- maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutionException.java (original) +++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutionException.java Thu Nov 8 12:33:27 2007 @@ -4,7 +4,6 @@ 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.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 @@ -120,13 +118,6 @@ } public LifecycleExecutionException( String message, MavenProject project, - MojoExecutionException cause ) - { - super( message, cause ); - this.project = project; - } - - public LifecycleExecutionException( String message, MavenProject project, PluginConfigurationException cause ) { super( message, cause ); @@ -135,14 +126,6 @@ public LifecycleExecutionException( String message, MavenProject project, PluginVersionNotFoundException cause ) - { - super( message, cause ); - this.project = project; - } - - public LifecycleExecutionException( String message, - MavenProject project, - PlexusContainerException cause ) { super( message, cause ); this.project = project; Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java?rev=593294&r1=593293&r2=593294&view=diff ============================================================================== --- maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java (original) +++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java Thu Nov 8 12:33:27 2007 @@ -485,7 +485,7 @@ public void executeMojo( MavenProject project, MojoExecution mojoExecution, MavenSession session ) - throws ArtifactResolutionException, MojoExecutionException, MojoFailureException, + throws ArtifactResolutionException, MojoFailureException, ArtifactNotFoundException, InvalidDependencyVersionException, PluginManagerException, PluginConfigurationException { @@ -495,7 +495,7 @@ // 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 @@ 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 @@ String goalName = mojoDescriptor.getFullGoalName(); - Mojo mojo; + Mojo mojo = null; PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor(); @@ -597,7 +597,7 @@ { session.getEventDispatcher().dispatchError( event, goalExecId, e ); - throw e; + throw new PluginExecutionException( mojoExecution, project, e ); } catch ( MojoFailureException e ) { @@ -607,6 +607,18 @@ } 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 @@ MavenProject project, boolean report, MojoExecution mojoExecution ) - throws PluginConfigurationException, ArtifactNotFoundException, PluginManagerException, - ArtifactResolutionException + throws PluginConfigurationException, PluginManagerException { MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); Added: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginExecutionException.java URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginExecutionException.java?rev=593294&view=auto ============================================================================== --- maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginExecutionException.java (added) +++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginExecutionException.java Thu Nov 8 12:33:27 2007 @@ -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; + } + +} Propchange: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginExecutionException.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginExecutionException.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java?rev=593294&r1=593293&r2=593294&view=diff ============================================================================== --- maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java (original) +++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java Thu Nov 8 12:33:27 2007 @@ -42,7 +42,7 @@ void executeMojo( MavenProject project, MojoExecution execution, MavenSession session ) - throws MojoExecutionException, ArtifactResolutionException, MojoFailureException, ArtifactNotFoundException, + throws ArtifactResolutionException, MojoFailureException, ArtifactNotFoundException, InvalidDependencyVersionException, PluginManagerException, PluginConfigurationException; MavenReport getReport( MavenProject project, Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginManagerException.java URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginManagerException.java?rev=593294&r1=593293&r2=593294&view=diff ============================================================================== --- maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginManagerException.java (original) +++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginManagerException.java Thu Nov 8 12:33:27 2007 @@ -7,14 +7,10 @@ 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 @@ 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 @@ 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 @@ } protected PluginManagerException( MojoDescriptor mojoDescriptor, - String message, - ComponentLookupException cause ) + String message, + Throwable cause ) { super( message, cause ); pluginGroupId = mojoDescriptor.getPluginDescriptor().getGroupId(); @@ -88,32 +85,35 @@ goal = mojoDescriptor.getGoal(); } - public PluginManagerException( Plugin plugin, - InvalidVersionSpecificationException cause ) + protected PluginManagerException( MojoDescriptor mojoDescriptor, + MavenProject project, + String message ) { - super( cause ); - - pluginGroupId = plugin.getGroupId(); - pluginArtifactId = plugin.getArtifactId(); - pluginVersion = plugin.getVersion(); + super( message ); + this.project = project; + pluginGroupId = mojoDescriptor.getPluginDescriptor().getGroupId(); + pluginArtifactId = mojoDescriptor.getPluginDescriptor().getArtifactId(); + pluginVersion = mojoDescriptor.getPluginDescriptor().getVersion(); + goal = mojoDescriptor.getGoal(); } - protected PluginManagerException( Plugin plugin, - String message, - DuplicateRealmException cause ) + protected PluginManagerException( MojoDescriptor mojoDescriptor, + MavenProject project, + String message, + Throwable cause ) { super( message, cause ); - - pluginGroupId = plugin.getGroupId(); - pluginArtifactId = plugin.getArtifactId(); - pluginVersion = plugin.getVersion(); + this.project = project; + pluginGroupId = mojoDescriptor.getPluginDescriptor().getGroupId(); + pluginArtifactId = mojoDescriptor.getPluginDescriptor().getArtifactId(); + pluginVersion = mojoDescriptor.getPluginDescriptor().getVersion(); + goal = mojoDescriptor.getGoal(); } - protected PluginManagerException( Plugin plugin, - String message, - MalformedURLException cause ) + public PluginManagerException( Plugin plugin, + InvalidVersionSpecificationException cause ) { - super( message, cause ); + super( cause ); pluginGroupId = plugin.getGroupId(); pluginArtifactId = plugin.getArtifactId(); Modified: maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java?rev=593294&r1=593293&r2=593294&view=diff ============================================================================== --- maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java (original) +++ maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java Thu Nov 8 12:33:27 2007 @@ -19,9 +19,12 @@ 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 @@ // ===================================================================== // // 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 @@ } writer.write( NEWLINE ); - writer.write( "Project Id: " ); + writer.write( "Failing project's id: " ); writer.write( e.getProjectId() ); writer.write( NEWLINE ); if ( e.getPomFile() == null ) Modified: maven/components/trunk/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/LifecycleException.java URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/LifecycleException.java?rev=593294&r1=593293&r2=593294&view=diff ============================================================================== --- maven/components/trunk/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/LifecycleException.java (original) +++ maven/components/trunk/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/LifecycleException.java Thu Nov 8 12:33:27 2007 @@ -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 ); }