Class BeforeExecutionExclusionFileFilter
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.api.AutomaticBean
-
- com.puppycrawl.tools.checkstyle.filefilters.BeforeExecutionExclusionFileFilter
-
- All Implemented Interfaces:
BeforeExecutionFileFilter,Configurable,Contextualizable
public final class BeforeExecutionExclusionFileFilter extends AutomaticBean implements BeforeExecutionFileFilter
File filter
BeforeExecutionExclusionFileFilterdecides which files should be excluded from being processed by the utility.By default Checkstyle includes all files and sub-directories in a directory to be processed and checked for violations. Users could have files that are in these sub-directories that shouldn't be processed with their checkstyle configuration for various reasons, one of which is a valid Java file that won't pass Checkstyle's parser. When Checkstyle tries to parse a Java file and fails, it will throw an
Exceptionand halt parsing any more files for violations. An example of a valid Java file Checkstyle can't parse is JDK 9'smodule-info.java. This file filter will exclude these problem files from being parsed, allowing the rest of the files to run normal and be validated.Note: When a file is excluded from the utility, it is excluded from all Checks and no testing for violations will be performed on them.
-
Property
fileNamePattern- Define regular expression to match the file name against. Type isjava.util.regex.Pattern. Default value isnull.
To configure the filter to exclude all 'module-info.java' files:
<module name="BeforeExecutionExclusionFileFilter"> <property name="fileNamePattern" value="module\-info\.java$"/> </module>
To configure the filter to run only on required files for example that ends with "Remote" or end with "Client" in names or named as "Remote.java" or "Client.java" use negative lookahead:
<module name="BeforeExecutionExclusionFileFilter"> <property name="fileNamePattern" value="^(?!.*(Remote\.java|Client\.java|[\\/]Remote\.java|[\\/]Client\.java)).*$"/> </module>
To configure the filter to exclude all Test folder files:
<module name="BeforeExecutionExclusionFileFilter"> <property name="fileNamePattern" value=".*[\\/]src[\\/]test[\\/].*$"/> </module>Parent is
com.puppycrawl.tools.checkstyle.Checker- Since:
- 7.2
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
AutomaticBean.OutputStreamOptions
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.regex.PatternfileNamePatternDefine regular expression to match the file name against.
-
Constructor Summary
Constructors Constructor Description BeforeExecutionExclusionFileFilter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaccept(java.lang.String uri)Determines whether or not a before execution file filtered event is accepted.protected voidfinishLocalSetup()Provides a hook to finish the part of this component's setup that was not handled by the bean introspection.voidsetFileNamePattern(java.util.regex.Pattern fileNamePattern)Setter to define regular expression to match the file name against.-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
configure, contextualize, getConfiguration, setupChild
-
-
-
-
Field Detail
-
fileNamePattern
private java.util.regex.Pattern fileNamePattern
Define regular expression to match the file name against.
-
-
Constructor Detail
-
BeforeExecutionExclusionFileFilter
public BeforeExecutionExclusionFileFilter()
-
-
Method Detail
-
setFileNamePattern
public void setFileNamePattern(java.util.regex.Pattern fileNamePattern)
Setter to define regular expression to match the file name against.- Parameters:
fileNamePattern- regular expression of the excluded file.
-
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
-
accept
public boolean accept(java.lang.String uri)
Description copied from interface:BeforeExecutionFileFilterDetermines whether or not a before execution file filtered event is accepted.- Specified by:
acceptin interfaceBeforeExecutionFileFilter- Parameters:
uri- the uri to filter.- Returns:
- true if the event is accepted.
-
-