From: Sébastien Lesaint Date: Thu, 28 Jan 2016 12:43:48 +0000 (+0100) Subject: SONAR-7166 fix check of projectKey for branches analyses X-Git-Tag: 5.4-M10~9 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F739%2Fhead;p=sonarqube.git SONAR-7166 fix check of projectKey for branches analyses --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/LoadReportAnalysisMetadataHolderStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/LoadReportAnalysisMetadataHolderStep.java index f3596cc2557..f602a4e027b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/LoadReportAnalysisMetadataHolderStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/LoadReportAnalysisMetadataHolderStep.java @@ -44,11 +44,8 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep { @Override public void execute() { BatchReport.Metadata reportMetadata = reportReader.readMetadata(); - checkState( - ceTask.getComponentKey().equals(reportMetadata.getProjectKey()), - "ProjectKey in report (%s) is not consistent with projectKey under which the report as been submitted (%s)", - reportMetadata.getProjectKey(), - ceTask.getComponentKey()); + + checkProjectKeyConsistency(reportMetadata); mutableAnalysisMetadataHolder.setRootComponentRef(reportMetadata.getRootComponentRef()); mutableAnalysisMetadataHolder.setBranch(reportMetadata.hasBranch() ? reportMetadata.getBranch() : null); @@ -56,6 +53,22 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep { mutableAnalysisMetadataHolder.setCrossProjectDuplicationEnabled(reportMetadata.hasCrossProjectDuplicationActivated() && reportMetadata.getCrossProjectDuplicationActivated()); } + 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()); + } + + private static String projectKeyFromReport(BatchReport.Metadata reportMetadata) { + if (reportMetadata.hasBranch()) { + return reportMetadata.getProjectKey() + ":" + reportMetadata.getBranch(); + } + return reportMetadata.getProjectKey(); + } + @Override public String getDescription() { return "Load analysis metadata"; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/LoadReportAnalysisMetadataHolderStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/LoadReportAnalysisMetadataHolderStepTest.java index 9d4032fcde6..762c507f09f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/LoadReportAnalysisMetadataHolderStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/LoadReportAnalysisMetadataHolderStepTest.java @@ -79,6 +79,9 @@ public class LoadReportAnalysisMetadataHolderStepTest { .setBranch(BRANCH) .build()); + CeTask ceTask = createCeTask(PROJECT_KEY + ":" + BRANCH); + ComputationStep underTest = new LoadReportAnalysisMetadataHolderStep(ceTask, reportReader, analysisMetadataHolder); + underTest.execute(); assertThat(analysisMetadataHolder.getBranch()).isEqualTo(BRANCH);