|
|
@ -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(); |
|
|
|
|
|
|
|
|
|
|
|