mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-27 00:38:11 -07:00
First pass at adding incremental tasks.
This commit is contained in:
parent
fdbbc8ebde
commit
8883055337
5 changed files with 46 additions and 10 deletions
|
@ -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)
|
|
@ -6,10 +6,10 @@ import com.beust.kobalt.internal.PluginInfo
|
||||||
import com.beust.kobalt.internal.TaskManager
|
import com.beust.kobalt.internal.TaskManager
|
||||||
import com.beust.kobalt.maven.DepFactory
|
import com.beust.kobalt.maven.DepFactory
|
||||||
import com.beust.kobalt.maven.LocalRepo
|
import com.beust.kobalt.maven.LocalRepo
|
||||||
|
import com.beust.kobalt.misc.JarUtils
|
||||||
import com.beust.kobalt.misc.KFiles
|
import com.beust.kobalt.misc.KFiles
|
||||||
import com.beust.kobalt.misc.KobaltExecutors
|
import com.beust.kobalt.misc.KobaltExecutors
|
||||||
import com.beust.kobalt.misc.log
|
import com.beust.kobalt.misc.log
|
||||||
import com.beust.kobalt.misc.JarUtils
|
|
||||||
import com.google.inject.Provider
|
import com.google.inject.Provider
|
||||||
import java.lang.reflect.Method
|
import java.lang.reflect.Method
|
||||||
import java.lang.reflect.Modifier
|
import java.lang.reflect.Modifier
|
||||||
|
@ -82,7 +82,7 @@ public class Plugins @Inject constructor (val taskManagerProvider : Provider<Tas
|
||||||
}
|
}
|
||||||
val annotation = it.second
|
val annotation = it.second
|
||||||
|
|
||||||
taskManager.staticTasks.add(TaskManager.StaticTask(plugin, it.first, annotation))
|
taskManager.addStaticTask(plugin, it.first, annotation)
|
||||||
}
|
}
|
||||||
|
|
||||||
currentClass = currentClass.superclass
|
currentClass = currentClass.superclass
|
||||||
|
|
|
@ -21,6 +21,21 @@ annotation class Task(
|
||||||
val alwaysRunAfter: Array<String> = arrayOf()
|
val alwaysRunAfter: Array<String> = arrayOf()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
annotation class IncrementalTask(
|
||||||
|
val name: String,
|
||||||
|
val description: String = "",
|
||||||
|
|
||||||
|
/** Tasks that this task depends on */
|
||||||
|
val runBefore: Array<String> = arrayOf(),
|
||||||
|
|
||||||
|
/** Tasks that this task will run after if they get run */
|
||||||
|
val runAfter: Array<String> = arrayOf(),
|
||||||
|
|
||||||
|
/** Tasks that this task will always run after */
|
||||||
|
val alwaysRunAfter: Array<String> = arrayOf()
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugins that export properties should annotate those with this annotation so they can be documented.
|
* Plugins that export properties should annotate those with this annotation so they can be documented.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.beust.kobalt.api.DynamicTask
|
||||||
import com.beust.kobalt.api.IPlugin
|
import com.beust.kobalt.api.IPlugin
|
||||||
import com.beust.kobalt.api.PluginTask
|
import com.beust.kobalt.api.PluginTask
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
|
import com.beust.kobalt.api.annotation.IncrementalTask
|
||||||
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.common.collect.ArrayListMultimap
|
import com.google.common.collect.ArrayListMultimap
|
||||||
|
@ -220,13 +221,28 @@ public class TaskManager @Inject constructor(val args: Args) {
|
||||||
// Manage the tasks
|
// 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<TaskAnnotation>()
|
||||||
|
class TaskAnnotation(val method: Method, val plugin: IPlugin, val name: String, val description: String,
|
||||||
|
val runBefore: Array<String>, val runAfter: Array<String>, val alwaysRunAfter: Array<String>)
|
||||||
|
|
||||||
|
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)
|
class PluginDynamicTask(val plugin: IPlugin, val task: DynamicTask)
|
||||||
|
|
||||||
val tasks = arrayListOf<PluginTask>()
|
val tasks = arrayListOf<PluginTask>()
|
||||||
val staticTasks = arrayListOf<StaticTask>()
|
|
||||||
val dynamicTasks = arrayListOf<PluginDynamicTask>()
|
val dynamicTasks = arrayListOf<PluginDynamicTask>()
|
||||||
|
|
||||||
|
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.
|
* 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<Project>) {
|
private fun addStaticTasks(projects: List<Project>) {
|
||||||
staticTasks.forEach { staticTask ->
|
taskAnnotations.forEach { staticTask ->
|
||||||
val method = staticTask.method
|
val method = staticTask.method
|
||||||
val annotation = staticTask.taskAnnotation
|
|
||||||
|
|
||||||
val methodName = method.declaringClass.toString() + "." + method.name
|
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 {
|
fun toTask(m: Method, project: Project, plugin: IPlugin): (Project) -> TaskResult {
|
||||||
val result: (Project) -> TaskResult = {
|
val result: (Project) -> TaskResult = {
|
||||||
|
@ -262,12 +277,13 @@ public class TaskManager @Inject constructor(val args: Args) {
|
||||||
|
|
||||||
val plugin = staticTask.plugin
|
val plugin = staticTask.plugin
|
||||||
projects.filter { plugin.accept(it) }.forEach { project ->
|
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(),
|
addTask(plugin, project, annotation.name, annotation.description, annotation.runBefore.toList(),
|
||||||
annotation.runAfter.toList(), annotation.alwaysRunAfter.toList(), task)
|
annotation.runAfter.toList(), annotation.alwaysRunAfter.toList(), task)
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,7 @@ class BuildScriptUtil @Inject constructor(val plugins: Plugins, val files: KFile
|
||||||
} else {
|
} else {
|
||||||
val taskAnnotation = method.getAnnotation(Task::class.java)
|
val taskAnnotation = method.getAnnotation(Task::class.java)
|
||||||
if (taskAnnotation != null) {
|
if (taskAnnotation != null) {
|
||||||
taskManager.staticTasks.add(TaskManager.StaticTask(defaultPlugin, method, taskAnnotation))
|
taskManager.addStaticTask(defaultPlugin, method, taskAnnotation)
|
||||||
}
|
}
|
||||||
|
|
||||||
}}
|
}}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue