Browse Source

Fix #99

pull/104/head
Decebal Suiu 9 years ago
parent
commit
fbf096655c
  1. 4
      pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java
  2. 25
      pf4j/src/main/java/ro/fortsoft/pf4j/DependencyResolver.java

4
pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java

@ -746,6 +746,8 @@ public class DefaultPluginManager implements PluginManager {
pluginStateListeners = new ArrayList<>(); pluginStateListeners = new ArrayList<>();
dependencyResolver = new DependencyResolver();
log.info("PF4J version {} in '{}' mode", getVersion(), getRuntimeMode()); log.info("PF4J version {} in '{}' mode", getVersion(), getRuntimeMode());
pluginClasspath = createPluginClasspath(); pluginClasspath = createPluginClasspath();
@ -853,7 +855,7 @@ public class DefaultPluginManager implements PluginManager {
} }
private void resolveDependencies() throws PluginException { private void resolveDependencies() throws PluginException {
dependencyResolver = new DependencyResolver(unresolvedPlugins); dependencyResolver.resolve(unresolvedPlugins);
resolvedPlugins = dependencyResolver.getSortedPlugins(); resolvedPlugins = dependencyResolver.getSortedPlugins();
for (PluginWrapper pluginWrapper : resolvedPlugins) { for (PluginWrapper pluginWrapper : resolvedPlugins) {
unresolvedPlugins.remove(pluginWrapper); unresolvedPlugins.remove(pluginWrapper);

25
pf4j/src/main/java/ro/fortsoft/pf4j/DependencyResolver.java

@ -15,14 +15,14 @@
*/ */
package ro.fortsoft.pf4j; package ro.fortsoft.pf4j;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import ro.fortsoft.pf4j.util.DirectedGraph; import ro.fortsoft.pf4j.util.DirectedGraph;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/** /**
* @author Decebal Suiu * @author Decebal Suiu
*/ */
@ -33,18 +33,29 @@ public class DependencyResolver {
private List<PluginWrapper> plugins; private List<PluginWrapper> plugins;
private DirectedGraph<String> dependenciesGraph; private DirectedGraph<String> dependenciesGraph;
private DirectedGraph<String> dependentsGraph; private DirectedGraph<String> dependentsGraph;
private boolean resolved;
public DependencyResolver(List<PluginWrapper> plugins) { public void resolve(List<PluginWrapper> plugins) {
this.plugins = plugins; this.plugins = plugins;
initGraph(); initGraph();
resolved = true;
} }
public List<String> getDependecies(String pluginsId) { public List<String> getDependecies(String pluginsId) {
if (!resolved) {
return Collections.emptyList();
}
return dependenciesGraph.getNeighbors(pluginsId); return dependenciesGraph.getNeighbors(pluginsId);
} }
public List<String> getDependents(String pluginsId) { public List<String> getDependents(String pluginsId) {
if (!resolved) {
return Collections.emptyList();
}
return dependentsGraph.getNeighbors(pluginsId); return dependentsGraph.getNeighbors(pluginsId);
} }
@ -52,6 +63,10 @@ public class DependencyResolver {
* Get the list of plugins in dependency sorted order. * Get the list of plugins in dependency sorted order.
*/ */
public List<PluginWrapper> getSortedPlugins() throws PluginException { public List<PluginWrapper> getSortedPlugins() throws PluginException {
if (!resolved) {
return Collections.emptyList();
}
log.debug("Graph: {}", dependenciesGraph); log.debug("Graph: {}", dependenciesGraph);
List<String> pluginsId = dependenciesGraph.reverseTopologicalSort(); List<String> pluginsId = dependenciesGraph.reverseTopologicalSort();

Loading…
Cancel
Save