Search in sources :

Example 11 with PluginDependencyInformation

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);
}
Also used : PluginDependencyResult(com.qcadoo.plugin.api.PluginDependencyResult) PluginDependencyInformation(com.qcadoo.plugin.api.PluginDependencyInformation) HashSet(java.util.HashSet) Plugin(com.qcadoo.plugin.api.Plugin)

Example 12 with PluginDependencyInformation

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);
}
Also used : PluginDependencyInformation(com.qcadoo.plugin.api.PluginDependencyInformation) HashSet(java.util.HashSet) Plugin(com.qcadoo.plugin.api.Plugin)

Example 13 with PluginDependencyInformation

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;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) PluginDependencyInformation(com.qcadoo.plugin.api.PluginDependencyInformation) Plugin(com.qcadoo.plugin.api.Plugin) HashSet(java.util.HashSet)

Example 14 with PluginDependencyInformation

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());
}
Also used : PluginDependencyResult(com.qcadoo.plugin.api.PluginDependencyResult) PluginDependencyInformation(com.qcadoo.plugin.api.PluginDependencyInformation) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) Test(org.junit.Test)

Example 15 with PluginDependencyInformation

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());
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) PluginDependencyResult(com.qcadoo.plugin.api.PluginDependencyResult) VersionOfDependency(com.qcadoo.plugin.api.VersionOfDependency) PluginDependencyInformation(com.qcadoo.plugin.api.PluginDependencyInformation) HashSet(java.util.HashSet) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) Test(org.junit.Test)

Aggregations

PluginDependencyInformation (com.qcadoo.plugin.api.PluginDependencyInformation)36 Plugin (com.qcadoo.plugin.api.Plugin)28 PluginDependencyResult (com.qcadoo.plugin.api.PluginDependencyResult)28 Test (org.junit.Test)28 InternalPlugin (com.qcadoo.plugin.internal.api.InternalPlugin)24 HashSet (java.util.HashSet)24 VersionOfDependency (com.qcadoo.plugin.api.VersionOfDependency)10 ArrayList (java.util.ArrayList)8 PluginOperationResult (com.qcadoo.plugin.api.PluginOperationResult)4 SimplePluginStatusResolver (com.qcadoo.plugin.internal.dependencymanager.SimplePluginStatusResolver)4 Version (com.qcadoo.plugin.api.Version)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 QcadooPluginPlugin (com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin)1 DefaultPlugin (com.qcadoo.plugin.internal.DefaultPlugin)1 PluginException (com.qcadoo.plugin.internal.PluginException)1 File (java.io.File)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1