diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java b/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java index 98c5573c9736..ec0a471a78a5 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java @@ -52,9 +52,9 @@ public class MavenSession private RepositorySystemSession repositorySession; - private Properties executionProperties; + private final Properties executionProperties; - private MavenProject currentProject; + private InheritableThreadLocal currentProject = new InheritableThreadLocal<>(); /** * These projects have already been topologically sorted in the {@link org.apache.maven.Maven} component before @@ -83,14 +83,14 @@ public void setProjects( List projects ) { if ( !projects.isEmpty() ) { - this.currentProject = projects.get( 0 ); - this.topLevelProject = - projects.stream().filter( project -> project.isExecutionRoot() ).findFirst() - .orElse( currentProject ); + MavenProject prj = projects.get( 0 ); + this.currentProject.set( prj ); + this.topLevelProject = projects.stream().filter( project -> project.isExecutionRoot() ).findFirst() + .orElse( prj ); } else { - this.currentProject = null; + this.currentProject.set( null ); this.topLevelProject = null; } this.projects = projects; @@ -151,12 +151,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() @@ -306,6 +306,9 @@ public MavenSession( PlexusContainer container, RepositorySystemSession reposito this.result = result; this.settings = new SettingsAdapter( request ); this.repositorySession = repositorySession; + this.executionProperties = new Properties(); + this.executionProperties.putAll( request.getSystemProperties() ); + this.executionProperties.putAll( request.getUserProperties() ); } @Deprecated @@ -351,6 +354,9 @@ public MavenSession( PlexusContainer container, MavenExecutionRequest request, M this.request = request; this.result = result; this.settings = new SettingsAdapter( request ); + this.executionProperties = new Properties(); + this.executionProperties.putAll( request.getSystemProperties() ); + this.executionProperties.putAll( request.getUserProperties() ); setProjects( projects ); } @@ -388,13 +394,6 @@ public boolean isUsingPOMsFromFilesystem() @Deprecated public Properties getExecutionProperties() { - if ( executionProperties == null ) - { - executionProperties = new Properties(); - executionProperties.putAll( request.getSystemProperties() ); - executionProperties.putAll( request.getUserProperties() ); - } - return executionProperties; } diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/BuildListCalculator.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/BuildListCalculator.java index 4fef69b4a9c7..0e0262779c0f 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/BuildListCalculator.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/BuildListCalculator.java @@ -61,9 +61,7 @@ public ProjectBuildList calculateProjectBuilds( MavenSession session, List