use of org.codehaus.staxmate.in.SMInputCursor in project sonar-java by SonarSource.
the class SurefireStaxHandler method stream.
public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException {
SMInputCursor testSuite = rootCursor.constructDescendantCursor(new ElementFilter("testsuite"));
SMEvent testSuiteEvent;
for (testSuiteEvent = testSuite.getNext(); testSuiteEvent != null; testSuiteEvent = testSuite.getNext()) {
if (testSuiteEvent.compareTo(SMEvent.START_ELEMENT) == 0) {
String testSuiteClassName = testSuite.getAttrValue("name");
parseTestCase(testSuiteClassName, testSuite.childCursor(new ElementFilter("testcase")));
}
}
}
use of org.codehaus.staxmate.in.SMInputCursor in project sonar-java by SonarSource.
the class SurefireStaxHandler method parseTestResult.
private static UnitTestResult parseTestResult(SMInputCursor testCaseCursor, String testSuiteClassName) throws XMLStreamException {
UnitTestResult detail = new UnitTestResult();
String name = getTestCaseName(testCaseCursor);
detail.setName(name);
detail.setTestSuiteClassName(testSuiteClassName);
String status = UnitTestResult.STATUS_OK;
String time = testCaseCursor.getAttrValue("time");
Long duration = null;
SMInputCursor childNode = testCaseCursor.descendantElementCursor();
if (childNode.getNext() != null) {
String elementName = childNode.getLocalName();
if ("skipped".equals(elementName)) {
status = UnitTestResult.STATUS_SKIPPED;
// bug with surefire reporting wrong time for skipped tests
duration = 0L;
} else if ("failure".equals(elementName)) {
status = UnitTestResult.STATUS_FAILURE;
setStackAndMessage(detail, childNode);
} else if ("error".equals(elementName)) {
status = UnitTestResult.STATUS_ERROR;
setStackAndMessage(detail, childNode);
}
}
while (childNode.getNext() != null) {
// make sure we loop till the end of the elements cursor
}
if (duration == null) {
duration = getTimeAttributeInMS(time);
}
detail.setDurationMilliseconds(duration);
detail.setStatus(status);
return detail;
}
use of org.codehaus.staxmate.in.SMInputCursor in project sonar-python by SonarSource.
the class TestSuiteParser method parseTestCaseTag.
private static TestCase parseTestCaseTag(SMInputCursor testCaseCursor) throws XMLStreamException {
String name = parseTestCaseName(testCaseCursor);
Double time = parseTime(testCaseCursor);
String status = TestCase.STATUS_OK;
String stack = "";
String msg = "";
String file = testCaseCursor.getAttrValue("file");
String testClassName = testCaseCursor.getAttrValue("classname");
SMInputCursor childCursor = testCaseCursor.childElementCursor();
if (childCursor.getNext() != null) {
String elementName = childCursor.getLocalName();
if (TestCase.STATUS_SKIPPED.equals(elementName)) {
status = TestCase.STATUS_SKIPPED;
} else if (TestCase.STATUS_FAILURE.equals(elementName)) {
status = TestCase.STATUS_FAILURE;
msg = getExpectedAttribute(childCursor, "message");
stack = childCursor.collectDescendantText();
} else if (TestCase.STATUS_ERROR.equals(elementName)) {
status = TestCase.STATUS_ERROR;
msg = getExpectedAttribute(childCursor, "message");
stack = childCursor.collectDescendantText();
}
}
return new TestCase(name, time.intValue(), status, stack, msg, file, testClassName);
}
use of org.codehaus.staxmate.in.SMInputCursor in project sonar-python by SonarSource.
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));
}
}
}
use of org.codehaus.staxmate.in.SMInputCursor in project sonar-python by SonarSource.
the class CoberturaParser method parseReport.
public void parseReport(File xmlFile, SensorContext context, final Map<InputFile, NewCoverage> coverageData) throws XMLStreamException {
LOG.info("Parsing report '{}'", xmlFile);
unresolvedFilenameCount = 0;
StaxParser parser = new StaxParser(rootCursor -> {
File defaultBaseDirectory = context.fileSystem().baseDir();
List<File> baseDirectories = Collections.singletonList(defaultBaseDirectory);
try {
rootCursor.advance();
} catch (com.ctc.wstx.exc.WstxEOFException eofExc) {
LOG.debug("Unexpected end of file is encountered", eofExc);
throw new EmptyReportException();
}
SMInputCursor cursor = rootCursor.childElementCursor();
while (cursor.getNext() != null) {
if ("sources".equals(cursor.getLocalName())) {
baseDirectories = extractBaseDirectories(cursor, defaultBaseDirectory);
} else if ("packages".equals(cursor.getLocalName())) {
collectFileMeasures(cursor.descendantElementCursor("class"), context, coverageData, baseDirectories);
}
}
});
parser.parse(xmlFile);
if (unresolvedFilenameCount > 1) {
LOG.error("Cannot resolve {} file paths, ignoring coverage measures for those files", unresolvedFilenameCount);
}
}
Aggregations