aboutsummaryrefslogtreecommitdiffstats
path: root/pf4j
diff options
context:
space:
mode:
authorDecebal Suiu <decebal.suiu@gmail.com>2015-06-05 18:09:17 +0300
committerDecebal Suiu <decebal.suiu@gmail.com>2015-06-05 18:09:17 +0300
commite15946819670226c8d38def7950c01a641ebb288 (patch)
tree10784c00e5a1e1cd5a8b4b3f8f4f9fe5e5979cd2 /pf4j
parent9416698908e273f1eafe6d186a544efade1bca00 (diff)
downloadpf4j-e15946819670226c8d38def7950c01a641ebb288.tar.gz
pf4j-e15946819670226c8d38def7950c01a641ebb288.zip
little preparation for #42
Diffstat (limited to 'pf4j')
-rw-r--r--pf4j/src/main/java/ro/fortsoft/pf4j/DependencyResolver.java38
1 files changed, 23 insertions, 15 deletions
diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/DependencyResolver.java b/pf4j/src/main/java/ro/fortsoft/pf4j/DependencyResolver.java
index 21ddf5d..022d46e 100644
--- a/pf4j/src/main/java/ro/fortsoft/pf4j/DependencyResolver.java
+++ b/pf4j/src/main/java/ro/fortsoft/pf4j/DependencyResolver.java
@@ -28,29 +28,18 @@ class DependencyResolver {
private static final Logger log = LoggerFactory.getLogger(DependencyResolver.class);
private List<PluginWrapper> plugins;
+ private DirectedGraph<String> graph;
public DependencyResolver(List<PluginWrapper> plugins) {
this.plugins = plugins;
+
+ initGraph();
}
/**
* Get the list of plugins in dependency sorted order.
*/
public List<PluginWrapper> getSortedPlugins() throws PluginException {
- DirectedGraph<String> graph = new DirectedGraph<>();
- for (PluginWrapper pluginWrapper : plugins) {
- PluginDescriptor descriptor = pluginWrapper.getDescriptor();
- String pluginId = descriptor.getPluginId();
- List<PluginDependency> dependencies = descriptor.getDependencies();
- if (!dependencies.isEmpty()) {
- for (PluginDependency dependency : dependencies) {
- graph.addEdge(pluginId, dependency.getPluginId());
- }
- } else {
- graph.addVertex(pluginId);
- }
- }
-
log.debug("Graph: {}", graph);
List<String> pluginsId = graph.reverseTopologicalSort();
@@ -67,7 +56,26 @@ class DependencyResolver {
return sortedPlugins;
}
- private PluginWrapper getPlugin(String pluginId) throws PluginNotFoundException {
+ private void initGraph() {
+ // create graph
+ graph = new DirectedGraph<>();
+
+ // populate graph
+ for (PluginWrapper pluginWrapper : plugins) {
+ PluginDescriptor descriptor = pluginWrapper.getDescriptor();
+ String pluginId = descriptor.getPluginId();
+ List<PluginDependency> dependencies = descriptor.getDependencies();
+ if (!dependencies.isEmpty()) {
+ for (PluginDependency dependency : dependencies) {
+ graph.addEdge(pluginId, dependency.getPluginId());
+ }
+ } else {
+ graph.addVertex(pluginId);
+ }
+ }
+ }
+
+ private PluginWrapper getPlugin(String pluginId) throws PluginNotFoundException {
for (PluginWrapper pluginWrapper : plugins) {
if (pluginId.equals(pluginWrapper.getDescriptor().getPluginId())) {
return pluginWrapper;