Author: dfabulich
Date: Wed Nov 21 01:40:34 2007
New Revision: 597008
URL: http://svn.apache.org/viewvc?rev=597008&view=rev
Log:
[SUREFIRE-385] Booter can't decode properties when TestNG groups contains commas
Added:
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/BooterConversionTest.java
Modified:
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/SurefireBooter.java
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-group-thread-parallel/pom.xml
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=597008&r1=597007&r2=597008&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
Wed Nov 21 01:40:34 2007
@@ -489,20 +489,20 @@
if ( this.parallel != null )
{
- properties.put( "parallel", this.parallel );
+ properties.setProperty( "parallel", this.parallel );
}
if ( this.excludedGroups != null )
{
- properties.put( "excludegroups", this.excludedGroups );
+ properties.setProperty( "excludegroups", this.excludedGroups );
}
if ( this.groups != null )
{
- properties.put( "groups", this.groups );
+ properties.setProperty( "groups", this.groups );
}
if ( this.threadCount > 0 )
{
- properties.put( "threadcount", new Integer( this.threadCount ) );
+ properties.setProperty( "threadcount", new Integer(
this.threadCount ).toString() );
}
}
@@ -545,7 +545,7 @@
if ( this.testClassesDirectory != null )
{
- properties.put( "testng.test.classpath",
testClassesDirectory.getAbsolutePath() );
+ properties.setProperty( "testng.test.classpath",
testClassesDirectory.getAbsolutePath() );
}
addArtifact( surefireBooter, testNgArtifact );
Modified:
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java?rev=597008&r1=597007&r2=597008&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
(original)
+++
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
Wed Nov 21 01:40:34 2007
@@ -19,23 +19,8 @@
* under the License.
*/
-import org.apache.maven.surefire.Surefire;
-import org.apache.maven.surefire.booter.output.FileOutputConsumerProxy;
-import org.apache.maven.surefire.booter.output.ForkingStreamConsumer;
-import org.apache.maven.surefire.booter.output.OutputConsumer;
-import org.apache.maven.surefire.booter.output.StandardOutputConsumer;
-import
org.apache.maven.surefire.booter.output.SupressFooterOutputConsumerProxy;
-import
org.apache.maven.surefire.booter.output.SupressHeaderOutputConsumerProxy;
-import org.apache.maven.surefire.testset.TestSetFailedException;
-import org.apache.maven.surefire.util.NestedRuntimeException;
-import org.apache.maven.surefire.util.UrlUtils;
-import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.StringUtils;
-import org.codehaus.plexus.util.cli.CommandLineException;
-import org.codehaus.plexus.util.cli.CommandLineUtils;
-import org.codehaus.plexus.util.cli.Commandline;
-import org.codehaus.plexus.util.cli.StreamConsumer;
-
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -55,6 +40,23 @@
import java.util.SortedMap;
import java.util.TreeMap;
+import org.apache.maven.surefire.Surefire;
+import org.apache.maven.surefire.booter.output.FileOutputConsumerProxy;
+import org.apache.maven.surefire.booter.output.ForkingStreamConsumer;
+import org.apache.maven.surefire.booter.output.OutputConsumer;
+import org.apache.maven.surefire.booter.output.StandardOutputConsumer;
+import
org.apache.maven.surefire.booter.output.SupressFooterOutputConsumerProxy;
+import
org.apache.maven.surefire.booter.output.SupressHeaderOutputConsumerProxy;
+import org.apache.maven.surefire.testset.TestSetFailedException;
+import org.apache.maven.surefire.util.NestedRuntimeException;
+import org.apache.maven.surefire.util.UrlUtils;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.Commandline;
+import org.codehaus.plexus.util.cli.StreamConsumer;
+
/**
* @author Jason van Zyl
* @author Emmanuel Venisse
@@ -527,7 +529,7 @@
}
}
- private String convert( Object param )
+ private static String convert( Object param )
{
if ( param instanceof File[] )
{
@@ -542,6 +544,17 @@
}
}
return s + "]";
+ } 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
{
@@ -805,17 +818,18 @@
paramObjects[i] = Integer.valueOf( params[i] );
}
else if (types[i].equals(Properties.class.getName())) {
- final Properties result = new Properties();
- final String value = params[i];
- if (!value.startsWith("{") || !value.endsWith("}")) {
- throw new IllegalArgumentException("Invalid input " +
value);
- }
- final String[] pairs = value.substring(1, value.length() -
1).split(", ");
- for (int j = 0; j < pairs.length; j++) {
- final String[] pair = pairs[j].split("=");
- result.put(pair[0], pair[1]);
- }
- paramObjects[i] = result;
+ final Properties result = new Properties();
+ final String value = params[i];
+ try
+ {
+ ByteArrayInputStream bais = new ByteArrayInputStream(
value.getBytes( "8859_1" ) );
+ result.load( bais );
+ }
+ catch ( Exception e )
+ {
+ throw new RuntimeException( "bug in property
conversion", e );
+ }
+ paramObjects[i] = result;
}
else
{
Added:
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/BooterConversionTest.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/BooterConversionTest.java?rev=597008&view=auto
==============================================================================
---
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/BooterConversionTest.java
(added)
+++
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/BooterConversionTest.java
Wed Nov 21 01:40:34 2007
@@ -0,0 +1,94 @@
+package org.apache.maven.surefire.booter;
+
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+public class BooterConversionTest
+ extends TestCase
+{
+ Method convert, constructParamObjects;
+ public void setUp() throws Exception {
+ convert = SurefireBooter.class.getDeclaredMethod( "convert", new
Class[] { Object.class } );
+ convert.setAccessible( true );
+ constructParamObjects = SurefireBooter.class.getDeclaredMethod(
"constructParamObjects", new Class[] { String.class, String.class } );
+ constructParamObjects.setAccessible( true );
+ }
+
+ public void testString() throws Exception {
+ doTest( "Hello world!" );
+ }
+
+ public void testFile() throws Exception {
+ doTest( new File( "."));
+ }
+
+ public void testFileArray() throws Exception {
+ doTestArray( new File[] {new File( ".")});
+ }
+
+ public void testArrayList() throws Exception {
+ doTest(new ArrayList());
+ }
+
+ public void testBoolean() throws Exception {
+ doTest(Boolean.TRUE);
+ doTest(Boolean.FALSE);
+ }
+
+ public void testInteger() throws Exception {
+ doTest(new Integer(0));
+ }
+
+ public void testProperties() throws Exception {
+ Properties p = new Properties();
+ p.setProperty( "foo", "bar" );
+ doTest(p);
+ }
+
+ public void testPropertiesEmpty() throws Exception {
+ Properties p = new Properties();
+ doTest(p);
+ }
+
+ public void testPropertiesWithComma() throws Exception {
+ Properties p = new Properties();
+ p.setProperty( "foo, comma", "bar" );
+
+ doTest(p);
+ }
+
+ public void doTest(Object o) throws Exception {
+ String serialized = serialize( o );
+ Object[] output = deserialize( serialized, o.getClass().getName() );
+ assertEquals ( "Wrong number of output elements: " + Arrays.toString(
output ), 1, output.length);
+ assertEquals ( o, output[0] );
+ }
+
+ public void doTestArray(Object[] o) throws Exception {
+ String serialized = serialize( o );
+ Object[] output = deserialize( serialized, o.getClass().getName() );
+ assertEquals ( "Wrong number of output elements: " + Arrays.toString(
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);
+ for (int i = 0; i < expected.length; i++) {
+ assertEquals( message + "; element " + i + " differs",
expected[i], actual[i]);
+ }
+ }
+
+ private Object[] deserialize (String paramProperty, String typeProperty)
throws IllegalArgumentException, IllegalAccessException,
InvocationTargetException {
+ return (Object[]) constructParamObjects.invoke( null, new Object[]
{paramProperty, typeProperty} );
+ }
+
+ private String serialize(Object o) throws IllegalArgumentException,
IllegalAccessException, InvocationTargetException {
+ return (String) convert.invoke( null, new Object[] { o } );
+ }
+}
Modified:
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-group-thread-parallel/pom.xml
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-group-thread-parallel/pom.xml?rev=597008&r1=597007&r2=597008&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-group-thread-parallel/pom.xml
(original)
+++
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-group-thread-parallel/pom.xml
Wed Nov 21 01:40:34 2007
@@ -45,7 +45,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
- <groups>functional</groups>
+ <groups>nonexistent, functional</groups>
<threadCount>3</threadCount>
<parallel>methods</parallel>
</configuration>