use of com.qcadoo.plugin.api.PluginDependencyInformation in project qcadoo by qcadoo.
the class PluginDependencyInformationTest method shouldThrowExceptionWhenWrongVersions.
@Test
public void shouldThrowExceptionWhenWrongVersions() throws Exception {
// when
try {
new PluginDependencyInformation("", new VersionOfDependency("[a1,1)"));
Assert.fail();
} catch (Exception e) {
LOG.info("empty catch");
}
try {
new PluginDependencyInformation("", new VersionOfDependency("[1,2s)"));
Assert.fail();
} catch (Exception e) {
LOG.info("empty catch");
}
try {
new PluginDependencyInformation("", new VersionOfDependency("[1.2.3.4,2s)"));
Assert.fail();
} catch (Exception e) {
LOG.info("empty catch");
}
try {
new PluginDependencyInformation("", new VersionOfDependency("[2,1.2.3.4)"));
Assert.fail();
} catch (Exception e) {
LOG.info("empty catch");
}
try {
new PluginDependencyInformation("", new VersionOfDependency("[1.1.1,1.1.0)"));
Assert.fail();
} catch (Exception e) {
LOG.info("empty catch");
}
try {
new PluginDependencyInformation("", new VersionOfDependency("(1.0.0,1]"));
Assert.fail();
} catch (Exception e) {
LOG.info("empty catch");
}
// then
}
use of com.qcadoo.plugin.api.PluginDependencyInformation in project qcadoo by qcadoo.
the class PluginDependencyInformationTest method init.
@Before
public void init() {
dependencyInformation1 = new PluginDependencyInformation("testPlugin1", new VersionOfDependency("[1,1.2.01)"));
dependencyInformation2 = new PluginDependencyInformation("testPlugin2", new VersionOfDependency("2.2.01]"));
dependencyInformation3 = new PluginDependencyInformation("testPlugin3", new VersionOfDependency("[1.2.10"));
dependencyInformation4 = new PluginDependencyInformation("testPlugin4", new VersionOfDependency("(3.0.1,4.2]"));
dependencyInformation5 = new PluginDependencyInformation("testPlugin5", new VersionOfDependency("[3.0.1,3.0.1]"));
}
use of com.qcadoo.plugin.api.PluginDependencyInformation in project qcadoo by qcadoo.
the class PluginDependencyManagerTest method shouldCheckDependenciesDependenciesAndReturnMultipleDependencies.
@Test
public void shouldCheckDependenciesDependenciesAndReturnMultipleDependencies() throws Exception {
// given
Set<PluginDependencyInformation> disabledRequiredPlugins = new HashSet<PluginDependencyInformation>();
disabledRequiredPlugins.add(dependencyInfo2);
given(plugin1.getRequiredPlugins()).willReturn(disabledRequiredPlugins);
given(plugin2.getState()).willReturn(PluginState.DISABLED);
Set<PluginDependencyInformation> disabledRequiredPlugins2 = new HashSet<PluginDependencyInformation>();
disabledRequiredPlugins2.add(dependencyInfo3);
given(plugin2.getRequiredPlugins()).willReturn(disabledRequiredPlugins2);
given(plugin3.getState()).willReturn(PluginState.TEMPORARY);
given(pluginAccessor.getPlugin("testPlugin2")).willReturn(plugin2);
given(pluginAccessor.getPlugin("testPlugin3")).willReturn(plugin3);
// when
PluginDependencyResult result = manager.getDependenciesToEnable(singletonList((Plugin) plugin1), pluginStatusResolver);
// then
assertFalse(result.isCyclic());
assertEquals(2, result.getDependenciesToEnable().size());
assertTrue(result.getDependenciesToEnable().contains(new PluginDependencyInformation("testPlugin2")));
assertTrue(result.getDependenciesToEnable().contains(new PluginDependencyInformation("testPlugin3")));
assertEquals(0, result.getUnsatisfiedDependencies().size());
assertEquals(0, result.getDependenciesToDisable().size());
}
use of com.qcadoo.plugin.api.PluginDependencyInformation in project qcadoo by qcadoo.
the class PluginDependencyManagerTest method shouldReturnValidResultForCyclicDependencies.
@Test
public void shouldReturnValidResultForCyclicDependencies() throws Exception {
// given
Set<PluginDependencyInformation> disabledRequiredPlugins1 = new HashSet<PluginDependencyInformation>();
disabledRequiredPlugins1.add(dependencyInfo2);
given(plugin1.getRequiredPlugins()).willReturn(disabledRequiredPlugins1);
Set<PluginDependencyInformation> disabledRequiredPlugins2 = new HashSet<PluginDependencyInformation>();
disabledRequiredPlugins2.add(dependencyInfo3);
disabledRequiredPlugins2.add(dependencyInfo4);
given(plugin2.getRequiredPlugins()).willReturn(disabledRequiredPlugins2);
Set<PluginDependencyInformation> disabledRequiredPlugins3 = new HashSet<PluginDependencyInformation>();
disabledRequiredPlugins3.add(dependencyInfo1);
given(plugin3.getRequiredPlugins()).willReturn(disabledRequiredPlugins3);
given(pluginAccessor.getPlugin("testPlugin1")).willReturn(plugin1);
given(pluginAccessor.getPlugin("testPlugin2")).willReturn(plugin2);
given(pluginAccessor.getPlugin("testPlugin3")).willReturn(plugin3);
given(pluginAccessor.getPlugin("testPlugin4")).willReturn(plugin4);
List<Plugin> plugins = new ArrayList<Plugin>();
plugins.add(plugin1);
plugins.add(plugin2);
plugins.add(plugin3);
// when
PluginDependencyResult result = manager.getDependenciesToEnable(plugins, pluginStatusResolver);
// then
assertTrue(result.isCyclic());
assertEquals(0, result.getDependenciesToEnable().size());
assertEquals(0, result.getUnsatisfiedDependencies().size());
assertEquals(0, result.getDependenciesToDisable().size());
}
use of com.qcadoo.plugin.api.PluginDependencyInformation 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();
}
}
}
Aggregations