Added ConfigActor injection.

Added Tarvis CI configuration.
This commit is contained in:
Erik C. Thauvin 2016-07-12 17:56:49 -07:00
parent 47beeb1510
commit 0063848981
9 changed files with 105 additions and 73 deletions

9
.idea/codeStyleSettings.xml generated Normal file
View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectCodeStyleSettingsManager">
<option name="PER_PROJECT_SETTINGS">
<value />
</option>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Erik's Code Style" />
</component>
</project>

2
.idea/kobalt.xml generated
View file

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

4
.idea/misc.xml generated
View file

@ -40,6 +40,10 @@
</component> </component>
<component name="EntryPointsManager"> <component name="EntryPointsManager">
<entry_points version="2.0" /> <entry_points version="2.0" />
<list size="2">
<item index="0" class="java.lang.String" itemvalue="com.beust.kobalt.api.annotation.Directive" />
<item index="1" class="java.lang.String" itemvalue="com.beust.kobalt.api.annotation.Task" />
</list>
</component> </component>
<component name="MavenImportPreferences"> <component name="MavenImportPreferences">
<option name="generalSettings"> <option name="generalSettings">

13
.travis.yml Normal file
View file

@ -0,0 +1,13 @@
language: java
jdk:
- oraclejdk8
install: true
cache:
directories:
- $HOME/.m2
- $HOME/.kobalt
script: ./kobaltw clean assemble

View file

@ -6,10 +6,10 @@ import net.thauvin.erik.kobalt.plugin.exec.*
val repos = repos("https://dl.bintray.com/ethauvin/maven/") val repos = repos("https://dl.bintray.com/ethauvin/maven/")
//val pl = plugins(file("../kobaltBuild/libs/kobalt-exec-0.5.0-beta.jar")) 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("net.thauvin.erik:kobalt-exec:0.5.1-beta")
val p = project { val example = project {
name = "example" name = "example"
group = "com.example" group = "com.example"
@ -40,7 +40,15 @@ val p = project {
} }
exec { exec {
commandLine(listOf("cmd", "/c", "echo", "Test"), os = setOf("Win")) commandLine(listOf("cmd", "/c", "echo", "Test Example 1"), os = setOf("Win"))
commandLine(args = listOf("ls", "-l"), dir = "../libs", os = setOf("Linux", "Win")) commandLine(args = listOf("ls", "-l"), dir = "../libs", os = setOf("Linux", "Win"))
} }
} }
val example2 = project {
name = "example2"
exec {
commandLine(listOf("cmd", "/c", "echo", "Test Example 2"), os = setOf("Win"))
}
}

View file

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

View file

