From ea9a00e5cc53df75480e247127fd1311868051cc Mon Sep 17 00:00:00 2001 From: David Waltermire Date: Fri, 6 Dec 2024 11:04:25 -0500 Subject: [PATCH] Added SARIF help URIs to console output. Resolves #276. --- .../modules/sarif/SarifValidationHandler.java | 6 +++--- .../cli/util/LoggingValidationHandler.java | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/databind-metaschema/src/main/java/gov/nist/secauto/metaschema/modules/sarif/SarifValidationHandler.java b/databind-metaschema/src/main/java/gov/nist/secauto/metaschema/modules/sarif/SarifValidationHandler.java index 31b4e779b..8070b5feb 100644 --- a/databind-metaschema/src/main/java/gov/nist/secauto/metaschema/modules/sarif/SarifValidationHandler.java +++ b/databind-metaschema/src/main/java/gov/nist/secauto/metaschema/modules/sarif/SarifValidationHandler.java @@ -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 diff --git a/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/util/LoggingValidationHandler.java b/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/util/LoggingValidationHandler.java index b283e36fb..623cc1ce2 100644 --- a/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/util/LoggingValidationHandler.java +++ b/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/util/LoggingValidationHandler.java @@ -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; @@ -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; @@ -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 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