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());
}
}
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations