extract AbstractMavenLifecycleParticipant dispatch methods

This commit is contained in:
Hervé Boutemy 2021-02-20 19:55:40 +01:00
parent 441cf73c06
commit 9b5b8d4082
1 changed files with 32 additions and 17 deletions

View File

@ -227,12 +227,7 @@ public class DefaultMaven
{
try
{
// CHECKSTYLE_OFF: LineLength
for ( AbstractMavenLifecycleParticipant listener : getLifecycleParticipants( Collections.<MavenProject>emptyList() ) )
{
listener.afterSessionStart( session );
}
// CHECKSTYLE_ON: LineLength
afterSessionStart( session );
}
catch ( MavenExecutionException e )
{
@ -279,24 +274,14 @@ public class DefaultMaven
repoSession.setReadOnly();
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try
{
for ( AbstractMavenLifecycleParticipant listener : getLifecycleParticipants( session.getProjects() ) )
{
Thread.currentThread().setContextClassLoader( listener.getClass().getClassLoader() );
listener.afterProjectsRead( session );
}
afterProjectsRead( session );
}
catch ( MavenExecutionException e )
{
return addExceptionToResult( result, e );
}
finally
{
Thread.currentThread().setContextClassLoader( originalClassLoader );
}
//
// The projects need to be topologically after the participants have run their afterProjectsRead(session)
@ -368,6 +353,36 @@ public class DefaultMaven
return result;
}
private void afterSessionStart( MavenSession session )
throws MavenExecutionException
{
// CHECKSTYLE_OFF: LineLength
for ( AbstractMavenLifecycleParticipant listener : getLifecycleParticipants( Collections.<MavenProject>emptyList() ) )
// CHECKSTYLE_ON: LineLength
{
listener.afterSessionStart( session );
}
}
private void afterProjectsRead( MavenSession session )
throws MavenExecutionException
{
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try
{
for ( AbstractMavenLifecycleParticipant listener : getLifecycleParticipants( session.getProjects() ) )
{
Thread.currentThread().setContextClassLoader( listener.getClass().getClassLoader() );
listener.afterProjectsRead( session );
}
}
finally
{
Thread.currentThread().setContextClassLoader( originalClassLoader );
}
}
private void afterSessionEnd( Collection<MavenProject> projects, MavenSession session )
throws MavenExecutionException
{