diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7..d175698 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,5 +2,7 @@ + + \ No newline at end of file diff --git a/README.md b/README.md index c495118..4cd7712 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,13 @@ [![License (3-Clause BSD)](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg?style=flat-square)](http://opensource.org/licenses/BSD-3-Clause) [![Build Status](https://travis-ci.org/ethauvin/kobalt-exec.svg?branch=master)](https://travis-ci.org/ethauvin/kobalt-exec) +The plug-in allows for the execution of system commands, similarly to the [Gradle Exec](https://docs.gradle.org/current/dsl/org.gradle.api.tasks.Exec.html) or [Ant Exec](https://ant.apache.org/manual/Tasks/exec.html) tasks. + To use the plug-in included the following in your `Build.kt` file: ```kotlin +import net.thauvin.erik.kobalt.plugin.exec.* + var pl = plugins("net.thauvin.erik:kobalt-exc:") var p = project { @@ -15,6 +19,8 @@ var p = project { } } ``` +[Examples](https://github.com/ethauvin/kobalt-exec/blob/master/example/kobalt/src/Build.kt) + To invoke the `exec` task: ```sh @@ -42,7 +48,7 @@ The full command line including the executable and all parameters. ```kotlin exec { commandLine(listOf("ls", "-l")) - comamndLine(args = listOf("touch", "README.md")) + commandLine(args = listOf("cmd", "/c", "dir /Q")) } ``` @@ -53,6 +59,7 @@ The working directory in which the command should be executed. Defaults to the p ```kotlin exec { commandLine(listOf("cmd", "/c", "stop.bat"), dir = "../tomcat/bin") + commandLine("./stop.sh", dir = "../tomcat/bin") } ``` @@ -95,6 +102,7 @@ Name | Failure When `Fail.STDERR` | Any data to stderr. `Fail.STDOUT` | Any data to stdout. `Fail.ALL` | Any of the conditions above. +`Fail.NONE` | Never fails. `Fail.NORMAL` is the default value. @@ -107,10 +115,18 @@ exec { ## Logging / Debugging +To view the output of the `exec` task, use: ```sh ./kobaltw exec --log 2 ``` +You could also redirect the error stream to a file: + +```kotlin +exec { + commandLine(listOf("/bin/sh", "-c", "./stop.sh 2> error.txt"), os = setOf(Os.LINUX)) + commandLine(listOf("cmd", "/c", "stop.bat 2> error.txt"), os = setOf(Os.WINDOWS)) +} +``` - diff --git a/example/kobalt/src/Build.kt b/example/kobalt/src/Build.kt index c4576d5..00056c5 100644 --- a/example/kobalt/src/Build.kt +++ b/example/kobalt/src/Build.kt @@ -6,8 +6,8 @@ import net.thauvin.erik.kobalt.plugin.exec.* val repos = repos("https://dl.bintray.com/ethauvin/maven/") -val pl = plugins(file("../kobaltBuild/libs/kobalt-exec-0.5.1-beta.jar")) -//val pl = plugins("net.thauvin.erik:kobalt-exec:0.5.1-beta") +//val pl = plugins(file("../kobaltBuild/libs/kobalt-exec-0.6.0-beta.jar")) +val pl = plugins("net.thauvin.erik:kobalt-exec:0.6.0-beta") val example = project { @@ -40,8 +40,10 @@ val example = project { } exec { + commandLine(listOf( "echo", "Test Example 1"), os = setOf(Os.LINUX)) commandLine(listOf("cmd", "/c", "echo", "Test Example 1"), os = setOf(Os.WINDOWS)) - commandLine(args = listOf("ls", "-l"), dir = "../libs", os = setOf(Os.LINUX, Os.WINDOWS)) + commandLine(args = listOf("ls", "-l"), dir = "../libs", os = setOf(Os.LINUX)) + commandLine(args = listOf("cmd", "/c", "dir /Q"), dir = "../libs", os = setOf(Os.WINDOWS)) } } @@ -50,7 +52,8 @@ val example2 = project { exec { commandLine(listOf("cmd", "/c", "echo", "Test Example 2"), os = setOf(Os.WINDOWS)) - commandLine(listOf("echo", "Hello, World!")) - commandLine(listOf("sh", "-c", "ps aux | grep bash"), fail = setOf(Fail.EXIT)) + commandLine(listOf("echo", "Test example 2"), os = setOf(Os.LINUX)) + commandLine(listOf("cmd", "/c", "tasklist | find \"cmd.exe\""), os = setOf(Os.WINDOWS), fail = setOf(Fail.NONE)) + commandLine(listOf("/bin/sh", "-c", "ps aux | grep bash"), os = setOf(Os.LINUX)) } } \ No newline at end of file diff --git a/example/kobalt/wrapper/kobalt-wrapper.properties b/example/kobalt/wrapper/kobalt-wrapper.properties index 183e047..c69467d 100644 --- a/example/kobalt/wrapper/kobalt-wrapper.properties +++ b/example/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=0.851 \ No newline at end of file +kobalt.version=0.852 \ No newline at end of file diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt index ced64ec..beb61f3 100644 --- a/kobalt/src/Build.kt +++ b/kobalt/src/Build.kt @@ -17,7 +17,7 @@ val p = project { name = "kobalt-exec" group = "net.thauvin.erik" artifactId = name - version = "0.5.1-beta" + version = "0.6.0-beta" pom = Model().apply { description = "Command Line Execution plug-in for the Kobalt build system." 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 3eb7542..fb99d3a 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 @@ -75,35 +75,27 @@ class ExecPlugin @Inject constructor(val configActor: ConfigActor) : Os.WINDOWS -> { return curOs.contains("windows") } - Os.MAC -> { return (curOs.contains("mac") || curOs.contains("darwin") || curOs.contains("osx")) } - - Os.SOLARIS -> { - return (curOs.contains("sunos") || curOs.contains("solaris")) - } - Os.LINUX -> { return curOs.contains("linux") } - Os.FREEBSD -> { return curOs.contains("freebsd") } - - Os.ZOS -> { - return (curOs.contains("z/os") || curOs.contains("os/390")) + Os.SOLARIS -> { + return (curOs.contains("sunos") || curOs.contains("solaris")) } - Os.OPENVMS -> { return curOs.contains("openvms") } - + Os.ZOS -> { + return (curOs.contains("z/os") || curOs.contains("os/390")) + } Os.TANDEM -> { return curOs.contains("nonstop_kernel") } - Os.OS400 -> { return curOs.contains("os/400") } @@ -137,7 +129,7 @@ class ExecPlugin @Inject constructor(val configActor: ConfigActor) : if (err == false) { errorMessage.append(cmdInfo).append("TIMEOUT") success = false - } else if (fail.isNotEmpty()) { + } else if (!fail.contains(Fail.NONE)) { val all = fail.contains(Fail.ALL) val output = fail.contains(Fail.OUTPUT) if ((all || fail.contains(Fail.EXIT) || fail.contains(Fail.NORMAL)) && proc.exitValue() > 0) { @@ -185,11 +177,11 @@ class ExecPlugin @Inject constructor(val configActor: ConfigActor) : } enum class Fail() { - ALL, NORMAL, STDERR, STDOUT, OUTPUT, EXIT + ALL, EXIT, NONE, NORMAL, OUTPUT, STDERR, STDOUT } enum class Os() { - WINDOWS, MAC, SOLARIS, LINUX, FREEBSD, ZOS, OPENVMS, TANDEM, OS400 + FREEBSD, LINUX, MAC, OPENVMS, OS400, SOLARIS, TANDEM, WINDOWS, ZOS } data class CommandLine(var args: List = emptyList(), var dir: String = "", var os: Set = emptySet(),