Search in sources :

Example 1 with BuildCoverage

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);
    }
}
Also used : TemporaryException(com.hp.octane.integrations.exceptions.TemporaryException) InputStream(java.io.InputStream) PermanentException(com.hp.octane.integrations.exceptions.PermanentException) BuildCoverage(com.hp.octane.integrations.dto.coverage.BuildCoverage) JsonNode(com.fasterxml.jackson.databind.JsonNode) OctaneResponse(com.hp.octane.integrations.dto.connectivity.OctaneResponse)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 OctaneResponse (com.hp.octane.integrations.dto.connectivity.OctaneResponse)1 BuildCoverage (com.hp.octane.integrations.dto.coverage.BuildCoverage)1 PermanentException (com.hp.octane.integrations.exceptions.PermanentException)1 TemporaryException (com.hp.octane.integrations.exceptions.TemporaryException)1 InputStream (java.io.InputStream)1