Search in sources :

Example 11 with QcadooPluginPlugin

use of com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin 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 12 with QcadooPluginPlugin

use of com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin in project qcadoo by qcadoo.

the class DefaultPluginManager method getEnabledPluginsList.

@Override
public List<Plugin> getEnabledPluginsList() {
    List<Plugin> pluginIdentifierList = new ArrayList<Plugin>();
    Set<QcadooPluginPlugin> pluginList = pluginDao.list();
    for (QcadooPluginPlugin qcadooPlugin : pluginList) {
        Plugin plugin = pluginAccessor.getEnabledPlugin(qcadooPlugin.getIdentifier());
        if (plugin != null) {
            pluginIdentifierList.add(plugin);
        }
    }
    return pluginIdentifierList;
}
Also used : QcadooPluginPlugin(com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) QcadooPluginPlugin(com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin)

Aggregations

QcadooPluginPlugin (com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin)12 InternalPlugin (com.qcadoo.plugin.internal.api.InternalPlugin)11 Test (org.junit.Test)9 Plugin (com.qcadoo.plugin.api.Plugin)8 Version (com.qcadoo.plugin.api.Version)4 InOrder (org.mockito.InOrder)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 ArrayList (java.util.ArrayList)1 Transactional (org.springframework.transaction.annotation.Transactional)1