use of com.hp.octane.integrations.dto.coverage.BuildCoverage in project octane-ci-java-sdk by MicroFocus.
the class SonarServiceImpl method retrieveAndPushSonarDataToOctane.
private void retrieveAndPushSonarDataToOctane(SonarBuildCoverageQueueItem queueItem) {
// preflight
if (!coverageService.isSonarReportRelevant(queueItem.jobId)) {
return;
}
StringBuilder errorMessage = new StringBuilder().append("failed to inject sonarqube coverage data to octane for project key: ").append(queueItem.projectKey).append(" with ciIdentity: ").append(configurer.octaneConfiguration.getInstanceId()).append(" with jobId: ").append(queueItem.jobId).append(" with buildId: ").append(queueItem.buildId);
try {
// retrieve coverage report from Sonar
Integer pageIndex = 0;
BuildCoverage buildCoverageReport = dtoFactory.newDTO(BuildCoverage.class);
JsonNode jsonReport;
do {
pageIndex++;
InputStream reportStream = getPageFromSonar(queueItem, pageIndex);
jsonReport = CIPluginSDKUtils.getObjectMapper().readTree(reportStream);
buildCoverageReport.mergeSonarCoverageReport(jsonReport);
} while (SonarUtils.sonarReportHasAnotherPage(pageIndex, jsonReport));
// push coverage to Octane
OctaneResponse response = coverageService.pushCoverage(queueItem.jobId, queueItem.buildId, CoverageReportType.SONAR_REPORT, dtoFactory.dtoToJsonStream(buildCoverageReport));
if (response.getStatus() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
errorMessage.append(" with status code: ").append(response.getStatus());
throw new TemporaryException(errorMessage.toString());
} else if (response.getStatus() != HttpStatus.SC_OK) {
errorMessage.append(" with status code: ").append(response.getStatus()).append(" and response body: ").append(response.getBody());
throw new PermanentException(errorMessage.toString());
}
} catch (Throwable throwable) {
logger.error(configurer.octaneConfiguration.getLocationForLog() + errorMessage.toString(), throwable);
throw new PermanentException(throwable);
}
}
Aggregations