Package dev.metaschema.modules.sarif
Class SarifValidationHandler
java.lang.Object
dev.metaschema.modules.sarif.SarifValidationHandler
- All Implemented Interfaces:
ValidationEventListener
Supports building a Static Analysis Results Interchange Format (SARIF)
document based on a set of validation findings.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final IAttributable.KeyThe property key for specifying markdown-formatted help content for a constraint.static final IAttributable.KeyThe property key for specifying plain text help content for a constraint.static final IAttributable.KeyThe property key for specifying a URL that provides help information for a constraint. -
Constructor Summary
ConstructorsConstructorDescriptionSarifValidationHandler(URI source, IVersionInfo toolVersion) Construct a new validation handler. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFinding(IValidationFinding finding) Register a validation finding.voidaddFindings(Collection<? extends IValidationFinding> findings) Register a collection of validation finding.voidafterConstraintEvaluation(IConstraint constraint, INodeItem target) Called after a single constraint evaluation completes.voidafterLetEvaluation(ILet let) Called after a let-statement variable binding evaluation completes.voidafterPhase(ValidationPhase phase) Called after a validation phase completes.voidafterValidation(URI document) Called after validation of a document completes.voidbeforeConstraintEvaluation(IConstraint constraint, INodeItem target) Called before a single constraint is evaluated against a target node.voidbeforeLetEvaluation(ILet let) Called before a let-statement variable binding is evaluated.voidbeforePhase(ValidationPhase phase) Called before a validation phase begins.voidbeforeValidation(URI document) Called before validation of a document begins.voidsetTimingCollector(TimingCollector collector) Set the timing collector to enrich SARIF output with performance data.voidwrite(Path outputFile, IBindingContext bindingContext) Write the collection of findings to the provided output file.writeToString(IBindingContext bindingContext) Write the collection of findings to a string in SARIF format.
-
Field Details
-
SARIF_HELP_URL_KEY
The property key for specifying a URL that provides help information for a constraint. -
SARIF_HELP_TEXT_KEY
The property key for specifying plain text help content for a constraint. -
SARIF_HELP_MARKDOWN_KEY
The property key for specifying markdown-formatted help content for a constraint.
-
-
Constructor Details
-
SarifValidationHandler
Construct a new validation handler.- Parameters:
source- the URI of the content that was validatedtoolVersion- the version information for the tool producing the validation results
-
-
Method Details
-
setTimingCollector
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, ornullto disable timing output
-
beforeValidation
Description copied from interface:ValidationEventListenerCalled before validation of a document begins.- Specified by:
beforeValidationin interfaceValidationEventListener- Parameters:
document- the URI of the document being validated
-
afterValidation
Description copied from interface:ValidationEventListenerCalled after validation of a document completes.- Specified by:
afterValidationin interfaceValidationEventListener- Parameters:
document- the URI of the document that was validated
-
beforePhase
Description copied from interface:ValidationEventListenerCalled before a validation phase begins.- Specified by:
beforePhasein interfaceValidationEventListener- Parameters:
phase- the phase about to start
-
afterPhase
Description copied from interface:ValidationEventListenerCalled after a validation phase completes.- Specified by:
afterPhasein interfaceValidationEventListener- Parameters:
phase- the phase that completed
-
beforeConstraintEvaluation
Description copied from interface:ValidationEventListenerCalled before a single constraint is evaluated against a target node.- Specified by:
beforeConstraintEvaluationin interfaceValidationEventListener- Parameters:
constraint- the constraint being evaluatedtarget- the node item the constraint is evaluated against
-
afterConstraintEvaluation
Description copied from interface:ValidationEventListenerCalled after a single constraint evaluation completes.- Specified by:
afterConstraintEvaluationin interfaceValidationEventListener- Parameters:
constraint- the constraint that was evaluatedtarget- the node item the constraint was evaluated against
-
beforeLetEvaluation
Description copied from interface:ValidationEventListenerCalled before a let-statement variable binding is evaluated.- Specified by:
beforeLetEvaluationin interfaceValidationEventListener- Parameters:
let- the let expression being evaluated
-
afterLetEvaluation
Description copied from interface:ValidationEventListenerCalled after a let-statement variable binding evaluation completes.- Specified by:
afterLetEvaluationin interfaceValidationEventListener- Parameters:
let- the let expression that was evaluated
-
addFindings
Register a collection of validation finding.- Parameters:
findings- the findings to register
-
addFinding
Register a validation finding.- Parameters:
finding- the finding to register
-
writeToString
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 tobindingContext- the context used to access Metaschema module information based on Java class bindings- Throws:
IOException- if an error occurred while writing the SARIF file
-