Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNG-7455] Use a single session object during the whole build #713

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public class MavenSession

private RepositorySystemSession repositorySession;

private Properties executionProperties;
private volatile 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 Expand Up @@ -396,9 +397,15 @@ public Properties getExecutionProperties()
{
if ( executionProperties == null )
{
executionProperties = new Properties();
executionProperties.putAll( request.getSystemProperties() );
executionProperties.putAll( request.getUserProperties() );
synchronized ( this )
{
if ( executionProperties == null )
{
executionProperties = new Properties();
executionProperties.putAll( request.getSystemProperties() );
executionProperties.putAll( request.getUserProperties() );
}
}
}

return executionProperties;
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