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">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</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)
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))
}
```

View file

@ -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))
}
}

View file

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

View file

@ -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."

View file

@ -75,35 +75,27 @@ class ExecPlugin @Inject constructor(val configActor: ConfigActor<ExecConfig>) :
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<ExecConfig>) :
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<ExecConfig>) :
}
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<String> = emptyList(), var dir: String = "", var os: Set<Os> = emptySet(),