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 void buildProject( MavenSession session, MavenSession rootSession, Reacto
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
{

View File

@ -19,7 +19,6 @@
* 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 MavenExecutionPlan resolveBuildPlan( MavenSession session, MavenProject p
}
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 )
// 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 );
long buildEndTime = System.currentTimeMillis();
buildContext.getResult().addBuildSummary( new BuildFailure( mavenProject, buildEndTime - buildStartTime, e ) );
eventCatapult.fire( ExecutionEvent.Type.ProjectFailed, currentSession, null, e );
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 @@ else if ( MavenExecutionRequest.REACTOR_FAIL_FAST.equals( rootSession.getReactor
}
else
{
throw new IllegalArgumentException(
"invalid reactor failure behavior " + rootSession.getReactorFailureBehavior() );
logger.error( "invalid reactor failure behavior " + rootSession.getReactorFailureBehavior() );
buildContext.getReactorBuildStatus().halt();
}
}

View File

@ -150,6 +150,7 @@ private void multiThreadedProjectTaskSegmentBuild( ConcurrencyDependencyGraph an
}
catch ( ExecutionException e )
{
// TODO MNG-5766 changes likely made this redundant
rootSession.getResult().addException( e );
break;
}