Browse Source

SONAR-7166 fix check of projectKey for branches analyses

tags/5.4-M10
Sébastien Lesaint 8 years ago
parent
commit
9b79004bd2

+ 18
- 5
server/sonar-server/src/main/java/org/sonar/server/computation/step/LoadReportAnalysisMetadataHolderStep.java View 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";

+ 3
- 0
server/sonar-server/src/test/java/org/sonar/server/computation/step/LoadReportAnalysisMetadataHolderStepTest.java View 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);

Loading…
Cancel
Save