Class CheckstyleAntTask
java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
com.puppycrawl.tools.checkstyle.ant.CheckstyleAntTask
- All Implemented Interfaces:
Cloneable
An implementation of an ANT task for calling checkstyle. See the documentation
of the task for usage.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDetails about a formatter to be used.static classPoor man enumeration for the formatter types.static classRepresents a property that consists of a key and value. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate StringConfig file containing configuration.private static final StringPoor man's enum for a plain formatter.private static final StringPoor man's enum for a sarif formatter.private static final StringPoor man's enum for an xml formatter.private booleanWhether to execute ignored modules - some modules may log above their severity depending on their configuration (e.g.private booleanWhether to fail build on violations.private StringProperty to set on violations.private StringName of file to check.private final List<org.apache.tools.ant.types.FileSet>Contains the filesets to process.private final List<CheckstyleAntTask.Formatter>Contains the formatters to log to.private intThe maximum number of errors that are tolerated.private intThe maximum number of warnings that are tolerated.private final List<CheckstyleAntTask.Property>Contains the Properties to override.private final List<org.apache.tools.ant.types.Path>Contains the paths to process.private PathThe name of the properties file.private static final StringSuffix for time string.Fields inherited from class org.apache.tools.ant.Task
target, taskName, taskType, wrapperFields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFileset(org.apache.tools.ant.types.FileSet fileSet) Adds set of files (nested fileset attribute).voidaddFormatter(CheckstyleAntTask.Formatter formatter) Add a formatter.voidaddPath(org.apache.tools.ant.types.Path path) Adds a path.voidaddProperty(CheckstyleAntTask.Property property) Add an override property.org.apache.tools.ant.types.PathDeprecated.left in implementation until #12556 only to allow users to migrate to new gradle plugins.private PropertiesCreate the Properties object based on the arguments specified to the ANT task.private RootModuleCreates new instance of the root module.voidexecute()Returns the list of files (full path name) to process.private AuditListener[]Return the array of listeners set in this task.private voidprocessFiles(RootModule rootModule, SeverityLevelCounter warningCounter, String checkstyleVersion) Scans and processes files by means given root module.private voidrealExecute(String checkstyleVersion) Helper implementation to perform execution.retrieveAllScannedFiles(org.apache.tools.ant.FileScanner scanner, int logIndex) Retrieves all matched files from the given scanner.Returns the list of files (full path name) to process.scanPath(org.apache.tools.ant.types.Path path, int pathIndex) Scans the given path and retrieves all files for the given path.Retrieves all files from the defined paths.voidSets configuration file.voidsetExecuteIgnoredModules(boolean omit) Sets flag - whether to execute ignored modules.voidsetFailOnViolation(boolean fail) Sets flag - whether to fail if a violation is found.voidsetFailureProperty(String propertyName) Tells this task to write failure message to the named property when there is a violation.voidSets file to be checked.voidsetMaxErrors(int maxErrors) Sets the maximum number of errors allowed.voidsetMaxWarnings(int maxWarnings) Sets the maximum number of warnings allowed.voidsetProperties(File props) Sets a properties file for use instead of individually setting them.Methods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskTypeMethods inherited from class org.apache.tools.ant.ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
-
Field Details
-
E_XML
Poor man's enum for an xml formatter.- See Also:
-
E_PLAIN
Poor man's enum for a plain formatter.- See Also:
-
E_SARIF
Poor man's enum for a sarif formatter.- See Also:
-
TIME_SUFFIX
Suffix for time string.- See Also:
-
paths
Contains the paths to process. -
fileSets
Contains the filesets to process. -
formatters
Contains the formatters to log to. -
overrideProps
Contains the Properties to override. -
fileName
Name of file to check. -
config
Config file containing configuration. -
failOnViolation
Whether to fail build on violations. -
failureProperty
Property to set on violations. -
properties
The name of the properties file. -
maxErrors
The maximum number of errors that are tolerated. -
maxWarnings
The maximum number of warnings that are tolerated. -
executeIgnoredModules
Whether to execute ignored modules - some modules may log above their severity depending on their configuration (e.g. WriteTag) so need to be included
-
-
Constructor Details
-
CheckstyleAntTask
public CheckstyleAntTask()
-
-
Method Details
-
setFailureProperty
Tells this task to write failure message to the named property when there is a violation.- Parameters:
propertyName- the name of the property to set in the event of a failure.
-
setFailOnViolation
Sets flag - whether to fail if a violation is found.- Parameters:
fail- whether to fail if a violation is found
-
setMaxErrors
Sets the maximum number of errors allowed. Default is 0.- Parameters:
maxErrors- the maximum number of errors allowed.
-
setMaxWarnings
Sets the maximum number of warnings allowed. Default isInteger.MAX_VALUE.- Parameters:
maxWarnings- the maximum number of warnings allowed.
-
addPath
Adds a path.- Parameters:
path- the path to add.
-
addFileset
Adds set of files (nested fileset attribute).- Parameters:
fileSet- the file set to add
-
addFormatter
Add a formatter.- Parameters:
formatter- the formatter to add for logging.
-
addProperty
Add an override property.- Parameters:
property- the property to add
-
createClasspath
Deprecated.left in implementation until #12556 only to allow users to migrate to new gradle plugins. This method will be removed in Checkstyle 11.x.x .Creates classpath.- Returns:
- a created path for locating classes
-
setFile
Sets file to be checked.- Parameters:
file- the file to be checked
-
setConfig
Sets configuration file.- Parameters:
configuration- the configuration file, URL, or resource to use- Throws:
org.apache.tools.ant.BuildException- when config was already set
-
setExecuteIgnoredModules
Sets flag - whether to execute ignored modules.- Parameters:
omit- whether to execute ignored modules
-
setProperties
Sets a properties file for use instead of individually setting them.- Parameters:
props- the properties File to use
-
execute
- Overrides:
executein classorg.apache.tools.ant.Task
-
realExecute
Helper implementation to perform execution.- Parameters:
checkstyleVersion- Checkstyle compile version.
-
processFiles
private void processFiles(RootModule rootModule, SeverityLevelCounter warningCounter, String checkstyleVersion) Scans and processes files by means given root module.- Parameters:
rootModule- Root module to process fileswarningCounter- Root Module's counter of warningscheckstyleVersion- Checkstyle compile version- Throws:
org.apache.tools.ant.BuildException- if the files could not be processed, or if the build failed due to violations.
-
createRootModule
Creates new instance of the root module.- Returns:
- new instance of the root module
- Throws:
org.apache.tools.ant.BuildException- if the root module could not be created.
-
createOverridingProperties
Create the Properties object based on the arguments specified to the ANT task.- Returns:
- the properties for property expansion
- Throws:
org.apache.tools.ant.BuildException- if the properties file could not be loaded.
-
getListeners
Return the array of listeners set in this task.- Returns:
- the array of listeners.
- Throws:
org.apache.tools.ant.BuildException- if the listeners could not be created.
-
getFilesToCheck
Returns the list of files (full path name) to process.- Returns:
- the list of files included via the fileName, filesets and paths.
-
scanPaths
Retrieves all files from the defined paths.- Returns:
- a list of files defined via paths.
-
scanPath
Scans the given path and retrieves all files for the given path.- Parameters:
path- A path to scan.pathIndex- The index of the given path. Used in log messages only.- Returns:
- A list of files, extracted from the given path.
-
scanFileSets
Returns the list of files (full path name) to process.- Returns:
- the list of files included via the filesets.
-
retrieveAllScannedFiles
Retrieves all matched files from the given scanner.- Parameters:
scanner- A directory scanner. Note, thatDirectoryScanner.scan()must be called before calling this method.logIndex- A log entry index. Used only for log messages.- Returns:
- A list of files, retrieved from the given scanner.
-