Author: krosenvold
Date: Sun Nov 28 22:47:24 2010
New Revision: 1039971
URL: http://svn.apache.org/viewvc?rev=1039971&view=rev
Log:
o Cleaned up/simplified serialization further
Modified:
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/booterclient/BooterSerializer.java
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerTest.java
maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/testset/TestSuiteDefinition.java
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemPropertyManager.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=1039971&r1=1039970&r2=1039971&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 Nov 28 22:47:24 2010
@@ -273,7 +273,7 @@ public abstract class AbstractSurefireMo
TestArtifactInfo testNg =
isTestNg ? new TestArtifactInfo( testNgArtifact.getVersion(),
testNgArtifact.getClassifier() ) : null;
TestSuiteDefinition testSuiteDefinition =
- new TestSuiteDefinition( getSuiteXmlFiles(), null,
getTestSourceDirectory(), getTest() );
+ new TestSuiteDefinition( getSuiteXmlFiles(),
getTestSourceDirectory(), getTest() );
final boolean failIfNoTests;
if ( isValidSuiteXmlFileConfig() && getTest() == null )
@@ -285,7 +285,7 @@ public abstract class AbstractSurefireMo
}
testSuiteDefinition =
- new TestSuiteDefinition( getSuiteXmlFiles(), getTest(),
getTestSourceDirectory(), getTest() );
+ new TestSuiteDefinition( getSuiteXmlFiles(),
getTestSourceDirectory(), getTest() );
}
else
{
Modified:
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java?rev=1039971&r1=1039970&r2=1039971&view=diff
==============================================================================
---
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java
(original)
+++
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java
Sun Nov 28 22:47:24 2010
@@ -21,6 +21,7 @@ package org.apache.maven.plugin.surefire
import org.apache.maven.surefire.booter.BooterConfiguration;
import org.apache.maven.surefire.booter.BooterDeserializer;
import org.apache.maven.surefire.booter.ClassLoaderConfiguration;
+import org.apache.maven.surefire.booter.SystemPropertyManager;
import org.apache.maven.surefire.report.ReporterConfiguration;
import org.apache.maven.surefire.testset.DirectoryScannerParameters;
import org.apache.maven.surefire.testset.TestArtifactInfo;
@@ -52,11 +53,34 @@ import java.util.Properties;
*/
public class BooterSerializer
{
- public void setForkProperties( Properties properties, BooterConfiguration
booterConfiguration,
- ClassLoaderConfiguration forkConfiguration )
+ private final ForkConfiguration forkConfiguration;
+
+ public BooterSerializer( ForkConfiguration forkConfiguration )
{
- if (properties == null){
- throw new IllegalStateException( "Properties cannot be null");
+ this.forkConfiguration = forkConfiguration;
+ }
+
+
+ public File serialize( Properties properties, BooterConfiguration
booterConfiguration,
+ ForkConfiguration forkConfiguration, Object testSet
)
+ throws IOException
+ {
+ setForkProperties( properties, booterConfiguration );
+
+ if ( testSet != null && testSet instanceof String )
+ {
+ properties.setProperty( "testSet", (String) testSet );
+ }
+ SystemPropertyManager systemPropertyManager = new
SystemPropertyManager();
+ return systemPropertyManager.writePropertiesFile( properties,
forkConfiguration.getTempDirectory(), "surefire",
+
forkConfiguration.isDebug() );
+ }
+
+ public void setForkProperties( Properties properties, BooterConfiguration
booterConfiguration )
+ {
+ if ( properties == null )
+ {
+ throw new IllegalStateException( "Properties cannot be null" );
}
addList( booterConfiguration.getReports(), properties,
BooterDeserializer.REPORT_PROPERTY_PREFIX );
List params = new ArrayList();
@@ -115,19 +139,21 @@ public class BooterSerializer
Boolean rep = reporterConfiguration.isTrimStackTrace();
properties.setProperty( "isTrimStackTrace", rep.toString() );
properties.setProperty( "reportsDirectory",
reporterConfiguration.getReportsDirectory().toString() );
- properties.setProperty( "useSystemClassLoader", String.valueOf(
forkConfiguration.isUseSystemClassLoader() ) );
+ ClassLoaderConfiguration classLoaderConfiguration =
this.forkConfiguration.getClassLoaderConfiguration();
+ properties.setProperty( "useSystemClassLoader",
+ String.valueOf(
classLoaderConfiguration.isUseSystemClassLoader() ) );
properties.setProperty( "useManifestOnlyJar",
- String.valueOf(
forkConfiguration.isManifestOnlyJarRequestedAndUsable() ) );
+ String.valueOf(
classLoaderConfiguration.isManifestOnlyJarRequestedAndUsable() ) );
properties.setProperty( "failIfNoTests", String.valueOf(
booterConfiguration.isFailIfNoTests() ) );
properties.setProperty( "providerConfiguration",
booterConfiguration.getProviderConfiguration().getClassName() );
}
- public File writePropertiesFile( String name, Properties properties,
boolean debug, File tempDirectory )
+ public File writePropertiesFile( String name, Properties properties )
throws IOException
{
- File file = File.createTempFile( name, "tmp", tempDirectory );
- if ( !debug )
+ File file = File.createTempFile( name, "tmp",
forkConfiguration.getTempDirectory() );
+ if ( !forkConfiguration.isDebug() )
{
file.deleteOnExit();
}
Modified:
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java?rev=1039971&r1=1039970&r2=1039971&view=diff
==============================================================================
---
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
(original)
+++
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
Sun Nov 28 22:47:24 2010
@@ -32,6 +32,7 @@ import org.apache.maven.surefire.booter.
import org.apache.maven.surefire.booter.SurefireExecutionException;
import org.apache.maven.surefire.booter.SurefireReflector;
import org.apache.maven.surefire.booter.SurefireStarter;
+import org.apache.maven.surefire.booter.SystemPropertyManager;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.cli.CommandLineException;
import org.codehaus.plexus.util.cli.CommandLineUtils;
@@ -106,7 +107,7 @@ public class ForkStarter
private int runSuitesForkOnce()
throws SurefireBooterForkException
{
- return forkSuites( true, true );
+ return fork( null, booterConfiguration.getProviderProperties(), true,
true );
}
private int runSuitesForkPerTestSet()
@@ -138,7 +139,8 @@ public class ForkStarter
{
Object testSet = suites.next();
boolean showFooter = !suites.hasNext();
- int result = forkSuite( testSet, showHeading, showFooter,
properties );
+ int result = fork( testSet, properties, showHeading, showFooter );
+
if ( result > globalResult )
{
globalResult = result;
@@ -154,50 +156,24 @@ public class ForkStarter
return booterConfiguration.getClasspathConfiguration();
}
- private int forkSuites( boolean showHeading, boolean showFooter )
- throws SurefireBooterForkException
- {
- Properties properties = booterConfiguration.getProviderProperties();
-
- BooterSerializer booterSerializer = new BooterSerializer();
- booterSerializer.setForkProperties( properties, booterConfiguration,
-
forkConfiguration.getClassLoaderConfiguration() );
-
- return fork( properties, showHeading, showFooter );
- }
-
- private int forkSuite( Object testSet, boolean showHeading, boolean
showFooter, Properties properties )
- throws SurefireBooterForkException
- {
- BooterSerializer booterSerializer = new BooterSerializer();
- booterSerializer.setForkProperties( properties, booterConfiguration,
-
forkConfiguration.getClassLoaderConfiguration() );
-
- if ( testSet instanceof String )
- {
- properties.setProperty( "testSet", (String) testSet );
- }
-
- return fork( properties, showHeading, showFooter );
- }
-
- private int fork( Properties properties, boolean showHeading, boolean
showFooter )
+ private int fork( Object testSet, Properties properties, boolean
showHeading, boolean showFooter )
throws SurefireBooterForkException
{
File surefireProperties;
File systemProperties = null;
try
{
- BooterSerializer booterSerializer = new BooterSerializer();
+ BooterSerializer booterSerializer = new BooterSerializer(
forkConfiguration );
+
surefireProperties =
- booterSerializer.writePropertiesFile( "surefire", properties,
forkConfiguration.isDebug(),
-
forkConfiguration.getTempDirectory() );
+ booterSerializer.serialize( properties, booterConfiguration,
forkConfiguration, testSet );
+
if ( forkConfiguration.getSystemProperties() != null )
{
- systemProperties =
- booterSerializer.writePropertiesFile( "surefire",
forkConfiguration.getSystemProperties(),
-
forkConfiguration.isDebug(),
-
forkConfiguration.getTempDirectory() );
+ SystemPropertyManager systemPropertyManager = new
SystemPropertyManager();
+ systemProperties = systemPropertyManager.writePropertiesFile(
forkConfiguration.getSystemProperties(),
+
forkConfiguration.getTempDirectory(),
+
"surefire", forkConfiguration.isDebug() );
}
}
catch ( IOException e )
Modified:
maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerTest.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerTest.java?rev=1039971&r1=1039970&r2=1039971&view=diff
==============================================================================
---
maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerTest.java
(original)
+++
maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerTest.java
Sun Nov 28 22:47:24 2010
@@ -174,10 +174,10 @@ public class BooterDeserializerTest
BooterConfiguration
booterConfiguration )
throws IOException
{
- BooterSerializer booterSerializer = new BooterSerializer();
+ BooterSerializer booterSerializer = new
BooterSerializer(ForkConfigurationTest.getForkConfiguration());
Properties props = new Properties();
- booterSerializer.setForkProperties( props, booterConfiguration,
forkConfiguration );
- final File propsTest = booterSerializer.writePropertiesFile(
"propsTest", props, false, null );
+ booterSerializer.setForkProperties( props, booterConfiguration );
+ final File propsTest = booterSerializer.writePropertiesFile(
"propsTest", props );
BooterDeserializer booterDeserializer = new BooterDeserializer();
return booterDeserializer.deserialize( new FileInputStream( propsTest
) );
}
Modified:
maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/testset/TestSuiteDefinition.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/testset/TestSuiteDefinition.java?rev=1039971&r1=1039970&r2=1039971&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/testset/TestSuiteDefinition.java
(original)
+++
maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/testset/TestSuiteDefinition.java
Sun Nov 28 22:47:24 2010
@@ -46,6 +46,12 @@ public class TestSuiteDefinition
}
+ public TestSuiteDefinition( File[] suiteXmlFiles, File
testSourceDirectory, String requestedTest )
+ {
+ this( suiteXmlFiles, null, testSourceDirectory, requestedTest );
+ }
+
+
public TestSuiteDefinition( File[] suiteXmlFiles, String testForFork, File
testSourceDirectory,
String requestedTest )
{
Modified:
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemPropertyManager.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemPropertyManager.java?rev=1039971&r1=1039970&r2=1039971&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemPropertyManager.java
(original)
+++
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemPropertyManager.java
Sun Nov 28 22:47:24 2010
@@ -19,7 +19,11 @@ package org.apache.maven.surefire.booter
* under the License.
*/
-import java.io.*;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.Iterator;
import java.util.Properties;
@@ -36,6 +40,9 @@ public class SystemPropertyManager
/**
* Loads the properties, closes the stream
+ * @param inStream The stream to read from, will be closed
+ * @return The properties
+ * @throws java.io.IOException If something bad happens
*/
public static Properties loadProperties( InputStream inStream )
throws IOException
@@ -68,6 +75,36 @@ public class SystemPropertyManager
}
}
+ public File writePropertiesFile( Properties properties, File
tempDirectory, String name, boolean deleteOnExit)
+ throws IOException
+ {
+ File file = File.createTempFile( name, "tmp", tempDirectory );
+ if ( deleteOnExit )
+ {
+ file.deleteOnExit();
+ }
+
+ writePropertiesFile( file, name, properties );
+
+ return file;
+ }
+
+ void writePropertiesFile( File file, String name, Properties properties )
+ throws IOException
+ {
+ FileOutputStream out = new FileOutputStream( file );
+
+ try
+ {
+ properties.store( out, name );
+ }
+ finally
+ {
+ out.close();
+ }
+ }
+
+
/**
* Closes the input stream. The input stream can be null and any
IOException's will be swallowed.
*