mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 00:45:44 +01:00
Add detection of circular dependencies
This commit is contained in:
@@ -51,7 +51,7 @@ import java.util.Set;
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public final class ExplodedSmp implements Comparable<ExplodedSmp>
|
||||
public final class ExplodedSmp
|
||||
{
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ExplodedSmp.class);
|
||||
@@ -90,60 +90,6 @@ public final class ExplodedSmp implements Comparable<ExplodedSmp>
|
||||
return new ExplodedSmp(directory, Plugins.parsePluginDescriptor(desc));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int compareTo(ExplodedSmp o)
|
||||
{
|
||||
int result;
|
||||
|
||||
Set<String> depends = plugin.getDependenciesInclusiveOptionals();
|
||||
Set<String> odepends = o.plugin.getDependenciesInclusiveOptionals();
|
||||
|
||||
if (depends.isEmpty() && odepends.isEmpty())
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
else if (depends.isEmpty() &&!odepends.isEmpty())
|
||||
{
|
||||
result = -1;
|
||||
}
|
||||
else if (!depends.isEmpty() && odepends.isEmpty())
|
||||
{
|
||||
result = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
String id = plugin.getInformation().getName(false);
|
||||
String oid = o.plugin.getInformation().getName(false);
|
||||
|
||||
if (depends.contains(oid) && odepends.contains(id))
|
||||
{
|
||||
StringBuilder b = new StringBuilder("circular dependency detected: ");
|
||||
|
||||
b.append(id).append(" depends on ").append(oid).append(" and ");
|
||||
b.append(oid).append(" depends on ").append(id);
|
||||
|
||||
throw new PluginCircularDependencyException(b.toString());
|
||||
}
|
||||
else if (depends.contains(oid))
|
||||
{
|
||||
result = 999;
|
||||
}
|
||||
else if (odepends.contains(id))
|
||||
{
|
||||
result = -999;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user