From 4195619a3277b4e975f5e082197e6cd1262548e4 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 10 Oct 2015 04:35:19 -0700 Subject: [PATCH] wrapAfter() --- src/main/kotlin/com/beust/kobalt/api/Plugin.kt | 4 +++- .../com/beust/kobalt/api/annotation/Annotations.kt | 4 +++- .../kotlin/com/beust/kobalt/internal/TaskManager.kt | 10 +++++++++- .../com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt | 8 -------- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/api/Plugin.kt b/src/main/kotlin/com/beust/kobalt/api/Plugin.kt index 5b5ead57..6692b07d 100644 --- a/src/main/kotlin/com/beust/kobalt/api/Plugin.kt +++ b/src/main/kotlin/com/beust/kobalt/api/Plugin.kt @@ -19,12 +19,13 @@ public interface Plugin { fun addStaticTask(annotation: Task, project: Project, task: (Project) -> TaskResult) { addTask(project, annotation.name, annotation.description, annotation.runBefore.toList(), - annotation.runAfter.toList(), task) + annotation.runAfter.toList(), annotation.wrapAfter.toList(), task) } fun addTask(project: Project, name: String, description: String = "", runBefore: List = arrayListOf(), runAfter: List = arrayListOf(), + wrapAfter: List = arrayListOf(), task: (Project) -> TaskResult) { tasks.add( object : BasePluginTask(this, name, description, project) { @@ -35,6 +36,7 @@ public interface Plugin { }) runBefore.forEach { taskManager.runBefore(it, name) } runAfter.forEach { taskManager.runBefore(name, it) } + wrapAfter.forEach { taskManager.wrapAfter(it, name)} } var taskManager : TaskManager diff --git a/src/main/kotlin/com/beust/kobalt/api/annotation/Annotations.kt b/src/main/kotlin/com/beust/kobalt/api/annotation/Annotations.kt index 6896a5cc..86eeb670 100644 --- a/src/main/kotlin/com/beust/kobalt/api/annotation/Annotations.kt +++ b/src/main/kotlin/com/beust/kobalt/api/annotation/Annotations.kt @@ -8,4 +8,6 @@ annotation class Directive annotation class Task(val name: String, val description: String, val runBefore: Array = arrayOf(), - val runAfter: Array = arrayOf()) + val runAfter: Array = arrayOf(), + val wrapAfter: Array = arrayOf() + ) diff --git a/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt b/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt index 7bcf06fc..dee8304d 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt @@ -15,7 +15,8 @@ import javax.inject.Singleton @Singleton public class TaskManager @Inject constructor(val plugins: Plugins, val args: Args) : KobaltLogger { private val runBefore = TreeMultimap.create() - private val runAfter= TreeMultimap.create() + private val runAfter = TreeMultimap.create() + private val wrapAfter = TreeMultimap.create() /** * Called by plugins to indicate task dependencies defined at runtime. Keys depend on values. @@ -29,6 +30,10 @@ public class TaskManager @Inject constructor(val plugins: Plugins, val args: Arg runAfter.put(task1, task2) } + fun wrapAfter(task1: String, task2: String) { + wrapAfter.put(task1, task2) + } + class TaskInfo(val id: String) { val project: String? get() = if (id.contains(":")) id.split(":").get(0) else null @@ -101,6 +106,9 @@ public class TaskManager @Inject constructor(val plugins: Plugins, val args: Arg target } if (actualTarget != null) { + wrapAfter.get(actualTarget).let { + newToProcess.addAll(it) + } transitiveClosure.add(actualTarget) val tasks = tasksByNames.get(actualTarget) if (tasks.isEmpty()) { diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt index 59754056..df91ab2d 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt @@ -32,14 +32,6 @@ public class KotlinPlugin @Inject constructor( Kobalt.registerCompiler(KotlinCompilerInfo()) } - override fun apply(project: Project, context: KobaltContext) { - log(1, "ADD SYNTH TASK") -// addTask(project, "syntheticTask", "A dynamic task", runBefore = listOf("clean")) { p: Project -> -// println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Synthetic task") -// TaskResult() -// } - } - companion object { public const val TASK_COMPILE: String = "compile" public const val TASK_COMPILE_TEST: String = "compileTest"