MNG-5766 consistently handle all throwables in LifecycleModuleBuilder

Signed-off-by: Igor Fedorenko <ifedorenko@apache.org>
This commit is contained in:
Igor Fedorenko 2015-02-18 10:47:52 -05:00
parent c28348024a
commit cd52e5b51e
3 changed files with 33 additions and 18 deletions

View File

@ -124,12 +124,22 @@ public class LifecycleModuleBuilder
eventCatapult.fire( ExecutionEvent.Type.ProjectSucceeded, session, null ); 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, 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 finally
{ {

View File

@ -19,7 +19,6 @@ package org.apache.maven.lifecycle.internal.builder;
* under the License. * under the License.
*/ */
import org.apache.maven.InternalErrorException;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.execution.BuildFailure; import org.apache.maven.execution.BuildFailure;
import org.apache.maven.execution.ExecutionEvent; import org.apache.maven.execution.ExecutionEvent;
@ -139,23 +138,28 @@ public class BuilderCommon
} }
public void handleBuildError( final ReactorContext buildContext, final MavenSession rootSession, 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 ) final long buildStartTime )
{ {
if ( e instanceof RuntimeException ) // 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 ) );
// notify listeners about "soft" project build failures only
if ( t instanceof Exception && !( t instanceof RuntimeException ) )
{ {
e = new InternalErrorException( "Internal error: " + e, e ); eventCatapult.fire( ExecutionEvent.Type.ProjectFailed, currentSession, null, (Exception) t );
} }
buildContext.getResult().addException( e ); // reactor failure modes
if ( t instanceof RuntimeException || !( t instanceof Exception ) )
long buildEndTime = System.currentTimeMillis(); {
// fail fast on RuntimeExceptions, Errors and "other" Throwables
buildContext.getResult().addBuildSummary( new BuildFailure( mavenProject, buildEndTime - buildStartTime, e ) ); // assume these are system errors and further build is meaningless
buildContext.getReactorBuildStatus().halt();
eventCatapult.fire( ExecutionEvent.Type.ProjectFailed, currentSession, null, e ); }
else if ( MavenExecutionRequest.REACTOR_FAIL_NEVER.equals( rootSession.getReactorFailureBehavior() ) )
if ( MavenExecutionRequest.REACTOR_FAIL_NEVER.equals( rootSession.getReactorFailureBehavior() ) )
{ {
// continue the build // continue the build
} }
@ -170,8 +174,8 @@ public class BuilderCommon
} }
else else
{ {
throw new IllegalArgumentException( logger.error( "invalid reactor failure behavior " + rootSession.getReactorFailureBehavior() );
"invalid reactor failure behavior " + rootSession.getReactorFailureBehavior() ); buildContext.getReactorBuildStatus().halt();
} }
} }

View File

@ -150,6 +150,7 @@ public class MultiThreadedBuilder
} }
catch ( ExecutionException e ) catch ( ExecutionException e )
{ {
// TODO MNG-5766 changes likely made this redundant
rootSession.getResult().addException( e ); rootSession.getResult().addException( e );
break; break;
} }