Kotlin 1.1 and Kobalt 1.0.x optimization

This commit is contained in:
Erik C. Thauvin 2017-03-06 14:08:05 -08:00
parent 572ddd0a9f
commit 53e80b18e7
2 changed files with 13 additions and 9 deletions

View file

@ -4,8 +4,9 @@ import com.beust.kobalt.plugin.application.*
import com.beust.kobalt.plugin.java.* import com.beust.kobalt.plugin.java.*
import net.thauvin.erik.kobalt.plugin.exec.* import net.thauvin.erik.kobalt.plugin.exec.*
//val pl = plugins(file("../kobaltBuild/libs/kobalt-exec-0.6.2.jar")) val bs = buildScript {
val pl = plugins("net.thauvin.erik:kobalt-exec:0.6.2") plugins("net.thauvin.erik:kobalt-exec:0.6.2")
}
val example = project { val example = project {

View file

@ -1,7 +1,7 @@
/* /*
* ExecPlugin.kt * ExecPlugin.kt
* *
* Copyright (c) 2016, Erik C. Thauvin (erik@thauvin.net) * Copyright (c) 2016-2017, Erik C. Thauvin (erik@thauvin.net)
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -60,6 +60,7 @@ class ExecPlugin @Inject constructor(val configActor: ConfigActor<ExecConfig>) :
override val name = NAME override val name = NAME
@Suppress("unused")
@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 {
var result = TaskResult() var result = TaskResult()
@ -109,7 +110,7 @@ class ExecPlugin @Inject constructor(val configActor: ConfigActor<ExecConfig>) :
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) {
var execute = (os.size == 0) var execute = (os.isEmpty())
if (!execute) { if (!execute) {
for (name in os) { for (name in os) {
execute = matchOs(name) execute = matchOs(name)
@ -126,7 +127,7 @@ class ExecPlugin @Inject constructor(val configActor: ConfigActor<ExecConfig>) :
val stderr = if (proc.errorStream.available() > 0) fromStream(proc.errorStream) else emptyList() val stderr = if (proc.errorStream.available() > 0) fromStream(proc.errorStream) else emptyList()
val cmdInfo = "Program \"" + args.joinToString(" ") + "\" (in directory \"${wrkDir.path}\"): " val cmdInfo = "Program \"" + args.joinToString(" ") + "\" (in directory \"${wrkDir.path}\"): "
if (err == false) { if (!err) {
errorMessage.append(cmdInfo).append("TIMEOUT") errorMessage.append(cmdInfo).append("TIMEOUT")
success = false success = false
} else if (!fail.contains(Fail.NONE)) { } else if (!fail.contains(Fail.NONE)) {
@ -176,11 +177,11 @@ class ExecPlugin @Inject constructor(val configActor: ConfigActor<ExecConfig>) :
} }
} }
enum class Fail() { enum class Fail {
ALL, EXIT, NONE, NORMAL, OUTPUT, STDERR, STDOUT ALL, EXIT, NONE, NORMAL, OUTPUT, STDERR, STDOUT
} }
enum class Os() { enum class Os {
FREEBSD, LINUX, MAC, OPENVMS, OS400, SOLARIS, TANDEM, WINDOWS, ZOS FREEBSD, LINUX, MAC, OPENVMS, OS400, SOLARIS, TANDEM, WINDOWS, ZOS
} }
@ -188,15 +189,17 @@ data class CommandLine(var args: List<String> = emptyList(), var dir: String = "
var fail: Set<Fail> = setOf(Fail.NORMAL)) var fail: Set<Fail> = setOf(Fail.NORMAL))
@Directive @Directive
class ExecConfig() { class ExecConfig {
val commandLines = arrayListOf<CommandLine>() val commandLines = arrayListOf<CommandLine>()
@Suppress("unused")
fun commandLine(args: List<String> = emptyList(), dir: String = "", os: Set<Os> = emptySet(), fun commandLine(args: List<String> = emptyList(), dir: String = "", os: Set<Os> = 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.isNotEmpty()) commandLines.add(CommandLine(args, dir, os, fail))
} }
} }
@Suppress("unused")
@Directive @Directive
fun Project.exec(init: ExecConfig.() -> Unit) { fun Project.exec(init: ExecConfig.() -> Unit) {
ExecConfig().let { config -> ExecConfig().let { config ->