mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 00:45:44 +01:00
Fix plugin load order
The old algorithm failed, because the tree below lead to the issue, that
the scm-branchwp-plugin was loaded before the scm-review-plugin was
ready.
This commit changes the order in the way, that leafs are loaded last.
+- scm-editor-plugin d
+- scm-branchwp-plugin a
+- scm-mail-plugin c
+- scm-review-plugin b
+- scm-branchwp-plugin a
+- scm-branchwp-plugin a
This commit is contained in:
@@ -191,11 +191,11 @@ public final class PluginProcessor
|
||||
|
||||
logger.info("install plugin tree:\n{}", pluginTree);
|
||||
|
||||
List<PluginNode> rootNodes = pluginTree.getRootNodes();
|
||||
List<PluginNode> leafLastNodes = pluginTree.getLeafLastNodes();
|
||||
|
||||
logger.trace("create plugin wrappers and build classloaders");
|
||||
|
||||
Set<InstalledPlugin> wrappers = createPluginWrappers(classLoader, rootNodes);
|
||||
Set<InstalledPlugin> wrappers = createPluginWrappers(classLoader, leafLastNodes);
|
||||
|
||||
logger.debug("collected {} plugins", wrappers.size());
|
||||
|
||||
@@ -259,33 +259,6 @@ public final class PluginProcessor
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param plugins
|
||||
* @param classLoader
|
||||
* @param nodes
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
private void appendPluginWrappers(Set<InstalledPlugin> plugins,
|
||||
ClassLoader classLoader, List<PluginNode> nodes)
|
||||
throws IOException
|
||||
{
|
||||
|
||||
// TODO fix plugin loading order
|
||||
for (PluginNode node : nodes)
|
||||
{
|
||||
appendPluginWrapper(plugins, classLoader, node);
|
||||
}
|
||||
|
||||
for (PluginNode node : nodes)
|
||||
{
|
||||
appendPluginWrappers(plugins, classLoader, node.getChildren());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -484,19 +457,22 @@ public final class PluginProcessor
|
||||
*
|
||||
*
|
||||
* @param classLoader
|
||||
* @param rootNodes
|
||||
* @param nodes
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
private Set<InstalledPlugin> createPluginWrappers(ClassLoader classLoader,
|
||||
List<PluginNode> rootNodes)
|
||||
List<PluginNode> nodes)
|
||||
throws IOException
|
||||
{
|
||||
Set<InstalledPlugin> plugins = Sets.newHashSet();
|
||||
|
||||
appendPluginWrappers(plugins, classLoader, rootNodes);
|
||||
for (PluginNode node : nodes)
|
||||
{
|
||||
appendPluginWrapper(plugins, classLoader, node);
|
||||
}
|
||||
|
||||
return plugins;
|
||||
}
|
||||
|
||||
@@ -39,6 +39,8 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
@@ -134,13 +136,26 @@ public final class PluginTree
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<PluginNode> getRootNodes()
|
||||
public List<PluginNode> getLeafLastNodes()
|
||||
{
|
||||
return rootNodes;
|
||||
LinkedHashSet<PluginNodeHashWrapper> leafFirst = new LinkedHashSet<>();
|
||||
|
||||
rootNodes.forEach(node -> appendLeafFirst(leafFirst, node));
|
||||
|
||||
LinkedList<PluginNode> leafLast = new LinkedList<>();
|
||||
|
||||
leafFirst.stream().map(PluginNodeHashWrapper::getPluginNode).forEach(leafLast::addFirst);
|
||||
|
||||
return leafLast;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
private void appendLeafFirst(LinkedHashSet<PluginNodeHashWrapper> leafFirst, PluginNode node) {
|
||||
node.getChildren().forEach(child -> appendLeafFirst(leafFirst, child));
|
||||
leafFirst.add(new PluginNodeHashWrapper(node));
|
||||
}
|
||||
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -235,8 +250,32 @@ public final class PluginTree
|
||||
append(buffer, indent + " ", child);
|
||||
}
|
||||
}
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private final List<PluginNode> rootNodes = Lists.newArrayList();
|
||||
|
||||
private static class PluginNodeHashWrapper {
|
||||
private final PluginNode pluginNode;
|
||||
|
||||
private PluginNodeHashWrapper(PluginNode pluginNode) {
|
||||
this.pluginNode = pluginNode;
|
||||
}
|
||||
|
||||
public PluginNode getPluginNode() {
|
||||
return pluginNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return pluginNode.getId().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof PluginNodeHashWrapper
|
||||
&& ((PluginNodeHashWrapper) obj).pluginNode.getId().equals(this.pluginNode.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user