From 45f3d0af08cb5e8e3d54c3d6015962b2b6120cdb Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Wed, 18 Oct 2017 14:17:10 +0200 Subject: SONAR-9996 synchronous uninstall of edition --- .../sonar/server/plugins/edition/EditionInstaller.java | 15 ++++++++++++--- .../server/plugins/edition/EditionInstallerTest.java | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) (limited to 'server/sonar-server') diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/edition/EditionInstaller.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/edition/EditionInstaller.java index 8b1e4240e4e..f72e157ee45 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/plugins/edition/EditionInstaller.java +++ b/server/sonar-server/src/main/java/org/sonar/server/plugins/edition/EditionInstaller.java @@ -21,6 +21,7 @@ package org.sonar.server.plugins.edition; import com.google.common.base.Optional; import java.util.Collection; +import java.util.Collections; import java.util.Map; import java.util.Set; import java.util.concurrent.locks.ReentrantLock; @@ -75,6 +76,12 @@ public class EditionInstaller { } } + public void uninstall() { + Map pluginInfosByKeys = pluginRepository.getPluginInfosByKeys(); + Set pluginsToRemove = pluginsToRemove(Collections.emptySet(), pluginInfosByKeys.values()); + uninstallPlugins(pluginsToRemove); + } + public boolean isOffline() { return !updateCenterMatrixFactory.getUpdateCenter(true).isPresent(); } @@ -93,9 +100,7 @@ public class EditionInstaller { try { editionPluginDownloader.downloadEditionPlugins(pluginsToInstall, updateCenter); - for (String pluginKey : pluginsToRemove) { - editionPluginUninstaller.uninstall(pluginKey); - } + uninstallPlugins(pluginsToRemove); editionManagementState.automaticInstallReady(); } finally { lock.unlock(); @@ -103,6 +108,10 @@ public class EditionInstaller { } } + private void uninstallPlugins(Set pluginsToRemove) { + pluginsToRemove.stream().forEach(editionPluginUninstaller::uninstall); + } + private Set pluginsToInstall(Set editionPluginKeys, Set installedPluginKeys) { return editionPluginKeys.stream() .filter(p -> !installedPluginKeys.contains(p)) diff --git a/server/sonar-server/src/test/java/org/sonar/server/plugins/edition/EditionInstallerTest.java b/server/sonar-server/src/test/java/org/sonar/server/plugins/edition/EditionInstallerTest.java index ff988300f94..e4c0603642f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/plugins/edition/EditionInstallerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/plugins/edition/EditionInstallerTest.java @@ -90,6 +90,22 @@ public class EditionInstallerTest { verifyNoMoreInteractions(downloader); } + @Test + public void uninstall_commercial_plugins() { + PluginInfo commercial1 = createPluginInfo("p1", true); + PluginInfo commercial2 = createPluginInfo("p2", true); + PluginInfo open1 = createPluginInfo("p3", false); + mockPluginRepository(commercial1, commercial2, open1); + + installer.uninstall(); + + verify(uninstaller).uninstall("p2"); + verify(uninstaller).uninstall("p1"); + + verifyNoMoreInteractions(uninstaller); + verifyZeroInteractions(downloader); + } + @Test public void do_nothing_if_offline() { mockPluginRepository(createPluginInfo("p1", true)); -- cgit v1.2.3