]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10315 do not fail if a plugin has been uninstalled between analysis and CE...
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 24 Jan 2018 12:37:58 +0000 (13:37 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 12 Feb 2018 15:44:07 +0000 (16:44 +0100)
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java
server/sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginJarExploder.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java
sonar-core/src/main/java/org/sonar/core/platform/PluginRepository.java

index 1010269638c43787f177e99504323e69ac9bf027..5fe57312e81e26b0ad5fd16e5c90155b323c9239 100644 (file)
@@ -29,7 +29,6 @@ import org.apache.commons.lang.StringUtils;
 import org.sonar.api.utils.MessageException;
 import org.sonar.ce.queue.CeTask;
 import org.sonar.core.component.ComponentKeys;
-import org.sonar.core.platform.PluginInfo;
 import org.sonar.core.platform.PluginRepository;
 import org.sonar.core.util.stream.MoreCollectors;
 import org.sonar.db.DbClient;
@@ -129,13 +128,12 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep {
 
   @CheckForNull
   private String getBasePluginKey(Plugin p) {
-    PluginInfo pluginInfo = pluginRepository.getPluginInfo(p.getKey());
-    if (pluginInfo == null) {
+    if (!pluginRepository.hasPlugin(p.getKey())) {
       // May happen if plugin was uninstalled between start of scanner analysis and now.
       // But it doesn't matter since all active rules are removed anyway, so no issues will be reported
       return null;
     }
-    return pluginInfo.getBasePlugin();
+    return pluginRepository.getPluginInfo(p.getKey()).getBasePlugin();
   }
 
   /**
index dc2aeb6e76edec27239c3bf6cdbad3f52ce91bfa..178a36334e34eb8d9344d43d295983d2cd725963 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.server.plugins;
 
 import java.io.File;
 import org.apache.commons.io.FileUtils;
-import org.sonar.api.ce.ComputeEngineSide;
 import org.sonar.api.server.ServerSide;
 import org.sonar.api.utils.ZipUtils;
 import org.sonar.core.platform.ExplodedPlugin;
@@ -32,7 +31,6 @@ import org.sonar.server.platform.ServerFileSystem;
 import static org.apache.commons.io.FileUtils.forceMkdir;
 
 @ServerSide
-@ComputeEngineSide
 public class ServerPluginJarExploder extends PluginJarExploder {
 
   private final ServerFileSystem fs;
index ba8bf417e1e8cd9d492a2f0b7f752e4c586f302e..f47b84d1dbe776cdd626bb91a0af332343ba6499 100644 (file)
@@ -302,20 +302,24 @@ public class LoadReportAnalysisMetadataHolderStepTest {
   }
 
   @Test
-  public void execute_read_plugins_from_report() {
+  public void execute_reads_plugins_from_report() {
     ScannerReport.Metadata.Builder metadataBuilder = newBatchReportBuilder();
     metadataBuilder.getMutablePluginsByKey().put("java", ScannerReport.Metadata.Plugin.newBuilder().setKey("java").setUpdatedAt(12345L).build());
     metadataBuilder.getMutablePluginsByKey().put("php", ScannerReport.Metadata.Plugin.newBuilder().setKey("php").setUpdatedAt(678910L).build());
     metadataBuilder.getMutablePluginsByKey().put("customjava", ScannerReport.Metadata.Plugin.newBuilder().setKey("customjava").setUpdatedAt(111111L).build());
-    when(pluginRepository.getPluginInfo("customjava")).thenReturn(new PluginInfo("customjava").setBasePlugin("java"));
-
     reportReader.setMetadata(metadataBuilder.build());
 
+    when(pluginRepository.hasPlugin("java")).thenReturn(true);
+    when(pluginRepository.getPluginInfo("java")).thenReturn(new PluginInfo("java"));
+    when(pluginRepository.hasPlugin("customjava")).thenReturn(true);
+    when(pluginRepository.getPluginInfo("customjava")).thenReturn(new PluginInfo("customjava").setBasePlugin("java"));
+    // php plugin has been uninstalled between runs of scanner and compute engine
+    when(pluginRepository.hasPlugin("php")).thenReturn(false);
+
     underTest.execute();
 
-    assertThat(analysisMetadataHolder.getScannerPluginsByKey()).containsOnlyKeys("java", "php", "customjava");
     assertThat(analysisMetadataHolder.getScannerPluginsByKey().values()).extracting(ScannerPlugin::getKey, ScannerPlugin::getBasePluginKey, ScannerPlugin::getUpdatedAt)
-      .containsOnly(
+      .containsExactlyInAnyOrder(
         tuple("java", null, 12345L),
         tuple("customjava", "java", 111111L),
         tuple("php", null, 678910L));
index e2f053cd744f295b419f426dff0a07d66955169b..42c44f8f28439604d571bbc3e12f802fc7fe58b7 100644 (file)
@@ -35,6 +35,10 @@ public interface PluginRepository {
 
   Collection<PluginInfo> getPluginInfos();
 
+  /**
+   * Never returns {@code null}, a runtime exception is thrown
+   * if no plugins have the specified key.
+   */
   PluginInfo getPluginInfo(String key);
 
   /**