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

Better cycle detection.

This commit is contained in:
Cedric Beust 2015-11-26 20:16:07 -08:00
parent 31994102ae
commit 4a2e33d777

View file

@ -93,6 +93,10 @@ public class DynamicGraphExecutor<T>(val graph: DynamicGraph<T>,
} }
} }
executor.shutdown() executor.shutdown()
if (graph.freeNodes.size == 0 && graph.nodesReady.size > 0) {
throw KobaltException("Couldn't find any free nodes but a few nodes still haven't run, there is " +
"a cycle in the dependencies.\n Nodes left: " + graph.dump(graph.nodesReady))
}
return if (lastResult.success) 0 else 1 return if (lastResult.success) 0 else 1
} }
} }
@ -101,7 +105,7 @@ public class DynamicGraphExecutor<T>(val graph: DynamicGraph<T>,
* Representation of the graph of methods. * Representation of the graph of methods.
*/ */
public class DynamicGraph<T> { public class DynamicGraph<T> {
private val nodesReady = linkedSetOf<T>() val nodesReady = linkedSetOf<T>()
private val nodesRunning = linkedSetOf<T>() private val nodesRunning = linkedSetOf<T>()
private val nodesFinished = linkedSetOf<T>() private val nodesFinished = linkedSetOf<T>()
private val nodesInError = linkedSetOf<T>() private val nodesInError = linkedSetOf<T>()
@ -258,21 +262,23 @@ public class DynamicGraph<T> {
val nodes = hashSetOf<T>() val nodes = hashSetOf<T>()
fun dump() : String { fun dump(nodes: Collection<T>) : String {
val result = StringBuffer() val result = StringBuffer()
val free = arrayListOf<T>() val free = arrayListOf<T>()
nodesReady.forEach { node -> nodes.forEach { node ->
val d = dependedUpon.get(node) val d = dependedUpon.get(node)
if (d == null || d.isEmpty()) { if (d == null || d.isEmpty()) {
free.add(node) free.add(node)
} }
} }
result.append("Free: $free").append("\n Dependencies:\n") result.append("Free nodes: $free").append("\n Dependent nodes:\n")
dependedUpon.keySet().forEach { nodes.forEach {
result.append(" $it -> ${dependedUpon.get(it)}\n") result.append(" $it -> ${dependedUpon.get(it)}\n")
} }
return result.toString() return result.toString()
} }
fun dump() = dump(nodesReady)
} }