Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Revert usage of cmd on Windows #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions 14 src/main/java/org/codehaus/plexus/util/cli/Commandline.java
Original file line number Diff line number Diff line change
Expand Up @@ -495,25 +495,19 @@ public String[] getEnvironmentVariables()
}

/**
* Returns the executable and all defined arguments.<br/>
* For Windows Family, {@link Commandline#getShellCommandline()} is returned
* Returns the executable and all defined arguments.
*/
public String[] getCommandline()
{
if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
{
return getShellCommandline();
}

final String[] args = getArguments();
String executable = getLiteralExecutable();
String executableTmp = getLiteralExecutable();

if ( executable == null )
if ( executableTmp == null )
{
return args;
}
final String[] result = new String[args.length + 1];
result[0] = executable;
result[0] = executableTmp;
System.arraycopy( args, 0, result, 1, args.length );
return result;
}
Expand Down
30 changes: 23 additions & 7 deletions 30 src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,15 @@ public void testExecuteBinaryOnPath()
try
{
// Maven startup script on PATH is required for this test
String binary = "mvn";
if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
{
binary += ".cmd";
}
Commandline cmd = new Commandline();
cmd.setWorkingDirectory( baseDir );
cmd.setExecutable( "mvn" );
assertEquals( "mvn", cmd.getShell().getOriginalExecutable() );
cmd.setExecutable( binary );
assertEquals( binary, cmd.getShell().getOriginalExecutable() );
cmd.createArg().setValue( "-version" );
Process process = cmd.execute();
String out = IOUtil.toString( process.getInputStream() );
Expand All @@ -116,11 +121,19 @@ public void testExecute()
try
{
// allow it to detect the proper shell here.
String binary = "echo";
Commandline cmd = new Commandline();
cmd.setWorkingDirectory( baseDir );
cmd.setExecutable( "echo" );
assertEquals( "echo", cmd.getShell().getOriginalExecutable() );
cmd.createArgument().setValue( "Hello" );
cmd.setWorkingDirectory( baseDir );
if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
{
binary = "cmd";
cmd.createArg().setValue("/X");
cmd.createArg().setValue("/C");
cmd.createArg().setValue("echo");
}
cmd.setExecutable( binary );
assertEquals( binary, cmd.getShell().getOriginalExecutable() );
cmd.createArg().setValue( "Hello" );

Process process = cmd.execute();
assertEquals( "Hello", IOUtil.toString( process.getInputStream() ).trim() );
Expand Down Expand Up @@ -491,7 +504,10 @@ public void testDollarSignInArgumentPath()
cmd.setExecutable( "cat" );
if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
{
cmd.setExecutable( "dir" );
cmd.setExecutable( "cmd" );
cmd.createArg().setLine( "/X" );
cmd.createArg().setLine( "/C" );
cmd.createArg().setLine( "dir" );
}
cmd.setWorkingDirectory( dir );
cmd.createArg().setLine( "test$1.txt" );
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.