private PluginFactory pluginFactory;
private ExtensionFactory extensionFactory;
private PluginStatusProvider pluginStatusProvider;
+ private DependencyResolver dependencyResolver;
/**
* The plugins repository.
*/
@Override
public PluginState stopPlugin(String pluginId) {
+ return stopPlugin(pluginId, true);
+ }
+
+ private PluginState stopPlugin(String pluginId, boolean stopDependents) {
if (!plugins.containsKey(pluginId)) {
throw new IllegalArgumentException(String.format("Unknown pluginId %s", pluginId));
}
return pluginState;
}
- for (PluginDependency dependency : pluginDescriptor.getDependencies()) {
- stopPlugin(dependency.getPluginId());
- }
+ if (stopDependents) {
+ List<String> dependents = dependencyResolver.getDependents(pluginId);
+ while (!dependents.isEmpty()) {
+ String dependent = dependents.remove(0);
+ stopPlugin(dependent, false);
+ dependents.addAll(dependencyResolver.getDependents(dependent));
+ }
+ }
try {
log.info("Stop plugin '{}:{}'", pluginDescriptor.getPluginId(), pluginDescriptor.getVersion());
}
private void resolveDependencies() throws PluginException {
- DependencyResolver dependencyResolver = new DependencyResolver(unresolvedPlugins);
+ dependencyResolver = new DependencyResolver(unresolvedPlugins);
resolvedPlugins = dependencyResolver.getSortedPlugins();
for (PluginWrapper pluginWrapper : resolvedPlugins) {
unresolvedPlugins.remove(pluginWrapper);
private static final Logger log = LoggerFactory.getLogger(DependencyResolver.class);
private List<PluginWrapper> plugins;
- private DirectedGraph<String> graph;
+ private DirectedGraph<String> dependenciesGraph;
+ private DirectedGraph<String> dependentsGraph;
public DependencyResolver(List<PluginWrapper> plugins) {
this.plugins = plugins;
initGraph();
}
+ public List<String> getDependecies(String pluginsId) {
+ return dependenciesGraph.getNeighbors(pluginsId);
+ }
+
+ public List<String> getDependents(String pluginsId) {
+ return dependentsGraph.getNeighbors(pluginsId);
+ }
+
/**
* Get the list of plugins in dependency sorted order.
*/
public List<PluginWrapper> getSortedPlugins() throws PluginException {
- log.debug("Graph: {}", graph);
- List<String> pluginsId = graph.reverseTopologicalSort();
+ log.debug("Graph: {}", dependenciesGraph);
+ List<String> pluginsId = dependenciesGraph.reverseTopologicalSort();
if (pluginsId == null) {
- throw new CyclicDependencyException("Cyclic dependencies !!!" + graph.toString());
+ throw new CyclicDependencyException("Cyclic dependencies !!!" + dependenciesGraph.toString());
}
log.debug("Plugins order: {}", pluginsId);
private void initGraph() {
// create graph
- graph = new DirectedGraph<>();
+ dependenciesGraph = new DirectedGraph<>();
+ dependentsGraph = new DirectedGraph<>();
// populate graph
for (PluginWrapper pluginWrapper : plugins) {
List<PluginDependency> dependencies = descriptor.getDependencies();
if (!dependencies.isEmpty()) {
for (PluginDependency dependency : dependencies) {
- graph.addEdge(pluginId, dependency.getPluginId());
+ dependenciesGraph.addEdge(pluginId, dependency.getPluginId());
+ dependentsGraph.addEdge(dependency.getPluginId(), pluginId);
}
} else {
- graph.addVertex(pluginId);
+ dependenciesGraph.addVertex(pluginId);
+ dependentsGraph.addVertex(pluginId);
}
}
}