Author: krosenvold
Date: Fri Nov 19 07:58:06 2010
New Revision: 1036757
URL: http://svn.apache.org/viewvc?rev=1036757&view=rev
Log:
o Extracted deserializer from serializer, renamed Booter classes.
Restructuring only, no functional change
Added:
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booter/BooterSerializer.java
(with props)
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booter/ForkStarter.java
(contents, props changed)
- copied, changed from r1036640,
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booter/PluginSideBooter.java
maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booter/BooterConversionTest.java
(contents, props changed)
- copied, changed from r1036640,
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/BooterConversionTest.java
maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booter/BooterDeserializerTest.java
(contents, props changed)
- copied, changed from r1036640,
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/BooterSerializerTest.java
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterDeserializer.java
(contents, props changed)
- copied, changed from r1036640,
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterSerializer.java
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java
(contents, props changed)
- copied, changed from r1036640,
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/RemoteBooter.java
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireStarter.java
(contents, props changed)
- copied, changed from r1036640,
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/TestVmBooter.java
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemPropertyManager.java
(with props)
Removed:
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booter/PluginSideBooter.java
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterSerializer.java
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/RemoteBooter.java
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/TestVmBooter.java
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/BooterConversionTest.java
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/BooterSerializerTest.java
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/booter/PluginsideForkConfiguration.java
maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterConfiguration.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=1036757&r1=1036756&r2=1036757&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
Fri Nov 19 07:58:06 2010
@@ -38,12 +38,11 @@ import org.apache.maven.execution.MavenS
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.surefire.AbstractSurefireMojo;
-import org.apache.maven.plugin.surefire.booter.PluginSideBooter;
+import org.apache.maven.plugin.surefire.booter.ForkStarter;
import org.apache.maven.plugin.surefire.SurefireExecutionParameters;
import org.apache.maven.plugin.surefire.booter.PluginsideForkConfiguration;
import org.apache.maven.project.MavenProject;
import org.apache.maven.surefire.booter.BooterConfiguration;
-import org.apache.maven.surefire.booter.ForkConfiguration;
import org.apache.maven.surefire.booter.SurefireBooterForkException;
import org.apache.maven.surefire.booter.SurefireExecutionException;
import org.apache.maven.surefire.failsafe.model.FailsafeSummary;
@@ -605,7 +604,7 @@ public class IntegrationTestMojo
{
PluginsideForkConfiguration forkConfiguration =
getForkConfiguration();
BooterConfiguration booterConfiguration =
createBooterConfiguration( forkConfiguration );
- PluginSideBooter booter = new PluginSideBooter(
booterConfiguration, reportsDirectory, forkConfiguration );
+ ForkStarter booter = new ForkStarter( booterConfiguration,
reportsDirectory, forkConfiguration );
getLog().info(
StringUtils.capitalizeFirstLetter( getPluginName() ) + "
report directory: " + getReportsDirectory() );
Added:
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booter/BooterSerializer.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booter/BooterSerializer.java?rev=1036757&view=auto
==============================================================================
---
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booter/BooterSerializer.java
(added)
+++
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booter/BooterSerializer.java
Fri Nov 19 07:58:06 2010
@@ -0,0 +1,164 @@
+package org.apache.maven.plugin.surefire.booter;
+/*
+ * 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.booter.BooterConfiguration;
+import org.apache.maven.surefire.booter.ForkConfiguration;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.StringUtils;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * Knows how to serialize and deserialize the booter configuration.
+ * <p/>
+ * The internal serialization format is through a properties file. The
long-term goal of this
+ * class is not to expose this implementation information to its clients. This
still leaks somewhat,
+ * and there are some cases where properties are being accessed as
"Properties" instead of
+ * more representative domain objects.
+ * <p/>
+ *
+ * @author Jason van Zyl
+ * @author Emmanuel Venisse
+ * @author Kristian Rosenvold
+ * @version $Id$
+ */
+public class BooterSerializer
+{
+ private static final String TEST_SUITE_PROPERTY_PREFIX = "testSuite.";
+
+ private static final String DIRSCANNER_PROPERTY_PREFIX = "dirscanner.";
+
+ private static final String REPORT_PROPERTY_PREFIX = "report.";
+
+ private static final String PARAMS_SUFIX = ".params";
+
+ private static final String TYPES_SUFIX = ".types";
+
+
+ public void setForkProperties( Properties properties, List testSuites,
BooterConfiguration booterConfiguration,
+ ForkConfiguration forkConfiguration )
+ {
+ addPropertiesForTypeHolder( booterConfiguration.getReports(),
properties, REPORT_PROPERTY_PREFIX );
+ addPropertiesForTypeHolder( testSuites, properties,
TEST_SUITE_PROPERTY_PREFIX );
+ List params = new ArrayList();
+ params.add( new Object[]{ "directoryScannerOptions",
booterConfiguration.getDirScannerParams() } );
+ addPropertiesForTypeHolder( params, properties,
DIRSCANNER_PROPERTY_PREFIX );
+
+ booterConfiguration.getClasspathConfiguration().setForkProperties(
properties );
+
+ properties.setProperty( "useSystemClassLoader", String.valueOf(
forkConfiguration.isUseSystemClassLoader() ) );
+ properties.setProperty( "useManifestOnlyJar",
+ String.valueOf(
forkConfiguration.isManifestOnlyJarRequestedAndUsable() ) );
+ properties.setProperty( "failIfNoTests", String.valueOf(
booterConfiguration.isFailIfNoTests() ) );
+ }
+
+ public File writePropertiesFile( String name, Properties properties,
boolean debug, File tempDirectory )
+ throws IOException
+ {
+ File file = File.createTempFile( name, "tmp", tempDirectory );
+ if ( !debug )
+ {
+ 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
+ {
+ IOUtil.close( out );
+ }
+ }
+
+ private void addPropertiesForTypeHolder( List typeHolderList, Properties
properties, String propertyPrefix )
+ {
+ for ( int i = 0; i < typeHolderList.size(); i++ )
+ {
+ Object[] report = (Object[]) typeHolderList.get( i );
+
+ String className = (String) report[0];
+ Object[] params = (Object[]) report[1];
+
+ properties.setProperty( propertyPrefix + i, className );
+
+ if ( params != null )
+ {
+ String paramProperty = convert( params[0] );
+ String typeProperty = params[0].getClass().getName();
+ for ( int j = 1; j < params.length; j++ )
+ {
+ paramProperty += "|";
+ typeProperty += "|";
+ if ( params[j] != null )
+ {
+ paramProperty += convert( params[j] );
+ typeProperty += params[j].getClass().getName();
+ }
+ }
+ properties.setProperty( propertyPrefix + i + PARAMS_SUFIX,
paramProperty );
+ properties.setProperty( propertyPrefix + i + TYPES_SUFIX,
typeProperty );
+ }
+ }
+ }
+
+ private static String convert( Object param )
+ {
+ if ( param instanceof File[] )
+ {
+ File[] files = (File[]) param;
+ return "[" + StringUtils.join( files, "," ) + "]";
+ }
+ else if ( param instanceof Properties )
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try
+ {
+ ( (Properties) param ).store( baos, "" );
+ return new String( baos.toByteArray(), "8859_1" );
+ }
+ catch ( Exception e )
+ {
+ throw new RuntimeException( "bug in property conversion", e );
+ }
+ }
+ else
+ {
+ return param.toString();
+ }
+ }
+
+}
Propchange:
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booter/BooterSerializer.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied:
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booter/ForkStarter.java
(from r1036640,
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booter/PluginSideBooter.java)
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booter/ForkStarter.java?p2=maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booter/ForkStarter.java&p1=maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booter/PluginSideBooter.java&r1=1036640&r2=1036757&rev=1036757&view=diff
==============================================================================
---
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booter/PluginSideBooter.java
(original)
+++
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booter/ForkStarter.java
Fri Nov 19 07:58:06 2010
@@ -20,12 +20,11 @@ package org.apache.maven.plugin.surefire
*/
import org.apache.maven.surefire.booter.BooterConfiguration;
-import org.apache.maven.surefire.booter.BooterSerializer;
import org.apache.maven.surefire.booter.ClasspathConfiguration;
import org.apache.maven.surefire.booter.SurefireBooterForkException;
import org.apache.maven.surefire.booter.SurefireExecutionException;
import org.apache.maven.surefire.booter.SurefireReflector;
-import org.apache.maven.surefire.booter.TestVmBooter;
+import org.apache.maven.surefire.booter.SurefireStarter;
import org.apache.maven.surefire.booter.output.FileOutputConsumerProxy;
import org.apache.maven.surefire.booter.output.OutputConsumer;
import org.apache.maven.surefire.booter.output.StandardOutputConsumer;
@@ -52,16 +51,18 @@ import java.util.Properties;
/**
- * The part of the booter that lives only on the plugin-side (not present in
remote vms)
+ * Starts the fork or runs in-process.
+ *
+ * Lives only on the plugin-side (not present in remote vms)
* <p/>
* Knows how to fork new vms and also how to delegate non-forking invocation
to TestVmBooter directly
*
* @author Jason van Zyl
* @author Emmanuel Venisse
- * @author Kristian Rosenvold
+ * @author Kristian Rosenvold
* @version $Id$
*/
-public class PluginSideBooter
+public class ForkStarter
{
private int forkedProcessTimeoutInSeconds = 0;
@@ -73,7 +74,7 @@ public class PluginSideBooter
private File reportsDirectory;
- public PluginSideBooter( BooterConfiguration booterConfiguration, File
reportsDirectory,
+ public ForkStarter( BooterConfiguration booterConfiguration, File
reportsDirectory,
PluginsideForkConfiguration forkConfiguration )
{
this.forkConfiguration = forkConfiguration;
@@ -89,7 +90,7 @@ public class PluginSideBooter
final String requestedForkMode = forkConfiguration.getForkMode();
if ( PluginsideForkConfiguration.FORK_NEVER.equals( requestedForkMode
) )
{
- TestVmBooter testVmBooter = new TestVmBooter( booterConfiguration
);
+ SurefireStarter testVmBooter = new SurefireStarter(
booterConfiguration );
result = testVmBooter.runSuitesInProcess();
}
else if ( PluginsideForkConfiguration.FORK_ONCE.equals(
requestedForkMode ) )
Propchange:
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booter/ForkStarter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booter/ForkStarter.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified:
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booter/PluginsideForkConfiguration.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booter/PluginsideForkConfiguration.java?rev=1036757&r1=1036756&r2=1036757&view=diff
==============================================================================
---
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booter/PluginsideForkConfiguration.java
(original)
+++
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booter/PluginsideForkConfiguration.java
Fri Nov 19 07:58:06 2010
@@ -20,7 +20,7 @@ package org.apache.maven.plugin.surefire
*/
import org.apache.maven.surefire.booter.ForkConfiguration;
-import org.apache.maven.surefire.booter.RemoteBooter;
+import org.apache.maven.surefire.booter.ForkedBooter;
import org.apache.maven.surefire.booter.SurefireBooterForkException;
import org.apache.maven.surefire.util.UrlUtils;
import org.codehaus.plexus.util.StringUtils;
@@ -225,7 +225,7 @@ public class PluginsideForkConfiguration
cli.createArg().setValue( StringUtils.join( classPath.iterator(),
File.pathSeparator ) );
- cli.createArg().setValue( RemoteBooter.class.getName() );
+ cli.createArg().setValue( ForkedBooter.class.getName() );
}
cli.setWorkingDirectory( workingDirectory.getAbsolutePath() );
@@ -269,7 +269,7 @@ public class PluginsideForkConfiguration
man.getMainAttributes().putValue( "Manifest-Version", "1.0" );
man.getMainAttributes().putValue( "Class-Path", cp.trim() );
- man.getMainAttributes().putValue( "Main-Class",
RemoteBooter.class.getName() );
+ man.getMainAttributes().putValue( "Main-Class",
ForkedBooter.class.getName() );
man.write( jos );
jos.close();
Copied:
maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booter/BooterConversionTest.java
(from r1036640,
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/BooterConversionTest.java)
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booter/BooterConversionTest.java?p2=maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booter/BooterConversionTest.java&p1=maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/BooterConversionTest.java&r1=1036640&r2=1036757&rev=1036757&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/BooterConversionTest.java
(original)
+++
maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booter/BooterConversionTest.java
Fri Nov 19 07:58:06 2010
@@ -1,4 +1,4 @@
-package org.apache.maven.surefire.booter;
+package org.apache.maven.plugin.surefire.booter;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -26,7 +26,9 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Properties;
+import junit.framework.Assert;
import junit.framework.TestCase;
+import org.apache.maven.surefire.booter.BooterDeserializer;
public class BooterConversionTest
extends TestCase
@@ -38,7 +40,7 @@ public class BooterConversionTest
{
convert = BooterSerializer.class.getDeclaredMethod( "convert", new
Class[]{ Object.class } );
convert.setAccessible( true );
- constructParamObjects = BooterSerializer.class.getDeclaredMethod(
"constructParamObjects",
+ constructParamObjects = BooterDeserializer.class.getDeclaredMethod(
"constructParamObjects",
new
Class[]{ String.class, String.class } );
constructParamObjects.setAccessible( true );
}
@@ -109,8 +111,8 @@ public class BooterConversionTest
{
String serialized = serialize( o );
Object[] output = deserialize( serialized, o.getClass().getName() );
- assertEquals( "Wrong number of output elements: " + Arrays.asList(
output ), 1, output.length );
- assertEquals( o, output[0] );
+ Assert.assertEquals( "Wrong number of output elements: " +
Arrays.asList( output ), 1, output.length );
+ Assert.assertEquals( o, output[0] );
}
public void doTestArray( Object[] o )
@@ -118,16 +120,16 @@ public class BooterConversionTest
{
String serialized = serialize( o );
Object[] output = deserialize( serialized, o.getClass().getName() );
- assertEquals( "Wrong number of output elements: " + Arrays.asList(
output ), 1, output.length );
+ Assert.assertEquals( "Wrong number of output elements: " +
Arrays.asList( output ), 1, output.length );
assertArrayEquals( "Deserialized array didn't match", o, (Object[])
output[0] );
}
private void assertArrayEquals( String message, Object[] expected,
Object[] actual )
{
- assertEquals( message + "; wrong number of elements", expected.length,
actual.length );
+ Assert.assertEquals( message + "; wrong number of elements",
expected.length, actual.length );
for ( int i = 0; i < expected.length; i++ )
{
- assertEquals( message + "; element " + i + " differs",
expected[i], actual[i] );
+ Assert.assertEquals( message + "; element " + i + " differs",
expected[i], actual[i] );
}
}
Propchange:
maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booter/BooterConversionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied:
maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booter/BooterDeserializerTest.java
(from r1036640,
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/BooterSerializerTest.java)
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booter/BooterDeserializerTest.java?p2=maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booter/BooterDeserializerTest.java&p1=maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/BooterSerializerTest.java&r1=1036640&r2=1036757&rev=1036757&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/BooterSerializerTest.java
(original)
+++
maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booter/BooterDeserializerTest.java
Fri Nov 19 07:58:06 2010
@@ -1,4 +1,4 @@
-package org.apache.maven.surefire.booter;
+package org.apache.maven.plugin.surefire.booter;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,7 +18,12 @@ package org.apache.maven.surefire.booter
* under the License.
*/
+import junit.framework.Assert;
import junit.framework.TestCase;
+import org.apache.maven.surefire.booter.BooterConfiguration;
+import org.apache.maven.surefire.booter.BooterDeserializer;
+import org.apache.maven.surefire.booter.ClasspathConfiguration;
+import org.apache.maven.surefire.booter.ForkConfiguration;
import java.io.File;
import java.io.FileInputStream;
@@ -28,9 +33,10 @@ import java.util.List;
import java.util.Properties;
/**
+ * Performs roundtrip testing of serialization/deserialization
* @author Kristian Rosenvold
*/
-public class BooterSerializerTest
+public class BooterDeserializerTest
extends TestCase
{
@@ -60,13 +66,14 @@ public class BooterSerializerTest
booterSerializer.setForkProperties( props, new ArrayList(),
booterConfiguration, forkConfiguration );
final File propsTest = booterSerializer.writePropertiesFile(
"propsTest", props, false, null );
- BooterConfiguration read = booterSerializer.deserialize( new
FileInputStream( propsTest ) );
+ BooterDeserializer booterDeserializer = new BooterDeserializer();
+ BooterConfiguration read = booterDeserializer.deserialize( new
FileInputStream( propsTest ) );
- assertEquals( aDir, read.getBaseDir() );
- assertEquals( includes.get( 0 ), read.getIncludes().get( 0 ) );
- assertEquals( includes.get( 1 ), read.getIncludes().get( 1 ) );
- assertEquals( excludes.get( 0 ), read.getExcludes().get( 0 ) );
- assertEquals( excludes.get( 1 ), read.getExcludes().get( 1 ) );
+ Assert.assertEquals( aDir, read.getBaseDir() );
+ Assert.assertEquals( includes.get( 0 ), read.getIncludes().get( 0 ) );
+ Assert.assertEquals( includes.get( 1 ), read.getIncludes().get( 1 ) );
+ Assert.assertEquals( excludes.get( 0 ), read.getExcludes().get( 0 ) );
+ Assert.assertEquals( excludes.get( 1 ), read.getExcludes().get( 1 ) );
}
Propchange:
maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booter/BooterDeserializerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
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=1036757&r1=1036756&r2=1036757&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
Fri Nov 19 07:58:06 2010
@@ -26,7 +26,7 @@ import org.apache.maven.artifact.resolve
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugin.surefire.booter.PluginSideBooter;
+import org.apache.maven.plugin.surefire.booter.ForkStarter;
import org.apache.maven.plugin.surefire.booter.PluginsideForkConfiguration;
import org.apache.maven.project.MavenProject;
import org.apache.maven.surefire.booter.BooterConfiguration;
@@ -575,7 +575,7 @@ public class SurefirePlugin
getLog().info(
StringUtils.capitalizeFirstLetter( getPluginName() ) + "
report directory: " + getReportsDirectory() );
- PluginSideBooter booter = new PluginSideBooter(
booterConfiguration, reportsDirectory, forkConfiguration );
+ ForkStarter booter = new ForkStarter( booterConfiguration,
reportsDirectory, forkConfiguration );
booter.setForkedProcessTimeoutInSeconds(
getForkedProcessTimeoutInSeconds() );
int result;
Modified:
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterConfiguration.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterConfiguration.java?rev=1036757&r1=1036756&r2=1036757&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterConfiguration.java
(original)
+++
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterConfiguration.java
Fri Nov 19 07:58:06 2010
@@ -89,6 +89,7 @@ public class BooterConfiguration
}
+
public ClasspathConfiguration getClasspathConfiguration()
{
return classpathConfiguration;
@@ -148,10 +149,10 @@ public class BooterConfiguration
public File getBaseDir()
{
- return (File) getDirScannerParams()[0];
+ return (File) getDirScannerParamsPriv()[0];
}
- private Object[] getDirScannerParams()
+ private Object[] getDirScannerParamsPriv()
{
if ( dirScannerParams == null )
{
@@ -160,14 +161,20 @@ public class BooterConfiguration
return dirScannerParams;
}
+
+ public Object[] getDirScannerParams()
+ {
+ return dirScannerParams;
+ }
+
public List getIncludes()
{
- return (List) getDirScannerParams()[1];
+ return (List) getDirScannerParamsPriv()[1];
}
public List getExcludes()
{
- return (List) getDirScannerParams()[2];
+ return (List) getDirScannerParamsPriv()[2];
}
public void setSuiteDefinition( SuiteDefinition suiteDefinition )
Copied:
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterDeserializer.java
(from r1036640,
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterSerializer.java)
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterDeserializer.java?p2=maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterDeserializer.java&p1=maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterSerializer.java&r1=1036640&r2=1036757&rev=1036757&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterSerializer.java
(original)
+++
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterDeserializer.java
Fri Nov 19 07:58:06 2010
@@ -23,7 +23,6 @@ import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -50,7 +49,7 @@ import java.util.TreeMap;
* @author Kristian Rosenvold
* @version $Id$
*/
-public class BooterSerializer
+public class BooterDeserializer
{
private static final String TEST_SUITE_PROPERTY_PREFIX = "testSuite.";
@@ -66,7 +65,7 @@ public class BooterSerializer
public BooterConfiguration deserialize( InputStream inputStream )
throws IOException
{
- Properties properties = loadProperties( inputStream );
+ Properties properties = SystemPropertyManager.loadProperties(
inputStream );
final List reports = new ArrayList();
Object[] dirScannerParams = null;
boolean enableAssertions = false;
@@ -161,37 +160,6 @@ public class BooterSerializer
dirScannerParams, failIfNotests,
properties );
}
- public void setForkProperties( Properties properties, List testSuites,
BooterConfiguration booterConfiguration,
- ForkConfiguration forkConfiguration )
- {
- addPropertiesForTypeHolder( booterConfiguration.getReports(),
properties, REPORT_PROPERTY_PREFIX );
- addPropertiesForTypeHolder( testSuites, properties,
TEST_SUITE_PROPERTY_PREFIX );
- List params = new ArrayList();
- params.add( new Object[]{ "directoryScannerOptions",
booterConfiguration.dirScannerParams } ); // todo
- addPropertiesForTypeHolder( params, properties,
DIRSCANNER_PROPERTY_PREFIX );
-
- booterConfiguration.getClasspathConfiguration().setForkProperties(
properties );
-
- properties.setProperty( "useSystemClassLoader", String.valueOf(
forkConfiguration.isUseSystemClassLoader() ) );
- properties.setProperty( "useManifestOnlyJar",
- String.valueOf(
forkConfiguration.isManifestOnlyJarRequestedAndUsable() ) );
- properties.setProperty( "failIfNoTests", String.valueOf(
booterConfiguration.isFailIfNoTests() ) );
- }
-
- public File writePropertiesFile( String name, Properties properties,
boolean debug, File tempDirectory )
- throws IOException
- {
- File file = File.createTempFile( name, "tmp", tempDirectory );
- if ( !debug )
- {
- file.deleteOnExit();
- }
-
- writePropertiesFile( file, name, properties );
-
- return file;
- }
-
void writePropertiesFile( File file, String name, Properties properties )
throws IOException
{
@@ -207,63 +175,6 @@ public class BooterSerializer
}
}
- private void addPropertiesForTypeHolder( List typeHolderList, Properties
properties, String propertyPrefix )
- {
- for ( int i = 0; i < typeHolderList.size(); i++ )
- {
- Object[] report = (Object[]) typeHolderList.get( i );
-
- String className = (String) report[0];
- Object[] params = (Object[]) report[1];
-
- properties.setProperty( propertyPrefix + i, className );
-
- if ( params != null )
- {
- String paramProperty = convert( params[0] );
- String typeProperty = params[0].getClass().getName();
- for ( int j = 1; j < params.length; j++ )
- {
- paramProperty += "|";
- typeProperty += "|";
- if ( params[j] != null )
- {
- paramProperty += convert( params[j] );
- typeProperty += params[j].getClass().getName();
- }
- }
- properties.setProperty( propertyPrefix + i + PARAMS_SUFIX,
paramProperty );
- properties.setProperty( propertyPrefix + i + TYPES_SUFIX,
typeProperty );
- }
- }
- }
-
- private static String convert( Object param )
- {
- if ( param instanceof File[] )
- {
- File[] files = (File[]) param;
- return "[" + StringUtils.join( files, "," ) + "]";
- }
- else if ( param instanceof Properties )
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- try
- {
- ( (Properties) param ).store( baos, "" );
- return new String( baos.toByteArray(), "8859_1" );
- }
- catch ( Exception e )
- {
- throw new RuntimeException( "bug in property conversion", e );
- }
- }
- else
- {
- return param.toString();
- }
- }
-
private static List processStringList( String stringList )
{
String sl = stringList;
@@ -284,27 +195,6 @@ public class BooterSerializer
return list;
}
- /*
- Loads the properties, closes the stream
- */
-
- private static Properties loadProperties( InputStream inStream )
- throws IOException
- {
- Properties p = new Properties();
-
- try
- {
- p.load( inStream );
- }
- finally
- {
- IOUtil.close( inStream );
- }
-
- return p;
- }
-
private static Object[] constructParamObjects( String paramProperty,
String typeProperty )
{
Object[] paramObjects = null;
@@ -379,4 +269,5 @@ public class BooterSerializer
}
return paramObjects;
}
+
}
Propchange:
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterDeserializer.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied:
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java
(from r1036640,
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/RemoteBooter.java)
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java?p2=maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java&p1=maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/RemoteBooter.java&r1=1036640&r2=1036757&rev=1036757&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/RemoteBooter.java
(original)
+++
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java
Fri Nov 19 07:58:06 2010
@@ -33,48 +33,16 @@ import java.util.Properties;
* <p/>
* Deals with deserialization of the booter wire-level protocol
*
+ * Todo: Look at releationship between this class and BooterSerializer
(BooterDeserializer?)
+ *
* @author Jason van Zyl
* @author Emmanuel Venisse
* @author Kristian Rosenvold
* @version $Id$
*/
-public class RemoteBooter
+public class ForkedBooter
{
- private static Properties loadProperties( File file )
- throws IOException
- {
- Properties p = new Properties();
-
- if ( file != null && file.exists() )
- {
- FileInputStream inStream = new FileInputStream( file );
- try
- {
- p.load( inStream );
- }
- finally
- {
- IOUtil.close( inStream );
- }
- }
-
- return p;
- }
-
- private static void setSystemProperties( File file )
- throws IOException
- {
- Properties p = loadProperties( file );
-
- for ( Iterator i = p.keySet().iterator(); i.hasNext(); )
- {
- String key = (String) i.next();
-
- System.setProperty( key, p.getProperty( key ) );
- }
- }
-
/**
* This method is invoked when Surefire is forked - this method parses and
organizes the arguments passed to it and
* then calls the Surefire class' run method. <p/> The system exit code
will be 1 if an exception is thrown.
@@ -89,16 +57,16 @@ public class RemoteBooter
{
if ( args.length > 1 )
{
- setSystemProperties( new File( args[1] ) );
+ SystemPropertyManager.setSystemProperties( new File( args[1] )
);
}
File surefirePropertiesFile = new File( args[0] );
InputStream stream = surefirePropertiesFile.exists() ? new
FileInputStream( surefirePropertiesFile ) : null;
- BooterSerializer booterSerializer = new BooterSerializer();
- BooterConfiguration booterConfiguration =
booterSerializer.deserialize( stream );
+ BooterDeserializer booterDeserializer = new BooterDeserializer();
+ BooterConfiguration booterConfiguration =
booterDeserializer.deserialize( stream );
Properties p = booterConfiguration.getProperties();
- TestVmBooter booter = new TestVmBooter( booterConfiguration );
+ SurefireStarter booter = new SurefireStarter( booterConfiguration
);
String testSet = p.getProperty( "testSet" );
int result;
@@ -111,7 +79,7 @@ public class RemoteBooter
result = booter.runSuitesInProcess();
}
- booterSerializer.writePropertiesFile( surefirePropertiesFile,
"surefire", p );
+ booterDeserializer.writePropertiesFile( surefirePropertiesFile,
"surefire", p );
// noinspection CallToSystemExit
System.exit( result );
@@ -125,4 +93,38 @@ public class RemoteBooter
System.exit( 1 );
}
}
+
+ private static Properties loadProperties( File file )
+ throws IOException
+ {
+ Properties p = new Properties();
+
+ if ( file != null && file.exists() )
+ {
+ FileInputStream inStream = new FileInputStream( file );
+ try
+ {
+ p.load( inStream );
+ }
+ finally
+ {
+ IOUtil.close( inStream );
+ }
+ }
+
+ return p;
+ }
+
+ private static void setSystemProperties( File file )
+ throws IOException
+ {
+ Properties p = loadProperties( file );
+
+ for ( Iterator i = p.keySet().iterator(); i.hasNext(); )
+ {
+ String key = (String) i.next();
+
+ System.setProperty( key, p.getProperty( key ) );
+ }
+ }
}
Propchange:
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied:
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireStarter.java
(from r1036640,
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/TestVmBooter.java)
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireStarter.java?p2=maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireStarter.java&p1=maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/TestVmBooter.java&r1=1036640&r2=1036757&rev=1036757&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/TestVmBooter.java
(original)
+++
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireStarter.java
Fri Nov 19 07:58:06 2010
@@ -22,19 +22,21 @@ package org.apache.maven.surefire.booter
import java.util.Properties;
/**
- * The part of the booter that is always guaranteed to be in the
+ * Invokes surefire with the correct classloader setup.
+ *
+ * This part of the booter that is always guaranteed to be in the
* same vm as the tests will be run in.
*
* @author Jason van Zyl
* @author Emmanuel Venisse
* @version $Id$
*/
-public class TestVmBooter
+public class SurefireStarter
{
private final BooterConfiguration booterConfiguration;
- public TestVmBooter( BooterConfiguration booterConfiguration )
+ public SurefireStarter( BooterConfiguration booterConfiguration )
{
this.booterConfiguration = booterConfiguration;
}
Propchange:
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireStarter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
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=1036757&view=auto
==============================================================================
---
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemPropertyManager.java
(added)
+++
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemPropertyManager.java
Fri Nov 19 07:58:06 2010
@@ -0,0 +1,75 @@
+package org.apache.maven.surefire.booter;
+/*
+ * 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.codehaus.plexus.util.IOUtil;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Iterator;
+import java.util.Properties;
+
+/**
+ * @author Kristian Rosenvold
+ */
+public class SystemPropertyManager
+{
+ private static Properties loadProperties( File file )
+ throws IOException
+ {
+ return loadProperties( new FileInputStream( file ) );
+ }
+
+ /*
+ Loads the properties, closes the stream
+ */
+
+ public static Properties loadProperties( InputStream inStream )
+ throws IOException
+ {
+ Properties p = new Properties();
+
+ try
+ {
+ p.load( inStream );
+ }
+ finally
+ {
+ IOUtil.close( inStream );
+ }
+
+ return p;
+ }
+
+
+ public static void setSystemProperties( File file )
+ throws IOException
+ {
+ Properties p = loadProperties( file );
+
+ for ( Iterator i = p.keySet().iterator(); i.hasNext(); )
+ {
+ String key = (String) i.next();
+
+ System.setProperty( key, p.getProperty( key ) );
+ }
+ }
+}
Propchange:
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemPropertyManager.java
------------------------------------------------------------------------------
svn:eol-style = native