From 18964baa25e9c071d13186e4c03e3957b9381961 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Fri, 30 May 2014 15:26:54 +0200 Subject: [PATCH] Make sure participants and session scope exit are called Even in case of failing build. Signed-off-by: Jason van Zyl --- .../java/org/apache/maven/DefaultMaven.java | 64 +++++++++---------- 1 file changed, 31 insertions(+), 33 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 ab47efd00f..d8425b5d3a 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -336,47 +336,45 @@ public class DefaultMaven // projectDependencyGraph = createProjectDependencyGraph( session.getProjects(), request, result, false ); - if ( result.hasExceptions() ) + try { - try + if ( result.hasExceptions() ) + { + return result; + } + + session.setProjects( projectDependencyGraph.getSortedProjects() ); + + session.setProjectDependencyGraph( projectDependencyGraph ); + + result.setTopologicallySortedProjects( session.getProjects() ); + + result.setProject( session.getTopLevelProject() ); + + lifecycleStarter.execute( session ); + + validateActivatedProfiles( session.getProjects(), request.getActiveProfiles() ); + + if ( session.getResult().hasExceptions() ) + { + return addExceptionToResult( result, session.getResult().getExceptions().get( 0 ) ); + } + } + finally + { + try { afterSessionEnd( projects, session ); - } + } catch ( MavenExecutionException e ) { return addExceptionToResult( result, e ); } - - return result; + finally + { + sessionScope.exit(); + } } - - session.setProjects( projectDependencyGraph.getSortedProjects() ); - - session.setProjectDependencyGraph( projectDependencyGraph ); - - result.setTopologicallySortedProjects( session.getProjects() ); - - result.setProject( session.getTopLevelProject() ); - - lifecycleStarter.execute( session ); - - validateActivatedProfiles( session.getProjects(), request.getActiveProfiles() ); - - if ( session.getResult().hasExceptions() ) - { - return addExceptionToResult( result, session.getResult().getExceptions().get( 0 ) ); - } - - try - { - afterSessionEnd( projects, session ); - } - catch ( MavenExecutionException e ) - { - return addExceptionToResult( result, e ); - } - - sessionScope.exit(); return result; }