use of org.sonar.cxx.utils.CxxReportIssue 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.utils.CxxReportIssue 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.utils.CxxReportIssue 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);
}
}
use of org.sonar.cxx.utils.CxxReportIssue in project sonar-cxx by SonarOpenCommunity.
the class ClangTidyParser method parse.
public void parse(File report, String defaultEncoding) throws IOException {
try (var scanner = new TextScanner(report, defaultEncoding)) {
LOG.debug("Encoding='{}'", scanner.encoding());
CxxReportIssue currentIssue = null;
while (scanner.hasNextLine()) {
if (!parseLine(scanner.nextLine())) {
continue;
}
if ("note".equals(issue.level)) {
if (currentIssue != null) {
currentIssue.addFlowElement(issue.path, issue.line, issue.column, issue.info);
}
} else {
if (currentIssue != null) {
sensor.saveUniqueViolation(currentIssue);
}
currentIssue = new CxxReportIssue(issue.ruleId, issue.path, issue.line, issue.column, issue.info);
for (var aliasRuleId : issue.aliasRuleIds) {
currentIssue.addAliasRuleId(aliasRuleId);
}
}
}
if (currentIssue != null) {
sensor.saveUniqueViolation(currentIssue);
}
}
}
use of org.sonar.cxx.utils.CxxReportIssue in project sonar-cxx by SonarOpenCommunity.
the class CxxCompilerSensor method processReport.
@Override
protected void processReport(File report) {
final String reportEncoding = getEncoding();
final String reportRegEx = getRegex();
if (reportRegEx.isEmpty()) {
LOG.error("processReport terminated because of empty custom regular expression");
return;
}
if (!reportRegEx.contains("(?<")) {
LOG.error("processReport terminated because regular expression contains no named-capturing group");
return;
}
try (var scanner = new TextScanner(report, reportEncoding)) {
var pattern = Pattern.compile(reportRegEx);
LOG.debug("Processing '{}' report '{}', Encoding='{}', Pattern='{}'", getCompilerKey(), report, scanner.encoding(), pattern);
while (scanner.hasNextLine()) {
var matcher = pattern.matcher(scanner.nextLine());
if (matcher.find()) {
String filename = alignFilename(getSubSequence(matcher, "file"));
String line = alignLine(getSubSequence(matcher, "line"));
String column = alignColumn(getSubSequence(matcher, "column"));
String id = alignId(getSubSequence(matcher, "id"));
String msg = alignMessage(getSubSequence(matcher, "message"));
if (isInputValid(filename, line, column, id, msg)) {
var issue = new CxxReportIssue(id, filename, line, column, msg);
saveUniqueViolation(issue);
} else {
LOG.debug("Invalid compiler warning: '{}''{}', skipping", id, msg);
}
}
}
} catch (java.io.IOException | java.lang.IllegalArgumentException | java.lang.IllegalStateException e) {
throw new InvalidReportException("The compiler report is invalid", e);
}
}
Aggregations