use of com.qcadoo.plugin.api.PluginDependencyInformation in project qcadoo by qcadoo.
the class DefaultPluginDependencyManager method getDependenciesToEnable.
private PluginDependencyResult getDependenciesToEnable(final List<Plugin> plugins, final Set<String> marked, final DirectedGraph<String, DefaultEdge> graph, final PluginStatusResolver pluginStatusResolver) {
Set<PluginDependencyInformation> disabledDependencies = new HashSet<PluginDependencyInformation>();
Set<PluginDependencyInformation> unsatisfiedDependencies = new HashSet<PluginDependencyInformation>();
Set<String> argumentPluginIdentifiersSet = getArgumentIdentifiersSet(plugins);
for (Plugin plugin : plugins) {
if (marked.contains(plugin.getIdentifier())) {
continue;
}
marked.add(plugin.getIdentifier());
graph.addVertex(plugin.getIdentifier());
for (PluginDependencyInformation dependencyInfo : plugin.getRequiredPlugins()) {
Plugin requiredPlugin = pluginAccessor.getPlugin(dependencyInfo.getIdentifier());
if (requiredPlugin == null) {
if (!argumentPluginIdentifiersSet.contains(dependencyInfo.getIdentifier())) {
unsatisfiedDependencies.add(dependencyInfo);
}
continue;
}
graph.addVertex(dependencyInfo.getIdentifier());
graph.addEdge(plugin.getIdentifier(), dependencyInfo.getIdentifier());
if (!isPluginDisabled(requiredPlugin, pluginStatusResolver)) {
continue;
}
if (dependencyInfo.contains(requiredPlugin.getVersion())) {
disabledDependencies.add(dependencyInfo);
PluginDependencyResult nextLevelDependencioesResult = getDependenciesToEnable(Collections.singletonList(requiredPlugin), marked, graph, pluginStatusResolver);
if (!nextLevelDependencioesResult.getUnsatisfiedDependencies().isEmpty() || nextLevelDependencioesResult.isCyclic()) {
return nextLevelDependencioesResult;
}
disabledDependencies.addAll(nextLevelDependencioesResult.getDependenciesToEnable());
} else {
unsatisfiedDependencies.add(dependencyInfo);
}
}
}
if (!unsatisfiedDependencies.isEmpty()) {
return PluginDependencyResultImpl.unsatisfiedDependencies(unsatisfiedDependencies);
}
if (disabledDependencies.isEmpty()) {
return PluginDependencyResultImpl.satisfiedDependencies();
}
Iterator<PluginDependencyInformation> dependencyInfoIterator = disabledDependencies.iterator();
while (dependencyInfoIterator.hasNext()) {
if (argumentPluginIdentifiersSet.contains(dependencyInfoIterator.next().getIdentifier())) {
dependencyInfoIterator.remove();
}
}
return PluginDependencyResultImpl.dependenciesToEnable(disabledDependencies);
}
use of com.qcadoo.plugin.api.PluginDependencyInformation in project qcadoo by qcadoo.
the class DefaultPluginDependencyManager method getDependenciesToUpdate.
@Override
public PluginDependencyResult getDependenciesToUpdate(final Plugin existingPlugin, final Plugin newPlugin, final PluginStatusResolver pluginStatusResolver) {
Set<PluginDependencyInformation> dependentPlugins = getDependentPlugins(Collections.singletonList(existingPlugin), false, pluginStatusResolver);
Set<PluginDependencyInformation> dependenciesToDisableUnsatisfiedAfterUpdate = new HashSet<PluginDependencyInformation>();
for (Plugin plugin : pluginAccessor.getPlugins()) {
if (pluginStatusResolver.isPluginNotInstalled(plugin)) {
continue;
}
for (PluginDependencyInformation dependencyInfo : plugin.getRequiredPlugins()) {
if (dependencyInfo.getIdentifier().equals(existingPlugin.getIdentifier())) {
if (!dependencyInfo.contains(newPlugin.getVersion())) {
dependenciesToDisableUnsatisfiedAfterUpdate.add(new PluginDependencyInformation(plugin.getIdentifier()));
}
break;
}
}
}
return PluginDependencyResultImpl.dependenciesToUpdate(dependentPlugins, dependenciesToDisableUnsatisfiedAfterUpdate);
}
use of com.qcadoo.plugin.api.PluginDependencyInformation in project qcadoo by qcadoo.
the class DefaultPluginDependencyManager method createPluginsMapWithDependencies.
private Map<String, Set<String>> createPluginsMapWithDependencies(final Collection<Plugin> plugins) {
Map<String, Set<String>> resultMap = new HashMap<String, Set<String>>();
for (Plugin plugin : plugins) {
resultMap.put(plugin.getIdentifier(), null);
}
for (Plugin plugin : plugins) {
Set<String> dependencyIdentifiers = new HashSet<String>();
for (PluginDependencyInformation dependency : plugin.getRequiredPlugins()) {
if (resultMap.containsKey(dependency.getIdentifier())) {
dependencyIdentifiers.add(dependency.getIdentifier());
}
}
resultMap.put(plugin.getIdentifier(), dependencyIdentifiers);
}
return resultMap;
}
use of com.qcadoo.plugin.api.PluginDependencyInformation in project qcadoo by qcadoo.
the class PluginDependencyManagerTest method shouldReturnSingleDisabledDependencyForOnePlugin.
@Test
public void shouldReturnSingleDisabledDependencyForOnePlugin() throws Exception {
// given
given(plugin2.getState()).willReturn(PluginState.DISABLED);
given(pluginAccessor.getPlugin("testPlugin2")).willReturn(plugin2);
given(plugin1.getRequiredPlugins()).willReturn(Collections.singleton(dependencyInfo2));
// when
PluginDependencyResult result = manager.getDependenciesToEnable(singletonList((Plugin) plugin1), pluginStatusResolver);
// then
assertFalse(result.isCyclic());
assertEquals(1, result.getDependenciesToEnable().size());
assertTrue(result.getDependenciesToEnable().contains(new PluginDependencyInformation("testPlugin2")));
assertEquals(0, result.getUnsatisfiedDependencies().size());
assertEquals(0, result.getDependenciesToDisable().size());
}
use of com.qcadoo.plugin.api.PluginDependencyInformation in project qcadoo by qcadoo.
the class PluginDependencyManagerTest method shouldReturnUnsatisfiedDependenciesForOnePluginWhenNoDependencyPluginFoundOrVersionIsNotMet.
@Test
public void shouldReturnUnsatisfiedDependenciesForOnePluginWhenNoDependencyPluginFoundOrVersionIsNotMet() throws Exception {
// given
given(plugin1.getState()).willReturn(PluginState.DISABLED);
given(plugin1.getIdentifier()).willReturn("testPlugin1");
given(plugin2.getState()).willReturn(PluginState.TEMPORARY);
given(plugin2.getIdentifier()).willReturn("testPlugin2");
given(plugin3.getState()).willReturn(PluginState.TEMPORARY);
given(plugin3.getIdentifier()).willReturn("testPlugin3");
given(pluginAccessor.getPlugin("testPlugin1")).willReturn(plugin1);
given(pluginAccessor.getPlugin("testPlugin2")).willReturn(plugin2);
given(pluginAccessor.getPlugin("testPlugin3")).willReturn(plugin3);
given(pluginAccessor.getPlugin("testPlugin4")).willReturn(null);
dependencyInfo3 = new PluginDependencyInformation("testPlugin3", new VersionOfDependency("[2"));
InternalPlugin pluginToEnable = mock(InternalPlugin.class);
Set<PluginDependencyInformation> disabledRequiredPlugins = new HashSet<PluginDependencyInformation>();
disabledRequiredPlugins.add(dependencyInfo1);
disabledRequiredPlugins.add(dependencyInfo2);
disabledRequiredPlugins.add(dependencyInfo3);
disabledRequiredPlugins.add(dependencyInfo4);
given(pluginToEnable.getRequiredPlugins()).willReturn(disabledRequiredPlugins);
given(pluginToEnable.getIdentifier()).willReturn("plugin");
// when
PluginDependencyResult result = manager.getDependenciesToEnable(singletonList((Plugin) pluginToEnable), pluginStatusResolver);
// then
assertFalse(result.isCyclic());
assertEquals(0, result.getDependenciesToEnable().size());
assertEquals(2, result.getUnsatisfiedDependencies().size());
assertTrue(result.getUnsatisfiedDependencies().contains(new PluginDependencyInformation("testPlugin3", new VersionOfDependency("[2"))));
assertTrue(result.getUnsatisfiedDependencies().contains(new PluginDependencyInformation("testPlugin4")));
assertEquals(0, result.getDependenciesToDisable().size());
}
Aggregations