GithubHelp home page GithubHelp logo

ethauvin / kobalt-exec Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 136 KB

Command Line Execution Plug-in for the Kobalt build system

License: BSD 3-Clause "New" or "Revised" License

Kotlin 89.42% Java 2.19% Shell 6.74% Batchfile 1.65%
kobalt exec plugin kotlin

kobalt-exec's Introduction

Command Line Execution plug-in for Kobalt

License (3-Clause BSD) release Build Status CircleCI 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("sh", "-c", "ps aux | grep tomcat", os = setOf(Os.MAC, Os.LINUX), fail = setOf(Fail.EXIT))
    commandLine("cmd", "/c", "tasklist | find \"tomcat\"", os = setOf(Os.WINDOWS), fail = setOf(Fail.EXIT))
}

Parameters

args

The full command line including the executable and all arguments.

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.CYGWIN Cygwin for Windows
Os.FREEBSD FreeBSD
Os.LINUX Linux
Os.MAC Apple Macintosh / OS X
Os.MINGW Minimalist GNU for Windows
OS.MSYS MinGW Minimal System
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

* Excluding Cygwin, MinGW and MSYS.

exec {
    commandLine("cmd", "/c", "stop.bat", 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 tasks.

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("sh", "-c", "./stop.sh 2> error.txt", os = setOf(Os.LINUX))
    commandLine("cmd", "/c", "stop.bat 2> error.txt", os = setOf(Os.WINDOWS))
}

kobalt-exec's People

Contributors

cbeust avatar ethauvin avatar

Watchers

 avatar  avatar

Forkers

cbeust

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.