]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7166 add explicit error when CeTask.componentKey is null 764/head
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 2 Feb 2016 11:18:16 +0000 (12:18 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 4 Feb 2016 16:28:09 +0000 (17:28 +0100)
server/sonar-server/src/main/java/org/sonar/server/computation/step/LoadReportAnalysisMetadataHolderStep.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/LoadReportAnalysisMetadataHolderStepTest.java

index f602a4e027b2d74712dfa7aa4443bda9cb06a1c8..200e540a4007b338da2ee11249b79e69990fdac5 100644 (file)
  */
 package org.sonar.server.computation.step;
 
+import org.sonar.api.utils.MessageException;
 import org.sonar.batch.protocol.output.BatchReport;
 import org.sonar.server.computation.analysis.MutableAnalysisMetadataHolder;
 import org.sonar.server.computation.batch.BatchReportReader;
 import org.sonar.server.computation.queue.CeTask;
 
-import static com.google.common.base.Preconditions.checkState;
+import static java.lang.String.format;
 
 /**
  * Feed analysis metadata holder with metadata from the analysis report.
@@ -55,11 +56,19 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep {
 
   private void checkProjectKeyConsistency(BatchReport.Metadata reportMetadata) {
     String reportProjectKey = projectKeyFromReport(reportMetadata);
-    checkState(
-      ceTask.getComponentKey().equals(reportProjectKey),
-      "ProjectKey in report (%s) is not consistent with projectKey under which the report as been submitted (%s)",
-      reportProjectKey,
-      ceTask.getComponentKey());
+    if (ceTask.getComponentKey() == null) {
+      throw MessageException.of(format(
+        "Compute Engine task component key is null. Project with UUID %s must have been deleted since report was uploaded. Can not proceed.",
+        ceTask.getComponentUuid()
+        ));
+    }
+    if (!ceTask.getComponentKey().equals(reportProjectKey)) {
+      throw MessageException.of(format(
+        "ProjectKey in report (%s) is not consistent with projectKey under which the report as been submitted (%s)",
+        reportProjectKey,
+        ceTask.getComponentKey()
+        ));
+    }
   }
 
   private static String projectKeyFromReport(BatchReport.Metadata reportMetadata) {
index 762c507f09f3c4c738ccb7499f1dbbc5ce2a6f93..2ae20cd8289c15b4ddbd688161228d0fc3829335 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.server.computation.step;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
+import org.sonar.api.utils.MessageException;
 import org.sonar.batch.protocol.output.BatchReport;
 import org.sonar.server.computation.analysis.MutableAnalysisMetadataHolderRule;
 import org.sonar.server.computation.batch.BatchReportReaderRule;
@@ -134,13 +135,27 @@ public class LoadReportAnalysisMetadataHolderStepTest {
   }
 
   @Test
-  public void execute_fails_with_ISE_when_projectKey_in_report_is_different_from_componentKey_in_CE_task() {
+  public void execute_fails_with_MessageException_if_projectKey_is_null_in_CE_task() {
+    CeTask res = mock(CeTask.class);
+    when(res.getComponentUuid()).thenReturn("prj_uuid");
+    reportReader.setMetadata(BatchReport.Metadata.newBuilder().build());
+
+    ComputationStep underTest = new LoadReportAnalysisMetadataHolderStep(res, reportReader, analysisMetadataHolder);
+
+    expectedException.expect(MessageException.class);
+    expectedException.expectMessage("Compute Engine task component key is null. Project with UUID prj_uuid must have been deleted since report was uploaded. Can not proceed.");
+
+    underTest.execute();
+  }
+
+  @Test
+  public void execute_fails_with_MessageException_when_projectKey_in_report_is_different_from_componentKey_in_CE_task() {
     reportReader.setMetadata(
-        BatchReport.Metadata.newBuilder()
-            .setProjectKey("some other key")
-            .build());
+      BatchReport.Metadata.newBuilder()
+        .setProjectKey("some other key")
+        .build());
 
-    expectedException.expect(IllegalStateException.class);
+    expectedException.expect(MessageException.class);
     expectedException.expectMessage("ProjectKey in report (some other key) is not consistent with projectKey under which the report as been submitted (" + PROJECT_KEY + ")");
 
     underTest.execute();