You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by if...@apache.org on 2015/02/18 17:38:53 UTC

maven git commit: MNG-5766 consistently handle all throwables in LifecycleModuleBuilder

Repository: maven
Updated Branches:
  refs/heads/master c28348024 -> cd52e5b51


MNG-5766 consistently handle all throwables in LifecycleModuleBuilder

Signed-off-by: Igor Fedorenko <if...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/cd52e5b5
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/cd52e5b5
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/cd52e5b5

Branch: refs/heads/master
Commit: cd52e5b51e8e986b6daea8c0b56dd61968410695
Parents: c283480
Author: Igor Fedorenko <if...@apache.org>
Authored: Wed Feb 18 10:47:52 2015 -0500
Committer: Igor Fedorenko <if...@apache.org>
Committed: Wed Feb 18 10:47:52 2015 -0500

----------------------------------------------------------------------
 .../internal/LifecycleModuleBuilder.java        | 16 +++++++--
 .../internal/builder/BuilderCommon.java         | 34 +++++++++++---------
 .../multithreaded/MultiThreadedBuilder.java     |  1 +
 3 files changed, 33 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/cd52e5b5/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleModuleBuilder.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleModuleBuilder.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleModuleBuilder.java
index df7f674..d987a30 100644
--- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleModuleBuilder.java
+++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleModuleBuilder.java
@@ -124,12 +124,22 @@ public class LifecycleModuleBuilder
 
             eventCatapult.fire( ExecutionEvent.Type.ProjectSucceeded, session, null );
         }
-        catch ( Exception e )
+        catch ( Throwable t )
         {
-            builderCommon.handleBuildError( reactorContext, rootSession, session, currentProject, e, buildStartTime );
+            builderCommon.handleBuildError( reactorContext, rootSession, session, currentProject, t, buildStartTime );
 
             projectExecutionListener.afterProjectExecutionFailure( new ProjectExecutionEvent( session, currentProject,
-                                                                                              e ) );
+                                                                                              t ) );
+
+            // rethrow original errors and runtime exceptions
+            if ( t instanceof RuntimeException )
+            {
+                throw (RuntimeException) t;
+            }
+            if ( t instanceof Error )
+            {
+                throw (Error) t;
+            }
         }
         finally
         {

http://git-wip-us.apache.org/repos/asf/maven/blob/cd52e5b5/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/BuilderCommon.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/BuilderCommon.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/BuilderCommon.java
index 8110902..691c981 100644
--- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/BuilderCommon.java
+++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/BuilderCommon.java
@@ -19,7 +19,6 @@ package org.apache.maven.lifecycle.internal.builder;
  * under the License.
  */
 
-import org.apache.maven.InternalErrorException;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.execution.BuildFailure;
 import org.apache.maven.execution.ExecutionEvent;
@@ -139,23 +138,28 @@ public class BuilderCommon
     }
 
     public void handleBuildError( final ReactorContext buildContext, final MavenSession rootSession,
-                                  final MavenSession currentSession, final MavenProject mavenProject, Exception e,
+                                  final MavenSession currentSession, final MavenProject mavenProject, Throwable t,
                                   final long buildStartTime )
     {
-        if ( e instanceof RuntimeException )
-        {
-            e = new InternalErrorException( "Internal error: " + e, e );
-        }
-
-        buildContext.getResult().addException( e );
-
+        // record the error and mark the project as failed
         long buildEndTime = System.currentTimeMillis();
+        buildContext.getResult().addException( t );
+        buildContext.getResult().addBuildSummary( new BuildFailure( mavenProject, buildEndTime - buildStartTime, t ) );
 
-        buildContext.getResult().addBuildSummary( new BuildFailure( mavenProject, buildEndTime - buildStartTime, e ) );
-
-        eventCatapult.fire( ExecutionEvent.Type.ProjectFailed, currentSession, null, e );
+        // notify listeners about "soft" project build failures only
+        if ( t instanceof Exception && !( t instanceof RuntimeException ) )
+        {
+            eventCatapult.fire( ExecutionEvent.Type.ProjectFailed, currentSession, null, (Exception) t );
+        }
 
-        if ( MavenExecutionRequest.REACTOR_FAIL_NEVER.equals( rootSession.getReactorFailureBehavior() ) )
+        // reactor failure modes
+        if ( t instanceof RuntimeException || !( t instanceof Exception ) )
+        {
+            // fail fast on RuntimeExceptions, Errors and "other" Throwables
+            // assume these are system errors and further build is meaningless
+            buildContext.getReactorBuildStatus().halt();
+        }
+        else if ( MavenExecutionRequest.REACTOR_FAIL_NEVER.equals( rootSession.getReactorFailureBehavior() ) )
         {
             // continue the build
         }
@@ -170,8 +174,8 @@ public class BuilderCommon
         }
         else
         {
-            throw new IllegalArgumentException(
-                "invalid reactor failure behavior " + rootSession.getReactorFailureBehavior() );
+            logger.error( "invalid reactor failure behavior " + rootSession.getReactorFailureBehavior() );
+            buildContext.getReactorBuildStatus().halt();
         }
     }
 

http://git-wip-us.apache.org/repos/asf/maven/blob/cd52e5b5/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/multithreaded/MultiThreadedBuilder.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/multithreaded/MultiThreadedBuilder.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/multithreaded/MultiThreadedBuilder.java
index 88fa81b..906e5e7 100644
--- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/multithreaded/MultiThreadedBuilder.java
+++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/multithreaded/MultiThreadedBuilder.java
@@ -150,6 +150,7 @@ public class MultiThreadedBuilder
             }
             catch ( ExecutionException e )
             {
+                // TODO MNG-5766 changes likely made this redundant 
                 rootSession.getResult().addException( e );
                 break;
             }