Topological sort is actually very easy to implement, just a few lines of code. `hudson.util.CyclicGraphDetector` does it (in a rather verbose way, to provide good error detection I guess).