Search in sources :

Example 1 with EmptyReportException

use of org.sonar.cxx.sensors.utils.EmptyReportException in project sonar-cxx by SonarOpenCommunity.

the class InferParser method parse.

public void parse(File report) {
    InferIssue[] inferIssues;
    try {
        try (var reader = new JsonReader(new FileReader(report))) {
            inferIssues = new Gson().fromJson(reader, InferIssue[].class);
            if (inferIssues == null) {
                throw new EmptyReportException("The 'Infer JSON' report is empty");
            }
        }
    } catch (IOException e) {
        throw new InvalidReportException("The 'Infer JSON' report is invalid", e);
    }
    for (var issue : inferIssues) {
        if (issue.getFile() != null) {
            var cxxReportIssue = new CxxReportIssue(issue.getBugType(), issue.getFile(), String.valueOf(issue.getLine()), null, issue.getQualifier());
            sensor.saveUniqueViolation(cxxReportIssue);
        } else {
            LOG.debug("Invalid infer issue '{}', skipping", issue.toString());
        }
    }
}
Also used : EmptyReportException(org.sonar.cxx.sensors.utils.EmptyReportException) JsonReader(com.google.gson.stream.JsonReader) Gson(com.google.gson.Gson) FileReader(java.io.FileReader) IOException(java.io.IOException) InvalidReportException(org.sonar.cxx.sensors.utils.InvalidReportException) CxxReportIssue(org.sonar.cxx.utils.CxxReportIssue)

Example 2 with EmptyReportException

use of org.sonar.cxx.sensors.utils.EmptyReportException in project sonar-cxx by SonarOpenCommunity.

the class CoberturaParser method parse.

/**
 * {@inheritDoc}
 */
@Override
public Map<String, CoverageMeasures> parse(File report) {
    var coverageData = new HashMap<String, CoverageMeasures>();
    try {
        baseDir = Paths.get(".");
        var sourceParser = new StaxParser((SMHierarchicCursor rootCursor) -> {
            try {
                rootCursor.advance();
            } catch (com.ctc.wstx.exc.WstxEOFException e) {
                throw new EmptyReportException("Coverage report " + report + " result is empty (parsed by " + this + ")", e);
            }
            readBaseDir(rootCursor.descendantElementCursor("source"));
        });
        sourceParser.parse(report);
        var packageParser = new StaxParser((SMHierarchicCursor rootCursor) -> {
            rootCursor.advance();
            collectPackageMeasures(rootCursor.descendantElementCursor("package"), coverageData);
        });
        packageParser.parse(report);
    } catch (XMLStreamException e) {
        throw new InvalidReportException("Cobertura coverage report '" + report + "' cannot be parsed.", e);
    }
    return coverageData;
}
Also used : SMHierarchicCursor(org.codehaus.staxmate.in.SMHierarchicCursor) EmptyReportException(org.sonar.cxx.sensors.utils.EmptyReportException) XMLStreamException(javax.xml.stream.XMLStreamException) HashMap(java.util.HashMap) StaxParser(org.sonar.cxx.sensors.utils.StaxParser) InvalidReportException(org.sonar.cxx.sensors.utils.InvalidReportException)

Example 3 with EmptyReportException

use of org.sonar.cxx.sensors.utils.EmptyReportException in project sonar-cxx by SonarOpenCommunity.

the class VisualStudioParser method parse.

/**
 * {@inheritDoc}
 */
@Override
public Map<String, CoverageMeasures> parse(File report) {
    var coverageData = new HashMap<String, CoverageMeasures>();
    try {
        var parser = new StaxParser((SMHierarchicCursor rootCursor) -> {
            try {
                rootCursor.advance();
            } catch (com.ctc.wstx.exc.WstxEOFException e) {
                throw new EmptyReportException("Coverage report " + report + " result is empty (parsed by " + this + ")", e);
            }
            collectModuleMeasures(rootCursor.descendantElementCursor("module"), coverageData);
        });
        parser.parse(report);
    } catch (XMLStreamException e) {
        throw new InvalidReportException("Visual Studio coverage report '" + report + "' cannot be parsed.", e);
    }
    return coverageData;
}
Also used : SMHierarchicCursor(org.codehaus.staxmate.in.SMHierarchicCursor) EmptyReportException(org.sonar.cxx.sensors.utils.EmptyReportException) XMLStreamException(javax.xml.stream.XMLStreamException) HashMap(java.util.HashMap) StaxParser(org.sonar.cxx.sensors.utils.StaxParser) InvalidReportException(org.sonar.cxx.sensors.utils.InvalidReportException)

