diff --git a/src/main/java/org/codehaus/plexus/util/cli/Commandline.java b/src/main/java/org/codehaus/plexus/util/cli/Commandline.java
index a23d65eb..df909925 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/Commandline.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/Commandline.java
@@ -139,7 +139,7 @@ public class Commandline
* Create a new command line object.
* Shell is autodetected from operating system
*
- * Shell usage is only desirable when generating code for remote execution.
+ * For Linux, shell usage is only desirable when generating code for remote execution.
*
* @param toProcess
*/
@@ -170,7 +170,7 @@ public Commandline( String toProcess, Shell shell )
* Create a new command line object.
* Shell is autodetected from operating system
*
- * Shell usage is only desirable when generating code for remote execution.
+ * For Linux, shell usage is only desirable when generating code for remote execution.
*/
public Commandline( Shell shell )
{
@@ -417,7 +417,7 @@ public String getLiteralExecutable()
/**
* Return an executable name, quoted for shell use.
*
- * Shell usage is only desirable when generating code for remote execution.
+ * For Linux, shell usage is only desirable when generating code for remote execution.
*
* @return Executable to be run, quoted for shell interpretation
*/
@@ -487,7 +487,7 @@ public String[] getEnvironmentVariables()
for ( Object o : envVars.keySet() )
{
String name = (String) o;
- String value = (String) envVars.get( name );
+ String value = envVars.get( name );
environmentVars[i] = name + "=" + value;
i++;
}
@@ -495,10 +495,16 @@ public String[] getEnvironmentVariables()
}
/**
- * Returns the executable and all defined arguments.
+ * Returns the executable and all defined arguments.
+ * For Windows Family, {@link Commandline#getShellCommandline()} is returned
*/
public String[] getCommandline()
{
+ if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
+ {
+ return getShellCommandline();
+ }
+
final String[] args = getArguments();
String executable = getLiteralExecutable();
@@ -515,7 +521,7 @@ public String[] getCommandline()
/**
* Returns the shell, executable and all defined arguments.
*
- * Shell usage is only desirable when generating code for remote execution.
+ * For Linux, shell usage is only desirable when generating code for remote execution.
*/
public String[] getShellCommandline()
{
@@ -703,7 +709,7 @@ public Properties getSystemEnvVars()
/**
* Allows to set the shell to be used in this command line.
*
- * Shell usage is only desirable when generating code for remote execution.
+ * For Linux, shell usage is only desirable when generating code for remote execution.
*
* @param shell
* @since 1.2
@@ -716,7 +722,7 @@ public void setShell( Shell shell )
/**
* Get the shell to be used in this command line.
*
- * Shell usage is only desirable when generating code for remote execution.
+ * For Linux, shell usage is only desirable when generating code for remote execution.
* @since 1.2
*/
public Shell getShell()
diff --git a/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java b/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java
index eef58076..58b8b730 100644
--- a/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java
+++ b/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java
@@ -164,8 +164,8 @@ public void testFollowSymlinksFalse()
private void assertAlwaysIncluded( List included )
{
- assertTrue( included.contains( "aRegularDir/aRegularFile.txt" ) );
- assertTrue( included.contains( "targetDir/targetFile.txt" ) );
+ assertTrue( included.contains( "aRegularDir" + File.separator + "aRegularFile.txt" ) );
+ assertTrue( included.contains( "targetDir" + File.separator + "targetFile.txt" ) );
assertTrue( included.contains( "fileR.txt" ) );
assertTrue( included.contains( "fileW.txt" ) );
assertTrue( included.contains( "fileX.txt" ) );
@@ -183,8 +183,8 @@ public void testFollowSymlinks()
ds.scan();
List included = Arrays.asList( ds.getIncludedFiles() );
assertAlwaysIncluded( included );
- assertTrue( included.contains( "symDir/targetFile.txt" ) );
- assertTrue( included.contains( "symLinkToDirOnTheOutside/FileInDirOnTheOutside.txt" ) );
+ assertTrue( included.contains( "symDir" + File.separator + "targetFile.txt" ) );
+ assertTrue( included.contains( "symLinkToDirOnTheOutside" + File.separator + "FileInDirOnTheOutside.txt" ) );
assertEquals( 11, included.size() );
List includedDirs = Arrays.asList( ds.getIncludedDirectories() );
@@ -196,7 +196,6 @@ public void testFollowSymlinks()
assertEquals( 5, includedDirs.size() );
}
-
private void createTestDirectories()
throws IOException
{
diff --git a/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java b/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java
index 3468c5ff..5134e736 100644
--- a/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java
+++ b/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java
@@ -88,6 +88,29 @@ public void testCommandlineWithCommandInConstructor()
}
}
+ public void testExecuteBinaryOnPath()
+ {
+ try
+ {
+ // Maven binary on PATH is required for this test
+ Commandline cmd = new Commandline();
+ cmd.setWorkingDirectory( baseDir );
+ cmd.setExecutable( "mvn" );
+ assertEquals( "mvn", cmd.getShell().getOriginalExecutable() );
+ cmd.createArg().setValue( "-version" );
+ Process process = cmd.execute();
+ String out = IOUtil.toString( process.getInputStream() );
+ assertTrue( out.contains( "Apache Maven" ) );
+ assertTrue( out.contains( "Maven home:" ) );
+ assertTrue( out.contains( "Java version:" ) );
+ assertTrue( out.contains( "Java home:" ) );
+ }
+ catch ( Exception e )
+ {
+ fail( "Maven binary seems not on the PATH: " + e.getMessage() );
+ }
+ }
+
public void testExecute()
{
try
@@ -99,21 +122,8 @@ public void testExecute()
assertEquals( "echo", cmd.getShell().getOriginalExecutable() );
cmd.createArgument().setValue( "Hello" );
- StringWriter swriter = new StringWriter();
Process process = cmd.execute();
-
- Reader reader = new InputStreamReader( process.getInputStream() );
-
- char[] chars = new char[16];
- int read = -1;
- while ( ( read = reader.read( chars ) ) > -1 )
- {
- swriter.write( chars, 0, read );
- }
-
- String output = swriter.toString().trim();
-
- assertEquals( "Hello", output );
+ assertEquals( "Hello", IOUtil.toString( process.getInputStream() ).trim() );
}
catch ( Exception e )
{
@@ -248,7 +258,7 @@ public void testGetShellCommandLineBash()
String expectedShellCmd = "'/bin/echo' 'hello world'";
if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
{
- expectedShellCmd = "\\bin\\echo \'hello world\'";
+ expectedShellCmd = "'\\bin\\echo' \'hello world\'";
}
assertEquals( expectedShellCmd, shellCommandline[2] );
}
@@ -307,7 +317,7 @@ public void testGetShellCommandLineBash_WithSingleQuotedArg()
String expectedShellCmd = "'/bin/echo' ''\"'\"'hello world'\"'\"''";
if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
{
- expectedShellCmd = "\\bin\\echo \'hello world\'";
+ expectedShellCmd = expectedShellCmd.replace( "/bin/echo", "\\bin\\echo" );
}
assertEquals( expectedShellCmd, shellCommandline[2] );
}
@@ -330,7 +340,7 @@ public void testGetShellCommandLineNonWindows()
if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
{
- assertEquals( "\\usr\\bin a b", shellCommandline[2] );
+ assertEquals( "'\\usr\\bin' 'a' 'b'", shellCommandline[2] );
}
else
{