[MPATCH-3] Path with space makes command line invocation fail

git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@642018 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/it/projects/path with spaces/goals.txt b/src/it/projects/path with spaces/goals.txt
new file mode 100644
index 0000000..dfc317d
--- /dev/null
+++ b/src/it/projects/path with spaces/goals.txt
@@ -0,0 +1,2 @@
+clean
+initialize
diff --git a/src/it/projects/path with spaces/pom.xml b/src/it/projects/path with spaces/pom.xml
new file mode 100644
index 0000000..7027615
--- /dev/null
+++ b/src/it/projects/path with spaces/pom.xml
@@ -0,0 +1,79 @@
+<!--
+    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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  
+  <parent>
+    <groupId>org.apache.maven.plugins.patch.it</groupId>
+    <artifactId>it-project-parent</artifactId>
+    <version>1</version>
+  </parent>
+  
+  <artifactId>path-with-spaces</artifactId>
+  <name>path-with-spaces</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-patch-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>apply-patch-0</id>
+            <phase>initialize</phase>
+            <configuration>
+              <targetDirectory>${basedir}</targetDirectory>
+              <patches>
+                <patch>first.patch</patch>
+              </patches>
+            </configuration>
+            <goals>
+              <goal>apply</goal>
+            </goals>
+          </execution>
+          <execution>
+            <id>apply-patch-1</id>
+            <phase>initialize</phase>
+            <configuration>
+              <targetDirectory>${basedir}</targetDirectory>
+              <originalFile>${basedir}/target/test.txt</originalFile>
+              <destFile>${basedir}/target/test2.txt</destFile>
+              <patches>
+                <patch>second.patch</patch>
+              </patches>
+            </configuration>
+            <goals>
+              <goal>apply</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/src/it/projects/path with spaces/src/main/patches/first.patch b/src/it/projects/path with spaces/src/main/patches/first.patch
new file mode 100644
index 0000000..3dbd0bc
--- /dev/null
+++ b/src/it/projects/path with spaces/src/main/patches/first.patch
@@ -0,0 +1,25 @@
+#
+#  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.
+#
+Index: target/test.txt
+===================================================================
+--- target/test.txt	(revision 0)
++++ target/test.txt	(revision 0)
+@@ -0,0 +1 @@
++This is a test.
+
diff --git a/src/it/projects/path with spaces/src/main/patches/second.patch b/src/it/projects/path with spaces/src/main/patches/second.patch
new file mode 100644
index 0000000..ff8e04e
--- /dev/null
+++ b/src/it/projects/path with spaces/src/main/patches/second.patch
@@ -0,0 +1,26 @@
+#
+#  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.
+#
+Index: target/test.txt
+===================================================================
+--- target/test.txt	(revision 0)
++++ target/test.txt	(revision 0)
+@@ -1,1 +1,1 @@
+-This is a test.
++This is another test.
+
diff --git a/src/it/projects/path with spaces/verify.bsh b/src/it/projects/path with spaces/verify.bsh
new file mode 100644
index 0000000..dd3f3b8
--- /dev/null
+++ b/src/it/projects/path with spaces/verify.bsh
@@ -0,0 +1,45 @@
+/*
+    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 java.io.*;
+import java.util.*;
+
+try
+{
+    File testFile = new File( basedir, "target/test.txt" );
+    if ( !testFile.isFile() )
+    {
+        System.err.println( "Missing test file: " + testFile );
+        return false;
+    }
+
+    testFile = new File( basedir, "target/test2.txt" );
+    if ( !testFile.isFile() )
+    {
+        System.err.println( "Missing test file: " + testFile );
+        return false;
+    }
+}
+catch( Throwable t )
+{
+    t.printStackTrace();
+    return false;
+}
+
+return true;
diff --git a/src/main/java/org/apache/maven/plugin/patch/ApplyMojo.java b/src/main/java/org/apache/maven/plugin/patch/ApplyMojo.java
index d635603..f697516 100644
--- a/src/main/java/org/apache/maven/plugin/patch/ApplyMojo.java
+++ b/src/main/java/org/apache/maven/plugin/patch/ApplyMojo.java
@@ -558,34 +558,36 @@
 
         if ( originalFile != null )
         {
-            cli.createArg().setLine( originalFile.getAbsolutePath() );
+            cli.createArg().setFile( originalFile );
 
             if ( destFile != null )
             {
-                cli.createArg().setLine( "-o " + destFile.getAbsolutePath() );
+                cli.createArg().setValue( "-o" );
+                cli.createArg().setFile( destFile );
             }
 
-            cli.createArg().setLine( patchFile.getAbsolutePath() );
+            cli.createArg().setFile( patchFile );
         }
 
-        cli.createArg().setLine( "-p" + strip );
+        cli.createArg().setValue( "-p" + strip );
 
         if ( ignoreWhitespace )
         {
-            cli.createArg().setLine( "-l" );
+            cli.createArg().setValue( "-l" );
         }
 
         if ( reverse )
         {
-            cli.createArg().setLine( "-R" );
+            cli.createArg().setValue( "-R" );
         }
 
         if ( backups )
         {
-            cli.createArg().setLine( "-b" );
+            cli.createArg().setValue( "-b" );
         }
 
-        cli.createArg().setLine( " < " + patchFile.getAbsolutePath() );
+        cli.createArg().setValue( "<" );
+        cli.createArg().setFile( patchFile );
 
         return cli;
     }