Added predefined operating systems value.

Started documentation.
This commit is contained in:
Erik C. Thauvin 2016-07-13 00:26:17 -07:00
parent f2ff209389
commit 84f64f5437
6 changed files with 163 additions and 23 deletions

2
.idea/kobalt.xml generated
View file

@ -5,7 +5,7 @@
<KobaltProjectSettings>
<option name="autoDownloadKobalt" value="true" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="kobaltHome" value="$USER_HOME$/.kobalt/wrapper/dist/kobalt-0.851" />
<option name="kobaltHome" value="$USER_HOME$/.kobalt/wrapper/dist/kobalt-0.852" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />

View file

@ -6,6 +6,8 @@
var pl = plugins("net.thauvin.erik:kobalt-exc:")
var p = project {
name = "example"
exec {
commandLine(listOf("echo", "Hello, World!"))
}
@ -15,3 +17,95 @@ var p = project {
```sh
./kobaltw assemble exec
```
## CommandLine Directive
```kotlin
exec {
commandLine(listOf("cmd", "/c", "stop.bat"), dir = "../tomcat/bin", os = setOf(Os.WINDOWS))
commandLine(listOf("./stop.sh"), dir = "../tomcat/bin", os = setOf(Os.MAC, Os.LINUX))
commandLine(listOf("/bin/sh", "-c", "ps aux | grep tomcat"), fail = setOf(Fail.EXIT))
}
```
### Parameters
#### args
The full command line including the executable and its parameters.
```kotlin
exec {
commandLine(listOf("ls", "-l"))
comamndLine(args = listOf("touch", "README.md"))
}
```
#### dir
The working directory for the process. Defaults to the project directory.
```kotlin
exec {
commandLine(listOf("cmd", "/c", "stop.bat"), dir = "../tomcat/bin")
}
```
#### os
The operating system(s) to execute the command on. If the current operating system does not match, the command will not be executed.
The following predefined values are available:
Name | Operating System
------------|--------------------------------------------------------------------
Os.FREEBSD | FreeBSD
Os.LINUX | Linux
Os.MAC | Apple Macintosh / OS X
Os.OPENVMS | OpenVMS
Os.OS400 | OS/400
Os.SOLARIS | Solaris / SunOS
Os.TANDEM | Tandem's Non-Stop
Os.WINDOWS | Microsoft Windows
Os.ZOS | z/OS / OS/390
```kotlin
exec {
commandLine(listOf("cmd", "/c", "stop.cmd"), os = setOf(Os.WINDOWS))
commandLine(listOf("./stop.sh"), os = setOf(Os.LINUX, Os.MAC))
}
```
#### fail
Specifies whether output to the stderr, stdout and/or an abnormal exit value constitutes a failure.
The following predefined values are available:
Name | Failure When
------------|--------------------------------------------------------------------
Fail.EXIT | Exit value > 0
Fail.NORMAL | Exit value > 0 or any output to the standard error stream (stderr).
Fail.OUTPUT | Any output to the standard output stream (stdout) or stderr.
Fail.STDERR | Any output to stderr.
Fail.STDOUT | Any output to stdout.
Fail.ALL | Any of the conditions above.
`Fail.NORMAL` is the default value.
```kotlin
exec {
commandLine(listOf("cmd", "/c", "stop.bat"), fail = setOf(Fail.EXIT))
commandLine(listOf("./stop.sh"), fail = setOf(Fail.EXIT, Fail.STDOUT))
}
```
### Logging / Debugging
```sh
./kobaltw exec --log 2
```

View file

@ -40,8 +40,8 @@ val example = project {
}
exec {
commandLine(listOf("cmd", "/c", "echo", "Test Example 1"), os = setOf("Win"))
commandLine(args = listOf("ls", "-l"), dir = "../libs", os = setOf("Linux", "Win"))
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))
}
}
@ -49,7 +49,8 @@ val example2 = project {
name = "example2"
exec {
commandLine(listOf("cmd", "/c", "echo", "Test Example 2"), os = setOf("Win"))
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))
}
}

