mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 00:17:11 -07:00
Optimize graph run.
This commit is contained in:
parent
6c1afbfd99
commit
814777e553
2 changed files with 29 additions and 35 deletions
|
@ -4,6 +4,7 @@ import com.beust.kobalt.misc.NamedThreadFactory
|
|||
import com.beust.kobalt.misc.ToString
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.google.common.collect.ArrayListMultimap
|
||||
import com.google.common.collect.HashMultimap
|
||||
import java.util.concurrent.*
|
||||
|
||||
open class TaskResult2<T>(success: Boolean, val value: T) : TaskResult(success) {
|
||||
|
@ -88,8 +89,8 @@ public class DynamicGraph<T> {
|
|||
private val nodesFinished = linkedSetOf<T>()
|
||||
private val nodesInError = linkedSetOf<T>()
|
||||
private val nodesSkipped = linkedSetOf<T>()
|
||||
private val dependedUpon = ArrayListMultimap.create<T, T>()
|
||||
private val dependingOn = ArrayListMultimap.create<T, T>()
|
||||
private val dependedUpon = HashMultimap.create<T, T>()
|
||||
private val dependingOn = HashMultimap.create<T, T>()
|
||||
|
||||
/**
|
||||
* Define a comparator for the nodes of this graph, which will be used
|
||||
|
@ -156,7 +157,7 @@ public class DynamicGraph<T> {
|
|||
/**
|
||||
* @return a list of all the nodes that have a status other than FINISHED.
|
||||
*/
|
||||
private fun getUnfinishedNodes(nodes: List<T>) : Collection<T> {
|
||||
private fun getUnfinishedNodes(nodes: Set<T>) : Collection<T> {
|
||||
val result = hashSetOf<T>()
|
||||
nodes.forEach { node ->
|
||||
if (nodesReady.contains(node) || nodesRunning.contains(node)) {
|
||||
|
|
|
@ -45,7 +45,6 @@ public class TaskManager @Inject constructor(val plugins: Plugins, val args: Arg
|
|||
|
||||
public fun runTargets(targets: List<String>, projects: List<Project>) : Int {
|
||||
var result = 0
|
||||
val tasksAlreadyRun = hashSetOf<String>()
|
||||
projects.forEach { project ->
|
||||
val projectName = project.name!!
|
||||
val tasksByNames = hashMapOf<String, PluginTask>()
|
||||
|
@ -59,8 +58,8 @@ public class TaskManager @Inject constructor(val plugins: Plugins, val args: Arg
|
|||
log(1, " Building project ${project.name}")
|
||||
log(1, "")
|
||||
|
||||
val graph = DynamicGraph<PluginTask>()
|
||||
targets.forEach { target ->
|
||||
val graph = DynamicGraph<PluginTask>()
|
||||
|
||||
val ti = TaskInfo(target)
|
||||
if (ti.matches(projectName)) {
|
||||
|
@ -84,10 +83,7 @@ public class TaskManager @Inject constructor(val plugins: Plugins, val args: Arg
|
|||
if (currentFreeTask.size() == 1) {
|
||||
currentFreeTask.get(0).let {
|
||||
val thisTaskInfo = TaskInfo(projectName, it.name)
|
||||
if (! tasksAlreadyRun.contains(thisTaskInfo.id)) {
|
||||
graph.addNode(it)
|
||||
tasksAlreadyRun.add(thisTaskInfo.id)
|
||||
}
|
||||
graph.addNode(it)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,11 +96,7 @@ public class TaskManager @Inject constructor(val plugins: Plugins, val args: Arg
|
|||
rb.forEach {
|
||||
val to = tasksByNames.get(it)
|
||||
if (to != null) {
|
||||
val taskInfo = TaskInfo(projectName, to.name)
|
||||
if (! tasksAlreadyRun.contains(taskInfo.id)) {
|
||||
graph.addEdge(pluginTask, to)
|
||||
tasksAlreadyRun.add(taskInfo.id)
|
||||
}
|
||||
graph.addEdge(pluginTask, to)
|
||||
} else {
|
||||
throw KobaltException("Should have found $it")
|
||||
}
|
||||
|
@ -125,29 +117,30 @@ public class TaskManager @Inject constructor(val plugins: Plugins, val args: Arg
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
log(2, "About to run graph:\n ${graph.dump()} ")
|
||||
|
||||
//
|
||||
// Now that we have a full graph, run it
|
||||
//
|
||||
val factory = object : IThreadWorkerFactory<PluginTask> {
|
||||
override public fun createWorkers(nodes: List<PluginTask>): List<IWorker<PluginTask>> {
|
||||
val result = arrayListOf<IWorker<PluginTask>>()
|
||||
nodes.forEach {
|
||||
result.add(TaskWorker(arrayListOf(it), args.dryRun))
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
val executor = DynamicGraphExecutor(graph, factory)
|
||||
val thisResult = executor.run()
|
||||
if (result == 0) {
|
||||
result = thisResult
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Now that we have a full graph, run it
|
||||
//
|
||||
log(2, "About to run graph:\n ${graph.dump()} ")
|
||||
|
||||
val factory = object : IThreadWorkerFactory<PluginTask> {
|
||||
override public fun createWorkers(nodes: List<PluginTask>): List<IWorker<PluginTask>> {
|
||||
val result = arrayListOf<IWorker<PluginTask>>()
|
||||
nodes.forEach {
|
||||
result.add(TaskWorker(arrayListOf(it), args.dryRun))
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
val executor = DynamicGraphExecutor(graph, factory)
|
||||
val thisResult = executor.run()
|
||||
if (result == 0) {
|
||||
result = thisResult
|
||||
}
|
||||
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue