Skip to content

Commit c2db550

Browse files
committed
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).
1 parent 9d1c277 commit c2db550

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/main/java/com/e_gineering/maven/gitflowhelper/OtherBranchVersionExtension.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.apache.maven.model.Plugin;
1717
import org.apache.maven.model.ReportPlugin;
1818
import org.apache.maven.model.io.ModelWriter;
19+
import org.apache.maven.plugin.LegacySupport;
1920
import org.apache.maven.project.MavenProject;
2021
import org.codehaus.plexus.component.annotations.Component;
2122
import org.codehaus.plexus.component.annotations.Requirement;
@@ -34,6 +35,9 @@ public class OtherBranchVersionExtension extends AbstractBranchDetectingExtensio
3435

3536
@Requirement(role = Maven.class)
3637
Maven maven;
38+
39+
@Requirement(role = LegacySupport.class)
40+
LegacySupport legacySupport;
3741

3842
private static final int ORIGINAL_VERSION_IDX = 0;
3943
private static final int ADJUSTED_VERSION_IDX = 1;
@@ -106,7 +110,16 @@ public void afterProjectsRead(final MavenSession session) throws MavenExecutionE
106110

107111
// Perform the nested Maven execution, and grab the list of *all* projects (ie modules of the
108112
// multi-module build).
109-
final MavenExecutionResult mavenExecutionResult = maven.execute(request);
113+
final MavenExecutionResult mavenExecutionResult;
114+
try {
115+
mavenExecutionResult = maven.execute(request);
116+
} finally {
117+
// The additional Maven execution uses a new session, and at the end of the execution
118+
// clears the Session object in LegacySupport. This may break other plugins/uses of
119+
// LegacySupport; therefore always restore the session *after* the additional Maven
120+
// execution.
121+
legacySupport.setSession(session);
122+
}
110123
final List<MavenProject> topologicallySortedProjects = mavenExecutionResult.getTopologicallySortedProjects();
111124

112125
// Iterate over these modules and process the 'new' ones just as the modules that are part

0 commit comments

Comments
 (0)