Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class MavenSession

private Properties executionProperties;

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

/**
* These projects have already been topologically sorted in the {@link org.apache.maven.Maven} component before
Expand Down Expand Up @@ -90,20 +90,21 @@ public void setProjects( List<MavenProject> projects )
{
if ( !projects.isEmpty() )
{
this.currentProject = projects.get( 0 );
this.topLevelProject = currentProject;
MavenProject first = projects.get( 0 );
this.topLevelProject = first;
this.currentProject = ThreadLocal.withInitial( () -> first );
for ( MavenProject project : projects )
{
if ( project.isExecutionRoot() )
{
topLevelProject = project;
this.topLevelProject = project;
break;
}
}
}
else
{
this.currentProject = null;
this.currentProject = new ThreadLocal<>();
this.topLevelProject = null;
}
this.projects = projects;
Expand Down Expand Up @@ -164,12 +165,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 @@ -240,7 +241,12 @@ public MavenSession clone()
{
try
{
return (MavenSession) super.clone();
MavenSession clone = (MavenSession) super.clone();
// the default must become the current project of the thread that clones this
MavenProject current = getCurrentProject();
// we replace the thread local of the clone to prevent write through and enforce the new default value
clone.currentProject = ThreadLocal.withInitial( () -> current );
return clone;
}
catch ( CloneNotSupportedException e )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,16 @@ public ProjectBuildList calculateProjectBuilds( MavenSession session, List<TaskS
for ( MavenProject project : projects )
{
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 ) );
MavenProject currentProject = session.getCurrentProject();
try
{
session.setCurrentProject( project );
projectBuilds.add( new ProjectSegment( project, taskSegment, session ) );
}
finally
{
session.setCurrentProject( currentProject );
}
}
}
return new ProjectBuildList( projectBuilds );
Expand Down