diff options
author | Kamil Doległo <kamilok1965@interia.pl> | 2020-01-31 14:04:42 +0100 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-01-31 15:27:26 +0100 |
commit | 79ec42607f3bc090ef40547a01aabcd1cd55886e (patch) | |
tree | 63f01b2ed1d92e3a3040bd95c27a10d3b53a5f06 /buildSrc/src/main/groovy/org | |
parent | d6fab477e89b781c85cf123fa58078deaa15d480 (diff) | |
download | dokka-79ec42607f3bc090ef40547a01aabcd1cd55886e.tar.gz dokka-79ec42607f3bc090ef40547a01aabcd1cd55886e.tar.bz2 dokka-79ec42607f3bc090ef40547a01aabcd1cd55886e.zip |
Minor fixes, rewritten CrossPlatformExec.kt
Diffstat (limited to 'buildSrc/src/main/groovy/org')
-rw-r--r-- | buildSrc/src/main/groovy/org/jetbrains/CrossPlatformExec.groovy | 84 |
1 files changed, 0 insertions, 84 deletions
diff --git a/buildSrc/src/main/groovy/org/jetbrains/CrossPlatformExec.groovy b/buildSrc/src/main/groovy/org/jetbrains/CrossPlatformExec.groovy deleted file mode 100644 index d3973a8a..00000000 --- a/buildSrc/src/main/groovy/org/jetbrains/CrossPlatformExec.groovy +++ /dev/null @@ -1,84 +0,0 @@ -package org.jetbrains - -import org.gradle.api.tasks.AbstractExecTask -import org.gradle.api.tasks.TaskAction -import org.gradle.internal.os.OperatingSystem - -import java.nio.file.Files -import java.nio.file.Path -import java.nio.file.Paths - -class CrossPlatformExec extends AbstractExecTask { - private static final def windowsExtensions = ['bat', 'cmd', 'exe']; - private static final def unixExtensions = [null, 'sh']; - - private boolean windows; - - public CrossPlatformExec() { - super(CrossPlatformExec.class); - windows = OperatingSystem.current().windows; - } - - @Override - @TaskAction - protected void exec() { - List<String> commandLine = this.getCommandLine(); - - if (!commandLine.isEmpty()) { - commandLine[0] = findCommand(commandLine[0], windows); - } - - if (windows) { - if (!commandLine.isEmpty() && commandLine[0]) { - commandLine - } - commandLine.add(0, '/c'); - commandLine.add(0, 'cmd'); - } - - this.setCommandLine(commandLine); - - super.exec(); - } - - private static String findCommand(String command, boolean windows) { - command = normalizeCommandPaths(command); - def extensions = windows ? windowsExtensions : unixExtensions; - - return extensions.findResult(command) { extension -> - Path commandFile - if (extension) { - commandFile = Paths.get(command + '.' + extension); - } else { - commandFile = Paths.get(command); - } - - return resolveCommandFromFile(commandFile, windows); - }; - } - - private static String resolveCommandFromFile(Path commandFile, boolean windows) { - if (!Files.isExecutable(commandFile)) { - return null; - } - - return commandFile.toAbsolutePath().normalize(); - } - - private static String normalizeCommandPaths(String command) { - // need to escape backslash so it works with regex - String backslashSeparator = '\\\\'; - - String forwardSlashSeparator = '/'; - - // escape separator if it's a backslash - char backslash = '\\'; - String separator = File.separatorChar == backslash ? backslashSeparator : File.separator - - return command - // first replace all of the backslashes with forward slashes - .replaceAll(backslashSeparator, forwardSlashSeparator) - // then replace all forward slashes with whatever the separator actually is - .replaceAll(forwardSlashSeparator, separator); - } -}
\ No newline at end of file |