}
moduleNumbers.add(count);
count++;
}
DependencyGraph graph = new DependencyGraph(proposedModules.size());
int fromModule = 0;
for (Module proposedModule : proposedModules) {
if ((proposedModule.getUses() == null) || (proposedModule.getUses().isEmpty())) {
fromModule++;
continue;
}
SortedSet<Integer> dependentModuleNumbers = new TreeSet<Integer>();
for (String use : proposedModule.getUses()) {
SortedSet<Integer> moduleNumbers = proposedModuleNames.get(use);
if (moduleNumbers == null) {
continue;
}
dependentModuleNumbers.addAll(moduleNumbers);
}
dependentModuleNumbers.remove(fromModule);
graph.addDependency(fromModule, dependentModuleNumbers);
fromModule++;
}
if (options.isCheckCircularDependency()) {
Stack<Integer> circular = graph.getFirstCircularDependency();
if (circular != null) {
String message = "";
String delimiter = "";
for (int i : circular) {
message += delimiter;
message += "module '" + proposedModules.get(i).getName() + "'";
delimiter = " uses (depends on) ";
}
throw new DeploymentOrderException("Circular dependency detected in module uses-relationships: " + message);
}
}
List<Module> reverseDeployList = new ArrayList<Module>();
Set<Integer> ignoreList = new HashSet<Integer>();
while(ignoreList.size() < proposedModules.size()) {
// seconardy sort according to the order of listing
Set<Integer> rootNodes = new TreeSet<Integer>(new Comparator<Integer>() {
public int compare(Integer o1, Integer o2)
{
return -1 * o1.compareTo(o2);
}
});
rootNodes.addAll(graph.getRootNodes(ignoreList));
if (rootNodes.isEmpty()) { // circular dependency could cause this
for (int i = 0; i < proposedModules.size(); i++) {
if (!ignoreList.contains(i)) {
rootNodes.add(i);