Add detection of circular dependencies

This commit is contained in:
Rene Pfeuffer
2020-01-31 12:27:02 +01:00
parent f92ea41ca3
commit 931133353d
5 changed files with 28 additions and 228 deletions

View File

@@ -29,6 +29,8 @@ class SmpNodeBuilder {
otherNode.addChild(node);
}
});
nodes.forEach(this::checkForCircle);
});
return nodes;
@@ -47,4 +49,18 @@ class SmpNodeBuilder {
}
});
}
private void checkForCircle(PluginNode pluginNode) {
pluginNode.getChildren().forEach(child -> assertDoesNotContainsDependency(pluginNode, child));
}
private void assertDoesNotContainsDependency(PluginNode pluginNode, PluginNode childNode) {
if (childNode == pluginNode) {
throw new PluginCircularDependencyException("circular dependency detected: " +
childNode.getId() + " depends on " + pluginNode.getId() + " and " +
pluginNode.getId() + " depends on " + childNode.getId()
);
}
childNode.getChildren().forEach(child -> assertDoesNotContainsDependency(pluginNode, child));
}
}