Search in sources :

Example 31 with PluginDependencyInformation

use of com.qcadoo.plugin.api.PluginDependencyInformation in project qcadoo by qcadoo.

the class PluginDependencyInformationTest method shouldThrowExceptionWhenWrongVersions.

@Test
public void shouldThrowExceptionWhenWrongVersions() throws Exception {
    // when
    try {
        new PluginDependencyInformation("", new VersionOfDependency("[a1,1)"));
        Assert.fail();
    } catch (Exception e) {
        LOG.info("empty catch");
    }
    try {
        new PluginDependencyInformation("", new VersionOfDependency("[1,2s)"));
        Assert.fail();
    } catch (Exception e) {
        LOG.info("empty catch");
    }
    try {
        new PluginDependencyInformation("", new VersionOfDependency("[1.2.3.4,2s)"));
        Assert.fail();
    } catch (Exception e) {
        LOG.info("empty catch");
    }
    try {
        new PluginDependencyInformation("", new VersionOfDependency("[2,1.2.3.4)"));
        Assert.fail();
    } catch (Exception e) {
        LOG.info("empty catch");
    }
    try {
        new PluginDependencyInformation("", new VersionOfDependency("[1.1.1,1.1.0)"));
        Assert.fail();
    } catch (Exception e) {
        LOG.info("empty catch");
    }
    try {
        new PluginDependencyInformation("", new VersionOfDependency("(1.0.0,1]"));
        Assert.fail();
    } catch (Exception e) {
        LOG.info("empty catch");
    }
// then
}
Also used : VersionOfDependency(com.qcadoo.plugin.api.VersionOfDependency) PluginDependencyInformation(com.qcadoo.plugin.api.PluginDependencyInformation) Test(org.junit.Test)

Example 32 with PluginDependencyInformation

use of com.qcadoo.plugin.api.PluginDependencyInformation in project qcadoo by qcadoo.

the class PluginDependencyInformationTest method init.

@Before
public void init() {
    dependencyInformation1 = new PluginDependencyInformation("testPlugin1", new VersionOfDependency("[1,1.2.01)"));
    dependencyInformation2 = new PluginDependencyInformation("testPlugin2", new VersionOfDependency("2.2.01]"));
    dependencyInformation3 = new PluginDependencyInformation("testPlugin3", new VersionOfDependency("[1.2.10"));
    dependencyInformation4 = new PluginDependencyInformation("testPlugin4", new VersionOfDependency("(3.0.1,4.2]"));
    dependencyInformation5 = new PluginDependencyInformation("testPlugin5", new VersionOfDependency("[3.0.1,3.0.1]"));
}
Also used : VersionOfDependency(com.qcadoo.plugin.api.VersionOfDependency) PluginDependencyInformation(com.qcadoo.plugin.api.PluginDependencyInformation) Before(org.junit.Before)

Example 33 with PluginDependencyInformation

use of com.qcadoo.plugin.api.PluginDependencyInformation in project qcadoo by qcadoo.

the class PluginDependencyManagerTest method shouldCheckDependenciesDependenciesAndReturnMultipleDependencies.

@Test
public void shouldCheckDependenciesDependenciesAndReturnMultipleDependencies() throws Exception {
    // given
    Set<PluginDependencyInformation> disabledRequiredPlugins = new HashSet<PluginDependencyInformation>();
    disabledRequiredPlugins.add(dependencyInfo2);
    given(plugin1.getRequiredPlugins()).willReturn(disabledRequiredPlugins);
    given(plugin2.getState()).willReturn(PluginState.DISABLED);
    Set<PluginDependencyInformation> disabledRequiredPlugins2 = new HashSet<PluginDependencyInformation>();
    disabledRequiredPlugins2.add(dependencyInfo3);
    given(plugin2.getRequiredPlugins()).willReturn(disabledRequiredPlugins2);
    given(plugin3.getState()).willReturn(PluginState.TEMPORARY);
    given(pluginAccessor.getPlugin("testPlugin2")).willReturn(plugin2);
    given(pluginAccessor.getPlugin("testPlugin3")).willReturn(plugin3);
    // when
    PluginDependencyResult result = manager.getDependenciesToEnable(singletonList((Plugin) plugin1), pluginStatusResolver);
    // then
    assertFalse(result.isCyclic());
    assertEquals(2, result.getDependenciesToEnable().size());
    assertTrue(result.getDependenciesToEnable().contains(new PluginDependencyInformation("testPlugin2")));
    assertTrue(result.getDependenciesToEnable().contains(new PluginDependencyInformation("testPlugin3")));
    assertEquals(0, result.getUnsatisfiedDependencies().size());
    assertEquals(0, result.getDependenciesToDisable().size());
}
Also used : PluginDependencyResult(com.qcadoo.plugin.api.PluginDependencyResult) 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)

