use of com.contrastsecurity.sarif.ArtifactLocation in project bsl-language-server by 1c-syntax.
the class SarifReporter method createResult.
private static Result createResult(FileInfo fileInfo, Diagnostic diagnostic) {
var uri = Absolute.uri(fileInfo.getPath().toUri()).toString();
var message = new Message().withText(diagnostic.getMessage());
var ruleId = DiagnosticCode.getStringValue(diagnostic.getCode());
var level = severityToResultLevel.get(diagnostic.getSeverity());
var analysisTarget = new ArtifactLocation().withUri(uri);
var locations = List.of(createLocation(diagnostic.getMessage(), uri, diagnostic.getRange()));
var relatedLocations = Optional.ofNullable(diagnostic.getRelatedInformation()).stream().flatMap(Collection::stream).skip(1).map(relatedInformation -> createLocation(relatedInformation.getMessage(), relatedInformation.getLocation().getUri(), relatedInformation.getLocation().getRange())).collect(Collectors.toSet());
return new Result().withMessage(message).withRuleId(ruleId).withLevel(level).withAnalysisTarget(analysisTarget).withLocations(locations).withRelatedLocations(relatedLocations);
}
use of com.contrastsecurity.sarif.ArtifactLocation 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.ArtifactLocation in project bsl-language-server by 1c-syntax.
the class SarifReporter method createInvocation.
private Invocation createInvocation() {
Set<ConfigurationOverride> ruleConfigurationOverrides = new HashSet<>();
var diagnosticsOptions = configuration.getDiagnosticsOptions();
diagnosticsOptions.getParameters().forEach((String key, Either<Boolean, Map<String, Object>> option) -> {
var descriptor = new ReportingDescriptorReference().withId(key);
var configurationOverride = new ConfigurationOverride().withDescriptor(descriptor);
var reportingConfiguration = new ReportingConfiguration();
if (option.isLeft()) {
reportingConfiguration.setEnabled(option.getLeft());
} else {
var parameters = new PropertyBag();
var diagnosticParameters = option.getRight();
diagnosticParameters.forEach(parameters::setAdditionalProperty);
reportingConfiguration.setParameters(parameters);
}
configurationOverride.withConfiguration(reportingConfiguration);
ruleConfigurationOverrides.add(configurationOverride);
});
ArtifactLocation workingDirectory = new ArtifactLocation().withUri(Absolute.uri(new File(".").toURI()).toString());
return new Invocation().withExecutionSuccessful(true).withRuleConfigurationOverrides(ruleConfigurationOverrides).withWorkingDirectory(workingDirectory).withProcessId((int) ProcessHandle.current().pid());
}
Aggregations