From: Sébastien Lesaint Date: Mon, 19 Sep 2016 09:58:06 +0000 (+0200) Subject: SONAR-8093 set analysis date as early as possible X-Git-Tag: 6.1-RC1~5 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=032c10792d0d2e96c0bfa2bb9b8afea863568fff;p=sonarqube.git SONAR-8093 set analysis date as early as possible --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java index 086a4021d89..46fd1d3f653 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java @@ -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)); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java index 17c1ba89827..0d8c2a25581 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java @@ -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);