Class SuppressionFilter
- All Implemented Interfaces:
Configurable
,Contextualizable
,ExternalResourceHolder
,Filter
SuppressionFilter
rejects audit events for Check violations according to a
suppressions XML document
in a file. If there is no configured suppressions file or the optional is set to true and
suppressions file was not found the Filter accepts all audit events.
A suppressions XML document
contains a set of suppress
elements, where each suppress
element can have the following attributes:
-
files
- a Pattern matched against the file name associated with an audit event. It is optional. -
checks
- a Pattern matched against the name of the check associated with an audit event. Optional as long asid
ormessage
is specified. -
message
- a Pattern matched against the message of the check associated with an audit event. Optional as long aschecks
orid
is specified. -
id
- a String matched against the check id associated with an audit event. Optional as long aschecks
ormessage
is specified. -
lines
- a comma-separated list of values, where each value is an int or a range of integers denoted by integer-integer. It is optional. -
columns
- a comma-separated list of values, where each value is an int or a range of integers denoted by integer-integer. It is optional.
Each audit event is checked against each suppress
element.
It is suppressed if all specified attributes match against the audit event.
ATTENTION: filtering by message is dependent on runtime locale. If project is running in different languages it is better to avoid filtering by message.
You can download template of empty suppression filter here.
Location of the file defined in file
property is checked in the following order:
- as a filesystem location
-
if no file found, and the location starts with either
http://
orhttps://
, then it is interpreted as a URL -
if no file found, then passed to the
ClassLoader.getResource()
method.
SuppressionFilter can suppress Checks that have Treewalker or Checker as parent module.
-
Property
file
- Specify the location of the suppressions XML document file. Type isjava.lang.String
. Default value isnull
. -
Property
optional
- Control what to do when the file is not existing. Ifoptional
is set tofalse
the file must exist, or else it ends with error. On the other hand if optional istrue
and file is not found, the filter accept all audit events. Type isboolean
. Default value isfalse
.
Parent is com.puppycrawl.tools.checkstyle.Checker
- Since:
- 3.2
-
Nested Class Summary
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
accept
(AuditEvent event) Determines whether or not a filtered AuditEvent is accepted.protected void
Provides a hook to finish the part of this component's setup that was not handled by the bean introspection.Returns a set of external configuration resource locations which are used by the module.void
Setter to specify the location of the suppressions XML document file.void
setOptional
(boolean optional) Setter to control what to do when the file is not existing.Methods inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
configure, contextualize, getConfiguration, setupChild
-
Field Details
-
file
Specify the location of the suppressions XML document file. -
optional
Control what to do when the file is not existing. Ifoptional
is set tofalse
the file must exist, or else it ends with error. On the other hand if optional istrue
and file is not found, the filter accept all audit events. -
filters
Set of individual suppresses.
-
-
Constructor Details
-
SuppressionFilter
public SuppressionFilter()
-
-
Method Details
-
setFile
Setter to specify the location of the suppressions XML document file.- Parameters:
fileName
- name of the suppressions file.- Since:
- 3.2
-
setOptional
Setter to control what to do when the file is not existing. Ifoptional
is set tofalse
the file must exist, or else it ends with error. On the other hand if optional istrue
and file is not found, the filter accept all audit events.- Parameters:
optional
- tells if config file existence is optional.- Since:
- 6.15
-
accept
Description copied from interface:Filter
Determines whether or not a filtered AuditEvent is accepted. -
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
- Throws:
CheckstyleException
- if there is a configuration error.
-
getExternalResourceLocations
Description copied from interface:ExternalResourceHolder
Returns a set of external configuration resource locations which are used by the module. ATTENTION! If 'getExternalResourceLocations()' return null, there will beNullPointerException
inChecker
. Such behaviour will signal that your module (check or filter) is designed incorrectly. It makes sense to return an empty set from 'getExternalResourceLocations()' only for composite modules likeTreeWalker
.- Specified by:
getExternalResourceLocations
in interfaceExternalResourceHolder
- Returns:
- a set of external configuration resource locations which are used by the module.
-