Search in sources :

Example 16 with Version

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

the class PluginDependencyInformationTest method shouldReturnTrueWhenVersionIsNotSattisfied.

@Test
public void shouldReturnTrueWhenVersionIsNotSattisfied() throws Exception {
    // given
    Version v1 = new Version("0.9");
    Version v2 = new Version("2.3");
    Version v3 = new Version("1.2.09");
    Version v4 = new Version("3.0.1");
    Version v5 = new Version("3.0.2");
    // when
    boolean res1 = dependencyInformation1.contains(v1);
    boolean res2 = dependencyInformation2.contains(v2);
    boolean res3 = dependencyInformation3.contains(v3);
    boolean res4 = dependencyInformation4.contains(v4);
    boolean res5 = dependencyInformation5.contains(v5);
    // then
    Assert.assertFalse(res1);
    Assert.assertFalse(res2);
    Assert.assertFalse(res3);
    Assert.assertFalse(res4);
    Assert.assertFalse(res5);
}
Also used : Version(com.qcadoo.plugin.api.Version) Test(org.junit.Test)

Example 17 with Version

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

the class DefaultPluginAccessor method init.

public void init() {
    LOG.info("Plugin Framework initialization");
    long time = System.currentTimeMillis();
    pluginStateResolver.setPluginAccessor(this);
    Set<InternalPlugin> enabledPluginsFromDescriptor = pluginDescriptorParser.loadPlugins();
    Set<QcadooPluginPlugin> pluginsFromDatabase = pluginDao.list();
    for (InternalPlugin plugin : enabledPluginsFromDescriptor) {
        QcadooPluginPlugin existingPlugin = null;
        for (QcadooPluginPlugin databasePlugin : pluginsFromDatabase) {
            if (plugin.getIdentifier().equals(databasePlugin.getIdentifier())) {
                existingPlugin = databasePlugin;
                break;
            }
        }
        if (existingPlugin == null) {
            plugin.changeStateTo(PluginState.ENABLING);
        } else {
            plugin.changeStateTo(PluginState.valueOf(existingPlugin.getState()));
        }
        if (existingPlugin == null || plugin.compareVersion(new Version(existingPlugin.getVersion())) > 0) {
            pluginDao.save(plugin);
        } else if (plugin.compareVersion(new Version(existingPlugin.getVersion())) < 0) {
            throw new IllegalStateException("Unsupported operation: downgrade, for plugin: " + plugin.getIdentifier());
        }
        LOG.info("Registering plugin " + plugin);
        plugins.put(plugin.getIdentifier(), plugin);
    }
    for (QcadooPluginPlugin databasePlugin : pluginsFromDatabase) {
        if (databasePlugin.getState().equals(PluginState.TEMPORARY.toString())) {
            continue;
        }
        Plugin existingPlugin = null;
        for (Plugin plugin : enabledPluginsFromDescriptor) {
            if (databasePlugin.getIdentifier().equals(plugin.getIdentifier())) {
                existingPlugin = plugin;
                break;
            }
        }
        if (existingPlugin == null) {
            pluginDao.delete(databasePlugin);
        }
    }
    Set<InternalPlugin> temporaryPlugins = pluginDescriptorParser.getTemporaryPlugins();
    for (InternalPlugin plugin : temporaryPlugins) {
        plugins.put(plugin.getIdentifier(), plugin);
    }
    LOG.info("Plugin Framework initialized in " + (System.currentTimeMillis() - time) + "ms");
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) QcadooPluginPlugin(com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin) Version(com.qcadoo.plugin.api.Version) QcadooPluginPlugin(com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin)

Example 18 with Version

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

the class PluginIntegrationTest method shouldUpdateTemporaryPlugin.

@Test
public void shouldUpdateTemporaryPlugin() throws Exception {
    // given
    JarPluginArtifact artifact = new JarPluginArtifact(new File("src/test/resources/com/qcadoo/plugin/integration/plugin4.jar"));
    JarPluginArtifact artifact2 = new JarPluginArtifact(new File("src/test/resources/com/qcadoo/plugin/integration/plugin4.1.jar"));
    pluginManager.installPlugin(artifact);
    // when
    PluginOperationResult result = pluginManager.installPlugin(artifact2);
    // then
    assertTrue(result.isSuccess());
    assertFalse(result.isRestartNeccessary());
    assertNotNull(pluginAccessor.getPlugin("plugin4"));
    assertTrue(pluginAccessor.getPlugin("plugin4").hasState(PluginState.TEMPORARY));
    assertEquals(new Version("1.2.4"), pluginAccessor.getPlugin("plugin4").getVersion());
}
Also used : JarPluginArtifact(com.qcadoo.plugin.api.artifact.JarPluginArtifact) Version(com.qcadoo.plugin.api.Version) PluginOperationResult(com.qcadoo.plugin.api.PluginOperationResult) File(java.io.File) Test(org.junit.Test)

Aggregations

Version (com.qcadoo.plugin.api.Version)18 Test (org.junit.Test)16 InternalPlugin (com.qcadoo.plugin.internal.api.InternalPlugin)11 Plugin (com.qcadoo.plugin.api.Plugin)8 QcadooPluginPlugin (com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin)5 PluginDependencyInformation (com.qcadoo.plugin.api.PluginDependencyInformation)3 PluginOperationResult (com.qcadoo.plugin.api.PluginOperationResult)3 JarPluginArtifact (com.qcadoo.plugin.api.artifact.JarPluginArtifact)3 File (java.io.File)3 HashSet (java.util.HashSet)3 PluginDependencyResult (com.qcadoo.plugin.api.PluginDependencyResult)2 VersionOfDependency (com.qcadoo.plugin.api.VersionOfDependency)2 DefaultPlugin (com.qcadoo.plugin.internal.DefaultPlugin)2 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1