Search in sources :

Example 1 with Message

use of com.contrastsecurity.sarif.Message 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 Message

use of com.contrastsecurity.sarif.Message 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)

Aggregations

ArtifactLocation (com.contrastsecurity.sarif.ArtifactLocation)2 Location (com.contrastsecurity.sarif.Location)2 Message (com.contrastsecurity.sarif.Message)2 PhysicalLocation (com.contrastsecurity.sarif.PhysicalLocation)2 Region (com.contrastsecurity.sarif.Region)2 ConfigurationOverride (com.contrastsecurity.sarif.ConfigurationOverride)1 Invocation (com.contrastsecurity.sarif.Invocation)1 MultiformatMessageString (com.contrastsecurity.sarif.MultiformatMessageString)1 PropertyBag (com.contrastsecurity.sarif.PropertyBag)1 ReportingConfiguration (com.contrastsecurity.sarif.ReportingConfiguration)1 ReportingDescriptor (com.contrastsecurity.sarif.ReportingDescriptor)1 ReportingDescriptorReference (com.contrastsecurity.sarif.ReportingDescriptorReference)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 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)1 LanguageServerConfiguration (com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration)1