exit session scope in finally {} block

Signed-off-by: Igor Fedorenko <ifedorenko@apache.org>
This commit is contained in:
Igor Fedorenko 2015-02-14 08:56:22 -05:00
parent 6b79ac5e33
commit e2a0792840
1 changed files with 19 additions and 10 deletions

View File

@ -170,19 +170,32 @@ public class DefaultMaven
return addExceptionToResult( result, e );
}
DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) newRepositorySession( request );
MavenSession session = new MavenSession( container, repoSession, request, result );
//
// We enter the session scope right after the MavenSession creation and before any of the AbstractLifecycleParticipant lookups
// so that @SessionScoped components can be @Injected into AbstractLifecycleParticipants.
//
sessionScope.enter();
sessionScope.seed( MavenSession.class, session );
try
{
DefaultRepositorySystemSession repoSession =
(DefaultRepositorySystemSession) newRepositorySession( request );
MavenSession session = new MavenSession( container, repoSession, request, result );
legacySupport.setSession( session );
sessionScope.seed( MavenSession.class, session );
legacySupport.setSession( session );
return doExecute( request, session, result, repoSession );
}
finally
{
sessionScope.exit();
}
}
private MavenExecutionResult doExecute( MavenExecutionRequest request, MavenSession session,
MavenExecutionResult result, DefaultRepositorySystemSession repoSession )
{
try
{
for ( AbstractMavenLifecycleParticipant listener : getLifecycleParticipants( Collections.<MavenProject>emptyList() ) )
@ -321,10 +334,6 @@ public class DefaultMaven
{
return addExceptionToResult( result, e );
}
finally
{
sessionScope.exit();
}
}
return result;