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);
}
}
}
}
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);
}
}
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();
}
}
}
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);
}
}
Aggregations