diff --git a/maven-failsafe-plugin/pom.xml b/maven-failsafe-plugin/pom.xml
index 3a464997d5..e83d8d9cf8 100644
--- a/maven-failsafe-plugin/pom.xml
+++ b/maven-failsafe-plugin/pom.xml
@@ -23,7 +23,7 @@
org.apache.maven.surefiresurefire
- 3.3.2-SNAPSHOT
+ 3.4.0-SNAPSHOTorg.apache.maven.plugins
diff --git a/maven-surefire-common/pom.xml b/maven-surefire-common/pom.xml
index de13d98314..bba8dfddc6 100644
--- a/maven-surefire-common/pom.xml
+++ b/maven-surefire-common/pom.xml
@@ -23,7 +23,7 @@
org.apache.maven.surefiresurefire
- 3.3.2-SNAPSHOT
+ 3.4.0-SNAPSHOTmaven-surefire-common
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 47d691a130..094843123b 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
@@ -24,6 +24,7 @@
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.file.Files;
+import java.text.ChoiceFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -319,25 +320,45 @@ public abstract class AbstractSurefireMojo extends AbstractMojo implements Suref
*/
@Deprecated
@Parameter
- private Properties systemProperties;
+ Properties systemProperties;
/**
* List of System properties to pass to a provider.
* The effective system properties given to a provider are contributed from several sources:
*
+ *
properties set via {@link #argLine} with {@code -D} (only for forked executions)
*
{@link #systemProperties}
*
{@link AbstractSurefireMojo#getSystemPropertiesFile()} (set via parameter {@code systemPropertiesFile} on some goals)
*
{@link #systemPropertyVariables}
- *
User properties from {@link MavenSession#getUserProperties()}, usually set via CLI options given with {@code -D}
+ *
User properties from {@link MavenSession#getUserProperties()}, usually set via CLI options given with {@code -D} on the current Maven process (only used as source if {@link #promoteUserPropertiesToSystemProperties} is {@code true})
*
* Later sources may overwrite same named properties from earlier sources, that means for example that one cannot overwrite user properties with either
- * {@link #systemProperties}, {@link AbstractSurefireMojo#getSystemPropertiesFile()} or {@link #systemPropertyVariables}.
+ * {@link #systemProperties}, {@link #getSystemPropertiesFile()} or {@link #systemPropertyVariables}.
+ *
+ * Certain properties may only be overwritten via {@link #argLine} (applicable only for forked executions) because their values are cached and only evaluated at the start of the JRE.
+ * Those include:
+ *
+ *
{@code java.library.path}
+ *
{@code file.encoding}
+ *
{@code jdk.map.althashing.threshold}
+ *
{@code line.separator}
+ *
*
* @since 2.5
* @see #systemProperties
*/
@Parameter
- private Map systemPropertyVariables;
+ Map systemPropertyVariables;
+
+ /**
+ * If set to {@code true} will also pass all user properties exposed via {@link MavenSession#getUserProperties()} as system properties to a provider.
+ * Those always take precedence over same named system properties set via any other means.
+ *
+ * @since 3.4.0
+ * @see #systemPropertyVariables
+ */
+ @Parameter(defaultValue = "true")
+ boolean promoteUserPropertiesToSystemProperties;
/**
* List of properties for configuring the testing provider. This is the preferred method of
@@ -425,7 +446,7 @@ public abstract class AbstractSurefireMojo extends AbstractMojo implements Suref
private String jvm;
/**
- * Arbitrary JVM options to set on the command line.
+ * Arbitrary JVM options to set on the command line. Only effective for forked executions.
*
*
* Since the Version 2.17 using an alternate syntax for {@code argLine}, @{...} allows late replacement
@@ -438,6 +459,7 @@ public abstract class AbstractSurefireMojo extends AbstractMojo implements Suref
*
* http://maven.apache.org/surefire/maven-failsafe-plugin/faq.html
*
+ * @see #forkCount
* @since 2.1
*/
@Parameter(property = "argLine")
@@ -543,7 +565,7 @@ public abstract class AbstractSurefireMojo extends AbstractMojo implements Suref
* @since 2.14
*/
@Parameter(property = "forkCount", defaultValue = "1")
- private String forkCount;
+ String forkCount;
/**
* Indicates if forked VMs can be reused. If set to "false", a new VM is forked for each test class to be executed.
@@ -1139,10 +1161,10 @@ protected List createProviders(TestClassPath testClasspath) throws
new JUnit3ProviderInfo());
}
- private SurefireProperties setupProperties() {
- SurefireProperties sysProps = null;
+ SurefireProperties setupProperties() {
+ SurefireProperties sysPropsFromFile = null;
try {
- sysProps = SurefireProperties.loadProperties(getSystemPropertiesFile());
+ sysPropsFromFile = SurefireProperties.loadProperties(getSystemPropertiesFile());
} catch (IOException e) {
String msg = "The file '" + getSystemPropertiesFile().getAbsolutePath() + "' can't be read.";
if (getConsoleLogger().isDebugEnabled()) {
@@ -1152,8 +1174,11 @@ private SurefireProperties setupProperties() {
}
}
- SurefireProperties result = SurefireProperties.calculateEffectiveProperties(
- getSystemProperties(), getSystemPropertyVariables(), getUserProperties(), sysProps);
+ SurefireProperties result = calculateEffectiveProperties(
+ getSystemProperties(),
+ getSystemPropertyVariables(),
+ promoteUserPropertiesToSystemProperties ? getUserProperties() : new Properties(),
+ sysPropsFromFile);
result.setProperty("basedir", getBasedir().getAbsolutePath());
result.setProperty("localRepository", getLocalRepositoryPath());
@@ -1184,6 +1209,38 @@ private SurefireProperties setupProperties() {
return result;
}
+ private SurefireProperties calculateEffectiveProperties(
+ Properties systemProperties,
+ Map systemPropertyVariables,
+ Properties userProperties,
+ SurefireProperties sysPropsFromFile) {
+ SurefireProperties result = new SurefireProperties();
+ result.copyPropertiesFrom(systemProperties);
+
+ Collection overwrittenProperties = result.copyPropertiesFrom(sysPropsFromFile);
+ if (!overwrittenProperties.isEmpty() && getConsoleLogger().isDebugEnabled()) {
+ getConsoleLogger().debug(getOverwrittenPropertiesLogMessage(overwrittenProperties, "systemPropertiesFile"));
+ }
+ overwrittenProperties = result.copyPropertiesFrom(systemPropertyVariables);
+ if (!overwrittenProperties.isEmpty() && getConsoleLogger().isDebugEnabled()) {
+ getConsoleLogger()
+ .debug(getOverwrittenPropertiesLogMessage(overwrittenProperties, "systemPropertyVariables"));
+ }
+ // We used to take all of our system properties and dump them in with the
+ // user specified properties for SUREFIRE-121, causing SUREFIRE-491.
+ // Not gonna do THAT any more... instead, we only propagate those system properties
+ // that have been explicitly specified by the user via -Dkey=value on the CLI
+ if (!userProperties.isEmpty()) {
+ overwrittenProperties = result.copyPropertiesFrom(userProperties);
+ if (!overwrittenProperties.isEmpty()) {
+ getConsoleLogger()
+ .warning(getOverwrittenPropertiesLogMessage(
+ overwrittenProperties, "user properties from Maven session"));
+ }
+ }
+ return result;
+ }
+
private Set