Skip to content

Commit

Permalink
Attempt to use a single session
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Apr 12, 2022
1 parent 386def2 commit 8d0de00
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class MavenSession

private Properties executionProperties;

private MavenProject currentProject;
private InheritableThreadLocal<MavenProject> currentProject = new InheritableThreadLocal<>();

/**
* These projects have already been topologically sorted in the {@link org.apache.maven.Maven} component before
Expand Down Expand Up @@ -83,8 +83,9 @@ public void setProjects( List<MavenProject> projects )
{
if ( !projects.isEmpty() )
{
this.currentProject = projects.get( 0 );
this.topLevelProject = currentProject;
MavenProject prj = projects.get( 0 );
this.currentProject.set( prj );
this.topLevelProject = prj;
for ( MavenProject project : projects )
{
if ( project.isExecutionRoot() )
Expand All @@ -96,7 +97,7 @@ public void setProjects( List<MavenProject> projects )
}
else
{
this.currentProject = null;
this.currentProject.set( null );
this.topLevelProject = null;
}
this.projects = projects;
Expand Down Expand Up @@ -157,12 +158,12 @@ public MavenExecutionRequest getRequest()

public void setCurrentProject( MavenProject currentProject )
{
this.currentProject = currentProject;
this.currentProject.set( currentProject );
}

public MavenProject getCurrentProject()
{
return currentProject;
return currentProject.get();
}

public ProjectBuildingRequest getProjectBuildingRequest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ public ProjectBuildList calculateProjectBuilds( MavenSession session, List<TaskS
try
{
BuilderCommon.attachToThread( project ); // Not totally sure if this is needed for anything
MavenSession copiedSession = session.clone();
copiedSession.setCurrentProject( project );
projectBuilds.add( new ProjectSegment( project, taskSegment, copiedSession ) );
projectBuilds.add( new ProjectSegment( project, taskSegment, session ) );
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,10 @@ public void buildProject( MavenSession session, MavenSession rootSession, Reacto

long buildStartTime = System.currentTimeMillis();

// session may be different from rootSession seeded in DefaultMaven
// explicitly seed the right session here to make sure it is used by Guice
final boolean scoped = session != rootSession;
if ( scoped )
if ( session != rootSession )
{
sessionScope.enter();
sessionScope.seed( MavenSession.class, session );
// a single session is reused during the whole build
throw new UnsupportedOperationException();
}
try
{
Expand Down Expand Up @@ -149,11 +146,6 @@ public void buildProject( MavenSession session, MavenSession rootSession, Reacto
}
finally
{
if ( scoped )
{
sessionScope.exit();
}

session.setCurrentProject( null );

Thread.currentThread().setContextClassLoader( reactorContext.getOriginalContextClassLoader() );
Expand Down

0 comments on commit 8d0de00

Please sign in to comment.