*/
package org.sonar.server.computation.step;
+import org.sonar.api.utils.MessageException;
import org.sonar.batch.protocol.output.BatchReport;
import org.sonar.server.computation.analysis.MutableAnalysisMetadataHolder;
import org.sonar.server.computation.batch.BatchReportReader;
import org.sonar.server.computation.queue.CeTask;
-import static com.google.common.base.Preconditions.checkState;
+import static java.lang.String.format;
/**
* Feed analysis metadata holder with metadata from the analysis report.
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());
+ if (ceTask.getComponentKey() == null) {
+ throw MessageException.of(format(
+ "Compute Engine task component key is null. Project with UUID %s must have been deleted since report was uploaded. Can not proceed.",
+ ceTask.getComponentUuid()
+ ));
+ }
+ if (!ceTask.getComponentKey().equals(reportProjectKey)) {
+ throw MessageException.of(format(
+ "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) {
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.sonar.api.utils.MessageException;
import org.sonar.batch.protocol.output.BatchReport;
import org.sonar.server.computation.analysis.MutableAnalysisMetadataHolderRule;
import org.sonar.server.computation.batch.BatchReportReaderRule;
}
@Test
- public void execute_fails_with_ISE_when_projectKey_in_report_is_different_from_componentKey_in_CE_task() {
+ public void execute_fails_with_MessageException_if_projectKey_is_null_in_CE_task() {
+ CeTask res = mock(CeTask.class);
+ when(res.getComponentUuid()).thenReturn("prj_uuid");
+ reportReader.setMetadata(BatchReport.Metadata.newBuilder().build());
+
+ ComputationStep underTest = new LoadReportAnalysisMetadataHolderStep(res, reportReader, analysisMetadataHolder);
+
+ expectedException.expect(MessageException.class);
+ expectedException.expectMessage("Compute Engine task component key is null. Project with UUID prj_uuid must have been deleted since report was uploaded. Can not proceed.");
+
+ underTest.execute();
+ }
+
+ @Test
+ public void execute_fails_with_MessageException_when_projectKey_in_report_is_different_from_componentKey_in_CE_task() {
reportReader.setMetadata(
- BatchReport.Metadata.newBuilder()
- .setProjectKey("some other key")
- .build());
+ BatchReport.Metadata.newBuilder()
+ .setProjectKey("some other key")
+ .build());
- expectedException.expect(IllegalStateException.class);
+ expectedException.expect(MessageException.class);
expectedException.expectMessage("ProjectKey in report (some other key) is not consistent with projectKey under which the report as been submitted (" + PROJECT_KEY + ")");
underTest.execute();