Author: evenisse
Date: Mon May 9 11:28:44 2011
New Revision: 1100966
URL: http://svn.apache.org/viewvc?rev=1100966&view=rev
Log:
[SUREFIRE-736] Add a list of system properties from a properties file
Added:
maven/surefire/trunk/surefire-integration-tests/src/test/resources/system-properties/src/test/config/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/system-properties/src/test/config/propsfile.properties
Modified:
maven/surefire/trunk/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireExecutionParameters.java
maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
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/pom.xml
maven/surefire/trunk/surefire-integration-tests/src/test/resources/system-properties/src/test/java/systemProperties/BasicTest.java
Modified:
maven/surefire/trunk/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java?rev=1100966&r1=1100965&r2=1100966&view=diff
==============================================================================
---
maven/surefire/trunk/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java
(original)
+++
maven/surefire/trunk/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java
Mon May 9 11:28:44 2011
@@ -29,6 +29,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
+
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -259,6 +260,14 @@ public class IntegrationTestMojo
private Map systemPropertyVariables;
/**
+ * List of System properties, loaded from a file, to pass to the JUnit
tests.
+ *
+ * @parameter
+ * @since 2.8.2
+ */
+ private File systemPropertiesFile;
+
+ /**
* List of properties for configuring all TestNG related configurations.
This is the new preferred method of
* configuring TestNG.
*
@@ -681,8 +690,8 @@ public class IntegrationTestMojo
{
if ( StringUtils.isEmpty( encoding ) )
{
- getLog().warn( "File encoding has not been set, using platform
encoding " + ReaderFactory.FILE_ENCODING
- + ", i.e. build is platform dependent!" );
+ getLog().warn( "File encoding has not been set, using platform
encoding " + ReaderFactory.FILE_ENCODING +
+ ", i.e. build is platform dependent!" );
return ReaderFactory.FILE_ENCODING;
}
else
@@ -703,7 +712,7 @@ public class IntegrationTestMojo
protected String[] getDefaultIncludes()
{
- return new String[]{ "**/IT*.java", "**/*IT.java", "**/*ITCase.java" };
+ return new String[]{"**/IT*.java", "**/*IT.java", "**/*ITCase.java"};
}
public boolean isSkipTests()
@@ -922,6 +931,16 @@ public class IntegrationTestMojo
this.systemPropertyVariables = systemPropertyVariables;
}
+ public File getSystemPropertiesFile()
+ {
+ return systemPropertiesFile;
+ }
+
+ public void setSystemPropertiesFile( File systemPropertiesFile )
+ {
+ this.systemPropertiesFile = systemPropertiesFile;
+ }
+
public Properties getProperties()
{
return properties;
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=1100966&r1=1100965&r2=1100966&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
Mon May 9 11:28:44 2011
@@ -20,16 +20,20 @@ package org.apache.maven.plugin.surefire
*/
import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
+
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
@@ -148,9 +152,9 @@ public abstract class AbstractSurefireMo
{
final Artifact junitDepArtifact = getJunitDepArtifact();
ProviderList wellKnownProviders = new ProviderList(
- new ProviderInfo[]{ new TestNgProviderInfo(
getTestNgArtifact() ),
+ new ProviderInfo[]{new TestNgProviderInfo( getTestNgArtifact()
),
new JUnitCoreProviderInfo( getJunitArtifact(),
junitDepArtifact ),
- new JUnit4ProviderInfo( getJunitArtifact(),
junitDepArtifact ), new JUnit3ProviderInfo() },
+ new JUnit4ProviderInfo( getJunitArtifact(),
junitDepArtifact ), new JUnit3ProviderInfo()},
new DynamicProviderInfo( null ) );
return wellKnownProviders.resolve( getLog() );
@@ -491,7 +495,7 @@ public abstract class AbstractSurefireMo
// Have to wrap in an ArrayList as surefire expects an ArrayList
instead of a List for some reason
if ( excludes == null || excludes.size() == 0 )
{
- excludes = new ArrayList( Arrays.asList( new String[]{
"**/*$*" } ) );
+ excludes = new ArrayList( Arrays.asList( new
String[]{"**/*$*"} ) );
}
}
return excludes;
@@ -549,8 +553,8 @@ public abstract class AbstractSurefireMo
if ( !range.containsVersion( new DefaultArtifactVersion(
artifact.getVersion() ) ) )
{
throw new MojoFailureException(
- "TestNG support requires version 4.7 or above. You have
declared version "
- + artifact.getVersion() );
+ "TestNG support requires version 4.7 or above. You have
declared version " +
+ artifact.getVersion() );
}
}
return artifact;
@@ -580,15 +584,14 @@ public abstract class AbstractSurefireMo
}
protected SurefireStarter createInprocessStarter( ProviderInfo provider,
ForkConfiguration forkConfiguration,
-
ClassLoaderConfiguration classLoaderConfiguration )
+ ClassLoaderConfiguration
classLoaderConfiguration )
throws MojoExecutionException, MojoFailureException
{
StartupConfiguration startupConfiguration =
createStartupConfiguration( forkConfiguration, provider,
classLoaderConfiguration );
StartupReportConfiguration startupReportConfiguration =
getStartupReportConfiguration();
ProviderConfiguration providerConfiguration =
createProviderConfiguration();
- return
- new SurefireStarter( startupConfiguration, providerConfiguration,
startupReportConfiguration );
+ return new SurefireStarter( startupConfiguration,
providerConfiguration, startupReportConfiguration );
}
@@ -727,6 +730,7 @@ public abstract class AbstractSurefireMo
checksum.add( getLocalRepository() );
checksum.add( getSystemProperties() );
checksum.add( getSystemPropertyVariables() );
+ checksum.add( getSystemPropertiesFile() );
checksum.add( getProperties() );
checksum.add( isPrintSummary() );
checksum.add( getReportFormat() );
@@ -782,8 +786,7 @@ public abstract class AbstractSurefireMo
protected ClassLoaderConfiguration getClassLoaderConfiguration(
ForkConfiguration fork )
{
- return fork.isForking()
- ? new ClassLoaderConfiguration( isUseSystemClassLoader(),
isUseManifestOnlyJar() )
+ return fork.isForking() ? new ClassLoaderConfiguration(
isUseSystemClassLoader(), isUseManifestOnlyJar() )
: new ClassLoaderConfiguration( false, false );
}
@@ -947,8 +950,8 @@ public abstract class AbstractSurefireMo
Artifact artifact = (Artifact) i.next();
getLog().debug(
- "Adding to " + getPluginName() + " booter test classpath: " +
artifact.getFile().getAbsolutePath()
- + " Scope: " + artifact.getScope() );
+ "Adding to " + getPluginName() + " booter test classpath: " +
artifact.getFile().getAbsolutePath() +
+ " Scope: " + artifact.getScope() );
items.add( artifact.getFile().getAbsolutePath() );
}
@@ -959,6 +962,39 @@ public abstract class AbstractSurefireMo
{
copyPropertiesToInternalSystemProperties( getSystemProperties() );
+ if ( this.getSystemPropertiesFile() != null )
+ {
+ Properties props = new Properties();
+ try
+ {
+ FileInputStream fis = new FileInputStream(
getSystemPropertiesFile() );
+ props.load( fis );
+ fis.close();
+ }
+ catch ( IOException e )
+ {
+ String msg =
+ "The system property file '" +
getSystemPropertiesFile().getAbsolutePath() + "' can't be read.";
+ if ( getLog().isDebugEnabled() )
+ {
+ getLog().warn( msg, e );
+ }
+ else
+ {
+ getLog().warn( msg );
+ }
+ }
+
+ Enumeration keys = props.propertyNames();
+ //loop through all properties
+ while ( keys.hasMoreElements() )
+ {
+ String key = (String) keys.nextElement();
+ String value = props.getProperty( key );
+ getInternalSystemProperties().setProperty( key, value );
+ }
+ }
+
if ( this.getSystemPropertyVariables() != null )
{
for ( Iterator i =
getSystemPropertyVariables().keySet().iterator(); i.hasNext(); )
@@ -1026,8 +1062,8 @@ public abstract class AbstractSurefireMo
}
catch ( Exception e )
{
- String msg = "Build uses Maven 2.0.x, cannot propagate system
properties"
- + " from command line to tests (cf. SUREFIRE-121)";
+ 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 );
Modified:
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireExecutionParameters.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireExecutionParameters.java?rev=1100966&r1=1100965&r2=1100966&view=diff
==============================================================================
---
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireExecutionParameters.java
(original)
+++
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireExecutionParameters.java
Mon May 9 11:28:44 2011
@@ -19,6 +19,11 @@ package org.apache.maven.plugin.surefire
* under the License.
*/
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -27,11 +32,6 @@ import org.apache.maven.execution.MavenS
import org.apache.maven.project.MavenProject;
import org.apache.maven.toolchain.ToolchainManager;
-import java.io.File;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
/**
* The parameters required to execute surefire.
*
@@ -89,7 +89,7 @@ public interface SurefireExecutionParame
void setTestSourceDirectory( File testSourceDirectory );
String getTest();
-
+
String getTestMethod();
void setTest( String test );
@@ -114,6 +114,10 @@ public interface SurefireExecutionParame
void setSystemPropertyVariables( Map systemPropertyVariables );
+ File getSystemPropertiesFile();
+
+ void setSystemPropertiesFile( File systemPropertiesFile );
+
Properties getProperties();
void setProperties( Properties properties );
Modified:
maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java?rev=1100966&r1=1100965&r2=1100966&view=diff
==============================================================================
---
maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
(original)
+++
maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
Mon May 9 11:28:44 2011
@@ -24,6 +24,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
+
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -236,6 +237,14 @@ public class SurefirePlugin
private Map systemPropertyVariables;
/**
+ * List of System properties, loaded from a file, to pass to the JUnit
tests.
+ *
+ * @parameter
+ * @since 2.8.2
+ */
+ private File systemPropertiesFile;
+
+ /**
* List of properties for configuring all TestNG related configurations.
This is the new preferred method of
* configuring TestNG.
*
@@ -634,7 +643,7 @@ public class SurefirePlugin
protected String[] getDefaultIncludes()
{
- return new String[]{ "**/Test*.java", "**/*Test.java",
"**/*TestCase.java" };
+ return new String[]{"**/Test*.java", "**/*Test.java",
"**/*TestCase.java"};
}
// now for the implementation of the field accessors
@@ -867,6 +876,16 @@ public class SurefirePlugin
this.systemPropertyVariables = systemPropertyVariables;
}
+ public File getSystemPropertiesFile()
+ {
+ return systemPropertiesFile;
+ }
+
+ public void setSystemPropertiesFile( File systemPropertiesFile )
+ {
+ this.systemPropertiesFile = systemPropertiesFile;
+ }
+
public Properties getProperties()
{
return properties;
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=1100966&r1=1100965&r2=1100966&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
Mon May 9 11:28:44 2011
@@ -39,7 +39,7 @@ public class SystemPropertiesTestIT
addGoal( "-DsetOnArgLineWorkAround=baz" );
executeTest();
verifyErrorFreeLog();
- assertTestSuiteResults( 7, 0, 0, 0 );
+ assertTestSuiteResults( 8, 0, 0, 0 );
}
public void testSystemPropertiesNoFork()
@@ -53,6 +53,6 @@ public class SystemPropertiesTestIT
executeTest();
verifyErrorFreeLog();
- assertTestSuiteResults( 7, 0, 0, 0 );
+ assertTestSuiteResults( 8, 0, 0, 0 );
}
}
Modified:
maven/surefire/trunk/surefire-integration-tests/src/test/resources/system-properties/pom.xml
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/system-properties/pom.xml?rev=1100966&r1=1100965&r2=1100966&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-integration-tests/src/test/resources/system-properties/pom.xml
(original)
+++
maven/surefire/trunk/surefire-integration-tests/src/test/resources/system-properties/pom.xml
Mon May 9 11:28:44 2011
@@ -70,7 +70,9 @@
<blankProperty> </blankProperty>
<!-- this is a work around for SUREFIRE-121 -->
<setOnArgLineWorkAround>${setOnArgLineWorkAround}</setOnArgLineWorkAround>
+ <overriddenPropertyFomFile>value2</overriddenPropertyFomFile>
</systemPropertyVariables>
+
<systemPropertiesFile>${project.basedir}/src/test/config/propsfile.properties</systemPropertiesFile>
<argLine>-DsetOnArgLine=bar</argLine>
</configuration>
</plugin>
Added:
maven/surefire/trunk/surefire-integration-tests/src/test/resources/system-properties/src/test/config/propsfile.properties
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/system-properties/src/test/config/propsfile.properties?rev=1100966&view=auto
==============================================================================
---
maven/surefire/trunk/surefire-integration-tests/src/test/resources/system-properties/src/test/config/propsfile.properties
(added)
+++
maven/surefire/trunk/surefire-integration-tests/src/test/resources/system-properties/src/test/config/propsfile.properties
Mon May 9 11:28:44 2011
@@ -0,0 +1,2 @@
+setInFile = bar
+overriddenPropertyFomFile = value1
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=1100966&r1=1100965&r2=1100966&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
Mon May 9 11:28:44 2011
@@ -1,10 +1,9 @@
package systemProperties;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
import java.io.File;
+import junit.framework.TestCase;
+
public class BasicTest
extends TestCase
{
@@ -12,52 +11,59 @@ public class BasicTest
public void testSetInPom()
{
- assertEquals("property setInPom not set", "foo",
System.getProperty("setInPom"));
+ assertEquals( "property setInPom not set", "foo", System.getProperty(
"setInPom" ) );
}
-
+
public void testSetOnArgLine()
{
- assertEquals("setOnArgLine property not set", "bar",
System.getProperty("setOnArgLine"));
+ assertEquals( "setOnArgLine property not set", "bar",
System.getProperty( "setOnArgLine" ) );
}
-
+
public void testSystemPropertyUsingMavenProjectProperties()
{
- String actualBuildDirectory = new File( System.getProperty( "basedir"
),"target" ).getAbsolutePath();
-
- String buildDirectoryFromPom = new File( System.getProperty(
"buildDirectory") ).getAbsolutePath();
-
+ String actualBuildDirectory = new File( System.getProperty( "basedir"
), "target" ).getAbsolutePath();
+
+ String buildDirectoryFromPom = new File( System.getProperty(
"buildDirectory" ) ).getAbsolutePath();
+
assertEquals( "Pom property not set.", actualBuildDirectory,
buildDirectoryFromPom );
}
-
+
public void testSystemPropertyGenerateByOtherPlugin()
throws Exception
{
- int reservedPort1 = Integer.parseInt( System.getProperty(
"reservedPort1" ) );
- int reservedPort2 = Integer.parseInt( System.getProperty(
"reservedPort2" ) );
+ int reservedPort1 = Integer.parseInt( System.getProperty(
"reservedPort1" ) );
+ int reservedPort2 = Integer.parseInt( System.getProperty(
"reservedPort2" ) );
System.out.println( "reservedPort1: " + reservedPort1 );
System.out.println( "reservedPort2: " + reservedPort2 );
-
+
assertTrue( reservedPort1 != reservedPort2 );
}
-
+
public void testEmptySystemProperties()
{
assertNull( "Null property is not null", System.getProperty(
"nullProperty" ) );
assertNull( "Blank property is not null", System.getProperty(
"blankProperty" ) );
- }
+ }
/**
* work around for SUREFIRE-121
*/
public void testSetOnArgLineWorkAround()
{
- assertEquals("property setOnArgLineWorkAround not set", "baz",
System.getProperty( "setOnArgLineWorkAround" ) );
+ assertEquals( "property setOnArgLineWorkAround not set", "baz",
+ System.getProperty( "setOnArgLineWorkAround" ) );
}
-
+
public void testSetOnMavenCommandLine()
{
- assertEquals("property setOnMavenCommandLine not set", "baz",
System.getProperty("setOnMavenCommandLine"));
+ assertEquals( "property setOnMavenCommandLine not set", "baz",
System.getProperty( "setOnMavenCommandLine" ) );
+ }
+
+ public void testSetInFile()
+ {
+ assertEquals( "property setInFile not set", "bar", System.getProperty(
"setInFile" ) );
+ assertEquals( "property overriddenPropertyFomFile not overridden",
"value2",
+ System.getProperty( "overriddenPropertyFomFile" ) );
}
-
}