Class SarifValidationHandler

java.lang.Object
dev.metaschema.modules.sarif.SarifValidationHandler
All Implemented Interfaces:
ValidationEventListener

public final class SarifValidationHandler extends Object implements ValidationEventListener
Supports building a Static Analysis Results Interchange Format (SARIF) document based on a set of validation findings.
  • Field Details

    • SARIF_HELP_URL_KEY

      @NonNull public static final IAttributable.Key SARIF_HELP_URL_KEY
      The property key for specifying a URL that provides help information for a constraint.
    • SARIF_HELP_TEXT_KEY

      @NonNull public static final IAttributable.Key SARIF_HELP_TEXT_KEY
      The property key for specifying plain text help content for a constraint.
    • SARIF_HELP_MARKDOWN_KEY

      @NonNull public static final IAttributable.Key SARIF_HELP_MARKDOWN_KEY
      The property key for specifying markdown-formatted help content for a constraint.
  • Constructor Details

    • SarifValidationHandler

      public SarifValidationHandler(@NonNull URI source, @Nullable IVersionInfo toolVersion)
      Construct a new validation handler.
      Parameters:
      source - the URI of the content that was validated
      toolVersion - the version information for the tool producing the validation results
  • Method Details

    • setTimingCollector

      public void setTimingCollector(@Nullable TimingCollector collector)
      Set the timing collector to enrich SARIF output with performance data.

      When set, the generated SARIF document will include:

      • An invocation element with start/end timestamps
      • Phase timing as tool execution notifications
      • Per-constraint timing in rule properties
      Parameters:
      collector - the timing collector containing measurement data, or null to disable timing output
    • beforeValidation

      public void beforeValidation(@NonNull URI document)
      Description copied from interface: ValidationEventListener
      Called before validation of a document begins.
      Specified by:
      beforeValidation in interface ValidationEventListener
      Parameters:
      document - the URI of the document being validated
    • afterValidation

      public void afterValidation(@NonNull URI document)
      Description copied from interface: ValidationEventListener
      Called after validation of a document completes.
      Specified by:
      afterValidation in interface ValidationEventListener
      Parameters:
      document - the URI of the document that was validated
    • beforePhase

      public void beforePhase(@NonNull ValidationPhase phase)
      Description copied from interface: ValidationEventListener
      Called before a validation phase begins.
      Specified by:
      beforePhase in interface ValidationEventListener
      Parameters:
      phase - the phase about to start
    • afterPhase

      public void afterPhase(@NonNull ValidationPhase phase)
      Description copied from interface: ValidationEventListener
      Called after a validation phase completes.
      Specified by:
      afterPhase in interface ValidationEventListener
      Parameters:
      phase - the phase that completed
    • beforeConstraintEvaluation

      public void beforeConstraintEvaluation(@NonNull IConstraint constraint, @NonNull INodeItem target)
      Description copied from interface: ValidationEventListener
      Called before a single constraint is evaluated against a target node.
      Specified by:
      beforeConstraintEvaluation in interface ValidationEventListener
      Parameters:
      constraint - the constraint being evaluated
      target - the node item the constraint is evaluated against
    • afterConstraintEvaluation

      public void afterConstraintEvaluation(@NonNull IConstraint constraint, @NonNull INodeItem target)
      Description copied from interface: ValidationEventListener
      Called after a single constraint evaluation completes.
      Specified by:
      afterConstraintEvaluation in interface ValidationEventListener
      Parameters:
      constraint - the constraint that was evaluated
      target - the node item the constraint was evaluated against
    • beforeLetEvaluation

      public void beforeLetEvaluation(@NonNull ILet let)
      Description copied from interface: ValidationEventListener
      Called before a let-statement variable binding is evaluated.
      Specified by:
      beforeLetEvaluation in interface ValidationEventListener
      Parameters:
      let - the let expression being evaluated
    • afterLetEvaluation

      public void afterLetEvaluation(@NonNull ILet let)
      Description copied from interface: ValidationEventListener
      Called after a let-statement variable binding evaluation completes.
      Specified by:
      afterLetEvaluation in interface ValidationEventListener
      Parameters:
      let - the let expression that was evaluated
    • addFindings

      public void addFindings(@NonNull Collection<? extends IValidationFinding> findings)
      Register a collection of validation finding.
      Parameters:
      findings - the findings to register
    • addFinding

      public void addFinding(@NonNull IValidationFinding finding)
      Register a validation finding.
      Parameters:
      finding - the finding to register
    • writeToString

      @NonNull public String writeToString(@NonNull IBindingContext bindingContext) throws IOException
      Write the collection of findings to a string in SARIF format.
      Parameters:
      bindingContext - the context used to access Metaschema module information based on Java class bindings
      Returns:
      the SARIF document as a string
      Throws:
      IOException - if an error occurred while generating the SARIF document
    • write

      public void write(@NonNull Path outputFile, @NonNull IBindingContext bindingContext) throws IOException
      Write the collection of findings to the provided output file.
      Parameters:
      outputFile - the path to the output file to write to
      bindingContext - the context used to access Metaschema module information based on Java class bindings
      Throws:
      IOException - if an error occurred while writing the SARIF file