Author: krosenvold
Date: Wed Nov 10 16:22:17 2010
New Revision: 1033565

URL: http://svn.apache.org/viewvc?rev=1033565&view=rev
Log:
[SUREFIRE-657] Newlines in argLine removed

Modified:
    
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkConfiguration.java
    
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ForkConfigurationTest.java

Modified: 
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkConfiguration.java
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkConfiguration.java?rev=1033565&r1=1033564&r2=1033565&view=diff
==============================================================================
--- 
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkConfiguration.java
 (original)
+++ 
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkConfiguration.java
 Wed Nov 10 16:22:17 2010
@@ -52,6 +52,7 @@ public class ForkConfiguration
     private String forkMode;
 
     private boolean useSystemClassLoader;
+
     private boolean useManifestOnlyJar;
 
     private Properties systemProperties;
@@ -67,7 +68,7 @@ public class ForkConfiguration
     private File tempDirectory;
 
     private boolean debug;
-    
+
     private String debugLine;
 
     public void setForkMode( String forkMode )
@@ -119,7 +120,7 @@ public class ForkConfiguration
     {
         this.argLine = argLine;
     }
-    
+
     public void setDebugLine( String debugLine )
     {
         this.debugLine = debugLine;
@@ -156,7 +157,9 @@ public class ForkConfiguration
     }
 
     /**
-     * @throws SurefireBooterForkException
+     * @param classPath cla the classpath arguments
+     * @return A commandline
+     * @throws SurefireBooterForkException when unable to perform the fork
      */
     public Commandline createCommandLine( List classPath )
         throws SurefireBooterForkException
@@ -173,7 +176,7 @@ public class ForkConfiguration
 
         if ( argLine != null )
         {
-            cli.createArg().setLine( argLine );
+            cli.createArg().setLine( stripNewLines( argLine ) );
         }
 
         if ( environmentVariables != null )
@@ -230,8 +233,8 @@ public class ForkConfiguration
      * for all classpath elements.
      *
      * @param classPath List<String> of all classpath elements.
-     * @return
-     * @throws IOException
+     * @return The file pointint to the jar
+     * @throws IOException When a file operation fails.
      */
     private File createJar( List classPath )
         throws IOException
@@ -283,7 +286,7 @@ public class ForkConfiguration
     {
         this.useManifestOnlyJar = useManifestOnlyJar;
     }
-    
+
     public boolean isUseManifestOnlyJar()
     {
         return useManifestOnlyJar;
@@ -294,4 +297,8 @@ public class ForkConfiguration
         return isUseSystemClassLoader() && isUseManifestOnlyJar();
     }
 
+    private String stripNewLines( String argline )
+    {
+        return argline.replace( "\n", " " ).replace( "\r", " " );
+    }
 }

Modified: 
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ForkConfigurationTest.java
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ForkConfigurationTest.java?rev=1033565&r1=1033564&r2=1033565&view=diff
==============================================================================
--- 
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ForkConfigurationTest.java
 (original)
+++ 
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ForkConfigurationTest.java
 Wed Nov 10 16:22:17 2010
@@ -19,6 +19,7 @@ package org.apache.maven.surefire.booter
  * under the License.
  */
 
+import junit.framework.TestCase;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.cli.Commandline;
 
@@ -26,8 +27,6 @@ import java.io.File;
 import java.io.IOException;
 import java.util.Collections;
 
-import junit.framework.TestCase;
-
 public class ForkConfigurationTest
     extends TestCase
 {
@@ -35,19 +34,50 @@ public class ForkConfigurationTest
     public void 
testCreateCommandLine_UseSystemClassLoaderForkOnce_ShouldConstructManifestOnlyJar()
         throws IOException, SurefireBooterForkException
     {
-        ForkConfiguration config = new ForkConfiguration();
+        ForkConfiguration config = getForkConfiguration();
+        File cpElement = getTempClasspathFile();
         config.setForkMode( ForkConfiguration.FORK_ONCE );
         config.setUseSystemClassLoader( true );
-        config.setWorkingDirectory( new File( "." ).getCanonicalFile() );
+        config.setUseSystemClassLoader( true );
         config.setJvmExecutable( "java" );
 
-        File cpElement = File.createTempFile( "ForkConfigurationTest.", 
".file" );
-        cpElement.deleteOnExit();
 
-        Commandline cli = config.createCommandLine( Collections.singletonList( 
cpElement.getAbsolutePath() ), config.isUseSystemClassLoader() );
+        Commandline cli = config.createCommandLine( Collections.singletonList( 
cpElement.getAbsolutePath() ),
+                                                    
config.isUseSystemClassLoader() );
 
         String line = StringUtils.join( cli.getCommandline(), " " );
         assertTrue( line.indexOf( "-jar" ) > -1 );
     }
 
+    public void testArglineWithNewline()
+        throws IOException, SurefireBooterForkException
+    {
+        // SUREFIRE-657
+        File cpElement = getTempClasspathFile();
+        ForkConfiguration forkConfiguration = getForkConfiguration();
+
+        forkConfiguration.setArgLine( "abc\ndef" );
+
+
+        final Commandline commandLine =
+            forkConfiguration.createCommandLine( Collections.singletonList( 
cpElement.getAbsolutePath() ), false );
+        assertTrue( commandLine.toString().contains( "abc def" ) );
+    }
+
+    private File getTempClasspathFile()
+        throws IOException
+    {
+        File cpElement = File.createTempFile( "ForkConfigurationTest.", 
".file" );
+        cpElement.deleteOnExit();
+        return cpElement;
+    }
+
+    private ForkConfiguration getForkConfiguration()
+        throws IOException
+    {
+        ForkConfiguration forkConfiguration = new ForkConfiguration();
+        forkConfiguration.setWorkingDirectory( new File( "." 
).getCanonicalFile() );
+        return forkConfiguration;
+    }
+
 }


Reply via email to