This is an automated email from the ASF dual-hosted git repository.

olamy pushed a commit to branch surefire-3.5.x
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git


The following commit(s) were added to refs/heads/surefire-3.5.x by this push:
     new 27742739c Ensure that the statistics filename is calculated only once. 
(#3326) (#3327)
27742739c is described below

commit 27742739c8cc6e4676611ac4bfe42870f74fd0f3
Author: Olivier Lamy <[email protected]>
AuthorDate: Mon Mar 23 21:09:27 2026 +1000

    Ensure that the statistics filename is calculated only once. (#3326) (#3327)
    
    The issue is that `getStatisticsFile()` uses `getConfigChecksum()` which 
relies on potentially mutable values such as system properties, provider 
properties, etc. `getStatisticsFile()` was called from different places with 
changes to the system properties in between, leading to different filenames.
    
    Co-authored-by: Alexey Venderov <[email protected]>
---
 .../plugin/surefire/AbstractSurefireMojo.java      | 11 ++++++----
 .../maven/plugin/surefire/MojoMocklessTest.java    | 25 ++++++++++++++++++----
 .../surefire/api/testset/RunOrderParameters.java   |  5 -----
 .../surefire/api/util/RunOrderCalculatorTest.java  |  5 ++++-
 4 files changed, 32 insertions(+), 14 deletions(-)

diff --git 
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
 
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
index 35addccf6..71723c4d0 100644
--- 
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
+++ 
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
@@ -2081,7 +2081,8 @@ private Artifact getShadefireArtifact() {
         return 
getPluginArtifactMap().get("org.apache.maven.surefire:surefire-shadefire");
     }
 
-    private StartupReportConfiguration getStartupReportConfiguration(boolean 
isForking, ProviderInfo providerInfo) {
+    private StartupReportConfiguration getStartupReportConfiguration(
+            boolean isForking, ProviderInfo providerInfo, RunOrderParameters 
runOrderParameters) {
         SurefireStatelessReporter xmlReporter =
                 statelessTestsetReporter == null ? new 
SurefireStatelessReporter() : statelessTestsetReporter;
 
@@ -2109,7 +2110,7 @@ private StartupReportConfiguration 
getStartupReportConfiguration(boolean isForki
                 getReportsDirectory(),
                 isTrimStackTrace(),
                 getReportNameSuffix(),
-                getStatisticsFile(),
+                runOrderParameters.getRunStatisticsFile(),
                 requiresRunHistory(),
                 getRerunFailingTestsCount(),
                 getReportSchemaLocation(),
@@ -2350,7 +2351,8 @@ private ForkStarter createForkStarter(
                 testClasspathWrapper,
                 platform,
                 resolvedJavaModularityResult);
-        StartupReportConfiguration startupReportConfiguration = 
getStartupReportConfiguration(true, provider);
+        StartupReportConfiguration startupReportConfiguration =
+                getStartupReportConfiguration(true, provider, 
runOrderParameters);
 
         ProviderConfiguration providerConfiguration = 
createProviderConfiguration(runOrderParameters);
         return new ForkStarter(
@@ -2378,7 +2380,8 @@ private InPluginVMSurefireStarter createInprocessStarter(
                 testClasspathWrapper,
                 platform,
                 new ResolvePathResultWrapper(null, true));
-        StartupReportConfiguration startupReportConfiguration = 
getStartupReportConfiguration(false, provider);
+        StartupReportConfiguration startupReportConfiguration =
+                getStartupReportConfiguration(false, provider, 
runOrderParameters);
         ProviderConfiguration providerConfiguration = 
createProviderConfiguration(runOrderParameters);
         return new InPluginVMSurefireStarter(
                 startupConfiguration, providerConfiguration, 
startupReportConfiguration, getConsoleLogger(), platform);
diff --git 
a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/MojoMocklessTest.java
 
b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/MojoMocklessTest.java
index 74b679942..d44cea49b 100644
--- 
a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/MojoMocklessTest.java
+++ 
b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/MojoMocklessTest.java
@@ -34,7 +34,9 @@
 import org.apache.maven.plugin.surefire.extensions.SurefireStatelessReporter;
 import 
org.apache.maven.plugin.surefire.extensions.SurefireStatelessTestsetInfoReporter;
 import org.apache.maven.surefire.api.suite.RunResult;
+import org.apache.maven.surefire.api.testset.RunOrderParameters;
 import org.apache.maven.surefire.api.util.DefaultScanResult;
+import org.apache.maven.surefire.api.util.RunOrder;
 import org.apache.maven.surefire.api.util.SureFireFileManager;
 import org.apache.maven.surefire.extensions.ForkNodeFactory;
 import org.apache.maven.surefire.providerapi.ProviderInfo;
@@ -53,11 +55,24 @@
  *
  */
 public class MojoMocklessTest {
+    @Test
+    public void 
testGetStartupReportConfigurationUsesProvidedRunStatisticsFile() throws 
Exception {
+        AbstractSurefireMojo surefirePlugin = new Mojo(null, null);
+        File runStatisticsFile = 
SureFireFileManager.createTempFile(".surefire-", "checksum");
+        RunOrderParameters runOrderParameters = new 
RunOrderParameters(RunOrder.DEFAULT, runStatisticsFile);
+        StartupReportConfiguration config = invokeMethod(
+                surefirePlugin, "getStartupReportConfiguration", false, 
mock(ProviderInfo.class), runOrderParameters);
+
+        assertThat(config.getStatisticsFile()).isSameAs(runStatisticsFile);
+    }
+
     @Test
     public void testGetStartupReportConfiguration() throws Exception {
         AbstractSurefireMojo surefirePlugin = new Mojo(null, null);
-        StartupReportConfiguration config =
-                invokeMethod(surefirePlugin, "getStartupReportConfiguration", 
false, mock(ProviderInfo.class));
+        RunOrderParameters runOrderParameters =
+                new RunOrderParameters(RunOrder.DEFAULT, 
SureFireFileManager.createTempFile(".surefire-", "checksum"));
+        StartupReportConfiguration config = invokeMethod(
+                surefirePlugin, "getStartupReportConfiguration", false, 
mock(ProviderInfo.class), runOrderParameters);
 
         
assertThat(config.getXmlReporter()).isNotNull().isInstanceOf(SurefireStatelessReporter.class);
 
@@ -69,6 +84,8 @@ public void testGetStartupReportConfiguration() throws 
Exception {
     @Test
     public void testGetStartupReportConfiguration2() throws Exception {
         AbstractSurefireMojo surefirePlugin = new Mojo(null, null);
+        RunOrderParameters runOrderParameters =
+                new RunOrderParameters(RunOrder.DEFAULT, 
SureFireFileManager.createTempFile(".surefire-", "checksum"));
         SurefireStatelessReporter xmlReporter = new 
SurefireStatelessReporter();
         SurefireConsoleOutputReporter consoleReporter = new 
SurefireConsoleOutputReporter();
         SurefireStatelessTestsetInfoReporter testsetInfoReporter = new 
SurefireStatelessTestsetInfoReporter();
@@ -76,8 +93,8 @@ public void testGetStartupReportConfiguration2() throws 
Exception {
         setInternalState(surefirePlugin, "consoleOutputReporter", 
consoleReporter);
         setInternalState(surefirePlugin, "statelessTestsetInfoReporter", 
testsetInfoReporter);
 
-        StartupReportConfiguration config =
-                invokeMethod(surefirePlugin, "getStartupReportConfiguration", 
false, mock(ProviderInfo.class));
+        StartupReportConfiguration config = invokeMethod(
+                surefirePlugin, "getStartupReportConfiguration", false, 
mock(ProviderInfo.class), runOrderParameters);
 
         assertThat(config.getXmlReporter()).isNotNull().isSameAs(xmlReporter);
 
diff --git 
a/surefire-api/src/main/java/org/apache/maven/surefire/api/testset/RunOrderParameters.java
 
b/surefire-api/src/main/java/org/apache/maven/surefire/api/testset/RunOrderParameters.java
index f07cffc8d..f5256e4fc 100644
--- 
a/surefire-api/src/main/java/org/apache/maven/surefire/api/testset/RunOrderParameters.java
+++ 
b/surefire-api/src/main/java/org/apache/maven/surefire/api/testset/RunOrderParameters.java
@@ -22,7 +22,6 @@
 
 import org.apache.maven.surefire.api.util.RunOrder;
 
-import static org.apache.maven.surefire.api.util.RunOrder.ALPHABETICAL;
 import static org.apache.maven.surefire.api.util.RunOrder.DEFAULT;
 
 /**
@@ -53,10 +52,6 @@ public RunOrderParameters(RunOrder[] runOrder, File 
runStatisticsFile, Long runO
         this.runOrderRandomSeed = runOrderRandomSeed;
     }
 
-    public static RunOrderParameters alphabetical() {
-        return new RunOrderParameters(new RunOrder[] {ALPHABETICAL}, null);
-    }
-
     public RunOrder[] getRunOrder() {
         return runOrder;
     }
diff --git 
a/surefire-api/src/test/java/org/apache/maven/surefire/api/util/RunOrderCalculatorTest.java
 
b/surefire-api/src/test/java/org/apache/maven/surefire/api/util/RunOrderCalculatorTest.java
index 3ff55dc1f..2e1d65ecb 100644
--- 
a/surefire-api/src/test/java/org/apache/maven/surefire/api/util/RunOrderCalculatorTest.java
+++ 
b/surefire-api/src/test/java/org/apache/maven/surefire/api/util/RunOrderCalculatorTest.java
@@ -24,6 +24,8 @@
 import junit.framework.TestCase;
 import org.apache.maven.surefire.api.testset.RunOrderParameters;
 
+import static org.apache.maven.surefire.api.util.RunOrder.ALPHABETICAL;
+
 /**
  * @author Kristian Rosenvold
  */
@@ -32,7 +34,8 @@ public class RunOrderCalculatorTest extends TestCase {
     public void testOrderTestClasses() {
         getClassesToRun();
         TestsToRun testsToRun = new TestsToRun(getClassesToRun());
-        RunOrderCalculator runOrderCalculator = new 
DefaultRunOrderCalculator(RunOrderParameters.alphabetical(), 1);
+        RunOrderParameters alphabetical = new RunOrderParameters(new 
RunOrder[] {ALPHABETICAL}, null);
+        RunOrderCalculator runOrderCalculator = new 
DefaultRunOrderCalculator(alphabetical, 1);
         final TestsToRun testsToRun1 = 
runOrderCalculator.orderTestClasses(testsToRun);
         assertEquals(A.class, testsToRun1.iterator().next());
     }

Reply via email to