use of com.qcadoo.plugin.internal.api.InternalPlugin in project qcadoo by qcadoo.
the class DefaultPluginManager method enablePlugin.
@Override
public PluginOperationResult enablePlugin(final String... keys) {
List<Plugin> plugins = new ArrayList<Plugin>();
for (String key : keys) {
Plugin plugin = pluginAccessor.getPlugin(key);
if (!plugin.hasState(PluginState.ENABLED)) {
plugins.add(plugin);
}
}
if (plugins.isEmpty()) {
return PluginOperationResultImpl.success();
}
PluginDependencyResult pluginDependencyResult = pluginDependencyManager.getDependenciesToEnable(plugins, pluginStatusResolver);
if (pluginDependencyResult.isCyclic()) {
return PluginOperationResultImpl.dependenciesCyclesExists();
}
if (!pluginDependencyResult.isDependenciesSatisfied()) {
if (!pluginDependencyResult.getUnsatisfiedDependencies().isEmpty()) {
return PluginOperationResultImpl.unsatisfiedDependencies(pluginDependencyResult);
}
if (!pluginDependencyResult.getDependenciesToEnable().isEmpty()) {
return PluginOperationResultImpl.dependenciesToEnable(pluginDependencyResult);
}
}
boolean shouldRestart = false;
List<String> fileNames = new ArrayList<String>();
for (Plugin plugin : plugins) {
if (plugin.hasState(PluginState.TEMPORARY)) {
fileNames.add(plugin.getFilename());
}
}
if (!fileNames.isEmpty()) {
if (!pluginFileManager.installPlugin(fileNames.toArray(new String[fileNames.size()]))) {
return PluginOperationResultImpl.cannotInstallPlugin();
}
shouldRestart = true;
}
plugins = pluginDependencyManager.sortPluginsInDependencyOrder(plugins);
for (Plugin plugin : plugins) {
if (plugin.hasState(PluginState.TEMPORARY)) {
((InternalPlugin) plugin).changeStateTo(PluginState.ENABLING);
} else {
try {
((InternalPlugin) plugin).changeStateTo(PluginState.ENABLED);
} catch (Exception e) {
LOG.error(e.getMessage());
((InternalPlugin) plugin).changeStateTo(PluginState.DISABLED);
return PluginOperationResultImpl.pluginEnablingEncounteredErrors();
}
}
pluginDao.save(plugin);
pluginAccessor.savePlugin(plugin);
}
if (shouldRestart) {
return PluginOperationResultImpl.successWithRestart();
} else {
return PluginOperationResultImpl.success();
}
}
use of com.qcadoo.plugin.internal.api.InternalPlugin in project qcadoo by qcadoo.
the class DefaultPluginDescriptorParser method loadPlugins.
@Override
public Set<InternalPlugin> loadPlugins() {
Map<String, InternalPlugin> loadedplugins = new HashMap<String, InternalPlugin>();
Resource[] resources = pluginDescriptorResolver.getDescriptors();
for (Resource resource : resources) {
InternalPlugin plugin = parse(resource);
if (loadedplugins.containsKey(plugin.getIdentifier())) {
throw new PluginException("Duplicated plugin identifier: " + plugin.getIdentifier());
}
loadedplugins.put(plugin.getIdentifier(), plugin);
}
return new HashSet<InternalPlugin>(loadedplugins.values());
}
use of com.qcadoo.plugin.internal.api.InternalPlugin in project qcadoo by qcadoo.
the class PluginDependencyManagerTest method shouldReturnUnsatisfiedDependenciesForOnePluginWhenNoDependencyPluginFoundOrVersionIsNotMet.
@Test
public void shouldReturnUnsatisfiedDependenciesForOnePluginWhenNoDependencyPluginFoundOrVersionIsNotMet() throws Exception {
// given
given(plugin1.getState()).willReturn(PluginState.DISABLED);
given(plugin1.getIdentifier()).willReturn("testPlugin1");
given(plugin2.getState()).willReturn(PluginState.TEMPORARY);
given(plugin2.getIdentifier()).willReturn("testPlugin2");
given(plugin3.getState()).willReturn(PluginState.TEMPORARY);
given(plugin3.getIdentifier()).willReturn("testPlugin3");
given(pluginAccessor.getPlugin("testPlugin1")).willReturn(plugin1);
given(pluginAccessor.getPlugin("testPlugin2")).willReturn(plugin2);
given(pluginAccessor.getPlugin("testPlugin3")).willReturn(plugin3);
given(pluginAccessor.getPlugin("testPlugin4")).willReturn(null);
dependencyInfo3 = new PluginDependencyInformation("testPlugin3", new VersionOfDependency("[2"));
InternalPlugin pluginToEnable = mock(InternalPlugin.class);
Set<PluginDependencyInformation> disabledRequiredPlugins = new HashSet<PluginDependencyInformation>();
disabledRequiredPlugins.add(dependencyInfo1);
disabledRequiredPlugins.add(dependencyInfo2);
disabledRequiredPlugins.add(dependencyInfo3);
disabledRequiredPlugins.add(dependencyInfo4);
given(pluginToEnable.getRequiredPlugins()).willReturn(disabledRequiredPlugins);
given(pluginToEnable.getIdentifier()).willReturn("plugin");
// when
PluginDependencyResult result = manager.getDependenciesToEnable(singletonList((Plugin) pluginToEnable), pluginStatusResolver);
// then
assertFalse(result.isCyclic());
assertEquals(0, result.getDependenciesToEnable().size());
assertEquals(2, result.getUnsatisfiedDependencies().size());
assertTrue(result.getUnsatisfiedDependencies().contains(new PluginDependencyInformation("testPlugin3", new VersionOfDependency("[2"))));
assertTrue(result.getUnsatisfiedDependencies().contains(new PluginDependencyInformation("testPlugin4")));
assertEquals(0, result.getDependenciesToDisable().size());
}
use of com.qcadoo.plugin.internal.api.InternalPlugin in project qcadoo by qcadoo.
the class PluginDependencyManagerTest method shouldReturnMultipleDisabledDependencyForOnePlugin.
@Test
public void shouldReturnMultipleDisabledDependencyForOnePlugin() throws Exception {
// given
given(plugin1.getState()).willReturn(PluginState.DISABLED);
given(plugin1.getIdentifier()).willReturn("testPlugin1");
given(plugin2.getState()).willReturn(PluginState.TEMPORARY);
given(plugin2.getIdentifier()).willReturn("testPlugin2");
given(plugin3.getState()).willReturn(PluginState.ENABLED);
given(plugin3.getIdentifier()).willReturn("testPlugin3");
given(pluginAccessor.getPlugin("testPlugin1")).willReturn(plugin1);
given(pluginAccessor.getPlugin("testPlugin2")).willReturn(plugin2);
given(pluginAccessor.getPlugin("testPlugin3")).willReturn(plugin3);
InternalPlugin pluginToEnable = mock(InternalPlugin.class);
Set<PluginDependencyInformation> disabledRequiredPlugins = new HashSet<PluginDependencyInformation>();
disabledRequiredPlugins.add(dependencyInfo1);
disabledRequiredPlugins.add(dependencyInfo2);
disabledRequiredPlugins.add(dependencyInfo3);
given(pluginToEnable.getRequiredPlugins()).willReturn(disabledRequiredPlugins);
given(pluginToEnable.getIdentifier()).willReturn("plugin");
// when
PluginDependencyResult result = manager.getDependenciesToEnable(singletonList((Plugin) pluginToEnable), pluginStatusResolver);
// then
assertFalse(result.isCyclic());
assertEquals(2, result.getDependenciesToEnable().size());
assertTrue(result.getDependenciesToEnable().contains(new PluginDependencyInformation("testPlugin1")));
assertTrue(result.getDependenciesToEnable().contains(new PluginDependencyInformation("testPlugin2")));
assertEquals(0, result.getUnsatisfiedDependencies().size());
assertEquals(0, result.getDependenciesToDisable().size());
}
use of com.qcadoo.plugin.internal.api.InternalPlugin in project qcadoo by qcadoo.
the class PluginManagerTest method shouldDisableMultipleEnabledPlugin.
@Test
public void shouldDisableMultipleEnabledPlugin() throws Exception {
// given
given(plugin.hasState(PluginState.ENABLED)).willReturn(true);
InternalPlugin nextPlugin = mock(InternalPlugin.class, "nextPlugin");
given(nextPlugin.hasState(PluginState.ENABLED)).willReturn(true);
given(pluginAccessor.getPlugin("nextPluginname")).willReturn(nextPlugin);
PluginDependencyResult pluginDependencyResult = PluginDependencyResultImpl.satisfiedDependencies();
given(pluginDependencyManager.getDependenciesToDisable(Mockito.eq(newArrayList((Plugin) plugin, (Plugin) nextPlugin)), Mockito.any(SimplePluginStatusResolver.class))).willReturn(pluginDependencyResult);
given(pluginDependencyManager.sortPluginsInDependencyOrder(newArrayList((Plugin) plugin, (Plugin) nextPlugin))).willReturn(newArrayList((Plugin) plugin, (Plugin) nextPlugin));
// when
PluginOperationResult pluginOperationResult = pluginManager.disablePlugin("pluginname", "nextPluginname");
// then
InOrder inOrder = inOrder(nextPlugin, plugin);
inOrder.verify(nextPlugin).changeStateTo(PluginState.DISABLED);
inOrder.verify(plugin).changeStateTo(PluginState.DISABLED);
verify(pluginDao).save(nextPlugin);
verify(pluginAccessor).savePlugin(nextPlugin);
verify(pluginDao).save(plugin);
verify(pluginAccessor).savePlugin(plugin);
assertTrue(pluginOperationResult.isSuccess());
assertEquals(PluginOperationStatus.SUCCESS, pluginOperationResult.getStatus());
assertEquals(0, pluginOperationResult.getPluginDependencyResult().getDependenciesToDisable().size());
}
Aggregations