Changed Os.WINDOWS to no longer include Cygwin, MinGW or MSYS.

This commit is contained in:
Erik C. Thauvin 2017-04-29 17:11:06 -07:00
parent 6530e8f7be
commit 43d55803a9
3 changed files with 37 additions and 14 deletions

View file

@ -84,9 +84,11 @@ Name | Operating System
`Os.OS400` | OS/400 `Os.OS400` | OS/400
`Os.SOLARIS` | Solaris / SunOS `Os.SOLARIS` | Solaris / SunOS
`Os.TANDEM` | Tandem's Non-Stop `Os.TANDEM` | Tandem's Non-Stop
`Os.WINDOWS` | Microsoft Windows `Os.WINDOWS` | Microsoft Windows*
`Os.ZOS` | z/OS / OS/390 `Os.ZOS` | z/OS / OS/390
<sub>* Not including Cygwin, MinGW or MSYS.</sub>
```kotlin ```kotlin
exec { exec {
commandLine("cmd", "/c", "stop.cmd", os = setOf(Os.WINDOWS)) commandLine("cmd", "/c", "stop.cmd", os = setOf(Os.WINDOWS))
@ -135,7 +137,7 @@ exec {
} }
``` ```
```shell ```sh
./kobaltw start ./kobaltw start
./kobaltw stop ./kobaltw stop
``` ```
@ -155,6 +157,7 @@ exec {
## Logging / Debugging ## Logging / Debugging
To view the output of the `exec` task, use: To view the output of the `exec` task, use:
```sh ```sh
./kobaltw exec --log 2 ./kobaltw exec --log 2
``` ```

View file

@ -30,8 +30,6 @@ val example = project {
} }
exec { 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("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)) commandLine("cmd", "/c", "dir /Q", dir = "../kobalt/wrapper", os = setOf(Os.WINDOWS))
} }
@ -40,7 +38,7 @@ val example = project {
taskName = "echo" taskName = "echo"
dependsOn = listOf("exec", "run") 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("cmd", "/c", *echo, os = setOf(Os.WINDOWS))
commandLine(*echo, os = setOf(Os.LINUX, Os.MINGW, Os.CYGWIN)) commandLine(*echo, os = setOf(Os.LINUX, Os.MINGW, Os.CYGWIN))
} }
@ -49,6 +47,6 @@ val example = project {
taskName = "ps" taskName = "ps"
dependsOn = listOf() // no dependencies dependsOn = listOf() // no dependencies
commandLine("cmd", "/c", "tasklist | find \"cmd.exe\"", os = setOf(Os.WINDOWS), fail = setOf(Fail.NONE)) 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))
} }
} }

View file

@ -76,7 +76,11 @@ class ExecPlugin @Inject constructor(val taskContributor: TaskContributor, val c
val curOs: String = System.getProperty("os.name").toLowerCase(Locale.US) val curOs: String = System.getProperty("os.name").toLowerCase(Locale.US)
when (os) { when (os) {
Os.WINDOWS -> { Os.WINDOWS -> {
return curOs.contains("windows") if (!isMinGW(any = true) && !isCygwin()) {
return curOs.contains("windows")
} else {
return false
}
} }
Os.MAC -> { Os.MAC -> {
return (curOs.contains("mac") || curOs.contains("darwin") || curOs.contains("osx")) 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") return curOs.contains("os/400")
} }
Os.CYGWIN -> { Os.CYGWIN -> {
val cygwin: String? = System.getenv("ORIGINAL_PATH") return isCygwin()
return cygwin?.contains("/cygdrive/") ?: false
} }
Os.MINGW -> { Os.MINGW -> {
val mingw: String? = System.getenv("MSYSTEM") return isMinGW()
return mingw?.startsWith("MINGW") ?: false
} }
Os.MSYS -> { Os.MSYS -> {
val msys: String? = System.getenv("MSYSTEM") return isMinGW(Os.MSYS)
return msys?.startsWith("MSYS") ?: false
} }
} }
} }
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 { private fun executeCommands(project: Project, config: ExecConfig): TaskResult {
var success = true var success = true
val errorMessage = StringBuilder() val errorMessage = StringBuilder()
@ -132,7 +154,7 @@ class ExecPlugin @Inject constructor(val taskContributor: TaskContributor, val c
} }
} }
if (execute) { if (execute) {
log(2, "> " + args.joinToString(" ")) log(2, (if (!wrkDir.name.equals(".")) wrkDir.name else "") + "> " + args.joinToString(" "))
val pb = ProcessBuilder().command(args.toList()) val pb = ProcessBuilder().command(args.toList())
pb.directory(wrkDir) pb.directory(wrkDir)
val proc = pb.start() val proc = pb.start()