use of com.qcadoo.plugin.internal.api.InternalPlugin in project qcadoo by qcadoo.
the class DefaultPluginManager method disablePlugin.
@Override
public PluginOperationResult disablePlugin(final String... keys) {
List<Plugin> plugins = new ArrayList<>();
for (String key : keys) {
Plugin plugin = pluginAccessor.getPlugin(key);
if (plugin.isSystemPlugin()) {
return PluginOperationResultImpl.systemPluginDisabling();
}
if (plugin.hasState(PluginState.ENABLED)) {
plugins.add(plugin);
}
}
if (plugins.isEmpty()) {
return PluginOperationResultImpl.success();
}
PluginDependencyResult pluginDependencyResult = pluginDependencyManager.getDependenciesToDisable(plugins, pluginStatusResolver);
if (!pluginDependencyResult.isDependenciesSatisfied() && !pluginDependencyResult.getDependenciesToDisable().isEmpty()) {
return PluginOperationResultImpl.dependenciesToDisable(pluginDependencyResult);
}
plugins = pluginDependencyManager.sortPluginsInDependencyOrder(plugins);
Collections.reverse(plugins);
for (Plugin plugin : plugins) {
((InternalPlugin) plugin).changeStateTo(PluginState.DISABLED);
pluginDao.save(plugin);
pluginAccessor.savePlugin(plugin);
}
return PluginOperationResultImpl.success();
}
use of com.qcadoo.plugin.internal.api.InternalPlugin in project qcadoo by qcadoo.
the class DefaultPluginDescriptorParser method getTemporaryPlugins.
@Override
public Set<InternalPlugin> getTemporaryPlugins() {
Set<InternalPlugin> plugins = new HashSet<InternalPlugin>();
if (pluginsTmpPath == null || pluginsTmpPath.trim().isEmpty()) {
return plugins;
}
File pluginsTmpFile = new File(pluginsTmpPath);
if (!pluginsTmpFile.exists()) {
LOG.warn("Plugins temporary directory does not exist: " + pluginsTmpPath);
return plugins;
}
try {
FilenameFilter jarsFilter = new WildcardFileFilter("*.jar");
if (!pluginsTmpFile.exists()) {
throw new IOException();
}
File[] pluginJars = pluginsTmpFile.listFiles(jarsFilter);
for (int i = 0; i < pluginJars.length; ++i) {
File jarRes = pluginJars[i];
InternalPlugin plugin = parse(jarRes);
plugin.changeStateTo(PluginState.TEMPORARY);
plugins.add(plugin);
}
return plugins;
} catch (IOException e) {
throw new IllegalStateException("Failed to reading plugins from " + pluginsTmpPath, e);
}
}
use of com.qcadoo.plugin.internal.api.InternalPlugin 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.api.InternalPlugin in project qcadoo by qcadoo.
the class DefaultPluginAccessor method onApplicationEvent.
@Override
public void onApplicationEvent(final ContextRefreshedEvent event) {
if (!alreadyInitialized) {
synchronized (this) {
if (!alreadyInitialized) {
init();
alreadyInitialized = true;
}
}
}
if (event != null && event.getSource() instanceof XmlWebApplicationContext) {
XmlWebApplicationContext eventSource = (XmlWebApplicationContext) event.getSource();
if (eventSource.getParent() != null) {
return;
}
}
long time = System.currentTimeMillis();
List<Plugin> sortedPlugins = pluginDependencyManager.sortPluginsInDependencyOrder(plugins.values(), plugins);
moduleFactoryAccessor.init(sortedPlugins);
for (Plugin plugin : sortedPlugins) {
if (plugin.hasState(PluginState.ENABLING)) {
((InternalPlugin) plugin).changeStateTo(PluginState.ENABLED);
pluginDao.save(plugin);
}
}
LOG.info("Plugin Framework started in " + (System.currentTimeMillis() - time) + "ms");
}
use of com.qcadoo.plugin.internal.api.InternalPlugin 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");
}
Aggregations