Skip to content

Commit

Permalink
Added SARIF help URIs to console output. Resolves metaschema-framewor…
Browse files Browse the repository at this point in the history
  • Loading branch information
david-waltermire committed Dec 8, 2024
1 parent bcfee31 commit ea9a00e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ public String getLabel() {
@NonNull
static final String SARIF_NS = "https://docs.oasis-open.org/sarif/sarif/v2.1.0";
@NonNull
static final IAttributable.Key SARIF_HELP_URL_KEY
public static final IAttributable.Key SARIF_HELP_URL_KEY
= IAttributable.key("help-url", SARIF_NS);
@NonNull
static final IAttributable.Key SARIF_HELP_TEXT_KEY
public static final IAttributable.Key SARIF_HELP_TEXT_KEY
= IAttributable.key("help-text", SARIF_NS);
@NonNull
static final IAttributable.Key SARIF_HELP_MARKDOWN_KEY
public static final IAttributable.Key SARIF_HELP_MARKDOWN_KEY
= IAttributable.key("help-markdown", SARIF_NS);

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import gov.nist.secauto.metaschema.core.model.validation.IValidationFinding;
import gov.nist.secauto.metaschema.core.model.validation.JsonSchemaContentValidator.JsonValidationFinding;
import gov.nist.secauto.metaschema.core.model.validation.XmlSchemaContentValidator.XmlValidationFinding;
import gov.nist.secauto.metaschema.modules.sarif.SarifValidationHandler;

import org.apache.logging.log4j.LogBuilder;
import org.apache.logging.log4j.LogManager;
Expand All @@ -22,6 +23,8 @@
import org.xml.sax.SAXParseException;

import java.net.URI;
import java.util.Set;
import java.util.stream.Collectors;

import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
Expand Down Expand Up @@ -130,7 +133,17 @@ protected void handleConstraintValidationFinding(@NonNull ConstraintValidationFi
ansi.format(" %s:", id);
}

getLogger(finding).log(ansi.format(" %s", finding.getMessage()));
ansi.format(" %s", finding.getMessage());

Set<String> helpUrls = finding.getConstraints().stream()
.flatMap(constraint -> constraint.getPropertyValues(SarifValidationHandler.SARIF_HELP_URL_KEY).stream())
.collect(Collectors.toSet());
if (!helpUrls.isEmpty()) {
ansi.format(" (help: %s)",
helpUrls.stream().collect(Collectors.joining(", ")));
}

getLogger(finding).log();
}

@NonNull
Expand Down

0 comments on commit ea9a00e

Please sign in to comment.