Search in sources :

Example 6 with PluginException

use of com.qcadoo.plugin.internal.PluginException in project qcadoo by qcadoo.

the class DefaultPluginDescriptorParser method parse.

@Override
public InternalPlugin parse(final File file) {
    JarFile jarFile = null;
    try {
        LOG.info("Parsing descriptor for:" + file.getAbsolutePath());
        boolean ignoreModules = true;
        jarFile = new JarFile(file);
        JarEntry descriptorEntry = findDescriptorEntry(jarFile.entries(), file.getAbsolutePath());
        return parse(jarFile.getInputStream(descriptorEntry), ignoreModules, file.getName());
    } catch (IOException e) {
        throw new PluginException("Plugin descriptor " + descriptor + " not found in " + file.getAbsolutePath(), e);
    } catch (Exception e) {
        throw new PluginException(e.getMessage(), e);
    } finally {
        if (jarFile != null) {
            try {
                jarFile.close();
            } catch (IOException e) {
                throw new PluginException("Plugin descriptor " + descriptor + " not found in " + file.getAbsolutePath(), e);
            }
        }
    }
}
Also used : PluginException(com.qcadoo.plugin.internal.PluginException) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) PluginException(com.qcadoo.plugin.internal.PluginException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 7 with PluginException

use of com.qcadoo.plugin.internal.PluginException in project qcadoo by qcadoo.

the class DefaultPluginDescriptorParser method parse.

private InternalPlugin parse(final InputStream inputStream, final boolean ignoreModules, final String fileName) throws IOException {
    try {
        Document document = documentBuilder.parse(inputStream);
        Node root = document.getDocumentElement();
        Builder pluginBuilder = parsePluginNode(root, ignoreModules);
        InternalPlugin plugin = pluginBuilder.withFileName(fileName).build();
        LOG.info("Parse complete");
        return plugin;
    } catch (SAXException e) {
        throw new PluginException(e.getMessage(), e);
    }
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) Node(org.w3c.dom.Node) Builder(com.qcadoo.plugin.internal.DefaultPlugin.Builder) DOMBuilder(org.jdom.input.DOMBuilder) DocumentBuilder(javax.xml.parsers.DocumentBuilder) PluginException(com.qcadoo.plugin.internal.PluginException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Example 8 with PluginException

use of com.qcadoo.plugin.internal.PluginException 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)

Example 9 with PluginException

use of com.qcadoo.plugin.internal.PluginException in project qcadoo by qcadoo.

the class DefaultPluginServerManager method restart.

@Override
public void restart() {
    try {
        Process shutdownProcess = Runtime.getRuntime().exec(restartCommand);
        shutdownProcess.waitFor();
        if (LOG.isDebugEnabled()) {
            LOG.debug("Shutdown exit value: " + shutdownProcess.exitValue());
        }
    } catch (IOException e) {
        throw new PluginException("Restart failed - " + e.getMessage(), e);
    } catch (InterruptedException e) {
        throw new PluginException("Restart failed - " + e.getMessage(), e);
    }
}
Also used : PluginException(com.qcadoo.plugin.internal.PluginException) IOException(java.io.IOException)

Aggregations

PluginException (com.qcadoo.plugin.internal.PluginException)9 IOException (java.io.IOException)4 InternalPlugin (com.qcadoo.plugin.internal.api.InternalPlugin)3 SAXException (org.xml.sax.SAXException)3 File (java.io.File)2 UnknownHostException (java.net.UnknownHostException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 Test (org.junit.Test)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 QcadooPluginPlugin (com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin)1 Plugin (com.qcadoo.plugin.api.Plugin)1 PluginDependencyInformation (com.qcadoo.plugin.api.PluginDependencyInformation)1 PluginDependencyResult (com.qcadoo.plugin.api.PluginDependencyResult)1 Builder (com.qcadoo.plugin.internal.DefaultPlugin.Builder)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 JarEntry (java.util.jar.JarEntry)1 JarFile (java.util.jar.JarFile)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1