diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..dffffe6 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,31 @@ +version: 2 +jobs: + build: + docker: + - image: circleci/openjdk:8-jdk + + working_directory: ~/repo + + environment: + JVM_OPTS: -Xmx3200m + TERM: dumb + + steps: + - checkout + - restore_cache: + keys: + - kobalt-dependencies-{{ checksum "kobalt/src/Build.kt" }} + # fallback to using the latest cache if no exact match is found + - kobalt-dependencies- + + - run: + name: Check Versions + command: ./kobaltw checkVersions + + - save_cache: + paths: ~/.kobalt + key: kobalt-dependencies-{{ checksum "kobalt/src/Build.kt" }} + + - run: + name: Assemble + command: ./kobaltw assemble \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index 17b1e81..8ff795e 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -1,9 +1,8 @@ diff --git a/.idea/kobalt.xml b/.idea/kobalt.xml index 07b6593..c71b85c 100644 --- a/.idea/kobalt.xml +++ b/.idea/kobalt.xml @@ -4,13 +4,15 @@ diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml deleted file mode 100644 index 1c24f9a..0000000 --- a/.idea/kotlinc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index f1a9bb1..7826943 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,66 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Java + + + Portability issuesJava + + + + + Android + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index cc61fa9..48f8f9e 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -3,7 +3,6 @@ - diff --git a/.idea/vcs.xml b/.idea/vcs.xml index d175698..94a25f7 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,7 +2,5 @@ - - \ No newline at end of file diff --git a/README.md b/README.md index 6ee4f49..7081070 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Command Line Execution plug-in for [Kobalt](http://beust.com/kobalt/home/index.html) -[![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) [![Download](https://api.bintray.com/packages/ethauvin/maven/kobalt-exec/images/download.svg)](https://bintray.com/ethauvin/maven/kobalt-exec/_latestVersion) +[![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) [![release](https://img.shields.io/github/release/ethauvin/kobalt-exec.svg)](https://github.com/ethauvin/kobalt-exec/releases/latest) [![Build Status](https://travis-ci.org/ethauvin/kobalt-exec.svg?branch=master)](https://travis-ci.org/ethauvin/kobalt-exec) [![CircleCI](https://circleci.com/gh/ethauvin/kobalt-exec/tree/master.svg?style=shield)](https://circleci.com/gh/ethauvin/kobalt-exec/tree/master) [![Download](https://api.bintray.com/packages/ethauvin/maven/kobalt-exec/images/download.svg)](https://bintray.com/ethauvin/maven/kobalt-exec/_latestVersion) 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. @@ -17,7 +17,7 @@ val p = project { name = "example" exec { - commandLine(listOf("echo", "Hello, World!")) + commandLine("echo", "Hello, World!") } } ``` @@ -35,9 +35,10 @@ The `commandLine` directive is used to execute command line(s) during the build ```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)) + 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)) } ``` @@ -45,12 +46,13 @@ exec { ### `args` -The full command line including the executable and all parameters. +The full command line including the executable and all arguments. ```kotlin exec { - commandLine(listOf("ls", "-l")) - commandLine(args = listOf("cmd", "/c", "dir /Q")) + commandLine(args = "ls") + commandLine("ls", "-l") + commandLine("cmd", "/c", "dir /Q") } ``` @@ -60,7 +62,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("cmd", "/c", "stop.bat", dir = "../tomcat/bin") commandLine("./stop.sh", dir = "../tomcat/bin") } ``` @@ -72,21 +74,26 @@ List of operating systems on which the command may be executed. If the current O 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.WINDOWS` | Microsoft Windows* `Os.ZOS` | z/OS / OS/390 +* Excluding Cygwin, MinGW and MSYS. + ```kotlin exec { - commandLine(listOf("cmd", "/c", "stop.cmd"), os = setOf(Os.WINDOWS)) - commandLine(listOf("./stop.sh"), os = setOf(Os.LINUX, Os.MAC)) + commandLine("cmd", "/c", "stop.bat", os = setOf(Os.WINDOWS)) + commandLine("./stop.sh", os = setOf(Os.LINUX, Os.MAC)) } ``` @@ -97,7 +104,7 @@ List of error options to specify whether data returned to the standard streams a 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. @@ -110,14 +117,48 @@ Name | Failure When ```kotlin exec { - commandLine(listOf("cmd", "/c", "stop.bat"), fail = setOf(Fail.EXIT)) - commandLine(listOf("./stop.sh"), fail = setOf(Fail.EXIT, Fail.STDOUT)) + 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. + +```kotlin +exec { + taskName = "start" + commandLine("./start.sh", os = setOf(Os.LINUX, Os.MAC)) +} + +exec { + taskName = "stop" + commandLine("./stop.sh", os = setOf(Os.LINUX, Os.MAC)) +} +``` + +```sh +./kobaltw start +./kobaltw stop +``` + +## dependsOn + + +By default the `exec` task depends on `assemble`, use the `dependsOn` parameter to change the dependencies: + +```kotlin +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: + ```sh ./kobaltw exec --log 2 ``` @@ -125,10 +166,7 @@ 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)) + commandLine("sh", "-c", "./stop.sh 2> error.txt", os = setOf(Os.LINUX)) + commandLine("cmd", "/c", "stop.bat 2> error.txt", os = setOf(Os.WINDOWS)) } -``` - - - +``` \ No newline at end of file diff --git a/clean.sh b/clean.sh new file mode 100644 index 0000000..552252d --- /dev/null +++ b/clean.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +DEBUG=false + +rm="rm -rf" + +if [ "$DEBUG" = true ]; then + rm="echo rm -rf" +fi + +buildkt="kobalt/src/Build.kt" + +name=$(cat $buildkt | grep -m 1 "name = " | cut -d"\"" -f 2) +group=$(cat $buildkt | grep -m 1 "group = " | cut -d"\"" -f 2) + +if [ -z "$1" ]; then + version=$(cat $buildkt | grep -m 1 "version = " | cut -d"\"" -f 2) +else + version="$1" +fi + +maven="/k/maven/repository/${group//.//}/${name}/${version}" +kobalt="$HOME/.kobalt/cache/${group//.//}/${name}/${version}" +localRepo="$HOME/.kobalt/localMavenRepo/${group//.//}/${name}/${version}" + +read -p "Delete version ${version}? " -n 1 -r +echo +if [[ $REPLY =~ ^[Yy]$ ]]; then + for dir in "$kobalt" "$maven" "$localRepo"; do + if [ -d "$dir" ]; then + echo -e "Deleting : \e[32;1m$dir\e[0m" + $rm "$dir" + else + echo -e "Not Found: \e[31;1m$dir\e[0m" + fi + done +fi \ No newline at end of file diff --git a/example/kobalt/Build.kt.iml b/example/kobalt/Build.kt.iml deleted file mode 100644 index d022bf6..0000000 --- a/example/kobalt/Build.kt.iml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/example/kobalt/src/Build.kt b/example/kobalt/src/Build.kt index f3372f2..76e2c24 100644 --- a/example/kobalt/src/Build.kt +++ b/example/kobalt/src/Build.kt @@ -3,12 +3,13 @@ import com.beust.kobalt.plugin.application.* import com.beust.kobalt.plugin.packaging.* import net.thauvin.erik.kobalt.plugin.exec.* +// ./kobaltw exec echo ps --log 2 // ./kobaltw exec --log 2 -// ./kobaltw example:exec --log 2 -// ./kobaltw example2:exec --log 2 +// ./kobaltw echo --log 2 +// ./kobaltw ps --log 2 val bs = buildScript { - //repos(file("K:/maven/repository")) + repos(localMaven()) plugins("net.thauvin.erik:kobalt-exec:") } @@ -29,20 +30,23 @@ 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)) - commandLine(args = listOf("cmd", "/c", "dir /Q"), dir = "../libs", os = setOf(Os.WINDOWS)) + commandLine("ls", "-l", dir = "../kobalt/wrapper", os = setOf(Os.LINUX, Os.MINGW, Os.CYGWIN)) + commandLine("cmd", "/c", "dir /Q", dir = "../kobalt/wrapper", os = setOf(Os.WINDOWS)) } -} - -val example2 = project { - name = "example2" exec { - commandLine(listOf("cmd", "/c", "echo", "Test Example 2"), os = setOf(Os.WINDOWS)) - 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)) + taskName = "echo" + dependsOn = listOf("exec", "run") + + val echo = arrayOf("echo", "Test", "Example") + commandLine(*echo, os = setOf(Os.LINUX, Os.MINGW, Os.CYGWIN)) + commandLine("cmd", "/c", *echo, os = setOf(Os.WINDOWS)) } -} + + exec { + taskName = "ps" + dependsOn = listOf() // no dependencies + commandLine("sh", "-c", "ps aux | grep bash", os = setOf(Os.LINUX, Os.MINGW, Os.CYGWIN)) + commandLine("cmd", "/c", "tasklist | find \"cmd.exe\"", os = setOf(Os.WINDOWS), fail = setOf(Fail.EXIT)) + } +} \ No newline at end of file diff --git a/example/kobalt/wrapper/kobalt-wrapper.properties b/example/kobalt/wrapper/kobalt-wrapper.properties index 02e723d..a6a4316 100644 --- a/example/kobalt/wrapper/kobalt-wrapper.properties +++ b/example/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.75 \ No newline at end of file +kobalt.version=1.0.90 diff --git a/kobalt-exec.iml b/kobalt-exec.iml index d3359c4..bffb9cc 100644 --- a/kobalt-exec.iml +++ b/kobalt-exec.iml @@ -21,6 +21,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -42,7 +87,7 @@ - + @@ -111,15 +156,6 @@ - - - - - - - - - @@ -210,6 +246,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -363,6 +471,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -435,6 +615,68 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/kobalt/Build.kt.iml b/kobalt/Build.kt.iml index db31b14..0098d0a 100644 --- a/kobalt/Build.kt.iml +++ b/kobalt/Build.kt.iml @@ -10,32 +10,33 @@ - + - + - + - + - + - + - + + + - \ No newline at end of file diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt index 79929cc..7a5bf23 100644 --- a/kobalt/src/Build.kt +++ b/kobalt/src/Build.kt @@ -1,13 +1,19 @@ - -import com.beust.kobalt.* +import com.beust.kobalt.buildScript +import com.beust.kobalt.localMaven +import com.beust.kobalt.file import com.beust.kobalt.plugin.packaging.assemble import com.beust.kobalt.plugin.publish.autoGitTag import com.beust.kobalt.plugin.publish.bintray +import com.beust.kobalt.profile +import com.beust.kobalt.project import net.thauvin.erik.kobalt.plugin.versioneye.versionEye -import org.apache.maven.model.* +import org.apache.maven.model.Developer +import org.apache.maven.model.License +import org.apache.maven.model.Model +import org.apache.maven.model.Scm val bs = buildScript { - repos(file("K:/maven/repository")) + repos(localMaven()) plugins("net.thauvin.erik:kobalt-versioneye:", "net.thauvin.erik:kobalt-maven-local:") } @@ -19,7 +25,7 @@ val p = project { name = "kobalt-exec" group = "net.thauvin.erik" artifactId = name - version = "0.6.5" + version = "0.7.0" pom = Model().apply { description = "Command Line Execution plug-in for the Kobalt build system." @@ -42,10 +48,12 @@ val p = project { dependencies { compile("com.beust:$kobaltDependency:") + compile("org.jetbrains.kotlin:kotlin-stdlib:1.1.51") } dependenciesTest { - compile("org.testng:testng:") + compile("org.testng:testng:6.12") + compile("org.jetbrains.kotlin:kotlin-test:1.1.51") } assemble { @@ -56,6 +64,7 @@ val p = project { autoGitTag { enabled = true + push = false message = "Version $version" } diff --git a/kobalt/wrapper/kobalt-wrapper.properties b/kobalt/wrapper/kobalt-wrapper.properties index 02e723d..a6a4316 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.75 \ No newline at end of file +kobalt.version=1.0.90 diff --git a/src/main/kotlin/net/thauvin/erik/kobalt/plugin/exec/ExecPlugin.kt b/src/main/kotlin/net/thauvin/erik/kobalt/plugin/exec/ExecPlugin.kt index 94eb440..9dccff5 100644 --- a/src/main/kotlin/net/thauvin/erik/kobalt/plugin/exec/ExecPlugin.kt +++ b/src/main/kotlin/net/thauvin/erik/kobalt/plugin/exec/ExecPlugin.kt @@ -44,8 +44,8 @@ import java.util.* import java.util.concurrent.TimeUnit @Singleton -class ExecPlugin @Inject constructor(val configActor: ConfigActor) : - BasePlugin(), ITaskContributor, IConfigActor by configActor { +class ExecPlugin @Inject constructor(val taskContributor: TaskContributor, val configActor: ConfigsActor) : + BasePlugin(), ITaskContributor, IConfigsActor by configActor { // ITaskContributor override fun tasksFor(project: Project, context: KobaltContext): List { return emptyList() @@ -57,21 +57,51 @@ class ExecPlugin @Inject constructor(val configActor: ConfigActor) : override val name = NAME - @Suppress("unused") - @Task(name = "exec", description = "Execute a command line process.") - fun taskExec(project: Project): TaskResult { - configurationFor(project)?.let { config -> - return executeCommands(project, config) + override fun apply(project: Project, context: KobaltContext) { + configurationFor(project)?.let { configs -> + configs.forEach { config -> + taskManager.addTask(this, project, config.taskName, + description = "Execute a command line process.", + group = "Other", + dependsOn = config.dependsOn, + task = { executeCommands(project, config) }) + taskContributor.addVariantTasks(this, project, context, config.taskName, + dependsOn = config.dependsOn, + runTask = { executeCommands(project, config) }) + } + } + } + + private fun isCygwin(): Boolean { + val path: String? = System.getenv("ORIGINAL_PATH") + return path?.contains("/cygdrive/") ?: false + } + + private fun isMinGW(os: Os = Os.MINGW, any: Boolean = false): Boolean { + val msys: String? = System.getenv("MSYSTEM") + + if (!msys.isNullOrBlank()) { + if (any) { + return true + } else if (os.equals(Os.MSYS)) { + return msys!!.startsWith("MSYS") + } else if (os.equals(Os.MINGW)) { + return msys!!.startsWith("MINGW") + } } - return TaskResult() + return false } private fun matchOs(os: Os): Boolean { val curOs: String = System.getProperty("os.name").toLowerCase(Locale.US) when (os) { Os.WINDOWS -> { - return curOs.contains("windows") + if (!isMinGW(any = true) && !isCygwin()) { + return curOs.contains("windows") + } else { + return false + } } Os.MAC -> { return (curOs.contains("mac") || curOs.contains("darwin") || curOs.contains("osx")) @@ -97,6 +127,15 @@ class ExecPlugin @Inject constructor(val configActor: ConfigActor) : Os.OS400 -> { return curOs.contains("os/400") } + Os.CYGWIN -> { + return isCygwin() + } + Os.MINGW -> { + return isMinGW() + } + Os.MSYS -> { + return isMinGW(Os.MSYS) + } } } @@ -115,7 +154,7 @@ class ExecPlugin @Inject constructor(val configActor: ConfigActor) : } } if (execute) { - log(2, "> " + args.joinToString(" ")) + log(2, (if (!wrkDir.name.equals(".")) wrkDir.name else "") + "> " + args.joinToString(" ")) val pb = ProcessBuilder().command(args.toList()) pb.directory(wrkDir) val proc = pb.start() @@ -179,7 +218,7 @@ enum class Fail { } enum class Os { - FREEBSD, LINUX, MAC, OPENVMS, OS400, SOLARIS, TANDEM, WINDOWS, ZOS + CYGWIN, FREEBSD, LINUX, MAC, MINGW, MSYS, OPENVMS, OS400, SOLARIS, TANDEM, WINDOWS, ZOS } data class CommandLine(var args: List = emptyList(), var dir: String = "", var os: Set = emptySet(), @@ -187,12 +226,14 @@ data class CommandLine(var args: List = emptyList(), var dir: String = " @Directive class ExecConfig { + var taskName: String = "exec" val commandLines = arrayListOf() + var dependsOn = listOf("assemble") @Suppress("unused") - fun commandLine(args: List = emptyList(), dir: String = "", os: Set = emptySet(), + fun commandLine(vararg args: String, dir: String = "", os: Set = emptySet(), fail: Set = setOf(Fail.NORMAL)) { - if (args.isNotEmpty()) commandLines.add(CommandLine(args, dir, os, fail)) + if (args.isNotEmpty()) commandLines.add(CommandLine(listOf(*args), dir, os, fail)) } }