diff --git a/build.gradle b/build.gradle index 624f813..93d0561 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { apply plugin: "groovy" group = 'com.github.jlouns' -version = '0.3.0' +version = '0.4.0' repositories { jcenter() @@ -32,5 +32,5 @@ pluginBundle { } task wrapper(type: Wrapper) { - gradleVersion = '2.4' + gradleVersion = '2.8' } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 2322723..05ef575 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 76485a7..f5ad1f4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Jun 18 23:29:45 EDT 2015 +#Wed Nov 04 00:09:34 EST 2015 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-bin.zip diff --git a/gradlew b/gradlew index 91a7e26..9d82f78 100755 --- a/gradlew +++ b/gradlew @@ -42,11 +42,6 @@ case "`uname`" in ;; esac -# For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` -fi - # Attempt to set APP_HOME # Resolve links: $0 may be a link PRG="$0" @@ -61,9 +56,9 @@ while [ -h "$PRG" ] ; do fi done SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >&- +cd "`dirname \"$PRG\"`/" >/dev/null APP_HOME="`pwd -P`" -cd "$SAVED" >&- +cd "$SAVED" >/dev/null CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -114,6 +109,7 @@ fi if $cygwin ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` diff --git a/src/main/groovy/com/github/jlouns/gradle/cpe/tasks/CrossPlatformExec.groovy b/src/main/groovy/com/github/jlouns/gradle/cpe/tasks/CrossPlatformExec.groovy index 43689ae..7c4b8e2 100644 --- a/src/main/groovy/com/github/jlouns/gradle/cpe/tasks/CrossPlatformExec.groovy +++ b/src/main/groovy/com/github/jlouns/gradle/cpe/tasks/CrossPlatformExec.groovy @@ -39,15 +39,12 @@ class CrossPlatformExec extends AbstractExecTask { } private String findCommand(String command) { + command = normalizeCommandPaths(command); if (windows) { return windowsExtensions.findResult(command) { extension -> - String commandFile = command + '.' + extension; + Path commandFile = Paths.get(command + '.' + extension); - if (Files.isExecutable(Paths.get(commandFile))) { - return commandFile; - } - - return null; + return CrossPlatformExec.resolveCommandFromFile(commandFile); }; } else { return unixExtensions.findResult(command) { extension -> @@ -58,20 +55,28 @@ class CrossPlatformExec extends AbstractExecTask { commandFile = Paths.get(command); } - if (Files.isExecutable(commandFile)) { - Path cwd = Paths.get('.').toAbsolutePath().normalize(); - String resolvedCommand = cwd.relativize(commandFile.toAbsolutePath().normalize()); + return CrossPlatformExec.resolveCommandFromFile(commandFile); + }; + } + } - if (!resolvedCommand.startsWith('.')) { - resolvedCommand = './' + resolvedCommand; - } + private static String resolveCommandFromFile(Path commandFile) { + if (!Files.isExecutable(commandFile)) { + return null; + } - return resolvedCommand; - } + Path cwd = Paths.get('.').toAbsolutePath().normalize(); - return null; - }; + String resolvedCommand = cwd.relativize(commandFile.toAbsolutePath().normalize()); + + if (!resolvedCommand.startsWith('.')) { + resolvedCommand = '.' + File.separator + resolvedCommand; } + + return resolvedCommand; } + private static String normalizeCommandPaths(String command) { + return command.replaceAll('\\\\', '/').replaceAll('/', File.separator); + } } diff --git a/src/test/groovy/com/github/jlouns/gradle/cpe/tasks/CrossPlatformExecTest.groovy b/src/test/groovy/com/github/jlouns/gradle/cpe/tasks/CrossPlatformExecTest.groovy index 701c96f..c54efa5 100644 --- a/src/test/groovy/com/github/jlouns/gradle/cpe/tasks/CrossPlatformExecTest.groovy +++ b/src/test/groovy/com/github/jlouns/gradle/cpe/tasks/CrossPlatformExecTest.groovy @@ -11,29 +11,38 @@ import java.nio.file.attribute.PosixFilePermission class CrossPlatformExecTest extends GroovyTestCase { + private static String separator = File.separator; + private Project project; + private Path testDir; private Path[] commandFiles; @Override void setUp() { project = ProjectBuilder.builder().build() - project.apply plugin: 'com.github.jlouns.cpe' + project.apply plugin: "com.github.jlouns.cpe" + + testDir = Paths.get("testdir"); commandFiles = [ - Paths.get('one'), - Paths.get('one.cmd'), - Paths.get('two.bat'), - Paths.get('two.sh'), - Paths.get('three'), - Paths.get('three.exe') + Paths.get("one"), + Paths.get("one.cmd"), + Paths.get("two.bat"), + Paths.get("two.sh"), + Paths.get("three"), + Paths.get("three.exe"), + testDir.resolve("four.sh"), + testDir.resolve("four.exe") ]; + Files.createDirectory(testDir); + commandFiles.each { Files.createFile(it) try { - Files.setPosixFilePermissions(it, EnumSet.allOf(PosixFilePermission)); - } catch (Exception ex) { + Files.setPosixFilePermissions(it, EnumSet.allOf(PosixFilePermission)) + } catch (Exception ignore) { // Ignore it, probably on windows } } @@ -44,81 +53,98 @@ class CrossPlatformExecTest extends GroovyTestCase { commandFiles.each { Files.delete(it) } + Files.delete(testDir); } Task createTask(String executable) { - Task task = project.task([ 'type': CrossPlatformExec ], 'testCpe') { - commandLine executable, 'foo' + Task task = project.task([ "type": CrossPlatformExec ], "testCpe") { + commandLine executable, "foo" } try { task.exec() - } catch (Exception ex) { - println(ex.stackTrace) - // Ignore it + } catch (Exception ignore) { + ignore.printStackTrace() } task } static void asOs(String os) { - System.setProperty('os.name', os) + System.setProperty("os.name", os) } void testFormsLinuxExecCallForCommand() { - asOs('linux') + asOs("linux") - Task task = createTask('echo') + Task task = createTask("echo") - assertArrayEquals(['echo', 'foo'].toArray(), task.commandLine.toArray()); + assertArrayEquals(["echo", "foo"].toArray(), task.commandLine.toArray()); } void testFormsLinuxExecCallForFile() { - asOs('linux') + asOs("linux") - Task task = createTask('one') + Task task = createTask("one") - assertArrayEquals(['./one', 'foo'].toArray(), task.commandLine.toArray()); + assertArrayEquals([".${separator}one", "foo"].toArray(), task.commandLine.toArray()); } void testFormsLinuxExecCallForShFile() { - asOs('linux') + asOs("linux") - Task task = createTask('two') + Task task = createTask("two") - assertArrayEquals(['./two.sh', 'foo'].toArray(), task.commandLine.toArray()); + assertArrayEquals([".${separator}two.sh", "foo"].toArray(), task.commandLine.toArray()); } void testFormsWindowsExecCallForCommand() { - asOs('windows') + asOs("windows") - Task task = createTask('echo') + Task task = createTask("echo") - assertArrayEquals(['cmd', '/c', 'echo', 'foo'].toArray(), task.commandLine.toArray()); + assertArrayEquals(["cmd", "/c", "echo", "foo"].toArray(), task.commandLine.toArray()); } void testFormsWindowsExecCallForCmdFile() { - asOs('windows') + asOs("windows") - Task task = createTask('one') + Task task = createTask("one") - assertArrayEquals(['cmd', '/c', 'one.cmd', 'foo'].toArray(), task.commandLine.toArray()); + assertArrayEquals(["cmd", "/c", ".${separator}one.cmd", "foo"].toArray(), task.commandLine.toArray()); } void testFormsWindowsExecCallForBatFile() { - asOs('windows') + asOs("windows") - Task task = createTask('two') + Task task = createTask("two") - assertArrayEquals(['cmd', '/c', 'two.bat', 'foo'].toArray(), task.commandLine.toArray()); + assertArrayEquals(["cmd", "/c", ".${separator}two.bat", "foo"].toArray(), task.commandLine.toArray()); } void testFormsWindowsExecCallForExeFile() { - asOs('windows') + asOs("windows") + + Task task = createTask("three") + + assertArrayEquals(["cmd", "/c", ".${separator}three.exe", "foo"].toArray(), task.commandLine.toArray()); + } + + void testFixesPathSeparatorsOnLinux() { + asOs("linux") + + Task task = createTask(".\\testdir\\four") + + assertArrayEquals([".${separator}testdir${separator}four.sh", "foo"].toArray(), task.commandLine.toArray()); + } + + void testFixesPathSeparatorsOnWindows() { + asOs("windows") - Task task = createTask('three') + Task task = createTask("./testdir/four") - assertArrayEquals(['cmd', '/c', 'three.exe', 'foo'].toArray(), task.commandLine.toArray()); + assertArrayEquals(["cmd", "/c", ".${separator}testdir${separator}four.exe", "foo"].toArray(), + task.commandLine.toArray()); } }