diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/IncrementalTaskInfo.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/IncrementalTaskInfo.kt new file mode 100644 index 00000000..c5c56a8a --- /dev/null +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/IncrementalTaskInfo.kt @@ -0,0 +1,5 @@ +package com.beust.kobalt + +import com.beust.kobalt.api.Project + +class IncrementalTaskInfo(val inputChecksum: String, val outputChecksum: String, task: (Project) -> TaskResult) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Plugins.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Plugins.kt index 29b94799..cb9a199c 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Plugins.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Plugins.kt @@ -6,10 +6,10 @@ import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.internal.TaskManager import com.beust.kobalt.maven.DepFactory import com.beust.kobalt.maven.LocalRepo +import com.beust.kobalt.misc.JarUtils import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.KobaltExecutors import com.beust.kobalt.misc.log -import com.beust.kobalt.misc.JarUtils import com.google.inject.Provider import java.lang.reflect.Method import java.lang.reflect.Modifier @@ -82,7 +82,7 @@ public class Plugins @Inject constructor (val taskManagerProvider : Provider = arrayOf() ) +@Retention(AnnotationRetention.RUNTIME) +annotation class IncrementalTask( + val name: String, + val description: String = "", + + /** Tasks that this task depends on */ + val runBefore: Array = arrayOf(), + + /** Tasks that this task will run after if they get run */ + val runAfter: Array = arrayOf(), + + /** Tasks that this task will always run after */ + val alwaysRunAfter: Array = arrayOf() +) + /** * Plugins that export properties should annotate those with this annotation so they can be documented. */ diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt index 4534b907..5fe99237 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt @@ -5,6 +5,7 @@ import com.beust.kobalt.api.DynamicTask import com.beust.kobalt.api.IPlugin import com.beust.kobalt.api.PluginTask import com.beust.kobalt.api.Project +import com.beust.kobalt.api.annotation.IncrementalTask import com.beust.kobalt.api.annotation.Task import com.beust.kobalt.misc.log import com.google.common.collect.ArrayListMultimap @@ -220,13 +221,28 @@ public class TaskManager @Inject constructor(val args: Args) { // Manage the tasks // - class StaticTask(val plugin: IPlugin, val method: Method, val taskAnnotation: Task) + // Both @Task and @IncrementalTask get stored as a TaskAnnotation so they can be treated uniformly + private val taskAnnotations = arrayListOf() + class TaskAnnotation(val method: Method, val plugin: IPlugin, val name: String, val description: String, + val runBefore: Array, val runAfter: Array, val alwaysRunAfter: Array) + + fun toTaskAnnotation(method: Method, plugin: IPlugin, ta: Task) + = TaskAnnotation(method, plugin, ta.name, ta.description, ta.runBefore, ta.runAfter, ta.alwaysRunAfter) + + fun toTaskAnnotation(method: Method, plugin: IPlugin, ta: IncrementalTask) + = TaskAnnotation(method, plugin, ta.name, ta.description, ta.runBefore, ta.runAfter, ta.alwaysRunAfter) + class PluginDynamicTask(val plugin: IPlugin, val task: DynamicTask) val tasks = arrayListOf() - val staticTasks = arrayListOf() val dynamicTasks = arrayListOf() + fun addStaticTask(plugin: IPlugin, method: Method, annotation: Task) = + taskAnnotations.add(toTaskAnnotation(method, plugin, annotation)) + + fun addIncrementalTask(plugin: IPlugin, method: Method, annotation: IncrementalTask) = + taskAnnotations.add(toTaskAnnotation(method, plugin, annotation)) + /** * Turn all the static and dynamic tasks into plug-in tasks, which are then suitable to be executed. */ @@ -246,12 +262,11 @@ public class TaskManager @Inject constructor(val args: Args) { } private fun addStaticTasks(projects: List) { - staticTasks.forEach { staticTask -> + taskAnnotations.forEach { staticTask -> val method = staticTask.method - val annotation = staticTask.taskAnnotation val methodName = method.declaringClass.toString() + "." + method.name - log(3, " Found task:${annotation.name} method: $methodName") + log(3, " Found task:${staticTask.name} method: $methodName") fun toTask(m: Method, project: Project, plugin: IPlugin): (Project) -> TaskResult { val result: (Project) -> TaskResult = { @@ -262,12 +277,13 @@ public class TaskManager @Inject constructor(val args: Args) { val plugin = staticTask.plugin projects.filter { plugin.accept(it) }.forEach { project -> - addStaticTask(plugin, project, staticTask.taskAnnotation, toTask(method, project, plugin)) + addStaticTask(plugin, project, staticTask, toTask(method, project, plugin)) } } } - private fun addStaticTask(plugin: IPlugin, project: Project, annotation: Task, task: (Project) -> TaskResult) { + private fun addStaticTask(plugin: IPlugin, project: Project, annotation: TaskAnnotation, + task: (Project) -> TaskResult) { addTask(plugin, project, annotation.name, annotation.description, annotation.runBefore.toList(), annotation.runAfter.toList(), annotation.alwaysRunAfter.toList(), task) } diff --git a/src/main/kotlin/com/beust/kobalt/app/BuildScriptUtil.kt b/src/main/kotlin/com/beust/kobalt/app/BuildScriptUtil.kt index 1d5f407d..e6b49b32 100644 --- a/src/main/kotlin/com/beust/kobalt/app/BuildScriptUtil.kt +++ b/src/main/kotlin/com/beust/kobalt/app/BuildScriptUtil.kt @@ -87,7 +87,7 @@ class BuildScriptUtil @Inject constructor(val plugins: Plugins, val files: KFile } else { val taskAnnotation = method.getAnnotation(Task::class.java) if (taskAnnotation != null) { - taskManager.staticTasks.add(TaskManager.StaticTask(defaultPlugin, method, taskAnnotation)) + taskManager.addStaticTask(defaultPlugin, method, taskAnnotation) } }}