]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7166 fix check of projectKey for branches analyses 739/head
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 28 Jan 2016 12:43:48 +0000 (13:43 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 28 Jan 2016 13:55:17 +0000 (14:55 +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 f3596cc2557b595b127e0e251d13cc0563eee939..f602a4e027b2d74712dfa7aa4443bda9cb06a1c8 100644 (file)
@@ -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";
index 9d4032fcde677c568c94a2a56daef3c512a5ff6d..762c507f09f3c4c738ccb7499f1dbbc5ce2a6f93 100644 (file)
@@ -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);