简体   繁体   English

如何在Java中对依赖图进行排序?

[英]How to Sort a Dependency Graph in Java?

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. 我已获得一项任务,可以处理文件中的几个RPM软件包名称,使用“级联删除”选项将其卸载(如有必要),然后以相反的顺序进行安装。 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 . 例如,如果有程序包abc ,其中c取决于bb取决于a ,则卸载顺序应为c, b, a ,安装顺序应为c, b, aa, 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. 到目前为止,我已经找到了两个库JGraphTGrph ,它们都很有希望,但是它们的代码样本很少根本不存在。 The former has a org.jgrapht.alg.util.VertexDegreeComparator and the later grph.algo.sort. OutDegreeSorter 前者具有org.jgrapht.alg.util.VertexDegreeComparator ,而后者具有grph.algo.sort. OutDegreeSorter grph.algo.sort. OutDegreeSorter . 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. 软件包的数量不会很大(<100),因此性能并不是一个大问题。 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. 那里的发布者正在询问如何构建依赖关系图,这不是我的问题。

Instead of building a dependency graph myself, I decided to use yum for local package installation as below: 我决定自己使用yum进行本地软件包安装,而不是自己构建依赖关系图,如下所示:

PKGS=$(find "$RPM_DIR" -iname "*.rpm" -type f -exec rpm -qp --qf "%{NAME} " {} \; | sed 's/ $//')
RPMS=$(find "$RPM_DIR" -iname "*.rpm" -type f | awk '{print}' ORS=' ')

if [ "$INTERACTIVE" != true ]; then
  sudo yum -y --disablerepo=* remove $PKGS
  sudo yum -y --nogpgcheck localinstall $RPMS
else
  sudo yum --disablerepo=* remove $PKGS
  sudo yum --nogpgcheck localinstall $RPMS
fi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM