Added Fail.NONE

More documentation.
This commit is contained in:
Erik C. Thauvin 2016-07-13 10:50:00 -07:00
parent adbfa2b2dd
commit 51110488b5
6 changed files with 38 additions and 25 deletions

2
.idea/vcs.xml generated
View file

@ -2,5 +2,7 @@
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" /> <mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component> </component>
</project> </project>

View file

@ -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) [![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: To use the plug-in included the following in your `Build.kt` file:
```kotlin ```kotlin
import net.thauvin.erik.kobalt.plugin.exec.*
var pl = plugins("net.thauvin.erik:kobalt-exc:") var pl = plugins("net.thauvin.erik:kobalt-exc:")
var p = project { 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: To invoke the `exec` task:
```sh ```sh
@ -42,7 +48,7 @@ The full command line including the executable and all parameters.
```kotlin ```kotlin
exec { exec {
commandLine(listOf("ls", "-l")) 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 ```kotlin
exec { exec {
commandLine(listOf("cmd", "/c", "stop.bat"), dir = "../tomcat/bin") 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.STDERR` | Any data to stderr.
`Fail.STDOUT` | Any data to stdout. `Fail.STDOUT` | Any data to stdout.
`Fail.ALL` | Any of the conditions above. `Fail.ALL` | Any of the conditions above.
`Fail.NONE` | Never fails.
`Fail.NORMAL` is the default value. `Fail.NORMAL` is the default value.
@ -107,10 +115,18 @@ exec {
## Logging / Debugging ## Logging / Debugging
To view the output of the `exec` task, use:
```sh ```sh
./kobaltw exec --log 2 ./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))
}
```

View file

@ -6,8 +6,8 @@ import net.thauvin.erik.kobalt.plugin.exec.*
val repos = repos("https://dl.bintray.com/ethauvin/maven/") 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(file("../kobaltBuild/libs/kobalt-exec-0.6.0-beta.jar"))
//val pl = plugins("net.thauvin.erik:kobalt-exec:0.5.1-beta") val pl = plugins("net.thauvin.erik:kobalt-exec:0.6.0-beta")
val example = project { val example = project {
@ -40,8 +40,10 @@ val example = project {
} }
exec { exec {
commandLine(listOf( "echo", "Test Example 1"), os = setOf(Os.LINUX))
commandLine(listOf("cmd", "/c", "echo", "Test Example 1"), os = setOf(Os.WINDOWS)) 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 { exec {
commandLine(listOf("cmd", "/c", "echo", "Test Example 2"), os = setOf(Os.WINDOWS)) commandLine(listOf("cmd", "/c", "echo", "Test Example 2"), os = setOf(Os.WINDOWS))
commandLine(listOf("echo", "Hello, World!")) commandLine(listOf("echo", "Test example 2"), os = setOf(Os.LINUX))
commandLine(listOf("sh", "-c", "ps aux | grep bash"), fail = setOf(Fail.EXIT)) 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))
} }
} }

View file

@ -1 +1 @@
kobalt.version=0.851 kobalt.version=0.852

View file

@ -17,7 +17,7 @@ val p = project {
name = "kobalt-exec" name = "kobalt-exec"
group = "net.thauvin.erik" group = "net.thauvin.erik"
artifactId = name artifactId = name
version = "0.5.1-beta" version = "0.6.0-beta"
pom = Model().apply { pom = Model().apply {
description = "Command Line Execution plug-in for the Kobalt build system." description = "Command Line Execution plug-in for the Kobalt build system."

View file

@ -75,35 +75,27 @@ class ExecPlugin @Inject constructor(val configActor: ConfigActor<ExecConfig>) :
Os.WINDOWS -> { Os.WINDOWS -> {
return curOs.contains("windows") return curOs.contains("windows")
} }
Os.MAC -> { Os.MAC -> {
return (curOs.contains("mac") || curOs.contains("darwin") || curOs.contains("osx")) return (curOs.contains("mac") || curOs.contains("darwin") || curOs.contains("osx"))
} }
Os.SOLARIS -> {
return (curOs.contains("sunos") || curOs.contains("solaris"))
}
Os.LINUX -> { Os.LINUX -> {
return curOs.contains("linux") return curOs.contains("linux")
} }
Os.FREEBSD -> { Os.FREEBSD -> {
return curOs.contains("freebsd") return curOs.contains("freebsd")
} }
Os.SOLARIS -> {
Os.ZOS -> { return (curOs.contains("sunos") || curOs.contains("solaris"))
return (curOs.contains("z/os") || curOs.contains("os/390"))
} }
Os.OPENVMS -> { Os.OPENVMS -> {
return curOs.contains("openvms") return curOs.contains("openvms")
} }
Os.ZOS -> {
return (curOs.contains("z/os") || curOs.contains("os/390"))
}
Os.TANDEM -> { Os.TANDEM -> {
return curOs.contains("nonstop_kernel") return curOs.contains("nonstop_kernel")
} }
Os.OS400 -> { Os.OS400 -> {
return curOs.contains("os/400") return curOs.contains("os/400")
} }
@ -137,7 +129,7 @@ class ExecPlugin @Inject constructor(val configActor: ConfigActor<ExecConfig>) :
if (err == false) { if (err == false) {
errorMessage.append(cmdInfo).append("TIMEOUT") errorMessage.append(cmdInfo).append("TIMEOUT")
success = false success = false
} else if (fail.isNotEmpty()) { } else if (!fail.contains(Fail.NONE)) {
val all = fail.contains(Fail.ALL) val all = fail.contains(Fail.ALL)
val output = fail.contains(Fail.OUTPUT) val output = fail.contains(Fail.OUTPUT)
if ((all || fail.contains(Fail.EXIT) || fail.contains(Fail.NORMAL)) && proc.exitValue() > 0) { if ((all || fail.contains(Fail.EXIT) || fail.contains(Fail.NORMAL)) && proc.exitValue() > 0) {
@ -185,11 +177,11 @@ class ExecPlugin @Inject constructor(val configActor: ConfigActor<ExecConfig>) :
} }
enum class Fail() { enum class Fail() {
ALL, NORMAL, STDERR, STDOUT, OUTPUT, EXIT ALL, EXIT, NONE, NORMAL, OUTPUT, STDERR, STDOUT
} }
enum class Os() { 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<String> = emptyList(), var dir: String = "", var os: Set<Os> = emptySet(), data class CommandLine(var args: List<String> = emptyList(), var dir: String = "", var os: Set<Os> = emptySet(),