Example 4 with EmptyReportException

use of org.sonar.cxx.sensors.utils.EmptyReportException in project sonar-cxx by SonarOpenCommunity.

the class BullseyeParser method parse.

/**
 * {@inheritDoc}
 */
@Override
public Map<String, CoverageMeasures> parse(File report) {
    var coverageData = new HashMap<String, CoverageMeasures>();
    try {
        var topLevelparser = new StaxParser((SMHierarchicCursor rootCursor) -> {
            try {
                rootCursor.advance();
            } catch (com.ctc.wstx.exc.WstxEOFException e) {
                throw new EmptyReportException("Coverage report " + report + " result is empty (parsed by " + this + ")", e);
            }
            collectCoverageLeafNodes(rootCursor.getAttrValue("dir"), rootCursor.childElementCursor("src"), coverageData);
        });
        var parser = new StaxParser((SMHierarchicCursor rootCursor) -> {
            rootCursor.advance();
            collectCoverage2(rootCursor.getAttrValue("dir"), rootCursor.childElementCursor("folder"), coverageData);
        });
        topLevelparser.parse(report);
        parser.parse(report);
    } catch (XMLStreamException e) {
        throw new InvalidReportException("Bullseye coverage report '" + report + "' cannot be parsed.", e);
    }
    return coverageData;
}
Also used : SMHierarchicCursor(org.codehaus.staxmate.in.SMHierarchicCursor) EmptyReportException(org.sonar.cxx.sensors.utils.EmptyReportException) XMLStreamException(javax.xml.stream.XMLStreamException) HashMap(java.util.HashMap) StaxParser(org.sonar.cxx.sensors.utils.StaxParser) InvalidReportException(org.sonar.cxx.sensors.utils.InvalidReportException)

Example 5 with EmptyReportException

use of org.sonar.cxx.sensors.utils.EmptyReportException in project sonar-cxx by SonarOpenCommunity.

the class CxxVeraxxSensor method processReport.

@Override
protected void processReport(File report) {
    try {
        var parser = new StaxParser((SMHierarchicCursor rootCursor) -> {
            try {
                rootCursor.advance();
            } catch (com.ctc.wstx.exc.WstxEOFException e) {
                throw new EmptyReportException("The 'Vera++' report is empty", e);
            }
            SMInputCursor fileCursor = rootCursor.childElementCursor("file");
            while (fileCursor.getNext() != null) {
                String name = fileCursor.getAttrValue("name");
                SMInputCursor errorCursor = fileCursor.childElementCursor("error");
                while (errorCursor.getNext() != null) {
                    if (!"error".equals(name)) {
                        String line = errorCursor.getAttrValue("line");
                        String message = errorCursor.getAttrValue("message");
                        String source = errorCursor.getAttrValue("source");
                        var issue = new CxxReportIssue(source, name, line, null, message);
                        saveUniqueViolation(issue);
                    } else {
                        LOG.debug("Error in file '{}', with message '{}'", name + "(" + errorCursor.getAttrValue("line") + ")", errorCursor.getAttrValue("message"));
                    }
                }
            }
        });
        parser.parse(report);
    } catch (XMLStreamException e) {
        throw new InvalidReportException("The 'Vera++' report is invalid", e);
    }
}
Also used : SMInputCursor(org.codehaus.staxmate.in.SMInputCursor) SMHierarchicCursor(org.codehaus.staxmate.in.SMHierarchicCursor) EmptyReportException(org.sonar.cxx.sensors.utils.EmptyReportException) XMLStreamException(javax.xml.stream.XMLStreamException) StaxParser(org.sonar.cxx.sensors.utils.StaxParser) InvalidReportException(org.sonar.cxx.sensors.utils.InvalidReportException) CxxReportIssue(org.sonar.cxx.utils.CxxReportIssue)

Aggregations

EmptyReportException (org.sonar.cxx.sensors.utils.EmptyReportException)6 XMLStreamException (javax.xml.stream.XMLStreamException)5 SMHierarchicCursor (org.codehaus.staxmate.in.SMHierarchicCursor)5 InvalidReportException (org.sonar.cxx.sensors.utils.InvalidReportException)5 StaxParser (org.sonar.cxx.sensors.utils.StaxParser)5 HashMap (java.util.HashMap)3 CxxReportIssue (org.sonar.cxx.utils.CxxReportIssue)3 SMInputCursor (org.codehaus.staxmate.in.SMInputCursor)2 Gson (com.google.gson.Gson)1 JsonReader (com.google.gson.stream.JsonReader)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1