mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 15:05:44 +01:00
Fix double loading of plugins (PluginProcessor#appendPluginWrapper)
Additionally: Add logging.
This commit is contained in:
@@ -34,6 +34,8 @@ package sonia.scm.plugin;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
@@ -52,17 +54,18 @@ import java.util.Set;
|
||||
public final class ExplodedSmp implements Comparable<ExplodedSmp>
|
||||
{
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ExplodedSmp.class);
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param path
|
||||
* @param pluginId
|
||||
* @param dependencies
|
||||
* @param plugin
|
||||
*/
|
||||
ExplodedSmp(Path path, Plugin plugin)
|
||||
{
|
||||
logger.trace("create exploded scm for plugin {} and dependencies {}", plugin.getInformation().getName(), plugin.getDependencies());
|
||||
this.path = path;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@@ -175,6 +175,11 @@ public final class PluginNode
|
||||
this.wrapper = wrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return plugin.getPath().toString() + " -> " + children;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
|
||||
@@ -162,34 +162,29 @@ public final class PluginProcessor
|
||||
|
||||
Set<Path> archives = collect(pluginDirectory, new PluginArchiveFilter());
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("extract {} archives", archives.size());
|
||||
}
|
||||
logger.debug("extract {} archives", archives.size());
|
||||
|
||||
extract(archives);
|
||||
|
||||
List<Path> dirs = collectPluginDirectories(pluginDirectory);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("process {} directories", dirs.size());
|
||||
}
|
||||
logger.debug("process {} directories: {}", dirs.size(), dirs);
|
||||
|
||||
List<ExplodedSmp> smps = Lists.transform(dirs, new PathTransformer());
|
||||
|
||||
logger.trace("start building plugin tree");
|
||||
|
||||
List<PluginNode> rootNodes = new PluginTree(smps).getRootNodes();
|
||||
PluginTree pluginTree = new PluginTree(smps);
|
||||
|
||||
logger.trace("build plugin tree: {}", pluginTree);
|
||||
|
||||
List<PluginNode> rootNodes = pluginTree.getRootNodes();
|
||||
|
||||
logger.trace("create plugin wrappers and build classloaders");
|
||||
|
||||
Set<PluginWrapper> wrappers = createPluginWrappers(classLoader, rootNodes);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("collected {} plugins", wrappers.size());
|
||||
}
|
||||
logger.debug("collected {} plugins", wrappers.size());
|
||||
|
||||
return ImmutableSet.copyOf(wrappers);
|
||||
}
|
||||
@@ -208,6 +203,9 @@ public final class PluginProcessor
|
||||
ClassLoader classLoader, PluginNode node)
|
||||
throws IOException
|
||||
{
|
||||
if (node.getWrapper() != null) {
|
||||
return;
|
||||
}
|
||||
ExplodedSmp smp = node.getPlugin();
|
||||
|
||||
List<ClassLoader> parents = Lists.newArrayList();
|
||||
|
||||
@@ -112,14 +112,14 @@ public final class PluginTree
|
||||
}
|
||||
else
|
||||
{
|
||||
appendNode(rootNodes, dependencies, smp);
|
||||
appendNode(smp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//J-
|
||||
throw new PluginConditionFailedException(
|
||||
condition,
|
||||
condition,
|
||||
String.format(
|
||||
"could not load plugin %s, the plugin condition does not match",
|
||||
plugin.getInformation().getId()
|
||||
@@ -149,23 +149,20 @@ public final class PluginTree
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param nodes
|
||||
* @param dependencies
|
||||
* @param smp
|
||||
*/
|
||||
private void appendNode(List<PluginNode> nodes, Set<String> dependencies,
|
||||
ExplodedSmp smp)
|
||||
private void appendNode(ExplodedSmp smp)
|
||||
{
|
||||
PluginNode child = new PluginNode(smp);
|
||||
|
||||
for (String dependency : dependencies)
|
||||
for (String dependency : smp.getPlugin().getDependencies())
|
||||
{
|
||||
if (!appendNode(nodes, child, dependency))
|
||||
if (!appendNode(rootNodes, child, dependency))
|
||||
{
|
||||
//J-
|
||||
throw new PluginNotInstalledException(
|
||||
String.format(
|
||||
"dependency %s of %s is not installed",
|
||||
"dependency %s of %s is not installed",
|
||||
dependency,
|
||||
child.getId()
|
||||
)
|
||||
@@ -188,7 +185,7 @@ public final class PluginTree
|
||||
private boolean appendNode(List<PluginNode> nodes, PluginNode child,
|
||||
String dependency)
|
||||
{
|
||||
logger.debug("check for {} {}", dependency, child.getId());
|
||||
logger.debug("check for {} as dependency of {}", dependency, child.getId());
|
||||
|
||||
boolean found = false;
|
||||
|
||||
@@ -196,29 +193,28 @@ public final class PluginTree
|
||||
{
|
||||
if (node.getId().equals(dependency))
|
||||
{
|
||||
logger.debug("add plugin {} as child of {}", child.getId(),
|
||||
node.getId());
|
||||
logger.debug("add plugin {} as child of {}", child.getId(), node.getId());
|
||||
node.addChild(child);
|
||||
found = true;
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
else if (appendNode(node.getChildren(), child, dependency))
|
||||
{
|
||||
if (appendNode(node.getChildren(), child, dependency))
|
||||
{
|
||||
found = true;
|
||||
|
||||
break;
|
||||
}
|
||||
found = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
@Override
|
||||
public String toString() {
|
||||
return "plugin tree: " + rootNodes.toString();
|
||||
}
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private final List<PluginNode> rootNodes = Lists.newArrayList();
|
||||
|
||||
Reference in New Issue
Block a user