Repository: maven-surefire
Updated Branches:
  refs/heads/SUREFIRE-1385 [created] 4de017b38


[SUREFIRE-1385] System properties defined in the Surefire and Failsafe plugin 
configuration should override user properties

When building the Surefire properties, user properties should be set first so 
that the more direct configuration of systemPropertyVariables and 
systemPropertyFile can possibly override them.


Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/4de017b3
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/4de017b3
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/4de017b3

Branch: refs/heads/SUREFIRE-1385
Commit: 4de017b38b101b0b28f9fbed135eae3921b99d0d
Parents: 7176d3c
Author: Guillaume Boué <gb...@apache.org>
Authored: Thu Jun 15 21:50:43 2017 +0200
Committer: Guillaume Boué <gb...@apache.org>
Committed: Thu Jun 15 21:50:43 2017 +0200

----------------------------------------------------------------------
 .../plugin/surefire/SurefireProperties.java     | 17 +++---
 .../plugin/surefire/SurefirePropertiesTest.java | 21 +++++++
 ...re1385SystemPropertyVariablesOverrideIT.java | 45 +++++++++++++++
 .../pom.xml                                     | 61 ++++++++++++++++++++
 .../src/test/java/ATest.java                    | 44 ++++++++++++++
 5 files changed, 181 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/4de017b3/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java
----------------------------------------------------------------------
diff --git 
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java
 
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java
index fd2b4fb..4b13898 100644
--- 
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java
+++ 
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java
@@ -143,19 +143,22 @@ public class SurefireProperties
                                                             Properties 
userProperties, SurefireProperties props )
     {
         SurefireProperties result = new SurefireProperties();
+
+        // SUREFIRE-1385: Make sure user properties are set first, so that 
system properties
+        // configured in the POM or properties file take precedence
+        
+        // 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.
+        result.copyPropertiesFrom( userProperties );
+
         result.copyPropertiesFrom( systemProperties );
 
         result.copyPropertiesFrom( props );
 
         copyProperties( result, systemPropertyVariables );
-        copyProperties( result, 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
 
-        result.copyPropertiesFrom( userProperties );
         return result;
     }
 

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/4de017b3/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefirePropertiesTest.java
----------------------------------------------------------------------
diff --git 
a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefirePropertiesTest.java
 
b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefirePropertiesTest.java
index af9ee75..6f727b0 100644
--- 
a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefirePropertiesTest.java
+++ 
b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefirePropertiesTest.java
@@ -19,6 +19,8 @@ package org.apache.maven.plugin.surefire;
  */
 
 import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Properties;
 
 import junit.framework.TestCase;
@@ -75,4 +77,23 @@ public class SurefirePropertiesTest
 
     }
 
+    public void 
testCalculateEffectiveProperties_SystemPropertyVariablesOverrideUserProperties()
+    {
+        Properties userProperties = new Properties();
+        userProperties.setProperty( "prop2", "user-property-2" );
+        userProperties.setProperty( "prop3", "user-property-3" );
+
+        Map<String, String> systemPropertyVariables = new HashMap<String, 
String>( 2 );
+        systemPropertyVariables.put( "prop1", "system-property-variable-1" );
+        systemPropertyVariables.put( "prop2", "system-property-variable-2" );
+
+        SurefireProperties surefireProperties =
+            SurefireProperties.calculateEffectiveProperties( null, 
systemPropertyVariables, userProperties, null );
+
+        assertEquals( 3, surefireProperties.size() );
+        assertEquals( "system-property-variable-1", surefireProperties.get( 
"prop1" ) );
+        assertEquals( "system-property-variable-2", surefireProperties.get( 
"prop2" ) );
+        assertEquals( "user-property-3", surefireProperties.get( "prop3" ) );
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/4de017b3/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1385SystemPropertyVariablesOverrideIT.java
----------------------------------------------------------------------
diff --git 
a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1385SystemPropertyVariablesOverrideIT.java
 
b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1385SystemPropertyVariablesOverrideIT.java
new file mode 100644
index 0000000..b82e603
--- /dev/null
+++ 
b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1385SystemPropertyVariablesOverrideIT.java
@@ -0,0 +1,45 @@
+package org.apache.maven.surefire.its.jiras;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
+import org.apache.maven.surefire.its.fixture.SurefireLauncher;
+import org.junit.Test;
+
+/**
+ * @author gboue
+ * @since 2.20.1
+ */
+public class Surefire1385SystemPropertyVariablesOverrideIT
+        extends SurefireJUnit4IntegrationTestCase
+{
+
+    @Test
+    public void systemPropertyVariablesShouldOverrideUserProperties()
+    {
+        unpack().sysProp( "prop-2", "from-cli-2" ).sysProp( "prop-3", 
"from-cli-3" ).executeTest().verifyErrorFree( 3 );
+    }
+
+    private SurefireLauncher unpack()
+    {
+        return unpack( "/surefire-1385-system-property-variables-override" );
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/4de017b3/surefire-integration-tests/src/test/resources/surefire-1385-system-property-variables-override/pom.xml
----------------------------------------------------------------------
diff --git 
a/surefire-integration-tests/src/test/resources/surefire-1385-system-property-variables-override/pom.xml
 
b/surefire-integration-tests/src/test/resources/surefire-1385-system-property-variables-override/pom.xml
new file mode 100644
index 0000000..4ea06c3
--- /dev/null
+++ 
b/surefire-integration-tests/src/test/resources/surefire-1385-system-property-variables-override/pom.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~   http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.maven.surefire</groupId>
+    <artifactId>it-parent</artifactId>
+    <version>1.0</version>
+    <relativePath>../pom.xml</relativePath>
+  </parent>
+
+  <groupId>org.apache.maven.plugins.surefire</groupId>
+  <artifactId>surefire-1385</artifactId>
+  <version>1.0</version>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.12</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <systemPropertyVariables>
+            <prop-1>from-system-property-variable-1</prop-1>
+            <prop-2>from-system-property-variable-2</prop-2>
+          </systemPropertyVariables>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/4de017b3/surefire-integration-tests/src/test/resources/surefire-1385-system-property-variables-override/src/test/java/ATest.java
----------------------------------------------------------------------
diff --git 
a/surefire-integration-tests/src/test/resources/surefire-1385-system-property-variables-override/src/test/java/ATest.java
 
b/surefire-integration-tests/src/test/resources/surefire-1385-system-property-variables-override/src/test/java/ATest.java
new file mode 100644
index 0000000..10ecdb3
--- /dev/null
+++ 
b/surefire-integration-tests/src/test/resources/surefire-1385-system-property-variables-override/src/test/java/ATest.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class ATest
+{
+
+    @Test
+    public void testProp1()
+    {
+        assertEquals( "from-system-property-variable-1", System.getProperty( 
"prop-1" ) );
+    }
+
+    @Test
+    public void testProp2()
+    {
+        assertEquals( "from-system-property-variable-2", System.getProperty( 
"prop-2" ) );
+    }
+
+    @Test
+    public void testProp3()
+    {
+        assertEquals( "from-cli-3", System.getProperty( "prop-3" ) );
+    }
+}

Reply via email to