From e10d95d4e16001eea7458580d6f1a31ba1c875b8 Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Mon, 27 Apr 2009 22:38:19 +0000 Subject: [PATCH] o starting the simplification of the error reporting git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@769193 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/maven/DefaultMaven.java | 3 +- .../maven/execution/MavenExecutionResult.java | 2 +- .../lifecycle/DefaultLifecycleExecutor.java | 34 +++++-------------- .../maven/lifecycle/LifecycleExecutor.java | 3 +- .../java/org/apache/maven/cli/MavenCli.java | 19 ++++++++++- .../project/DefaultMavenProjectBuilder.java | 18 +++++----- 6 files changed, 40 insertions(+), 39 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java index be675e6d62..7e5e7b87f6 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -31,6 +31,7 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.RuntimeInformation; import org.apache.maven.lifecycle.LifecycleExecutionException; import org.apache.maven.lifecycle.LifecycleExecutor; +import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.project.ProjectBuildingException; @@ -103,7 +104,7 @@ public class DefaultMaven return result; } - catch ( BuildFailureException e ) + catch ( MojoFailureException e ) { result.addException( e ); diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionResult.java b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionResult.java index 9fdad40c9a..bcea13badb 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionResult.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionResult.java @@ -46,7 +46,7 @@ public interface MavenExecutionResult // - project building exception // - invalid project model exception: list of markers // - xmlpull parser exception - List getExceptions(); + List getExceptions(); MavenExecutionResult addException( Throwable e ); diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java index 991f87ae7c..218c4785fb 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java @@ -23,7 +23,6 @@ import java.util.List; import java.util.Map; import java.util.StringTokenizer; -import org.apache.maven.BuildFailureException; import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.ReactorManager; import org.apache.maven.lifecycle.mapping.LifecycleMapping; @@ -73,7 +72,7 @@ public class DefaultLifecycleExecutor private Map phaseToLifecycleMap; public void execute( MavenSession session ) - throws BuildFailureException, LifecycleExecutionException + throws LifecycleExecutionException, MojoFailureException { // TODO: This is dangerous, particularly when it's just a collection of loose-leaf projects being built // within the same reactor (using an inclusion pattern to gather them up)... @@ -93,7 +92,7 @@ public class DefaultLifecycleExecutor if ( goals.isEmpty() ) { - throw new BuildFailureException( "\n\nYou must specify at least one goal. Try 'mvn install' to build or 'mvn --help' for options \nSee http://maven.apache.org for more information.\n\n" ); + throw new LifecycleExecutionException( "\n\nYou must specify at least one goal. Try 'mvn install' to build or 'mvn --help' for options \nSee http://maven.apache.org for more information.\n\n" ); } for ( MavenProject currentProject : session.getSortedProjects() ) @@ -126,7 +125,7 @@ public class DefaultLifecycleExecutor } private void executeGoalAndHandleFailures( String task, MavenSession session, MavenProject project, long buildStartTime, String target ) - throws BuildFailureException, LifecycleExecutionException + throws LifecycleExecutionException, MojoFailureException { try { @@ -139,13 +138,6 @@ public class DefaultLifecycleExecutor throw e; } } - catch ( BuildFailureException e ) - { - if ( handleExecutionFailure( session, project, e, task, buildStartTime ) ) - { - throw e; - } - } } private boolean handleExecutionFailure( MavenSession session, MavenProject project, Exception e, String task, long buildStartTime ) @@ -168,7 +160,7 @@ public class DefaultLifecycleExecutor } private void executeGoal( String task, MavenSession session, MavenProject project ) - throws LifecycleExecutionException, BuildFailureException + throws LifecycleExecutionException, MojoFailureException { List lifecyclePlan = calculateLifecyclePlan( task, session ); @@ -182,11 +174,6 @@ public class DefaultLifecycleExecutor { pluginManager.executeMojo( session, mojoExecution ); } - catch ( MojoFailureException e ) - { - // If the mojo actually screws up, like a compilation error - throw new LifecycleExecutionException( "Error executing goal.", e ); - } catch ( PluginExecutionException e ) { // This looks like a duplicate @@ -308,9 +295,9 @@ public class DefaultLifecycleExecutor MojoDescriptor md = getMojoDescriptor( s, session, project ); boolean include = lifecycle.getPhases().contains( md.getPhase() ); - System.out.println( ">>> " + goal ); - System.out.println( ">>> " + md.getPhase() ); - System.out.println( ">>> " + include ); +// System.out.println( ">>> " + goal ); +// System.out.println( ">>> " + md.getPhase() ); +// System.out.println( ">>> " + include ); // need to know if this plugin belongs to a phase in the lifecycle that's running if ( md.getPhase() != null && include ) @@ -336,12 +323,7 @@ public class DefaultLifecycleExecutor lifecyclePlan.add( getMojoDescriptor( mojo, session, project ) ); } } - - for ( MojoDescriptor md : lifecyclePlan ) - { - System.out.println( md.getGoal() ); - } - + return lifecyclePlan; } diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java index 2aebaec95e..83fbcc7450 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java @@ -23,6 +23,7 @@ import java.util.List; import org.apache.maven.BuildFailureException; import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.descriptor.MojoDescriptor; /** @@ -44,5 +45,5 @@ public interface LifecycleExecutor throws LifecycleExecutionException; void execute( MavenSession session ) - throws LifecycleExecutionException, BuildFailureException; + throws LifecycleExecutionException, MojoFailureException; } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index 67e6553dd4..c100e2ab94 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -20,6 +20,7 @@ package org.apache.maven.cli; */ import java.io.File; +import java.util.List; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.ParseException; @@ -33,6 +34,7 @@ import org.apache.maven.embedder.MavenEmbedderFileLogger; import org.apache.maven.embedder.MavenEmbedderLogger; import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenExecutionResult; +import org.apache.maven.plugin.MojoFailureException; import org.codehaus.plexus.classworlds.ClassWorld; /** @@ -165,8 +167,23 @@ public class MavenCli MavenExecutionResult result = mavenEmbedder.execute( request ); - CLIReportingUtils.logResult( request, result, logger ); + //CLIReportingUtils.logResult( request, result, logger ); + System.out.println( "exceptions: " + result.hasExceptions() ); + + System.out.println( result.getExceptions() ); + + Exception e = result.getExceptions().get( 0 ); + + if ( e instanceof MojoFailureException ) + { + System.out.println( ((MojoFailureException)e).getLongMessage() ); + } + else + { + System.out.println( e.getMessage() ); + } + if ( result.hasExceptions() ) { return 1; diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index 754757e135..3e9aedc8d8 100644 --- a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -22,10 +22,9 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.Properties; - import java.util.List; import java.util.Map; +import java.util.Properties; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.ArtifactUtils; @@ -48,14 +47,13 @@ import org.apache.maven.model.interpolator.PomInterpolatorTag; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.profiles.DefaultProfileManager; import org.apache.maven.profiles.ProfileActivationException; -import org.apache.maven.profiles.ProfileManagerInfo; import org.apache.maven.profiles.ProfileManager; +import org.apache.maven.profiles.ProfileManagerInfo; import org.apache.maven.project.artifact.InvalidDependencyVersionException; import org.apache.maven.project.validation.ModelValidationResult; import org.apache.maven.project.validation.ModelValidator; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.VersionNotFoundException; -import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.Logger; @@ -303,14 +301,16 @@ public class DefaultMavenProjectBuilder public MavenProject buildFromRepository( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository ) throws ProjectBuildingException { - if(remoteRepositories == null) + if(remoteRepositories == null) { throw new IllegalArgumentException("repositories: null"); } - ProjectBuilderConfiguration configuration = new DefaultProjectBuilderConfiguration() - .setLocalRepository( localRepository ) - .setRemoteRepositories(remoteRepositories); - return buildFromRepository(artifact, configuration); + + ProjectBuilderConfiguration configuration = new DefaultProjectBuilderConfiguration() + .setLocalRepository( localRepository ) + .setRemoteRepositories(remoteRepositories); + + return buildFromRepository(artifact, configuration); } /**