Skip to content

Commit

Permalink
Merge pull request #46 from arxes-tolina/master
Browse files Browse the repository at this point in the history
fixed #42, Execution of Windows executables broken in 1.5.0
  • Loading branch information
khmarbaise committed Jun 12, 2016
2 parents cf90e47 + 8534093 commit 9765f3a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/codehaus/mojo/exec/ExecMojo.java
Expand Up @@ -663,7 +663,7 @@ static String findExecutable( final String executable, final List<String> paths
search: for ( final String path : paths )
{
f = new File( path, executable );
if ( f.isFile() )
if ( !OS.isFamilyWindows() && f.isFile() )
break;
else
for ( final String extension : getExecutableExtensions() )
Expand Down
51 changes: 47 additions & 4 deletions src/test/java/org/codehaus/mojo/exec/ExecMojoTest.java
Expand Up @@ -35,7 +35,11 @@
import org.apache.maven.project.MavenProjectBuilder;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringOutputStream;
import org.junit.Assume;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;

/**
* @author Jerome Lacoste <jerome@coffeebreaks.org>
Expand All @@ -61,7 +65,7 @@ static class MockExecMojo

public String failureMsg;

public Map systemProperties = new HashMap();
public Map<String, String> systemProperties = new HashMap<String, String>();

protected int executeCommandLine( Executor exec, CommandLine commandLine, Map enviro, OutputStream out,
OutputStream err )
Expand All @@ -77,7 +81,7 @@ protected int executeCommandLine( Executor exec, CommandLine commandLine, Map en

protected String getSystemProperty( String key )
{
return (String) systemProperties.get( key );
return systemProperties.get( key );
}

int getAmountExecutedCommandLines()
Expand All @@ -87,7 +91,7 @@ int getAmountExecutedCommandLines()

CommandLine getExecutedCommandline( int index )
{
return ( (CommandLine) commandLines.get( index ) );
return commandLines.get( index );
}
}

Expand Down Expand Up @@ -268,7 +272,7 @@ public void testGetExecutablePath()
ExecMojo realMojo = new ExecMojo();

File workdir = new File( System.getProperty( "user.dir" ) );
Map enviro = new HashMap();
Map<String, String> enviro = new HashMap<String, String>();

String myJavaPath = "target" + File.separator + "javax";
File f = new File( myJavaPath );
Expand Down Expand Up @@ -306,6 +310,45 @@ public void testGetExecutablePath()
assertFalse( "file deleted...", f.exists() );
}
}

// under Windows cmd/bat files should be preferred over files with the same prefix without extension, e.g.
// if there are "node" and "node.cmd" the mojo should pick "node.cmd"
// see https://github.com/mojohaus/exec-maven-plugin/issues/42
public void testGetExecutablePathPreferExecutableExtensionsOnWindows()
throws IOException
{
// this test is for Windows
if (!OS.isFamilyWindows()) {
return;
}
final ExecMojo realMojo = new ExecMojo();

final String tmp = System.getProperty("java.io.tmpdir");
final File workdir = new File(tmp, "testGetExecutablePathPreferExecutableExtensionsOnWindows");
workdir.mkdirs();

final Map<String, String> enviro = new HashMap<String, String>();

final File f = new File(workdir, "mycmd");
final File fCmd = new File(workdir, "mycmd.cmd");
f.createNewFile();
fCmd.createNewFile();
assertTrue( "file exists...", f.exists() );
assertTrue( "file exists...", fCmd.exists() );

realMojo.setExecutable( "mycmd" );

final CommandLine cmd = realMojo.getExecutablePath( enviro, workdir );
// cmdline argumets are: [/c, %path-to-temp%\mycmd.cmd], so check second argument
assertTrue( "File should have cmd extension",
cmd.getArguments()[1].endsWith( "mycmd.cmd" ) );

f.delete();
fCmd.delete();
assertFalse( "file deleted...", f.exists() );
assertFalse( "file deleted...", fCmd.exists() );

}

public void testRunFailure()
{
Expand Down

0 comments on commit 9765f3a

Please sign in to comment.