use of org.sonar.cxx.sensors.utils.StaxParser in project sonar-cxx by SonarOpenCommunity.
the class CxxOtherSensor method processReport.
@Override
public void processReport(File report) {
try {
var parser = new StaxParser((SMHierarchicCursor rootCursor) -> {
rootCursor.advance();
SMInputCursor errorCursor = rootCursor.childElementCursor("error");
while (errorCursor.getNext() != null) {
String file = errorCursor.getAttrValue("file");
String line = errorCursor.getAttrValue("line");
String column = errorCursor.getAttrValue("column");
String id = errorCursor.getAttrValue("id");
String msg = errorCursor.getAttrValue("msg");
var issue = new CxxReportIssue(id, file, line, column, msg);
saveUniqueViolation(issue);
}
});
parser.parse(report);
} catch (XMLStreamException e) {
throw new InvalidReportException("The 'other' report is invalid", e);
}
}
use of org.sonar.cxx.sensors.utils.StaxParser 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;
}
use of org.sonar.cxx.sensors.utils.StaxParser 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;
}
use of org.sonar.cxx.sensors.utils.StaxParser 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;
}
use of org.sonar.cxx.sensors.utils.StaxParser in project sonar-cxx by SonarOpenCommunity.
the class XunitReportParserTest method shouldThrowWhenGivenInvalidTime.
@Test(expected = javax.xml.stream.XMLStreamException.class)
public void shouldThrowWhenGivenInvalidTime() throws javax.xml.stream.XMLStreamException {
parserHandler = new XunitReportParser("");
parser = new StaxParser(parserHandler, false);
File report = TestUtils.loadResource(pathPrefix + "invalid-time-xunit-report.xml");
parser.parse(report);
}
Aggregations