View file

@ -25,18 +25,9 @@
</library>
</orderEntry>
<orderEntry type="module-library" scope="TEST">
<library name="Kobalt: org.apache.ant:ant-launcher:jar:1.7.0">
<library name="Kobalt: org.apache.ant:ant:jar:1.7.0">
<CLASSES>
<root url="jar://$USER_HOME$/.kobalt/repository/org/apache/ant/ant-launcher/1.7.0/ant-launcher-1.7.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library" scope="TEST">
<library name="Kobalt: org.beanshell:bsh:jar:2.0b4">
<CLASSES>
<root url="jar://$USER_HOME$/.kobalt/repository/org/beanshell/bsh/2.0b4/bsh-2.0b4.jar!/" />
<root url="jar://$USER_HOME$/.kobalt/repository/org/apache/ant/ant/1.7.0/ant-1.7.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
@ -52,9 +43,18 @@
</library>
</orderEntry>
<orderEntry type="module-library" scope="TEST">
<library name="Kobalt: org.apache.ant:ant:jar:1.7.0">
<library name="Kobalt: org.beanshell:bsh:jar:2.0b4">
<CLASSES>
<root url="jar://$USER_HOME$/.kobalt/repository/org/apache/ant/ant/1.7.0/ant-1.7.0.jar!/" />
<root url="jar://$USER_HOME$/.kobalt/repository/org/beanshell/bsh/2.0b4/bsh-2.0b4.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library" scope="TEST">
<library name="Kobalt: org.apache.ant:ant-launcher:jar:1.7.0">
<CLASSES>
<root url="jar://$USER_HOME$/.kobalt/repository/org/apache/ant/ant-launcher/1.7.0/ant-launcher-1.7.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />

View file

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

View file

@ -43,6 +43,7 @@ import java.io.BufferedReader
import java.io.File
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import java.util.concurrent.TimeUnit
@Singleton
@ -68,6 +69,47 @@ class ExecPlugin @Inject constructor(val configActor: ConfigActor<ExecConfig>) :
return result
}
private fun matchOs(os: Os): Boolean {
val curOs: String = System.getProperty("os.name").toLowerCase(Locale.US)
when (os) {
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.OPENVMS -> {
return curOs.contains("openvms")
}
Os.TANDEM -> {
return curOs.contains("nonstop_kernel")
}
Os.OS400 -> {
return curOs.contains("os/400")
}
}
}
private fun executeCommands(project: Project, config: ExecConfig): TaskResult {
var success = true
val errorMessage = StringBuilder()
@ -77,9 +119,8 @@ class ExecPlugin @Inject constructor(val configActor: ConfigActor<ExecConfig>) :
if (wrkDir.isDirectory) {
var execute = (os.size == 0)
if (!execute) {
val curOs: String = System.getProperty("os.name")
for (name in os) {
execute = curOs.startsWith(name, true)
execute = matchOs(name)
if (execute) break
}
}
@ -147,14 +188,18 @@ enum class Fail() {
ALL, NORMAL, STDERR, STDOUT, OUTPUT, EXIT
}
data class CommandLine(var args: List<String> = emptyList(), var dir: String = "", var os: Set<String> = emptySet(),
enum class Os() {
WINDOWS, MAC, SOLARIS, LINUX, FREEBSD, ZOS, OPENVMS, TANDEM, OS400
}
data class CommandLine(var args: List<String> = emptyList(), var dir: String = "", var os: Set<Os> = emptySet(),
var fail: Set<Fail> = setOf(Fail.NORMAL))
@Directive
class ExecConfig() {
val commandLines = arrayListOf<CommandLine>()
fun commandLine(args: List<String> = emptyList(), dir: String = "", os: Set<String> = emptySet(),
fun commandLine(args: List<String> = emptyList(), dir: String = "", os: Set<Os> = emptySet(),
fail: Set<Fail> = setOf(Fail.NORMAL)) {
if (args.size > 0) commandLines.add(CommandLine(args, dir, os, fail))
}