Example 34 with PluginDependencyInformation

use of com.qcadoo.plugin.api.PluginDependencyInformation in project qcadoo by qcadoo.

the class PluginDependencyManagerTest method shouldReturnValidResultForCyclicDependencies.

@Test
public void shouldReturnValidResultForCyclicDependencies() throws Exception {
    // given
    Set<PluginDependencyInformation> disabledRequiredPlugins1 = new HashSet<PluginDependencyInformation>();
    disabledRequiredPlugins1.add(dependencyInfo2);
    given(plugin1.getRequiredPlugins()).willReturn(disabledRequiredPlugins1);
    Set<PluginDependencyInformation> disabledRequiredPlugins2 = new HashSet<PluginDependencyInformation>();
    disabledRequiredPlugins2.add(dependencyInfo3);
    disabledRequiredPlugins2.add(dependencyInfo4);
    given(plugin2.getRequiredPlugins()).willReturn(disabledRequiredPlugins2);
    Set<PluginDependencyInformation> disabledRequiredPlugins3 = new HashSet<PluginDependencyInformation>();
    disabledRequiredPlugins3.add(dependencyInfo1);
    given(plugin3.getRequiredPlugins()).willReturn(disabledRequiredPlugins3);
    given(pluginAccessor.getPlugin("testPlugin1")).willReturn(plugin1);
    given(pluginAccessor.getPlugin("testPlugin2")).willReturn(plugin2);
    given(pluginAccessor.getPlugin("testPlugin3")).willReturn(plugin3);
    given(pluginAccessor.getPlugin("testPlugin4")).willReturn(plugin4);
    List<Plugin> plugins = new ArrayList<Plugin>();
    plugins.add(plugin1);
    plugins.add(plugin2);
    plugins.add(plugin3);
    // when
    PluginDependencyResult result = manager.getDependenciesToEnable(plugins, pluginStatusResolver);
    // then
    assertTrue(result.isCyclic());
    assertEquals(0, result.getDependenciesToEnable().size());
    assertEquals(0, result.getUnsatisfiedDependencies().size());
    assertEquals(0, result.getDependenciesToDisable().size());
}
Also used : PluginDependencyResult(com.qcadoo.plugin.api.PluginDependencyResult) ArrayList(java.util.ArrayList) 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)

Example 35 with PluginDependencyInformation

use of com.qcadoo.plugin.api.PluginDependencyInformation in project qcadoo by qcadoo.

the class DefaultPluginManager method installPlugin.

