use of com.contrastsecurity.sarif.Region in project bsl-language-server by 1c-syntax.
the class SarifReporter method createLocation.
private static Location createLocation(String messageString, String uri, Range range) {
var message = new Message().withText(messageString);
var artifactLocation = new ArtifactLocation().withUri(uri);
var region = new Region().withStartLine(range.getStart().getLine() + 1).withStartColumn(range.getStart().getCharacter() + 1).withEndLine(range.getEnd().getLine() + 1).withEndColumn(range.getEnd().getCharacter() + 1);
var physicalLocation = new PhysicalLocation().withArtifactLocation(artifactLocation).withRegion(region);
return new Location().withMessage(message).withPhysicalLocation(physicalLocation);
}
use of com.contrastsecurity.sarif.Region in project aws-codeguru-cli by aws.
the class ResultsAdapter method createHtmlReport.
private static void createHtmlReport(final Path outputDir, final ScanMetaData scanMetaData, final List<RecommendationSummary> recommendations) throws IOException {
int validFindings = 0;
// sort by file name and line number
sortByFileName(recommendations);
Parser parser = Parser.builder().build();
HtmlRenderer renderer = HtmlRenderer.builder().build();
val htmlFile = outputDir.resolve("codeguru-report.html");
try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(htmlFile.toFile()), StandardCharsets.UTF_8)) {
writer.write("<!DOCTYPE html>\n<html lang=\"en\">\n");
writer.write("<body>\n");
writer.write("<h2>CodeGuru Reviewer Recommendations</h2>\n");
val awsUrlPrfix = "https://console.aws.amazon.com/codeguru/reviewer";
val associationUrl = String.format("%s?region=%s#/ciworkflows/associationdetails/%s", awsUrlPrfix, scanMetaData.getRegion(), scanMetaData.getAssociationArn());
val scanUrl = String.format("%s?region=%s#/codereviews/details/%s", awsUrlPrfix, scanMetaData.getRegion(), scanMetaData.getCodeReviewArn());
writer.write(renderer.render(parser.parse(String.format("**CodeGuru Repository ARN**: [%s](%s)%n", scanMetaData.getAssociationArn(), associationUrl))));
writer.write(renderer.render(parser.parse(String.format("**CodeGuru Scan ARN**: [%s](%s)%n", scanMetaData.getCodeReviewArn(), scanUrl))));
writer.write("\n<br/><hr style=\"width:90%\"><br/>\n");
for (val recommendation : recommendations) {
val filePath = scanMetaData.getRepositoryRoot().resolve(recommendation.filePath()).toAbsolutePath();
if (filePath == null || !filePath.toFile().isFile()) {
if (filePath != null && !(filePath.endsWith(".") || filePath.endsWith("/"))) {
Log.warn("Dropping finding because file not found on disk: %s", filePath);
}
continue;
}
validFindings++;
String lineMsg;
if (!recommendation.startLine().equals(recommendation.endLine()) && recommendation.endLine() != null) {
lineMsg = String.format("### In: [%s](%s) L%d %n", filePath, filePath.toUri(), recommendation.startLine());
} else {
lineMsg = String.format("### In: [%s](%s) L%d - L%d %n", filePath, filePath.toUri(), recommendation.startLine(), recommendation.endLine());
}
Node document = parser.parse(String.format("### In: [%s](%s) L%d %n", filePath, filePath.toUri(), recommendation.startLine()));
writer.write(renderer.render(document));
document = parser.parse("**Issue:** " + recommendation.description());
writer.write(renderer.render(document));
writer.write(String.format("<p><strong>Severity:</strong> %s<p/>", recommendation.severity()));
if (recommendation.ruleMetadata() != null && recommendation.ruleMetadata().ruleId() != null) {
val manifest = recommendation.ruleMetadata();
writer.write(String.format("<p><strong>Rule ID:</strong> %s<p/>", manifest.ruleId()));
writer.write(String.format("<p><strong>Rule Name:</strong> %s<p/>", manifest.ruleName()));
document = parser.parse("**Description:** " + manifest.longDescription());
writer.write(renderer.render(document));
if (manifest.ruleTags() != null && !manifest.ruleTags().isEmpty()) {
val mdList = manifest.ruleTags().stream().map(s -> String.format("- %s%n", s)).collect(Collectors.joining());
document = parser.parse("**Tags:**\n" + mdList);
writer.write(renderer.render(document));
}
}
writer.write("\n<hr style=\"width:80%\">\n");
}
writer.write("</body>\n");
writer.write("</html>\n");
}
Log.info("Report with %d recommendations written to:%n%s", validFindings, htmlFile.normalize().toUri());
}
Aggregations