mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-27 08:38:13 -07:00
runBefore/After experiment.
This commit is contained in:
parent
e831d33b82
commit
d2a739a171
4 changed files with 32 additions and 19 deletions
|
@ -33,13 +33,9 @@ public interface Plugin {
|
||||||
return TaskResult2(taskResult.success, this)
|
return TaskResult2(taskResult.success, this)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
runBefore.forEach { dependsOn(it, name) }
|
runBefore.forEach { taskManager.runBefore(it, name) }
|
||||||
runAfter.forEach { dependsOn(name, it) }
|
runAfter.forEach { taskManager.runBefore(name, it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
var taskManager : TaskManager
|
var taskManager : TaskManager
|
||||||
|
|
||||||
fun dependsOn(task1: String, task2: String) {
|
|
||||||
taskManager.dependsOn(task1, task2)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,8 @@ abstract public class PluginTask : Callable<TaskResult2<PluginTask>> {
|
||||||
open val name: String = ""
|
open val name: String = ""
|
||||||
open val doc: String = ""
|
open val doc: String = ""
|
||||||
abstract val project: Project
|
abstract val project: Project
|
||||||
val dependsOn = arrayListOf<String>()
|
val runBefore = arrayListOf<String>()
|
||||||
|
val runAfter = arrayListOf<String>()
|
||||||
|
|
||||||
override public fun toString() : String {
|
override public fun toString() : String {
|
||||||
return ToString("PluginTask", "id", project.name + ":" + name).s
|
return ToString("PluginTask", "id", project.name + ":" + name).s
|
||||||
|
|
|
@ -14,14 +14,19 @@ import javax.inject.Singleton
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class TaskManager @Inject constructor(val plugins: Plugins, val args: Args) : KobaltLogger {
|
public class TaskManager @Inject constructor(val plugins: Plugins, val args: Args) : KobaltLogger {
|
||||||
private val dependentTaskMap = TreeMultimap.create<String, String>()
|
private val runBefore = TreeMultimap.create<String, String>()
|
||||||
|
private val runAfter= TreeMultimap.create<String, String>()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by plugins to indicate task dependencies defined at runtime. Keys depend on values.
|
* Called by plugins to indicate task dependencies defined at runtime. Keys depend on values.
|
||||||
* Declare that `task1` depends on `task2`.
|
* Declare that `task1` depends on `task2`.
|
||||||
*/
|
*/
|
||||||
fun dependsOn(task1: String, task2: String) {
|
fun runBefore(task1: String, task2: String) {
|
||||||
dependentTaskMap.put(task1, task2)
|
runBefore.put(task1, task2)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun runAfter(task1: String, task2: String) {
|
||||||
|
runAfter.put(task1, task2)
|
||||||
}
|
}
|
||||||
|
|
||||||
class TaskInfo(val id: String) {
|
class TaskInfo(val id: String) {
|
||||||
|
@ -47,22 +52,22 @@ public class TaskManager @Inject constructor(val plugins: Plugins, val args: Arg
|
||||||
//
|
//
|
||||||
plugins.allTasks.filter { it.project.name == project.name }.forEach { rt ->
|
plugins.allTasks.filter { it.project.name == project.name }.forEach { rt ->
|
||||||
tasksByNames.put(rt.name, rt)
|
tasksByNames.put(rt.name, rt)
|
||||||
if (rt.dependsOn.size() > 0) {
|
if (rt.runBefore.size() > 0) {
|
||||||
rt.dependsOn.forEach { d ->
|
rt.runBefore.forEach { d ->
|
||||||
dependentTaskMap.put(rt.name, d)
|
runBefore.put(rt.name, d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val freeTaskMap = hashMapOf<String, PluginTask>()
|
val freeTaskMap = hashMapOf<String, PluginTask>()
|
||||||
tasksByNames.keySet().forEach {
|
tasksByNames.keySet().forEach {
|
||||||
if (!dependentTaskMap.containsKey(it)) freeTaskMap.put(it, tasksByNames.get(it).elementAt(0))
|
if (! runBefore.containsKey(it)) freeTaskMap.put(it, tasksByNames.get(it).elementAt(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
log(2, "Free tasks: ${freeTaskMap.keySet()}")
|
log(2, "Free tasks: ${freeTaskMap.keySet()}")
|
||||||
log(2, "Dependent tasks:")
|
log(2, "Dependent tasks:")
|
||||||
dependentTaskMap.keySet().forEach { t ->
|
runBefore.keySet().forEach { t ->
|
||||||
log(2, " ${t} -> ${dependentTaskMap.get(t)}}")
|
log(2, " ${t} -> ${runBefore.get(t)}}")
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -102,7 +107,7 @@ public class TaskManager @Inject constructor(val plugins: Plugins, val args: Arg
|
||||||
throw KobaltException("Unknown task: ${target}")
|
throw KobaltException("Unknown task: ${target}")
|
||||||
}
|
}
|
||||||
tasks.forEach { task ->
|
tasks.forEach { task ->
|
||||||
val dependencyNames = dependentTaskMap.get(task.name)
|
val dependencyNames = runBefore.get(task.name)
|
||||||
dependencyNames.forEach { dependencyName ->
|
dependencyNames.forEach { dependencyName ->
|
||||||
if (!seen.contains(dependencyName)) {
|
if (!seen.contains(dependencyName)) {
|
||||||
newToProcess.add(dependencyName)
|
newToProcess.add(dependencyName)
|
||||||
|
@ -127,7 +132,7 @@ public class TaskManager @Inject constructor(val plugins: Plugins, val args: Arg
|
||||||
//
|
//
|
||||||
val graph = DynamicGraph<PluginTask>()
|
val graph = DynamicGraph<PluginTask>()
|
||||||
freeTaskMap.values().filter { transitiveClosure.contains(it.name) } forEach { graph.addNode(it) }
|
freeTaskMap.values().filter { transitiveClosure.contains(it.name) } forEach { graph.addNode(it) }
|
||||||
dependentTaskMap.entries().filter {
|
runBefore.entries().filter {
|
||||||
transitiveClosure.contains(it.key)
|
transitiveClosure.contains(it.key)
|
||||||
}.forEach { entry ->
|
}.forEach { entry ->
|
||||||
plugins.findTasks(entry.key).filter { it.project.name == project.name }.forEach { from ->
|
plugins.findTasks(entry.key).filter { it.project.name == project.name }.forEach { from ->
|
||||||
|
|
|
@ -3,12 +3,15 @@ package com.beust.kobalt.plugin.kotlin
|
||||||
import com.beust.kobalt.Plugins
|
import com.beust.kobalt.Plugins
|
||||||
import com.beust.kobalt.api.ICompilerInfo
|
import com.beust.kobalt.api.ICompilerInfo
|
||||||
import com.beust.kobalt.api.Kobalt
|
import com.beust.kobalt.api.Kobalt
|
||||||
|
import com.beust.kobalt.api.KobaltContext
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
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.internal.JvmCompilerPlugin
|
import com.beust.kobalt.internal.JvmCompilerPlugin
|
||||||
import com.beust.kobalt.internal.TaskResult
|
import com.beust.kobalt.internal.TaskResult
|
||||||
|
import com.beust.kobalt.internal.TaskResult2
|
||||||
import com.beust.kobalt.maven.*
|
import com.beust.kobalt.maven.*
|
||||||
|
import com.beust.kobalt.misc.KFiles
|
||||||
import com.beust.kobalt.misc.KobaltExecutors
|
import com.beust.kobalt.misc.KobaltExecutors
|
||||||
import com.beust.kobalt.misc.KobaltLogger
|
import com.beust.kobalt.misc.KobaltLogger
|
||||||
import com.beust.kobalt.plugin.java.JavaProject
|
import com.beust.kobalt.plugin.java.JavaProject
|
||||||
|
@ -19,7 +22,7 @@ import javax.inject.Singleton
|
||||||
@Singleton
|
@Singleton
|
||||||
public class KotlinPlugin @Inject constructor(
|
public class KotlinPlugin @Inject constructor(
|
||||||
override val localRepo: LocalRepo,
|
override val localRepo: LocalRepo,
|
||||||
override val files: com.beust.kobalt.misc.KFiles,
|
override val files: KFiles,
|
||||||
override val depFactory: DepFactory,
|
override val depFactory: DepFactory,
|
||||||
override val dependencyManager: DependencyManager,
|
override val dependencyManager: DependencyManager,
|
||||||
override val executors: KobaltExecutors)
|
override val executors: KobaltExecutors)
|
||||||
|
@ -29,6 +32,14 @@ public class KotlinPlugin @Inject constructor(
|
||||||
Kobalt.registerCompiler(KotlinCompilerInfo())
|
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 {
|
companion object {
|
||||||
public const val TASK_COMPILE: String = "compile"
|
public const val TASK_COMPILE: String = "compile"
|
||||||
public const val TASK_COMPILE_TEST: String = "compileTest"
|
public const val TASK_COMPILE_TEST: String = "compileTest"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue