1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -07:00

Optimize graph run.

This commit is contained in:
Cedric Beust 2015-10-15 03:27:18 -07:00
parent 6c1afbfd99
commit 814777e553
2 changed files with 29 additions and 35 deletions

View file

@ -4,6 +4,7 @@ import com.beust.kobalt.misc.NamedThreadFactory
import com.beust.kobalt.misc.ToString import com.beust.kobalt.misc.ToString
import com.beust.kobalt.misc.log import com.beust.kobalt.misc.log
import com.google.common.collect.ArrayListMultimap import com.google.common.collect.ArrayListMultimap
import com.google.common.collect.HashMultimap
import java.util.concurrent.* import java.util.concurrent.*
open class TaskResult2<T>(success: Boolean, val value: T) : TaskResult(success) { 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 nodesFinished = linkedSetOf<T>()
private val nodesInError = linkedSetOf<T>() private val nodesInError = linkedSetOf<T>()
private val nodesSkipped = linkedSetOf<T>() private val nodesSkipped = linkedSetOf<T>()
private val dependedUpon = ArrayListMultimap.create<T, T>() private val dependedUpon = HashMultimap.create<T, T>()
private val dependingOn = ArrayListMultimap.create<T, T>() private val dependingOn = HashMultimap.create<T, T>()
/** /**
* Define a comparator for the nodes of this graph, which will be used * 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. * @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>() val result = hashSetOf<T>()
nodes.forEach { node -> nodes.forEach { node ->
if (nodesReady.contains(node) || nodesRunning.contains(node)) { if (nodesReady.contains(node) || nodesRunning.contains(node)) {

View file

@ -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 { public fun runTargets(targets: List<String>, projects: List<Project>) : Int {
var result = 0 var result = 0
val tasksAlreadyRun = hashSetOf<String>()
projects.forEach { project -> projects.forEach { project ->
val projectName = project.name!! val projectName = project.name!!
val tasksByNames = hashMapOf<String, PluginTask>() 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, " Building project ${project.name}")
log(1, "") log(1, "")
targets.forEach { target ->
val graph = DynamicGraph<PluginTask>() val graph = DynamicGraph<PluginTask>()
targets.forEach { target ->
val ti = TaskInfo(target) val ti = TaskInfo(target)
if (ti.matches(projectName)) { if (ti.matches(projectName)) {
@ -84,10 +83,7 @@ public class TaskManager @Inject constructor(val plugins: Plugins, val args: Arg
if (currentFreeTask.size() == 1) { if (currentFreeTask.size() == 1) {
currentFreeTask.get(0).let { currentFreeTask.get(0).let {
val thisTaskInfo = TaskInfo(projectName, it.name) val thisTaskInfo = TaskInfo(projectName, it.name)
if (! tasksAlreadyRun.contains(thisTaskInfo.id)) {
graph.addNode(it) graph.addNode(it)
tasksAlreadyRun.add(thisTaskInfo.id)
}
} }
} }
@ -100,11 +96,7 @@ public class TaskManager @Inject constructor(val plugins: Plugins, val args: Arg
rb.forEach { rb.forEach {
val to = tasksByNames.get(it) val to = tasksByNames.get(it)
if (to != null) { if (to != null) {
val taskInfo = TaskInfo(projectName, to.name)
if (! tasksAlreadyRun.contains(taskInfo.id)) {
graph.addEdge(pluginTask, to) graph.addEdge(pluginTask, to)
tasksAlreadyRun.add(taskInfo.id)
}
} else { } else {
throw KobaltException("Should have found $it") throw KobaltException("Should have found $it")
} }
@ -125,12 +117,14 @@ 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 // Now that we have a full graph, run it
// //
log(2, "About to run graph:\n ${graph.dump()} ")
val factory = object : IThreadWorkerFactory<PluginTask> { val factory = object : IThreadWorkerFactory<PluginTask> {
override public fun createWorkers(nodes: List<PluginTask>): List<IWorker<PluginTask>> { override public fun createWorkers(nodes: List<PluginTask>): List<IWorker<PluginTask>> {
val result = arrayListOf<IWorker<PluginTask>>() val result = arrayListOf<IWorker<PluginTask>>()
@ -146,8 +140,7 @@ public class TaskManager @Inject constructor(val plugins: Plugins, val args: Arg
if (result == 0) { if (result == 0) {
result = thisResult result = thisResult
} }
}
}
} }
return result return result
} }