From c2db5509a86e3cc1561aa21cb526ab39e4f1a39b Mon Sep 17 00:00:00 2001 From: Arnoud Glimmerveen Date: Mon, 23 Nov 2020 11:09:23 +0100 Subject: [PATCH] Restore Session in LegacySupport *after* running the additional Maven execution. This is due to that additional execution clearing a ThreadLocal reference to the Session, that subsequent plugins/code may depend on (ie IntelliJ's Maven integration). --- .../OtherBranchVersionExtension.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/e_gineering/maven/gitflowhelper/OtherBranchVersionExtension.java b/src/main/java/com/e_gineering/maven/gitflowhelper/OtherBranchVersionExtension.java index eec2ea9..e89f437 100644 --- a/src/main/java/com/e_gineering/maven/gitflowhelper/OtherBranchVersionExtension.java +++ b/src/main/java/com/e_gineering/maven/gitflowhelper/OtherBranchVersionExtension.java @@ -16,6 +16,7 @@ import org.apache.maven.model.Plugin; import org.apache.maven.model.ReportPlugin; import org.apache.maven.model.io.ModelWriter; +import org.apache.maven.plugin.LegacySupport; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; @@ -34,6 +35,9 @@ public class OtherBranchVersionExtension extends AbstractBranchDetectingExtensio @Requirement(role = Maven.class) Maven maven; + + @Requirement(role = LegacySupport.class) + LegacySupport legacySupport; private static final int ORIGINAL_VERSION_IDX = 0; private static final int ADJUSTED_VERSION_IDX = 1; @@ -106,7 +110,16 @@ public void afterProjectsRead(final MavenSession session) throws MavenExecutionE // Perform the nested Maven execution, and grab the list of *all* projects (ie modules of the // multi-module build). - final MavenExecutionResult mavenExecutionResult = maven.execute(request); + final MavenExecutionResult mavenExecutionResult; + try { + mavenExecutionResult = maven.execute(request); + } finally { + // The additional Maven execution uses a new session, and at the end of the execution + // clears the Session object in LegacySupport. This may break other plugins/uses of + // LegacySupport; therefore always restore the session *after* the additional Maven + // execution. + legacySupport.setSession(session); + } final List topologicallySortedProjects = mavenExecutionResult.getTopologicallySortedProjects(); // Iterate over these modules and process the 'new' ones just as the modules that are part