diff --git a/.idea/kobalt.xml b/.idea/kobalt.xml
index c1b8abc..48b08b1 100644
--- a/.idea/kobalt.xml
+++ b/.idea/kobalt.xml
@@ -16,7 +16,7 @@
-
+
diff --git a/example/kobalt/src/Build.kt b/example/kobalt/src/Build.kt
index c0fe72f..20bbbf4 100644
--- a/example/kobalt/src/Build.kt
+++ b/example/kobalt/src/Build.kt
@@ -37,7 +37,7 @@ val p = project {
}
exec {
- commandLine(args = arrayOf("ls", "-- a"), dir = "../libs", fail = arrayOf(Fail.EXIT))
- commandLine(arrayOf("cmd", "/c", "echo", "Test"), os = arrayOf("Win"), fail = arrayOf(Fail.STDERR))
+ commandLine(args = listOf("ls", "-- a"), dir = "../libs", fail = setOf(Fail.STDERR, Fail.EXIT))
+ commandLine(listOf("cmd", "/c", "echo", "Test"), os = listOf("Win"), fail = setOf(Fail.STDERR, Fail.EXIT))
}
}
\ No newline at end of file
diff --git a/kobalt-exec.iml b/kobalt-exec.iml
index 3773968..4b91eb9 100644
--- a/kobalt-exec.iml
+++ b/kobalt-exec.iml
@@ -25,9 +25,9 @@
-
+
-
+
@@ -43,9 +43,9 @@
-
+
-
+
diff --git a/kobalt/wrapper/kobalt-wrapper.properties b/kobalt/wrapper/kobalt-wrapper.properties
index 0d4030d..0630fba 100644
--- a/kobalt/wrapper/kobalt-wrapper.properties
+++ b/kobalt/wrapper/kobalt-wrapper.properties
@@ -1 +1 @@
-kobalt.version=0.845
\ No newline at end of file
+kobalt.version=0.846
\ 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 78e9829..d1e81f2 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
@@ -83,21 +83,23 @@ class ExecPlugin : BasePlugin(), ITaskContributor {
pb.directory(loc)
val proc = pb.start()
val err = proc.waitFor(30, TimeUnit.SECONDS)
- val stdin = if (proc.inputStream.available() > 0) fromStream(proc.inputStream) else listOf()
- val stderr = if (proc.errorStream.available() > 0) fromStream(proc.errorStream) else listOf()
+ val stdout = if (proc.inputStream.available() > 0) fromStream(proc.inputStream) else emptyList()
+ val stderr = if (proc.errorStream.available() > 0) fromStream(proc.errorStream) else emptyList()
+
+ val errMsg = "Program \"" + it.args.joinToString(" ") + "\" (in directory \"$dir\"): "
if (err == false) {
- error("Cannot run program \"" + it.args.joinToString(" ")
- + "\" (in directory \"$dir\"): TIMEOUT")
- } else if (it.fail.contains(Fail.EXIT) && proc.exitValue() > 0) {
- error("Program \"" + it.args.joinToString(" ")
- + "\" (in directory \"$dir\"): EXIT ${proc.exitValue()}")
- } else if (it.fail.contains(Fail.STDERR) && stderr.isNotEmpty()) {
- error("Program \"" + it.args.joinToString(" ") + "\" (in directory \"$dir\"): STDERR, "
- + stderr[0] + "...")
- } else if (it.fail.contains(Fail.STDIN) && stdin.isNotEmpty()) {
- error("Program \"" + it.args.joinToString(" ") + "\" (in directory \"$dir\"): STDIN, "
- + stdin[0] + "...")
+ error(errMsg + "TIMEOUT")
+ } else if (it.fail.isNotEmpty()) {
+ val all = it.fail.contains(Fail.ALL)
+ val output = it.fail.contains(Fail.OUTPUT)
+ if ((all || it.fail.contains(Fail.EXIT)) && proc.exitValue() > 0) {
+ error(errMsg + "EXIT ${proc.exitValue()}")
+ } else if ((all || output || it.fail.contains(Fail.STDERR)) && stderr.isNotEmpty()) {
+ error(errMsg + "STDERR, " + stderr[0])
+ } else if ((all || output || it.fail.contains(Fail.STDOUT)) && stdout.isNotEmpty()) {
+ error(errMsg + "STDOUT, " + stdout[0])
+ }
}
success = true
@@ -133,18 +135,18 @@ class ExecPlugin : BasePlugin(), ITaskContributor {
}
enum class Fail() {
- STDERR, STDIN, EXIT
+ ALL, STDERR, STDOUT, OUTPUT, EXIT
}
-data class CommandLine(var args: Array = emptyArray(), var dir: String = "",
- var os: Array = emptyArray(), var fail: Array = emptyArray())
+data class CommandLine(var args: List = emptyList(), var dir: String = "",
+ var os: List = emptyList(), var fail: Set = emptySet())
data class ExecConfig(val project: Project) {
val commandLines = arrayListOf()
@Directive
- public fun commandLine(args: Array = emptyArray(), dir: String = "", os: Array = emptyArray(),
- fail: Array = emptyArray()) {
+ public fun commandLine(args: List = emptyList(), dir: String = "", os: List = emptyList(),
+ fail: Set = emptySet()) {
if (args.size > 0) commandLines.add(CommandLine(args, dir, os, fail))
}
}
@@ -156,4 +158,4 @@ fun Project.exec(init: ExecConfig.() -> Unit): ExecConfig {
(Kobalt.findPlugin(ExecPlugin.NAME) as ExecPlugin).addExecConfig(name, this)
return this
}
-}
+}
\ No newline at end of file