]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9996 synchronous uninstall of edition
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 18 Oct 2017 12:17:10 +0000 (14:17 +0200)
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>
Mon, 23 Oct 2017 15:01:13 +0000 (08:01 -0700)
server/sonar-server/src/main/java/org/sonar/server/plugins/edition/EditionInstaller.java
server/sonar-server/src/test/java/org/sonar/server/plugins/edition/EditionInstallerTest.java

index 8b1e4240e4ee2cbf5a88946813e471aeef78e830..f72e157ee45201a86c1a1ba022a60f9e54c4f662 100644 (file)
@@ -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<String, PluginInfo> pluginInfosByKeys = pluginRepository.getPluginInfosByKeys();
+    Set<String> 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<String> pluginsToRemove) {
+    pluginsToRemove.stream().forEach(editionPluginUninstaller::uninstall);
+  }
+
   private Set<String> pluginsToInstall(Set<String> editionPluginKeys, Set<String> installedPluginKeys) {
     return editionPluginKeys.stream()
       .filter(p -> !installedPluginKeys.contains(p))
index ff988300f94282e78841e17d2e934ae277164a39..e4c0603642fe04f4eec70cc3017d259f765240ce 100644 (file)
@@ -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));