mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 16:35:45 +01:00
upgrade optional dependencies on plugin installation/upgrade
This commit is contained in:
@@ -253,21 +253,40 @@ public class DefaultPluginManager implements PluginManager {
|
|||||||
|
|
||||||
private void collectPluginsToInstallOrUpdate(List<AvailablePlugin> plugins, String name) {
|
private void collectPluginsToInstallOrUpdate(List<AvailablePlugin> plugins, String name) {
|
||||||
if (!isInstalledOrPending(name) || isUpdatable(name)) {
|
if (!isInstalledOrPending(name) || isUpdatable(name)) {
|
||||||
AvailablePlugin plugin = getAvailable(name).orElseThrow(() -> NotFoundException.notFound(entity(AvailablePlugin.class, name)));
|
collectDependentPlugins(plugins, name);
|
||||||
|
|
||||||
Set<String> dependencies = plugin.getDescriptor().getDependencies();
|
|
||||||
if (dependencies != null) {
|
|
||||||
for (String dependency : dependencies) {
|
|
||||||
collectPluginsToInstallOrUpdate(plugins, dependency);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins.add(plugin);
|
|
||||||
} else {
|
} else {
|
||||||
LOG.info("plugin {} is already installed or installation is pending, skipping installation", name);
|
LOG.info("plugin {} is already installed or installation is pending, skipping installation", name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void collectOptionalPluginToInstallOrUpdate(List<AvailablePlugin> plugins, String name) {
|
||||||
|
if (isInstalledOrPending(name) && isUpdatable(name)) {
|
||||||
|
collectDependentPlugins(plugins, name);
|
||||||
|
} else {
|
||||||
|
LOG.info("optional plugin {} is not installed or not updatable", name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void collectDependentPlugins(List<AvailablePlugin> plugins, String name) {
|
||||||
|
AvailablePlugin plugin = getAvailable(name).orElseThrow(() -> NotFoundException.notFound(entity(AvailablePlugin.class, name)));
|
||||||
|
|
||||||
|
Set<String> dependencies = plugin.getDescriptor().getDependencies();
|
||||||
|
if (dependencies != null) {
|
||||||
|
for (String dependency : dependencies) {
|
||||||
|
collectPluginsToInstallOrUpdate(plugins, dependency);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<String> optionalDependencies = plugin.getDescriptor().getOptionalDependencies();
|
||||||
|
if (dependencies != null) {
|
||||||
|
for (String optionalDependency : optionalDependencies) {
|
||||||
|
collectOptionalPluginToInstallOrUpdate(plugins, optionalDependency);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
plugins.add(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isInstalledOrPending(String name) {
|
private boolean isInstalledOrPending(String name) {
|
||||||
return getInstalled(name).isPresent() || getPending(name).isPresent();
|
return getInstalled(name).isPresent() || getPending(name).isPresent();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -260,6 +260,35 @@ class DefaultPluginManagerTest {
|
|||||||
verify(installer).install(review);
|
verify(installer).install(review);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldUpdateAlreadyInstalledOptionalDependenciesWhenNewerVersionIsAvailable() {
|
||||||
|
AvailablePlugin review = createAvailable("scm-review-plugin");
|
||||||
|
when(review.getDescriptor().getOptionalDependencies()).thenReturn(ImmutableSet.of("scm-mail-plugin"));
|
||||||
|
AvailablePlugin mail = createAvailable("scm-mail-plugin", "1.1.0");
|
||||||
|
when(center.getAvailable()).thenReturn(ImmutableSet.of(review, mail));
|
||||||
|
|
||||||
|
InstalledPlugin installedMail = createInstalled("scm-mail-plugin", "1.0.0");
|
||||||
|
when(loader.getInstalledPlugins()).thenReturn(ImmutableList.of(installedMail));
|
||||||
|
|
||||||
|
manager.install("scm-review-plugin", false);
|
||||||
|
|
||||||
|
verify(installer).install(mail);
|
||||||
|
verify(installer).install(review);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldNotUpdateOptionalDependenciesWhenNewerVersionIsAvailableButItIsNotInstalled() {
|
||||||
|
AvailablePlugin review = createAvailable("scm-review-plugin");
|
||||||
|
when(review.getDescriptor().getOptionalDependencies()).thenReturn(ImmutableSet.of("scm-mail-plugin"));
|
||||||
|
AvailablePlugin mail = createAvailable("scm-mail-plugin", "1.1.0");
|
||||||
|
when(center.getAvailable()).thenReturn(ImmutableSet.of(review, mail));
|
||||||
|
|
||||||
|
manager.install("scm-review-plugin", false);
|
||||||
|
|
||||||
|
verify(installer, never()).install(mail);
|
||||||
|
verify(installer).install(review);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldRollbackOnFailedInstallation() {
|
void shouldRollbackOnFailedInstallation() {
|
||||||
AvailablePlugin review = createAvailable("scm-review-plugin");
|
AvailablePlugin review = createAvailable("scm-review-plugin");
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ class PluginCenterDtoMapperTest {
|
|||||||
"555000444",
|
"555000444",
|
||||||
new Condition(Collections.singletonList("linux"), "amd64","2.0.0"),
|
new Condition(Collections.singletonList("linux"), "amd64","2.0.0"),
|
||||||
ImmutableSet.of("scm-review-plugin"),
|
ImmutableSet.of("scm-review-plugin"),
|
||||||
|
ImmutableSet.of(),
|
||||||
ImmutableMap.of("download", new Link("http://download.hitchhiker.com"))
|
ImmutableMap.of("download", new Link("http://download.hitchhiker.com"))
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -101,6 +102,7 @@ class PluginCenterDtoMapperTest {
|
|||||||
"12345678aa",
|
"12345678aa",
|
||||||
new Condition(Collections.singletonList("linux"), "amd64","2.0.0"),
|
new Condition(Collections.singletonList("linux"), "amd64","2.0.0"),
|
||||||
ImmutableSet.of("scm-review-plugin"),
|
ImmutableSet.of("scm-review-plugin"),
|
||||||
|
ImmutableSet.of(),
|
||||||
ImmutableMap.of("download", new Link("http://download.hitchhiker.com/review"))
|
ImmutableMap.of("download", new Link("http://download.hitchhiker.com/review"))
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -115,6 +117,7 @@ class PluginCenterDtoMapperTest {
|
|||||||
"555000444",
|
"555000444",
|
||||||
new Condition(Collections.singletonList("linux"), "amd64","2.0.0"),
|
new Condition(Collections.singletonList("linux"), "amd64","2.0.0"),
|
||||||
ImmutableSet.of("scm-review-plugin"),
|
ImmutableSet.of("scm-review-plugin"),
|
||||||
|
ImmutableSet.of(),
|
||||||
ImmutableMap.of("download", new Link("http://download.hitchhiker.com/hitchhiker"))
|
ImmutableMap.of("download", new Link("http://download.hitchhiker.com/hitchhiker"))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user