diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java b/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java index bdedc88..af85f1f 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java @@ -746,6 +746,8 @@ public class DefaultPluginManager implements PluginManager { pluginStateListeners = new ArrayList<>(); + dependencyResolver = new DependencyResolver(); + log.info("PF4J version {} in '{}' mode", getVersion(), getRuntimeMode()); pluginClasspath = createPluginClasspath(); @@ -853,7 +855,7 @@ public class DefaultPluginManager implements PluginManager { } private void resolveDependencies() throws PluginException { - dependencyResolver = new DependencyResolver(unresolvedPlugins); + dependencyResolver.resolve(unresolvedPlugins); resolvedPlugins = dependencyResolver.getSortedPlugins(); for (PluginWrapper pluginWrapper : resolvedPlugins) { unresolvedPlugins.remove(pluginWrapper); diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/DependencyResolver.java b/pf4j/src/main/java/ro/fortsoft/pf4j/DependencyResolver.java index 176245e..e281495 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/DependencyResolver.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/DependencyResolver.java @@ -15,14 +15,14 @@ */ package ro.fortsoft.pf4j; -import java.util.ArrayList; -import java.util.List; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import ro.fortsoft.pf4j.util.DirectedGraph; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + /** * @author Decebal Suiu */ @@ -33,18 +33,29 @@ public class DependencyResolver { private List plugins; private DirectedGraph dependenciesGraph; private DirectedGraph dependentsGraph; + private boolean resolved; - public DependencyResolver(List plugins) { + public void resolve(List plugins) { this.plugins = plugins; initGraph(); + + resolved = true; } public List getDependecies(String pluginsId) { + if (!resolved) { + return Collections.emptyList(); + } + return dependenciesGraph.getNeighbors(pluginsId); } public List getDependents(String pluginsId) { + if (!resolved) { + return Collections.emptyList(); + } + return dependentsGraph.getNeighbors(pluginsId); } @@ -52,6 +63,10 @@ public class DependencyResolver { * Get the list of plugins in dependency sorted order. */ public List getSortedPlugins() throws PluginException { + if (!resolved) { + return Collections.emptyList(); + } + log.debug("Graph: {}", dependenciesGraph); List pluginsId = dependenciesGraph.reverseTopologicalSort();