@ -20,9 +20,7 @@ val p = project {
version = "0.5.1-beta" version = "0.5.1-beta"
pom = Model().apply { pom = Model().apply {
name = project.name description = "Command line execution plugin for the Kobalt build system."
description = "Command line execution plugin for the Kobalt build system"
version = project.version
url = "https://github.com/ethauvin/kobalt-exec" url = "https://github.com/ethauvin/kobalt-exec"
licenses = listOf(License().apply { licenses = listOf(License().apply {
name = "BSD 3-Clause" name = "BSD 3-Clause"

View file

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

View file

@ -31,18 +31,23 @@
*/ */
package net.thauvin.erik.kobalt.plugin.exec package net.thauvin.erik.kobalt.plugin.exec
import com.beust.kobalt.Plugins
import com.beust.kobalt.TaskResult import com.beust.kobalt.TaskResult
import com.beust.kobalt.api.* import com.beust.kobalt.api.*
import com.beust.kobalt.api.annotation.Directive import com.beust.kobalt.api.annotation.Directive
import com.beust.kobalt.api.annotation.Task import com.beust.kobalt.api.annotation.Task
import com.beust.kobalt.misc.log import com.beust.kobalt.misc.log
import com.google.inject.Inject
import com.google.inject.Singleton
import java.io.BufferedReader import java.io.BufferedReader
import java.io.File import java.io.File
import java.io.InputStream import java.io.InputStream
import java.io.InputStreamReader import java.io.InputStreamReader
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
class ExecPlugin : BasePlugin(), ITaskContributor { @Singleton
class ExecPlugin @Inject constructor(val configActor: ConfigActor<ExecConfig>) :
BasePlugin(), ITaskContributor, IConfigActor<ExecConfig> by configActor {
// ITaskContributor // ITaskContributor
override fun tasksFor(project: Project, context: KobaltContext): List<DynamicTask> { override fun tasksFor(project: Project, context: KobaltContext): List<DynamicTask> {
return emptyList() return emptyList()
@ -56,15 +61,17 @@ class ExecPlugin : BasePlugin(), ITaskContributor {
@Task(name = "exec", description = "Execute a command line process.") @Task(name = "exec", description = "Execute a command line process.")
fun taskExec(project: Project): TaskResult { fun taskExec(project: Project): TaskResult {
return executeCommands(project) var result = TaskResult()
configurationFor(project)?.let { config ->
result = executeCommands(project, config)
}
return result
} }
private fun executeCommands(project: Project): TaskResult { private fun executeCommands(project: Project, config: ExecConfig): TaskResult {
var success = true var success = true
val config = configs[project.name]
val errorMessage = StringBuilder() val errorMessage = StringBuilder()
if (config != null) {
for ((args, dir, os, fail) in config.commandLines) { for ((args, dir, os, fail) in config.commandLines) {
val wrkDir = File(if (dir.isNullOrBlank()) project.directory else dir) val wrkDir = File(if (dir.isNullOrBlank()) project.directory else dir)
if (wrkDir.isDirectory) { if (wrkDir.isDirectory) {
@ -113,7 +120,6 @@ class ExecPlugin : BasePlugin(), ITaskContributor {
if (!success) break if (!success) break
} }
}
//@TODO until cedric fixes it. //@TODO until cedric fixes it.
if (!success) error(errorMessage) if (!success) error(errorMessage)
@ -121,11 +127,6 @@ class ExecPlugin : BasePlugin(), ITaskContributor {
return TaskResult(success, errorMessage.toString()) return TaskResult(success, errorMessage.toString())
} }
private val configs = hashMapOf<String, ExecConfig>()
fun addExecConfig(projectName: String, config: ExecConfig) {
configs.put(projectName, config)
}
private fun fromStream(ins: InputStream): List<String> { private fun fromStream(ins: InputStream): List<String> {
val result = arrayListOf<String>() val result = arrayListOf<String>()
val br = BufferedReader(InputStreamReader(ins)) val br = BufferedReader(InputStreamReader(ins))
@ -146,13 +147,13 @@ enum class Fail() {
ALL, NORMAL, STDERR, STDOUT, OUTPUT, EXIT ALL, NORMAL, STDERR, STDOUT, OUTPUT, EXIT
} }
data class CommandLine(var args: List<String> = emptyList(), var dir: String = "", data class CommandLine(var args: List<String> = emptyList(), var dir: String = "", var os: Set<String> = emptySet(),
var os: Set<String> = emptySet(), var fail: Set<Fail> = setOf(Fail.NORMAL)) var fail: Set<Fail> = setOf(Fail.NORMAL))
data class ExecConfig(val project: Project) { @Directive
class ExecConfig() {
val commandLines = arrayListOf<CommandLine>() val commandLines = arrayListOf<CommandLine>()
@Directive
fun commandLine(args: List<String> = emptyList(), dir: String = "", os: Set<String> = emptySet(), fun commandLine(args: List<String> = emptyList(), dir: String = "", os: Set<String> = emptySet(),
fail: Set<Fail> = setOf(Fail.NORMAL)) { fail: Set<Fail> = setOf(Fail.NORMAL)) {
if (args.size > 0) commandLines.add(CommandLine(args, dir, os, fail)) if (args.size > 0) commandLines.add(CommandLine(args, dir, os, fail))
@ -160,10 +161,9 @@ data class ExecConfig(val project: Project) {
} }
@Directive @Directive
fun Project.exec(init: ExecConfig.() -> Unit): ExecConfig { fun Project.exec(init: ExecConfig.() -> Unit) {
with(ExecConfig(this)) { ExecConfig().let { config ->
init() config.init()
(Kobalt.findPlugin(ExecPlugin.NAME) as ExecPlugin).addExecConfig(name, this) (Plugins.findPlugin(ExecPlugin.NAME) as ExecPlugin).addConfiguration(this, config)
return this
} }
} }