mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-10-25 13:30:10 +00:00
fix circular dependency checking
This commit is contained in:
1 parent
84537e2f99
commit
7bf1ba13c8
4 files changed
+17
-11
No files matched your search
Submodule common/addons/config-distributors updated: 63f9078601...56bac92799.
Submodule common/addons/config-feature updated: 648e8a7006...d2cd833fcf.
Submodule common/addons/config-locators updated: 9aca4dad90...bf177a6c93.
@@ -42,25 +42,31 @@ public class DependencySorter {
|
|||||||
|
|
||||||
sortDependencies(dependency, sort);
|
sortDependencies(dependency, sort);
|
||||||
|
|
||||||
if(sort.contains(dependency)) {
|
|
||||||
throw new CircularDependencyException(
|
|
||||||
"Addon " + addon.getID() + " has circular dependency beginning with " + dependency.getID());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
sort.add(dependency); // add it to the list.
|
sort.add(dependency); // add it to the list.
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkDependencies(BaseAddon base, BaseAddon current) {
|
||||||
|
current.getDependencies().forEach((id, range) -> {
|
||||||
|
BaseAddon dependency = addons.get(id);
|
||||||
|
if(dependency.getID().equals(base.getID())) {
|
||||||
|
throw new CircularDependencyException(
|
||||||
|
"Addon " + base.getID() + " has circular dependency beginning with " + dependency.getID());
|
||||||
|
}
|
||||||
|
checkDependencies(base, dependency);
|
||||||
|
});
|
||||||
|
}
|
||||||
public List<BaseAddon> sort() {
|
public List<BaseAddon> sort() {
|
||||||
List<BaseAddon> sorted = new ArrayList<>();
|
List<BaseAddon> sorted = new ArrayList<>();
|
||||||
|
|
||||||
for(int i = addonList.size() - 1; i >= 0; i--) {
|
for(int i = addonList.size() - 1; i >= 0; i--) {
|
||||||
BaseAddon addon = addonList.get(i);
|
BaseAddon addon = addonList.get(i);
|
||||||
|
|
||||||
|
checkDependencies(addon, addon);
|
||||||
|
|
||||||
addonList.remove(i);
|
addonList.remove(i);
|
||||||
|
|
||||||
System.out.println(addon.getID() + ": " + visited.get(addon.getID()));
|
|
||||||
if(!visited.get(addon.getID())) {
|
if(!visited.get(addon.getID())) {
|
||||||
sortDependencies(addon, sorted);
|
sortDependencies(addon, sorted);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user