I've been given a task to process several RPM package names from a file, uninstall them (if necessary) with a 'cascading delete' option and then install in the reverse order. For example, if there're packages a
, b
, and c
, where c
depends on b
and b
depends on a
, the uninstallation order should be c, b, a
and installation order a, b, c
.
After some thinking, it appears that one way to do this is to build a dependency graph and then sort on the degree of a vertex. So far, I've found 2 libraries, JGraphT and Grph, both promising but with pitiful or non-existent code samples. The former has a org.jgrapht.alg.util.VertexDegreeComparator
and the later grph.algo.sort. OutDegreeSorter
. Before I dig into the source code and try to figure out how to use those, I'm wondering if there are better ways to do this (including algorithm and libraries)? The number of packages is not going to be huge (< 100), so performance is not a big concern. Maintenance of the code I'll write, is.
Hasty duplicate call out alert: I read this thread and it is not what I'm looking for. The poster there is asking how to build a dependency graph, which is not my question.