From 43d55803a9c14ebb0fe3e3f88ed050993c1585fc Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sat, 29 Apr 2017 17:11:06 -0700 Subject: [PATCH] Changed Os.WINDOWS to no longer include Cygwin, MinGW or MSYS. --- README.md | 7 +++- example/kobalt/src/Build.kt | 6 +-- .../erik/kobalt/plugin/exec/ExecPlugin.kt | 38 +++++++++++++++---- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 3fbfd9a..ac86546 100644 --- a/README.md +++ b/README.md @@ -84,9 +84,11 @@ Name | Operating System `Os.OS400` | OS/400 `Os.SOLARIS` | Solaris / SunOS `Os.TANDEM` | Tandem's Non-Stop -`Os.WINDOWS` | Microsoft Windows +`Os.WINDOWS` | Microsoft Windows* `Os.ZOS` | z/OS / OS/390 +* Not including Cygwin, MinGW or MSYS. + ```kotlin exec { commandLine("cmd", "/c", "stop.cmd", os = setOf(Os.WINDOWS)) @@ -135,7 +137,7 @@ exec { } ``` -```shell +```sh ./kobaltw start ./kobaltw stop ``` @@ -155,6 +157,7 @@ exec { ## Logging / Debugging To view the output of the `exec` task, use: + ```sh ./kobaltw exec --log 2 ``` diff --git a/example/kobalt/src/Build.kt b/example/kobalt/src/Build.kt index 2858ecf..a9dfbb1 100644 --- a/example/kobalt/src/Build.kt +++ b/example/kobalt/src/Build.kt @@ -30,8 +30,6 @@ val example = project { } exec { - commandLine("echo", "Test Example 1", os = setOf(Os.LINUX, Os.MINGW, Os.CYGWIN)) - commandLine("cmd", "/c", "echo", "Test", "Example", "1", os = setOf(Os.WINDOWS)) commandLine("ls", "-l", dir = "../kobalt/wrapper", os = setOf(Os.LINUX, Os.MINGW, Os.CYGWIN)) commandLine("cmd", "/c", "dir /Q", dir = "../kobalt/wrapper", os = setOf(Os.WINDOWS)) } @@ -40,7 +38,7 @@ val example = project { taskName = "echo" dependsOn = listOf("exec", "run") - val echo = arrayOf("echo", "Test", "Example", "2") + val echo = arrayOf("echo", "Test", "Example") commandLine("cmd", "/c", *echo, os = setOf(Os.WINDOWS)) commandLine(*echo, os = setOf(Os.LINUX, Os.MINGW, Os.CYGWIN)) } @@ -49,6 +47,6 @@ val example = project { taskName = "ps" dependsOn = listOf() // no dependencies commandLine("cmd", "/c", "tasklist | find \"cmd.exe\"", os = setOf(Os.WINDOWS), fail = setOf(Fail.NONE)) - commandLine("/bin/sh", "-c", "ps aux | grep bash", os = setOf(Os.LINUX)) + commandLine("sh", "-c", "ps aux | grep bash", os = setOf(Os.LINUX, Os.MINGW, Os.CYGWIN)) } } \ No newline at end of file diff --git a/src/main/kotlin/net/thauvin/erik/kobalt/plugin/exec/ExecPlugin.kt b/src/main/kotlin/net/thauvin/erik/kobalt/plugin/exec/ExecPlugin.kt index ac5f138..d21bb39 100644 --- a/src/main/kotlin/net/thauvin/erik/kobalt/plugin/exec/ExecPlugin.kt +++ b/src/main/kotlin/net/thauvin/erik/kobalt/plugin/exec/ExecPlugin.kt @@ -76,7 +76,11 @@ class ExecPlugin @Inject constructor(val taskContributor: TaskContributor, val c val curOs: String = System.getProperty("os.name").toLowerCase(Locale.US) when (os) { Os.WINDOWS -> { - return curOs.contains("windows") + if (!isMinGW(any = true) && !isCygwin()) { + return curOs.contains("windows") + } else { + return false + } } Os.MAC -> { return (curOs.contains("mac") || curOs.contains("darwin") || curOs.contains("osx")) @@ -103,20 +107,38 @@ class ExecPlugin @Inject constructor(val taskContributor: TaskContributor, val c return curOs.contains("os/400") } Os.CYGWIN -> { - val cygwin: String? = System.getenv("ORIGINAL_PATH") - return cygwin?.contains("/cygdrive/") ?: false + return isCygwin() } Os.MINGW -> { - val mingw: String? = System.getenv("MSYSTEM") - return mingw?.startsWith("MINGW") ?: false + return isMinGW() } Os.MSYS -> { - val msys: String? = System.getenv("MSYSTEM") - return msys?.startsWith("MSYS") ?: false + return isMinGW(Os.MSYS) } } } + private fun isCygwin() : Boolean { + val path: String? = System.getenv("ORIGINAL_PATH") + return path?.contains("/cygdrive/") ?: false + } + + private fun isMinGW(os: Os = Os.MINGW, any: Boolean = false) : Boolean { + val msys: String? = System.getenv("MSYSTEM") + + if (!msys.isNullOrBlank()) { + if (any) { + return true + } else if (os.equals(Os.MSYS)) { + return msys!!.startsWith("MSYS") + } else if (os.equals(Os.MINGW)) { + return msys!!.startsWith("MINGW") + } + } + + return false + } + private fun executeCommands(project: Project, config: ExecConfig): TaskResult { var success = true val errorMessage = StringBuilder() @@ -132,7 +154,7 @@ class ExecPlugin @Inject constructor(val taskContributor: TaskContributor, val c } } if (execute) { - log(2, "> " + args.joinToString(" ")) + log(2, (if (!wrkDir.name.equals(".")) wrkDir.name else "") + "> " + args.joinToString(" ")) val pb = ProcessBuilder().command(args.toList()) pb.directory(wrkDir) val proc = pb.start()