]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9946 Log INFO edition installation
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Fri, 20 Oct 2017 14:24:29 +0000 (16:24 +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/main/java/org/sonar/server/plugins/edition/EditionPluginDownloader.java
server/sonar-server/src/test/java/org/sonar/server/plugins/edition/EditionInstallerTest.java
server/sonar-server/src/test/java/org/sonar/server/plugins/edition/EditionPluginDownloaderTest.java

index f13731a648012c08dbc307ec6de48a4e7477f2f9..bbafde3f785ff529033859c3c8bfc38ccecb3b54 100644 (file)
@@ -68,6 +68,7 @@ public class EditionInstaller {
       try {
         Optional<UpdateCenter> updateCenter = updateCenterMatrixFactory.getUpdateCenter(true);
         if (!updateCenter.isPresent()) {
+          LOG.info("Installation of edition '{}' needs to be done manually", newLicense.getEditionKey());
           editionManagementState.startManualInstall(newLicense);
           return;
         }
@@ -110,6 +111,9 @@ public class EditionInstaller {
       Set<String> pluginsToRemove = pluginsToRemove(editionPluginKeys, pluginInfosByKeys.values());
       Set<String> pluginsToInstall = pluginsToInstall(editionPluginKeys, pluginInfosByKeys.keySet());
 
+      LOG.info("Installing edition '{}', download: {}, remove: {}", 
+        newLicense.getEditionKey(), pluginsToInstall, pluginsToRemove);
+
       editionPluginDownloader.downloadEditionPlugins(pluginsToInstall, updateCenter);
       uninstallPlugins(pluginsToRemove);
       editionManagementState.automaticInstallReady();
@@ -125,13 +129,13 @@ public class EditionInstaller {
     pluginsToRemove.stream().forEach(editionPluginUninstaller::uninstall);
   }
 
-  private Set<String> pluginsToInstall(Set<String> editionPluginKeys, Set<String> installedPluginKeys) {
+  private static Set<String> pluginsToInstall(Set<String> editionPluginKeys, Set<String> installedPluginKeys) {
     return editionPluginKeys.stream()
       .filter(p -> !installedPluginKeys.contains(p))
       .collect(Collectors.toSet());
   }
 
-  private Set<String> pluginsToRemove(Set<String> editionPluginKeys, Collection<PluginInfo> installedPluginInfos) {
+  private static Set<String> pluginsToRemove(Set<String> editionPluginKeys, Collection<PluginInfo> installedPluginInfos) {
     Set<String> installedCommercialPluginKeys = installedPluginInfos.stream()
       .filter(EditionBundledPlugins::isEditionBundled)
       .map(PluginInfo::getKey)
index 9f344ef1b83c7dbedbceb1e196211494dc4393b0..7801af2fb12f8174d78a9aec3c0121e996b66916 100644 (file)
@@ -78,6 +78,7 @@ public class EditionPluginDownloader {
 
   protected void download(Release release) {
     try {
+      LOG.info("Downloading plugin: {}", release.getArtifact().getKey());
       downloadRelease(release);
     } catch (Exception e) {
       String message = String.format("Fail to download the plugin (%s, version %s) from %s (error is : %s)",
index 0c6aa349d0976b0a2917df322f3844af0f6828c6..e4987d1498d36d70770f085dce0debf1b638d657 100644 (file)
@@ -176,6 +176,8 @@ public class EditionInstallerTest {
     verify(uninstaller).uninstall("p2");
     verifyNoMoreInteractions(uninstaller);
     verifyNoMoreInteractions(downloader);
+    assertThat(logTester.logs()).containsOnly("Installing edition 'edition-key', download: [p4], remove: [p2]");
+
   }
 
   @Test
@@ -209,6 +211,7 @@ public class EditionInstallerTest {
     verifyZeroInteractions(downloader);
     verify(editionManagementState).startManualInstall(newLicense);
     verifyNoMoreInteractions(editionManagementState);
+    assertThat(logTester.logs()).containsOnly("Installation of edition 'edition-key' needs to be done manually");
   }
 
   @Test
@@ -283,7 +286,6 @@ public class EditionInstallerTest {
     verify(editionManagementState).startAutomaticInstall(newLicense);
     verify(editionManagementState).installFailed(expectedErrorMessage);
     verifyNoMoreInteractions(editionManagementState);
-    assertThat(logTester.logs()).hasSize(1);
     assertThat(logTester.logs(LoggerLevel.ERROR))
       .containsOnly("Failed to install edition " + newLicense.getEditionKey() + " with plugins " + newLicense.getPluginKeys());
   }
index c2659beacfe8100dea74c764dec9710eb9d29770..4f7d6498abd9cd672dbf5f757356e2ca97005879 100644 (file)
@@ -31,6 +31,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.utils.HttpDownloader;
+import org.sonar.api.utils.log.LogTester;
 import org.sonar.server.platform.ServerFileSystem;
 import org.sonar.updatecenter.common.Plugin;
 import org.sonar.updatecenter.common.Release;
@@ -45,6 +46,9 @@ import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 public class EditionPluginDownloaderTest {
+  @Rule
+  public LogTester logTester = new LogTester();
+
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
 
@@ -75,6 +79,7 @@ public class EditionPluginDownloaderTest {
     verify(httpDownloader).download(new URI("http://host/plugin1.jar"), new File(tmpDir, "plugin1.jar"));
     verify(httpDownloader).download(new URI("http://host/plugin2.jar"), new File(tmpDir, "plugin2.jar"));
 
+    assertThat(logTester.logs()).containsOnly("Downloading plugin: plugin1", "Downloading plugin: plugin2");
     assertThat(downloadDir).isDirectory();
     assertThat(tmpDir).doesNotExist();
   }