Search in sources :

Example 41 with SMInputCursor

use of org.codehaus.staxmate.in.SMInputCursor in project sonar-rust by elegoff.

the class CoberturaParser method readFileContent.

private static void readFileContent(SMInputCursor classCursor, NewCoverage coverage) throws XMLStreamException {
    SMInputCursor line = classCursor.childElementCursor(LINES).advance().childElementCursor(LINE);
    while (line.getNext() != null) {
        var linum = Integer.parseInt(line.getAttrValue(NUMBER));
        coverage.lineHits(linum, Integer.parseInt(line.getAttrValue(HITS)));
        String isBranch = line.getAttrValue(BRANCH);
        String text = line.getAttrValue(CONDITION_COVERAGE);
        if (!StringUtils.equals(isBranch, "true") || !StringUtils.isNotBlank(text)) {
            continue;
        }
        String[] conditions = StringUtils.split(StringUtils.substringBetween(text, "(", ")"), "/");
        coverage.conditions(linum, Integer.parseInt(conditions[1]), Integer.parseInt(conditions[0]));
    }
}
Also used : SMInputCursor(org.codehaus.staxmate.in.SMInputCursor)

Example 42 with SMInputCursor

use of org.codehaus.staxmate.in.SMInputCursor in project sonar-rust by elegoff.

the class TestSuiteParser method stream.

@Override
public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException {
    SMInputCursor testSuiteCursor = rootCursor.constructDescendantCursor(new ElementFilter("testsuite"));
    while (testSuiteCursor.getNext() != null) {
        String testSuiteClassName = getExpectedAttribute(testSuiteCursor, "name");
        TestSuite testSuite = new TestSuite(testSuiteClassName);
        testSuites.add(testSuite);
        SMInputCursor testCaseCursor = testSuiteCursor.childElementCursor("testcase");
        while (testCaseCursor.getNext() != null) {
            testSuite.addTestCase(parseTestCaseTag(testCaseCursor));
        }
    }
}
Also used : SMInputCursor(org.codehaus.staxmate.in.SMInputCursor) ElementFilter(org.codehaus.staxmate.in.ElementFilter)

Aggregations

SMInputCursor (org.codehaus.staxmate.in.SMInputCursor)42 XMLStreamException (javax.xml.stream.XMLStreamException)9 SMHierarchicCursor (org.codehaus.staxmate.in.SMHierarchicCursor)8 ArrayList (java.util.ArrayList)7 SMInputFactory (org.codehaus.staxmate.SMInputFactory)5 InputFile (org.sonar.api.batch.fs.InputFile)5 File (java.io.File)3 ElementFilter (org.codehaus.staxmate.in.ElementFilter)3 SonarException (org.sonar.api.utils.SonarException)3 StaxParser (org.sonar.cxx.sensors.utils.StaxParser)3 CxxReportIssue (org.sonar.cxx.utils.CxxReportIssue)3 HashMap (java.util.HashMap)2 RuleKey (org.sonar.api.rule.RuleKey)2 CoverageMeasures (org.sonar.cxx.sensors.coverage.CoverageMeasures)2 EmptyReportException (org.sonar.cxx.sensors.utils.EmptyReportException)2 InvalidReportException (org.sonar.cxx.sensors.utils.InvalidReportException)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1