Package com.puppycrawl.tools.checkstyle
Class SarifLogger
java.lang.Object
com.puppycrawl.tools.checkstyle.api.AutomaticBean
com.puppycrawl.tools.checkstyle.SarifLogger
- All Implemented Interfaces:
AuditListener,Configurable,Contextualizable,EventListener
Simple SARIF logger.
SARIF stands for the static analysis results interchange format.
Reference: https://sarifweb.azurewebsites.net/
-
Nested Class Summary
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
AutomaticBean.OutputStreamOptions -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intInput stream buffer size.private final booleanClose output stream in auditFinished.private static final StringThe placeholder for column.private static final StringThe placeholder for line.private static final StringThe placeholder for message.private final StringContent for the entire report.private final StringContent for result representing an error without filename or location.private final StringContent for result representing an error with filename only and without source location.private final StringContent for result representing an error with source line and column.private final StringContent for result representing an error with source line only.The results.private static final StringThe placeholder for results.private static final StringThe placeholder for rule id.private static final StringThe placeholder for severity level.private static final intUnicode escaping upper limit.private static final intThe length of unicode placeholder.private static final StringThe placeholder for uri.private static final StringThe placeholder for version.private final PrintWriterHelper writer that allows easy encoding and printing. -
Constructor Summary
ConstructorsConstructorDescriptionSarifLogger(OutputStream outputStream, AutomaticBean.OutputStreamOptions outputStreamOptions) Creates a newSarifLoggerinstance. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddError(AuditEvent event) Notify that an audit error was discovered on a specific file.voidaddException(AuditEvent event, Throwable throwable) Notify that an exception happened while performing audit.voidauditFinished(AuditEvent event) Notify that the audit is finished.voidauditStarted(AuditEvent event) Notify that the audit is about to start.static StringEscape \b, \f, \n, \r, \t, \", \\ and U+0000 through U+001F.private static StringescapeUnicode1F(char chr) Escape the character between 0x00 to 0x1F in JSON.voidfileFinished(AuditEvent event) Notify that audit is finished on a specific file.voidfileStarted(AuditEvent event) Notify that audit is about to start on a specific file.protected voidProvides a hook to finish the part of this component's setup that was not handled by the bean introspection.static StringreadResource(String name) Read string from given resource.private static StringrenderSeverityLevel(SeverityLevel severityLevel) Render the severity level into SARIF severity level.Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
configure, contextualize, getConfiguration, setupChild
-
Field Details
-
UNICODE_LENGTH
private static final int UNICODE_LENGTHThe length of unicode placeholder.- See Also:
-
UNICODE_ESCAPE_UPPER_LIMIT
private static final int UNICODE_ESCAPE_UPPER_LIMITUnicode escaping upper limit.- See Also:
-
BUFFER_SIZE
private static final int BUFFER_SIZEInput stream buffer size.- See Also:
-
MESSAGE_PLACEHOLDER
The placeholder for message.- See Also:
-
SEVERITY_LEVEL_PLACEHOLDER
The placeholder for severity level.- See Also:
-
URI_PLACEHOLDER
The placeholder for uri.- See Also:
-
LINE_PLACEHOLDER
The placeholder for line.- See Also:
-
COLUMN_PLACEHOLDER
The placeholder for column.- See Also:
-
RULE_ID_PLACEHOLDER
The placeholder for rule id.- See Also:
-
VERSION_PLACEHOLDER
The placeholder for version.- See Also:
-
RESULTS_PLACEHOLDER
The placeholder for results.- See Also:
-
writer
Helper writer that allows easy encoding and printing. -
closeStream
private final boolean closeStreamClose output stream in auditFinished. -
results
The results. -
report
Content for the entire report. -
resultLineColumn
Content for result representing an error with source line and column. -
resultLineOnly
Content for result representing an error with source line only. -
resultFileOnly
Content for result representing an error with filename only and without source location. -
resultErrorOnly
Content for result representing an error without filename or location.
-
-
Constructor Details
-
SarifLogger
public SarifLogger(OutputStream outputStream, AutomaticBean.OutputStreamOptions outputStreamOptions) throws IOException Creates a newSarifLoggerinstance.- Parameters:
outputStream- where to log audit eventsoutputStreamOptions- ifCLOSEthat should be closed in auditFinished()- Throws:
IllegalArgumentException- if outputStreamOptions is nullIOException- if there is reading errors.
-
-
Method Details
-
finishLocalSetup
protected void finishLocalSetup()Description copied from class:AutomaticBeanProvides a hook to finish the part of this component's setup that was not handled by the bean introspection.The default implementation does nothing.
- Specified by:
finishLocalSetupin classAutomaticBean
-
auditStarted
Description copied from interface:AuditListenerNotify that the audit is about to start.- Specified by:
auditStartedin interfaceAuditListener- Parameters:
event- the event details
-
auditFinished
Notify that the audit is finished. Following idea suppressions are false positives- Specified by:
auditFinishedin interfaceAuditListener- Parameters:
event- the event details
-
addError
Notify that an audit error was discovered on a specific file. Following idea suppressions are false positives- Specified by:
addErrorin interfaceAuditListener- Parameters:
event- the event details
-
addException
Notify that an exception happened while performing audit. Following idea suppressions are false positives- Specified by:
addExceptionin interfaceAuditListener- Parameters:
event- the event detailsthrowable- details of the exception
-
fileStarted
Description copied from interface:AuditListenerNotify that audit is about to start on a specific file.- Specified by:
fileStartedin interfaceAuditListener- Parameters:
event- the event details
-
fileFinished
Description copied from interface:AuditListenerNotify that audit is finished on a specific file.- Specified by:
fileFinishedin interfaceAuditListener- Parameters:
event- the event details
-
renderSeverityLevel
Render the severity level into SARIF severity level.- Parameters:
severityLevel- the Severity level.- Returns:
- the rendered severity level in string.
-
escape
Escape \b, \f, \n, \r, \t, \", \\ and U+0000 through U+001F. Reference: https://www.ietf.org/rfc/rfc4627.txt - 2.5. Strings- Parameters:
value- the value to escape.- Returns:
- the escaped value if necessary.
-
escapeUnicode1F
Escape the character between 0x00 to 0x1F in JSON.- Parameters:
chr- the character to be escaped.- Returns:
- the escaped string.
-
readResource
Read string from given resource.- Parameters:
name- name of the desired resource- Returns:
- the string content from the give resource
- Throws:
IOException- if there is reading errors
-