use of org.sonar.cxx.sensors.utils.InvalidReportException 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.InvalidReportException 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.InvalidReportException 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.InvalidReportException in project sonar-cxx by SonarOpenCommunity.
the class TestwellCtcTxtParser method parse.
/**
* {@inheritDoc}
*/
@Override
public Map<String, CoverageMeasures> parse(File report) {
var coverageData = new HashMap<String, CoverageMeasures>();
try (var scanner = new TextScanner(report, StandardCharsets.UTF_8.name())) {
scanner.useDelimiter(SECTION_SEP);
var headerMatcher = FILE_HEADER.matcher(scanner.next());
while (parseUnit(scanner, coverageData, headerMatcher)) {
headerMatcher.reset(scanner.next());
}
} catch (IOException | NoSuchElementException e) {
throw new InvalidReportException("Testwell CTC++ coverage report '" + report + "' cannot be parsed.", e);
}
return coverageData;
}
use of org.sonar.cxx.sensors.utils.InvalidReportException in project sonar-cxx by SonarOpenCommunity.
the class CxxClangSASensor method processReport.
@Override
protected void processReport(File report) {
try {
var f = new File(report.getPath());
var rootDict = (NSDictionary) PropertyListParser.parse(f);
NSObject[] diagnostics = ((NSArray) require(rootDict.objectForKey("diagnostics"), "Missing mandatory entry 'diagnostics'")).getArray();
NSObject[] sourceFiles = ((NSArray) require(rootDict.objectForKey("files"), "Missing mandatory entry 'files'")).getArray();
for (var diagnostic : diagnostics) {
var diag = (NSDictionary) diagnostic;
String description = ((NSString) require(diag.get("description"), "Missing mandatory entry 'diagnostics/description'")).getContent();
String checkerName = ((NSString) require(diag.get("check_name"), "Missing mandatory entry 'diagnostics/check_name'")).getContent();
var location = (NSDictionary) require(diag.get("location"), "Missing mandatory entry 'diagnostics/location'");
var line = ((NSNumber) require(location.get("line"), "Missing mandatory entry 'diagnostics/location/line'")).intValue();
var column = ((NSNumber) require(location.get("col"), "Missing mandatory entry 'diagnostics/location/col'")).intValue();
var fileIndex = ((NSNumber) require(location.get("file"), "Missing mandatory entry 'diagnostics/location/file'")).intValue();
if (fileIndex < 0 || fileIndex >= sourceFiles.length) {
throw new IllegalArgumentException("Invalid file index");
}
String filePath = ((NSString) sourceFiles[fileIndex]).getContent();
var issue = new CxxReportIssue(checkerName, filePath, Integer.toString(line), Integer.toString(column), description);
addFlowToIssue(diag, sourceFiles, issue);
saveUniqueViolation(issue);
}
} catch (Exception e) {
throw new InvalidReportException("The 'Clang Static Analyzer' report is invalid", e);
}
}
Aggregations