diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/GroupRepositoryMetadata.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/GroupRepositoryMetadata.java index 937c8c3925..9a0660eecb 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/GroupRepositoryMetadata.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/GroupRepositoryMetadata.java @@ -21,9 +21,6 @@ package org.apache.maven.artifact.repository.metadata; import org.apache.maven.artifact.repository.ArtifactRepository; -import java.util.Iterator; -import java.util.List; - /** * Metadata for the group directory of the repository. * 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 d747d9d46d..ce3ff7a5de 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -23,16 +23,16 @@ import java.util.Date; import java.util.List; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; +import org.apache.maven.exception.DefaultExceptionHandler; +import org.apache.maven.exception.ExceptionHandler; +import org.apache.maven.exception.ExceptionSummary; import org.apache.maven.execution.DefaultMavenExecutionResult; import org.apache.maven.execution.DuplicateProjectException; import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenExecutionResult; 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.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.project.ProjectBuildingException; @@ -98,25 +98,22 @@ public class DefaultMaven try { lifecycleExecutor.execute( session ); - } - catch ( LifecycleExecutionException e ) - { + } + catch ( Exception e ) + { + ExceptionHandler handler = new DefaultExceptionHandler(); + + // This will only be more then one if we have fail at end on and we collect + // them per project. + ExceptionSummary es = handler.handleException( result.getExceptions().get( 0 ) ); + result.addException( e ); + result.setExceptionSummary( es ); + return result; } - catch ( MojoFailureException e ) - { - result.addException( e ); - return result; - } - catch ( MojoExecutionException e ) - { - result.addException( e ); - - return result; - } result.setTopologicallySortedProjects( session.getReactorManager().getSortedProjects() ); result.setProject( session.getReactorManager().getTopLevelProject() ); diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionResult.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionResult.java index 71a4460b17..70b11f590e 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionResult.java +++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionResult.java @@ -24,6 +24,7 @@ import java.util.Collections; import java.util.List; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; +import org.apache.maven.exception.ExceptionSummary; import org.apache.maven.project.MavenProject; /** @author Jason van Zyl */ @@ -40,6 +41,8 @@ public class DefaultMavenExecutionResult private ReactorManager reactorManager; + private ExceptionSummary exceptionSummary; + public MavenExecutionResult setProject( MavenProject project ) { this.project = project; @@ -109,4 +112,16 @@ public class DefaultMavenExecutionResult return this; } + + public MavenExecutionResult setExceptionSummary( ExceptionSummary exceptionSummary ) + { + this.exceptionSummary = exceptionSummary; + + return this; + } + + public ExceptionSummary getExceptionSummary() + { + return exceptionSummary; + } } 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 bcea13badb..11d4aca62c 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 @@ -22,6 +22,7 @@ package org.apache.maven.execution; import java.util.List; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; +import org.apache.maven.exception.ExceptionSummary; import org.apache.maven.project.MavenProject; /** @@ -51,4 +52,7 @@ public interface MavenExecutionResult MavenExecutionResult addException( Throwable e ); boolean hasExceptions(); + + MavenExecutionResult setExceptionSummary( ExceptionSummary exceptionSummary ); + ExceptionSummary getExceptionSummary(); } 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 b9f5d2eedb..b3f79bef2b 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,7 +20,6 @@ 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; @@ -34,8 +33,6 @@ 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.lifecycle.LifecycleExecutor; -import org.apache.maven.plugin.MojoFailureException; import org.codehaus.plexus.classworlds.ClassWorld; /** @@ -148,6 +145,7 @@ public class MavenCli MavenEmbedder mavenEmbedder; MavenEmbedderLogger logger; + try { mavenEmbedder = new MavenEmbedder( configuration ); @@ -167,26 +165,13 @@ public class MavenCli } MavenExecutionResult result = mavenEmbedder.execute( request ); - - //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() ); - } + // The exception handling should be handled in Maven itself. if ( result.hasExceptions() ) { + System.out.println( result.getExceptionSummary().getMessage() ); + return 1; } else