]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8093 set analysis date as early as possible
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 19 Sep 2016 09:58:06 +0000 (11:58 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 19 Sep 2016 12:10:21 +0000 (14:10 +0200)
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java

index 086a4021d8990fd0426225d44823e2451d6464d9..46fd1d3f65372386585b629fd8caad6bfdab6927 100644 (file)
@@ -61,12 +61,12 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep {
   @Override
   public void execute() {
     ScannerReport.Metadata reportMetadata = reportReader.readMetadata();
+    mutableAnalysisMetadataHolder.setAnalysisDate(reportMetadata.getAnalysisDate());
 
     checkProjectKeyConsistency(reportMetadata);
 
     mutableAnalysisMetadataHolder.setRootComponentRef(reportMetadata.getRootComponentRef());
     mutableAnalysisMetadataHolder.setBranch(isNotEmpty(reportMetadata.getBranch()) ? reportMetadata.getBranch() : null);
-    mutableAnalysisMetadataHolder.setAnalysisDate(reportMetadata.getAnalysisDate());
     mutableAnalysisMetadataHolder.setCrossProjectDuplicationEnabled(reportMetadata.getCrossProjectDuplicationActivated());
     mutableAnalysisMetadataHolder.setQProfilesByLanguage(transformValues(reportMetadata.getQprofilesPerLanguage(), TO_COMPUTE_QPROFILE));
   }
index 17c1ba89827097584371b0333026a3a4b00c277d..0d8c2a25581364ef4b42e8ecb2fec233f5d385ce 100644 (file)
@@ -23,10 +23,10 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.utils.MessageException;
+import org.sonar.ce.queue.CeTask;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.server.computation.task.projectanalysis.analysis.MutableAnalysisMetadataHolderRule;
 import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReaderRule;
-import org.sonar.ce.queue.CeTask;
 import org.sonar.server.computation.task.step.ComputationStep;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -162,6 +162,21 @@ public class LoadReportAnalysisMetadataHolderStepTest {
     underTest.execute();
   }
 
+  @Test
+  public void execute_sets_analysis_date_even_if_MessageException_is_thrown_because_projectKey_is_different_from_componentKey_in_CE_task() {
+    reportReader.setMetadata(
+      ScannerReport.Metadata.newBuilder()
+        .setProjectKey("some other key")
+        .setAnalysisDate(ANALYSIS_DATE)
+        .build());
+
+    try {
+      underTest.execute();
+    } catch (MessageException e) {
+      assertThat(analysisMetadataHolder.getAnalysisDate()).isEqualTo(ANALYSIS_DATE);
+    }
+  }
+
   private static ScannerReport.Metadata.Builder newBatchReportBuilder() {
     return ScannerReport.Metadata.newBuilder()
       .setProjectKey(PROJECT_KEY);