Command Line Execution Plug-in for the Kobalt build system https://github.com/ethauvin/kobalt-exec
Find a file
Erik C. Thauvin 395fa127b9 Added taskName, dependsOn.
Changed commandLine(args) from List to vararg.
2017-04-28 00:26:04 -07:00
.idea Kobalt 1.0.69 update. 2017-04-18 17:58:33 -07:00
example Added taskName, dependsOn. 2017-04-28 00:26:04 -07:00
kobalt Added taskName, dependsOn. 2017-04-28 00:26:04 -07:00
src/main Added taskName, dependsOn. 2017-04-28 00:26:04 -07:00
.gitattributes Updated to Kobalt 1.0.19. 2017-03-21 15:17:08 -07:00
.gitignore Prep for 0.6.5 release. 2017-04-24 14:19:53 -07:00
.travis.yml Added before_cache 2017-03-21 18:39:07 -07:00
clean.sh Added clean for testing. 2017-04-28 00:24:10 -07:00
kobalt-exec.iml Kobalt 1.0.69 update. 2017-04-18 17:58:33 -07:00
kobaltw Debugging TravisCI. 2016-08-07 10:59:44 -07:00
kobaltw.bat Trying new Travis build. 2016-07-17 20:06:44 -07:00
LICENSE.txt Updated license copyright. 2017-03-08 12:19:43 -08:00
README.md Added taskName, dependsOn. 2017-04-28 00:26:04 -07:00

Command Line Execution plug-in for Kobalt

License (3-Clause BSD) Build Status Download

The plug-in allows for the execution of system commands, similarly to the Gradle Exec or Ant Exec tasks.

To use the plug-in include the following in your Build.kt file:

import net.thauvin.erik.kobalt.plugin.exec.*

val bs = buildScript {
    plugins("net.thauvin.erik:kobalt-exc:")
}

val p = project {
    name = "example"

    exec {
       commandLine("echo", "Hello, World!")
    }
}

View Example

To invoke the exec task:

./kobaltw exec

commandLine Directive

The commandLine directive is used to execute command line(s) during the build process:

exec {
    commandLine("cmd", "/c", "stop.bat", dir = "../tomcat/bin", os = setOf(Os.WINDOWS))
    commandLine("./stop.sh", dir = "../tomcat/bin", os = setOf(Os.MAC, Os.LINUX))
    commandLine("/bin/sh", "-c", "ps aux | grep tomcat", fail = setOf(Fail.EXIT))
}

Parameters

args

The full command line arguments including the executable and all parameters.

exec {
    commandLine(args="ls")
    commandLine("ls", "-l")
    commandLine("cmd", "/c", "dir /Q")
}

dir

The working directory in which the command should be executed. Defaults to the project directory.

exec {
    commandLine("cmd", "/c", "stop.bat", dir = "../tomcat/bin")
    commandLine("./stop.sh", dir = "../tomcat/bin")
}

os

List of operating systems on which the command may be executed. If the current OS is contained within the list, the command will 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
exec {
    commandLine("cmd", "/c", "stop.cmd", os = setOf(Os.WINDOWS))
    commandLine("./stop.sh", os = setOf(Os.LINUX, Os.MAC))
}

fail

List of error options to specify whether data returned to the standard streams and/or an abnormal exit value constitute build failure signaling.

The following predefined values are available:

Name Failure When
Fail.EXIT Exit value > 0
Fail.NORMAL Exit value > 0 or any data to the standard error stream (stderr)
Fail.OUTPUT Any data to the standard output stream (stdout) or stderr.
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.

exec {
    commandLine("cmd", "/c", "stop.bat", fail = setOf(Fail.EXIT))
    commandLine("./stop.sh", fail = setOf(Fail.EXIT, Fail.STDOUT))
}

taskName

Additionally, you can specify a task name to easily identify multiple exec directives.

exec {
    taskName = "start"
    commandLine("./start.sh", os = setOf(Os.LINUX, Os.MAC))
}

exec {
    taskName = "stop"
    commandLine("./stop.sh", os = setOf(Os.LINUX, Os.MAC))
}
./kobaltw start
./kobaltw stop

dependsOn

By default the exec task depends on assemble, use the dependsOn parameter to change the dependencies:

exec {
    dependsOn = listOf("assemble", "run")
    commandLine("cmd", "/c", "start.bat", fail = setOf(Fail.EXIT))
}

Logging / Debugging

To view the output of the exec task, use:

./kobaltw exec --log 2

You could also redirect the error stream to a file:

exec {
    commandLine("/bin/sh", "-c", "./stop.sh 2> error.txt", os = setOf(Os.LINUX))
    commandLine("cmd", "/c", "stop.bat 2> error.txt", os = setOf(Os.WINDOWS))
}