Resolve plugin installation conflict were the same plugin was tried to be installed multiple times for one single action. (#2138)

The pending queue is updated after all the plugins to be installed are collected, and then we already may have duplicate entries. Because of this we check right on the collecting step if the plugin was already added during this single action.
This commit is contained in:
Eduard Heimbuch
2022-10-20 20:38:58 +02:00
committed by GitHub
parent 976f71b33c
commit 8db2e76ecc
3 changed files with 27 additions and 1 deletions

View File

@@ -0,0 +1,2 @@
- type: fixed
description: Plugin installation conflict ([#2138](https://github.com/scm-manager/scm-manager/pull/2138))

View File

@@ -357,7 +357,13 @@ public class DefaultPluginManager implements PluginManager {
} }
} }
plugins.add(plugin); if (pluginWasNotAddedYet(plugins, plugin)) {
plugins.add(plugin);
}
}
private static boolean pluginWasNotAddedYet(List<AvailablePlugin> plugins, AvailablePlugin plugin) {
return plugins.stream().noneMatch(p -> p.getDescriptor().getInformation().getName().equals(plugin.getDescriptor().getInformation().getName()));
} }
private boolean isInstalledOrPending(String name) { private boolean isInstalledOrPending(String name) {

View File

@@ -242,6 +242,24 @@ class DefaultPluginManagerTest {
verify(installer).install(context, review); verify(installer).install(context, review);
} }
@Test
void shouldInstallMultipleSameDependingPluginsOnlyOnce() {
AvailablePlugin review = createAvailable("scm-review-plugin");
AvailablePlugin ci = createAvailable("scm-ci-plugin", "1.1.0");
InstalledPlugin oldCi = createInstalled("scm-ci-plugin", "1.0.0");
when(review.getDescriptor().getDependencies()).thenReturn(ImmutableSet.of("scm-mail-plugin", "scm-ci-plugin"));
AvailablePlugin mail = createAvailable("scm-mail-plugin");
when(mail.getDescriptor().getOptionalDependencies()).thenReturn(ImmutableSet.of("scm-ci-plugin"));
when(center.getAvailablePlugins()).thenReturn(ImmutableSet.of(review, mail, ci));
when(loader.getInstalledPlugins()).thenReturn(ImmutableSet.of(oldCi));
manager.install("scm-review-plugin", false);
verify(installer).install(context, mail);
verify(installer).install(context, review);
verify(installer, times(1)).install(context, ci);
}
@Test @Test
void shouldNotInstallAlreadyInstalledDependenciesWhenUpToDate() { void shouldNotInstallAlreadyInstalledDependenciesWhenUpToDate() {
AvailablePlugin review = createAvailable("scm-review-plugin"); AvailablePlugin review = createAvailable("scm-review-plugin");