@Override
public PluginOperationResult installPlugin(final PluginArtifact pluginArtifact) {
    File pluginFile = null;
    try {
        pluginFile = pluginFileManager.uploadPlugin(pluginArtifact);
    } catch (PluginException e) {
        return PluginOperationResultImpl.cannotUploadPlugin();
    }
    Plugin plugin = null;
    try {
        plugin = pluginDescriptorParser.parse(pluginFile);
    } catch (PluginException e) {
        LOG.error(e.getMessage());
        pluginFileManager.uninstallPlugin(pluginFile.getName());
        return PluginOperationResultImpl.corruptedPlugin();
    }
    if (plugin.isSystemPlugin()) {
        pluginFileManager.uninstallPlugin(plugin.getFilename());
        return PluginOperationResultImpl.systemPluginUpdating();
    }
    boolean shouldRestart = false;
    PluginDependencyResult pluginDependencyResult = pluginDependencyManager.getDependenciesToEnable(newArrayList(plugin), pluginStatusResolver);
    if (pluginDependencyResult.isCyclic()) {
        pluginFileManager.uninstallPlugin(plugin.getFilename());
        return PluginOperationResultImpl.dependenciesCyclesExists();
    }
    Plugin existingPlugin = pluginAccessor.getPlugin(plugin.getIdentifier());
    if (existingPlugin == null) {
        ((InternalPlugin) plugin).changeStateTo(PluginState.TEMPORARY);
        pluginDao.save(plugin);
        pluginAccessor.savePlugin(plugin);
        if (!pluginDependencyResult.isDependenciesSatisfied() && !pluginDependencyResult.getUnsatisfiedDependencies().isEmpty()) {
            return PluginOperationResultImpl.successWithMissingDependencies(pluginDependencyResult);
        }
        return PluginOperationResultImpl.success();
    } else {
        if (existingPlugin.getVersion().compareTo(plugin.getVersion()) >= 0) {
            pluginFileManager.uninstallPlugin(plugin.getFilename());
            return PluginOperationResultImpl.cannotDowngradePlugin();
        }
        if (existingPlugin.hasState(PluginState.TEMPORARY)) {
            if (!pluginDependencyResult.isDependenciesSatisfied() && !pluginDependencyResult.getUnsatisfiedDependencies().isEmpty()) {
                pluginFileManager.uninstallPlugin(existingPlugin.getFilename());
                ((InternalPlugin) plugin).changeStateTo(existingPlugin.getState());
                pluginDao.save(plugin);
                pluginAccessor.savePlugin(plugin);
                return PluginOperationResultImpl.successWithMissingDependencies(pluginDependencyResult);
            }
            ((InternalPlugin) plugin).changeStateTo(existingPlugin.getState());
        } else if (existingPlugin.hasState(PluginState.DISABLED)) {
            if (!pluginDependencyResult.isDependenciesSatisfied() && !pluginDependencyResult.getUnsatisfiedDependencies().isEmpty()) {
                pluginFileManager.uninstallPlugin(plugin.getFilename());
                return PluginOperationResultImpl.unsatisfiedDependencies(pluginDependencyResult);
            }
            if (!pluginFileManager.installPlugin(plugin.getFilename())) {
                pluginFileManager.uninstallPlugin(plugin.getFilename());
                return PluginOperationResultImpl.cannotInstallPlugin();
            }
            shouldRestart = true;
            ((InternalPlugin) plugin).changeStateTo(existingPlugin.getState());
        } else if (existingPlugin.hasState(PluginState.ENABLED)) {
            if (!pluginDependencyResult.isDependenciesSatisfied()) {
                if (!pluginDependencyResult.getUnsatisfiedDependencies().isEmpty()) {
                    pluginFileManager.uninstallPlugin(plugin.getFilename());
                    return PluginOperationResultImpl.unsatisfiedDependencies(pluginDependencyResult);
                }
                if (!pluginDependencyResult.getDependenciesToEnable().isEmpty()) {
                    pluginFileManager.uninstallPlugin(plugin.getFilename());
                    return PluginOperationResultImpl.dependenciesToEnable(pluginDependencyResult);
                }
            }
            if (!pluginFileManager.installPlugin(plugin.getFilename())) {
                pluginFileManager.uninstallPlugin(plugin.getFilename());
                return PluginOperationResultImpl.cannotInstallPlugin();
            }
            shouldRestart = true;
            PluginDependencyResult installPluginDependencyResult = pluginDependencyManager.getDependenciesToUpdate(existingPlugin, plugin, pluginStatusResolver);
            if (!installPluginDependencyResult.getDependenciesToDisableUnsatisfiedAfterUpdate().isEmpty()) {
                pluginFileManager.uninstallPlugin(plugin.getFilename());
                return PluginOperationResultImpl.unsatisfiedDependenciesAfterUpdate(installPluginDependencyResult);
            }
            List<Plugin> dependencyPlugins = new ArrayList<Plugin>();
            for (PluginDependencyInformation pluginDependencyInformation : installPluginDependencyResult.getDependenciesToDisable()) {
                dependencyPlugins.add(pluginAccessor.getPlugin(pluginDependencyInformation.getIdentifier()));
            }
            dependencyPlugins = pluginDependencyManager.sortPluginsInDependencyOrder(dependencyPlugins);
            Collections.reverse(dependencyPlugins);
            for (Plugin dependencyPlugin : dependencyPlugins) {
                ((InternalPlugin) dependencyPlugin).changeStateTo(PluginState.DISABLED);
            }
            ((InternalPlugin) existingPlugin).changeStateTo(PluginState.DISABLED);
            ((InternalPlugin) plugin).changeStateTo(PluginState.ENABLING);
            Collections.reverse(dependencyPlugins);
            for (Plugin dependencyPlugin : dependencyPlugins) {
                ((InternalPlugin) dependencyPlugin).changeStateTo(PluginState.ENABLING);
                pluginDao.save(dependencyPlugin);
            }
        }
        pluginFileManager.uninstallPlugin(existingPlugin.getFilename());
        pluginDao.save(plugin);
        pluginAccessor.savePlugin(plugin);
        if (shouldRestart) {
            return PluginOperationResultImpl.successWithRestart();
        } else {
            return PluginOperationResultImpl.success();
        }
    }
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) PluginDependencyResult(com.qcadoo.plugin.api.PluginDependencyResult) PluginException(com.qcadoo.plugin.internal.PluginException) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) PluginDependencyInformation(com.qcadoo.plugin.api.PluginDependencyInformation) File(java.io.File) QcadooPluginPlugin(com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin)

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