You are viewing a plain text version of this content. The canonical link for it is here.
Posted to surefire-commits@maven.apache.org by be...@apache.org on 2010/08/01 20:27:30 UTC
svn commit: r981279 - in /maven/surefire/trunk:
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/
surefire-integration-tests/
surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/
surefire-integration-tests/src/tes...
Author: bentmann
Date: Sun Aug 1 18:27:30 2010
New Revision: 981279
URL: http://svn.apache.org/viewvc?rev=981279&view=rev
Log:
[SUREFIRE-121] System properties set on the command line get clobbered
Modified:
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
maven/surefire/trunk/surefire-integration-tests/pom.xml
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/SystemPropertiesTestIT.java
maven/surefire/trunk/surefire-integration-tests/src/test/resources/system-properties/src/test/java/systemProperties/BasicTest.java
Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java?rev=981279&r1=981278&r2=981279&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java Sun Aug 1 18:27:30 2010
@@ -29,6 +29,7 @@ import org.apache.maven.toolchain.Toolch
import org.codehaus.plexus.util.StringUtils;
import java.io.File;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -680,13 +681,16 @@ public abstract class AbstractSurefireMo
// 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... but I'm leaving this code here in case
- // we need it later when we try to fix SUREFIRE-121 again.
+ // 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
- // Get the properties from the MavenSession instance to make embedded use work correctly
- Properties userSpecifiedProperties = (Properties) getSession().getExecutionProperties().clone();
- userSpecifiedProperties.putAll( getInternalSystemProperties() );
- //systemProperties = userSpecifiedProperties;
+ Properties userProperties = getUserProperties();
+ for ( Iterator it = userProperties.keySet().iterator(); it.hasNext(); )
+ {
+ String key = (String) it.next();
+ String value = userProperties.getProperty( key );
+ getInternalSystemProperties().setProperty( key, value );
+ }
getInternalSystemProperties().setProperty( "basedir", getBasedir().getAbsolutePath() );
getInternalSystemProperties().setProperty( "user.dir", getWorkingDirectory().getAbsolutePath() );
@@ -709,6 +713,36 @@ public abstract class AbstractSurefireMo
}
}
+ private Properties getUserProperties()
+ {
+ Properties props = null;
+ try
+ {
+ // try calling MavenSession.getUserProperties() from Maven 2.1.0-M1+
+ Method getUserProperties = getSession().getClass().getMethod( "getUserProperties", null );
+ props = (Properties) getUserProperties.invoke( getSession(), null );
+ }
+ catch ( Exception e )
+ {
+ String msg =
+ "Build uses Maven 2.0.x, cannot propagate system properties"
+ + " from command line to tests (cf. SUREFIRE-121)";
+ if ( getLog().isDebugEnabled() )
+ {
+ getLog().warn( msg, e );
+ }
+ else
+ {
+ getLog().warn( msg );
+ }
+ }
+ if ( props == null )
+ {
+ props = new Properties();
+ }
+ return props;
+ }
+
/**
* <p/>
* Adds Reporters that will generate reports with different formatting.
Modified: maven/surefire/trunk/surefire-integration-tests/pom.xml
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/pom.xml?rev=981279&r1=981278&r2=981279&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/pom.xml (original)
+++ maven/surefire/trunk/surefire-integration-tests/pom.xml Sun Aug 1 18:27:30 2010
@@ -186,6 +186,25 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>require-maven-2.1.0</id>
+ <goals>
+ <goal>enforce</goal>
+ </goals>
+ <configuration>
+ <rules>
+ <requireMavenVersion>
+ <!-- Some plugin features require a recent Maven runtime to work (e.g. SystemPropertiesTest) -->
+ <version>[2.1.0,)</version>
+ </requireMavenVersion>
+ </rules>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
Modified: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/SystemPropertiesTestIT.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/SystemPropertiesTestIT.java?rev=981279&r1=981278&r2=981279&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/SystemPropertiesTestIT.java (original)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/SystemPropertiesTestIT.java Sun Aug 1 18:27:30 2010
@@ -40,15 +40,13 @@ public class SystemPropertiesTestIT
Verifier verifier = new Verifier( testDir.getAbsolutePath() );
ArrayList goals = getInitialGoals();
goals.add( "test" );
- // SUREFIRE-121... someday we should re-enable this
- // goals.add( "-DsetOnMavenCommandLine=baz" );
-
+ goals.add( "-DsetOnMavenCommandLine=baz" );
goals.add( "-DsetOnArgLineWorkAround=baz" );
verifier.executeGoals( goals );
verifier.verifyErrorFreeLog();
verifier.resetStreams();
- HelperAssertions.assertTestSuiteResults( 6, 0, 0, 0, testDir );
+ HelperAssertions.assertTestSuiteResults( 7, 0, 0, 0, testDir );
}
public void testSystemPropertiesNoFork()
@@ -61,14 +59,13 @@ public class SystemPropertiesTestIT
goals.add( "test" );
goals.add( "-DforkMode=never" );
goals.add( "-DsetOnArgLineWorkAround=baz" );
- // SUREFIRE-121... someday we should re-enable this
- // goals.add( "-DsetOnMavenCommandLine=baz" );
+ goals.add( "-DsetOnMavenCommandLine=baz" );
// DGF fake the argLine, since we're not forking
goals.add( "-DsetOnArgLine=bar" );
verifier.executeGoals( goals );
verifier.verifyErrorFreeLog();
verifier.resetStreams();
- HelperAssertions.assertTestSuiteResults( 6, 0, 0, 0, testDir );
+ HelperAssertions.assertTestSuiteResults( 7, 0, 0, 0, testDir );
}
}
Modified: maven/surefire/trunk/surefire-integration-tests/src/test/resources/system-properties/src/test/java/systemProperties/BasicTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/system-properties/src/test/java/systemProperties/BasicTest.java?rev=981279&r1=981278&r2=981279&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/system-properties/src/test/java/systemProperties/BasicTest.java (original)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/system-properties/src/test/java/systemProperties/BasicTest.java Sun Aug 1 18:27:30 2010
@@ -55,10 +55,9 @@ public class BasicTest
assertEquals("property setOnArgLineWorkAround not set", "baz", System.getProperty( "setOnArgLineWorkAround" ) );
}
-// SUREFIRE-121; someday we should re-enable this
-// public void testSetOnMavenCommandLine()
-// {
-// assertEquals("property setOnMavenCommandLine not set", "baz", System.getProperty("setOnMavenCommandLine"));
-// }
+ public void testSetOnMavenCommandLine()
+ {
+ assertEquals("property setOnMavenCommandLine not set", "baz", System.getProperty("setOnMavenCommandLine"));
+ }
}