Search in sources :

Example 1 with SonarIssue

use of com.hp.octane.integrations.services.vulnerabilities.sonar.dto.SonarIssue in project octane-ci-java-sdk by MicroFocus.

the class SonarToOctaneIssueUtil method createOctaneIssues.

public static List<OctaneIssue> createOctaneIssues(List<SonarIssue> issues, String remoteTag, String sonarUrl, Set<String> issuesRequiredExtendedDataKeys, Map<String, SonarRule> rules) {
    if (issues == null) {
        return new ArrayList<>();
    }
    DTOFactory dtoFactory = DTOFactory.getInstance();
    List<OctaneIssue> octaneIssues = new ArrayList<>();
    for (SonarIssue issue : issues) {
        OctaneIssue octaneIssue = createOctaneIssue(dtoFactory, issue, rules, sonarUrl);
        octaneIssue.setRemoteTag(remoteTag);
        octaneIssues.add(octaneIssue);
        if (issuesRequiredExtendedDataKeys.contains(issue.getKey())) {
            Map<String, String> extendedData = prepareExtendedData(issue, rules);
            octaneIssue.setExtendedData(extendedData);
            setOctaneStatus(issue, octaneIssue, true);
        } else {
            setOctaneStatus(issue, octaneIssue, false);
        }
    }
    return octaneIssues;
}
Also used : SonarIssue(com.hp.octane.integrations.services.vulnerabilities.sonar.dto.SonarIssue) DTOFactory(com.hp.octane.integrations.dto.DTOFactory) OctaneIssue(com.hp.octane.integrations.dto.securityscans.OctaneIssue)

Example 2 with SonarIssue

use of com.hp.octane.integrations.services.vulnerabilities.sonar.dto.SonarIssue in project octane-ci-java-sdk by MicroFocus.

the class SonarVulnerabilitiesServiceImpl method getIssuesFromSecurityTool.

public List<SonarIssue> getIssuesFromSecurityTool(VulnerabilitiesQueueItem queueItem) {
    String projectKey = queueItem.getAdditionalProperties().get(PROJECT_KEY_KEY);
    String sonarToken = queueItem.getAdditionalProperties().get(SONAR_TOKEN_KEY);
    StringBuilder errorMessage = new StringBuilder().append("failed to get sonarqube vulnerability data for project key: ").append(projectKey).append(" with jobId: ").append(queueItem.getJobId()).append(" with buildId: ").append(queueItem.getBuildId());
    try {
        List<SonarIssue> sonarIssues = new ArrayList<>();
        // retrieve coverage report from Sonar
        Integer pageIndex = 0;
        JsonNode jsonReport;
        do {
            pageIndex++;
            URIBuilder vulnerabilityQuery = createQueryForSonarVulnerability(pageIndex, queueItem);
            InputStream reportStream = SonarUtils.getDataFromSonar(projectKey, sonarToken, vulnerabilityQuery);
            jsonReport = CIPluginSDKUtils.getObjectMapper().readTree(reportStream);
            sonarIssues.addAll(getSonarIssuesFromReport(jsonReport));
        } while (SonarUtils.sonarReportHasAnotherPage(pageIndex, jsonReport));
        return sonarIssues;
    } catch (IOException e) {
        logger.error(errorMessage, e);
        throw new PermanentException(e);
    }
}
Also used : InputStream(java.io.InputStream) PermanentException(com.hp.octane.integrations.exceptions.PermanentException) SonarIssue(com.hp.octane.integrations.services.vulnerabilities.sonar.dto.SonarIssue) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 3 with SonarIssue

use of com.hp.octane.integrations.services.vulnerabilities.sonar.dto.SonarIssue in project octane-ci-java-sdk by MicroFocus.

the class SonarVulnerabilitiesServiceImpl method getSonarIssuesFromReport.

public List<SonarIssue> getSonarIssuesFromReport(JsonNode jsonReport) {
    List<SonarIssue> sonarIssues;
    JsonNode issues = jsonReport.get("issues");
    try {
        sonarIssues = mapper.readValue(issues.toString(), new TypeReference<List<SonarIssue>>() {
        });
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return sonarIssues;
}
Also used : SonarIssue(com.hp.octane.integrations.services.vulnerabilities.sonar.dto.SonarIssue) JsonNode(com.fasterxml.jackson.databind.JsonNode) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException)

Aggregations

SonarIssue (com.hp.octane.integrations.services.vulnerabilities.sonar.dto.SonarIssue)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 IOException (java.io.IOException)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 DTOFactory (com.hp.octane.integrations.dto.DTOFactory)1 OctaneIssue (com.hp.octane.integrations.dto.securityscans.OctaneIssue)1 PermanentException (com.hp.octane.integrations.exceptions.PermanentException)1 InputStream (java.io.InputStream)1 URIBuilder (org.apache.http.client.utils.URIBuilder)1