Package com.puppycrawl.tools.checkstyle
Class ChecksAndFilesSuppressionFileGeneratorAuditListener
java.lang.Object
com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
com.puppycrawl.tools.checkstyle.ChecksAndFilesSuppressionFileGeneratorAuditListener
- All Implemented Interfaces:
AuditListener
,Configurable
,Contextualizable
,EventListener
public class ChecksAndFilesSuppressionFileGeneratorAuditListener
extends AbstractAutomaticBean
implements AuditListener
Generates suppressions.xml file, based on violations occurred.
See issue #5983
-
Nested Class Summary
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final boolean
Close output stream in auditFinished.Collects the check names corrosponds to file name.Collects the module ids corrosponds to file name.private boolean
Determines if xml header is printed.private static final String
The " quote character.private final PrintWriter
Helper writer that allows easy encoding and printing. -
Constructor Summary
ConstructorsConstructorDescriptionChecksAndFilesSuppressionFileGeneratorAuditListener
(OutputStream out, AbstractAutomaticBean.OutputStreamOptions outputStreamOptions) Creates a newChecksAndFilesSuppressionFileGeneratorAuditListener
instance. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addCheckOrModuleId
(Path fileName, String checkName, String moduleIdName) Adds either the check name or module ID to the corresponding collector map for the specified file path.void
addError
(AuditEvent event) Notify that an audit error was discovered on a specific file.void
addException
(AuditEvent event, Throwable throwable) Notify that an exception happened while performing audit.private static void
Adds a value (either a check name or module ID) to the set associated with the given file in the specified collector map.void
auditFinished
(AuditEvent event) Notify that the audit is finished.void
auditStarted
(AuditEvent event) Notify that the audit is about to start.void
fileFinished
(AuditEvent event) Notify that audit is finished on a specific file.void
fileStarted
(AuditEvent event) Notify that audit is about to start on a specific file.protected void
Provides a hook to finish the part of this component's setup that was not handled by the bean introspection.private boolean
isFileAndCheckNamePresent
(Path fileName, String checkName) Checks whether the check name is already associated with the given file in theFilesAndChecksCollector
map.private boolean
isFileAndModuleIdPresent
(Path fileName, String moduleIdName) Checks theFilesAndModuleIdCollector
map to see if the module ID has already been recorded for the specified file.private void
Prints XML header if only it was not printed before.private void
suppressXmlWriter
(Path fileName, String checkName, String moduleIdName) Prints XML suppression with check/id and file name.Methods inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
configure, contextualize, getConfiguration, setupChild
-
Field Details
-
QUOTE_CHAR
The " quote character.- See Also:
-
writer
Helper writer that allows easy encoding and printing. -
closeStream
Close output stream in auditFinished. -
filesAndChecksCollector
Collects the check names corrosponds to file name. -
filesAndModuleIdCollector
Collects the module ids corrosponds to file name. -
isXmlHeaderPrinted
Determines if xml header is printed.
-
-
Constructor Details
-
ChecksAndFilesSuppressionFileGeneratorAuditListener
public ChecksAndFilesSuppressionFileGeneratorAuditListener(OutputStream out, AbstractAutomaticBean.OutputStreamOptions outputStreamOptions) Creates a newChecksAndFilesSuppressionFileGeneratorAuditListener
instance. Sets the output to a defined stream.- Parameters:
out
- the output streamoutputStreamOptions
- ifCLOSE
stream should be closed in auditFinished()
-
-
Method Details
-
fileStarted
Description copied from interface:AuditListener
Notify that audit is about to start on a specific file.- Specified by:
fileStarted
in interfaceAuditListener
- Parameters:
event
- the event details
-
fileFinished
Description copied from interface:AuditListener
Notify that audit is finished on a specific file.- Specified by:
fileFinished
in interfaceAuditListener
- Parameters:
event
- the event details
-
auditStarted
Description copied from interface:AuditListener
Notify that the audit is about to start.- Specified by:
auditStarted
in interfaceAuditListener
- Parameters:
event
- the event details
-
auditFinished
Description copied from interface:AuditListener
Notify that the audit is finished.- Specified by:
auditFinished
in interfaceAuditListener
- Parameters:
event
- the event details
-
addError
Description copied from interface:AuditListener
Notify that an audit error was discovered on a specific file.- Specified by:
addError
in interfaceAuditListener
- Parameters:
event
- the event details
-
isFileAndCheckNamePresent
Checks whether the check name is already associated with the given file in theFilesAndChecksCollector
map.- Parameters:
fileName
- The path of the file where the violation occurred.checkName
- The name of the check that triggered the violation.- Returns:
true
if the collector already contains the check name for the file,false
otherwise.
-
isFileAndModuleIdPresent
Checks theFilesAndModuleIdCollector
map to see if the module ID has already been recorded for the specified file.- Parameters:
fileName
- The path of the file where the violation occurred.moduleIdName
- The module ID associated with the check name which trigger violation.- Returns:
true
if the module ID is not yet recorded for the file,false
otherwise.
-
addException
Description copied from interface:AuditListener
Notify that an exception happened while performing audit.- Specified by:
addException
in interfaceAuditListener
- Parameters:
event
- the event detailsthrowable
- details of the exception
-
suppressXmlWriter
Prints XML suppression with check/id and file name.- Parameters:
fileName
- The file path associated with the check or module ID.checkName
- The check name to write ifmoduleIdName
isnull
.moduleIdName
- The module ID name to write ifnull
,checkName
is used instead.
-
addCheckOrModuleId
Adds either the check name or module ID to the corresponding collector map for the specified file path.- Parameters:
fileName
- The path of the file associated with the check or module ID.checkName
- The name of the check to add ifmoduleIdName
isnull
.moduleIdName
- The name of the module ID to add ifnull
,checkName
is used instead.
-
addToCollector
Adds a value (either a check name or module ID) to the set associated with the given file in the specified collector map.- Parameters:
collector
- The map that collects values (check names or module IDs) for each file.fileName
- The file path for which the value should be recorded.value
- the check name or module ID to add to the set for the specified file.
-
printXmlHeader
Prints XML header if only it was not printed before. -
finishLocalSetup
Description copied from class:AbstractAutomaticBean
Provides 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:
finishLocalSetup
in classAbstractAutomaticBean
-