mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-02-27 00:40:51 +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 ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user