Search in sources :

Example 1 with ArtifactLocation

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);
}
Also used : ArtifactLocation(com.contrastsecurity.sarif.ArtifactLocation) ToolComponent(com.contrastsecurity.sarif.ToolComponent) SneakyThrows(lombok.SneakyThrows) ServerInfo(org.eclipse.lsp4j.ServerInfo) FileInfo(com.github._1c_syntax.bsl.languageserver.reporters.data.FileInfo) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Diagnostic(org.eclipse.lsp4j.Diagnostic) Range(org.eclipse.lsp4j.Range) ReportingDescriptor(com.contrastsecurity.sarif.ReportingDescriptor) Message(com.contrastsecurity.sarif.Message) Absolute(com.github._1c_syntax.utils.Absolute) ArrayList(java.util.ArrayList) Region(com.contrastsecurity.sarif.Region) HashSet(java.util.HashSet) AnalysisInfo(com.github._1c_syntax.bsl.languageserver.reporters.data.AnalysisInfo) LanguageServerConfiguration(com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration) Map(java.util.Map) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) ConfigurationOverride(com.contrastsecurity.sarif.ConfigurationOverride) Run(com.contrastsecurity.sarif.Run) URI(java.net.URI) Invocation(com.contrastsecurity.sarif.Invocation) Path(java.nio.file.Path) DiagnosticInfo(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo) DiagnosticSeverity(org.eclipse.lsp4j.DiagnosticSeverity) Location(com.contrastsecurity.sarif.Location) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) Collectors(java.util.stream.Collectors) File(java.io.File) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) List(java.util.List) ReportingDescriptorReference(com.contrastsecurity.sarif.ReportingDescriptorReference) PropertyBag(com.contrastsecurity.sarif.PropertyBag) Tool(com.contrastsecurity.sarif.Tool) Optional(java.util.Optional) ReportingConfiguration(com.contrastsecurity.sarif.ReportingConfiguration) SerializationFeature(com.fasterxml.jackson.databind.SerializationFeature) MultiformatMessageString(com.contrastsecurity.sarif.MultiformatMessageString) PhysicalLocation(com.contrastsecurity.sarif.PhysicalLocation) DiagnosticCode(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticCode) Result(com.contrastsecurity.sarif.Result) SarifSchema210(com.contrastsecurity.sarif.SarifSchema210) Message(com.contrastsecurity.sarif.Message) ArtifactLocation(com.contrastsecurity.sarif.ArtifactLocation) Result(com.contrastsecurity.sarif.Result)

Example 2 with ArtifactLocation

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);
}
Also used : Message(com.contrastsecurity.sarif.Message) ArtifactLocation(com.contrastsecurity.sarif.ArtifactLocation) Region(com.contrastsecurity.sarif.Region) PhysicalLocation(com.contrastsecurity.sarif.PhysicalLocation) ArtifactLocation(com.contrastsecurity.sarif.ArtifactLocation) Location(com.contrastsecurity.sarif.Location) PhysicalLocation(com.contrastsecurity.sarif.PhysicalLocation)

Example 3 with ArtifactLocation

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());
}
Also used : Invocation(com.contrastsecurity.sarif.Invocation) PropertyBag(com.contrastsecurity.sarif.PropertyBag) MultiformatMessageString(com.contrastsecurity.sarif.MultiformatMessageString) ReportingDescriptorReference(com.contrastsecurity.sarif.ReportingDescriptorReference) ConfigurationOverride(com.contrastsecurity.sarif.ConfigurationOverride) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) ArtifactLocation(com.contrastsecurity.sarif.ArtifactLocation) File(java.io.File) ReportingConfiguration(com.contrastsecurity.sarif.ReportingConfiguration) HashSet(java.util.HashSet)

Aggregations

ArtifactLocation (com.contrastsecurity.sarif.ArtifactLocation)3 ConfigurationOverride (com.contrastsecurity.sarif.ConfigurationOverride)2 Invocation (com.contrastsecurity.sarif.Invocation)2 Location (com.contrastsecurity.sarif.Location)2 Message (com.contrastsecurity.sarif.Message)2 MultiformatMessageString (com.contrastsecurity.sarif.MultiformatMessageString)2 PhysicalLocation (com.contrastsecurity.sarif.PhysicalLocation)2 PropertyBag (com.contrastsecurity.sarif.PropertyBag)2 Region (com.contrastsecurity.sarif.Region)2 ReportingConfiguration (com.contrastsecurity.sarif.ReportingConfiguration)2 ReportingDescriptorReference (com.contrastsecurity.sarif.ReportingDescriptorReference)2 File (java.io.File)2 HashSet (java.util.HashSet)2 ReportingDescriptor (com.contrastsecurity.sarif.ReportingDescriptor)1 Result (com.contrastsecurity.sarif.Result)1 Run (com.contrastsecurity.sarif.Run)1 SarifSchema210 (com.contrastsecurity.sarif.SarifSchema210)1 Tool (com.contrastsecurity.sarif.Tool)1 ToolComponent (com.contrastsecurity.sarif.ToolComponent)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1