public class CheckstyleAntTask
extends org.apache.tools.ant.Task
Modifier and Type | Class and Description |
---|---|
static class |
CheckstyleAntTask.Formatter
Details about a formatter to be used.
|
static class |
CheckstyleAntTask.FormatterType
Poor mans enumeration for the formatter types.
|
static class |
CheckstyleAntTask.Listener
Represents a custom listener.
|
static class |
CheckstyleAntTask.Property
Represents a property that consists of a key and value.
|
Modifier and Type | Field and Description |
---|---|
private org.apache.tools.ant.types.Path |
classpath
Class path to locate class files.
|
private java.lang.String |
config
Config file containing configuration.
|
private static java.lang.String |
E_PLAIN
Poor man's enum for an plain formatter.
|
private static java.lang.String |
E_XML
Poor man's enum for an xml formatter.
|
private boolean |
executeIgnoredModules
Whether to execute ignored modules - some modules may log above
their severity depending on their configuration (e.g.
|
private boolean |
failOnViolation
Whether to fail build on violations.
|
private java.lang.String |
failureProperty
Property to set on violations.
|
private java.lang.String |
fileName
Name of file to check.
|
private java.util.List<org.apache.tools.ant.types.FileSet> |
fileSets
Contains the filesets to process.
|
private java.util.List<CheckstyleAntTask.Formatter> |
formatters
Contains the formatters to log to.
|
private int |
maxErrors
The maximum number of errors that are tolerated.
|
private int |
maxWarnings
The maximum number of warnings that are tolerated.
|
private java.util.List<CheckstyleAntTask.Property> |
overrideProps
Contains the Properties to override.
|
private java.util.List<org.apache.tools.ant.types.Path> |
paths
Contains the paths to process.
|
private java.io.File |
properties
The name of the properties file.
|
private static java.lang.String |
TIME_SUFFIX
Suffix for time string.
|
Constructor and Description |
---|
CheckstyleAntTask() |
Modifier and Type | Method and Description |
---|---|
void |
addFileset(org.apache.tools.ant.types.FileSet fileSet)
Adds set of files (nested fileset attribute).
|
void |
addFormatter(CheckstyleAntTask.Formatter formatter)
Add a formatter.
|
void |
addPath(org.apache.tools.ant.types.Path path)
Adds a path.
|
void |
addProperty(CheckstyleAntTask.Property property)
Add an override property.
|
org.apache.tools.ant.types.Path |
createClasspath()
Creates classpath.
|
private java.util.Properties |
createOverridingProperties()
Create the Properties object based on the arguments specified
to the ANT task.
|
private RootModule |
createRootModule()
Creates new instance of the root module.
|
private static void |
destroyRootModule(RootModule rootModule)
Destroy root module.
|
void |
execute() |
protected java.util.List<java.io.File> |
getFilesToCheck()
Returns the list of files (full path name) to process.
|
private AuditListener[] |
getListeners()
Return the list of listeners set in this task.
|
private void |
processFiles(RootModule rootModule,
SeverityLevelCounter warningCounter,
java.lang.String checkstyleVersion)
Scans and processes files by means given root module.
|
private void |
realExecute(java.lang.String checkstyleVersion)
Helper implementation to perform execution.
|
private java.util.List<java.io.File> |
retrieveAllScannedFiles(org.apache.tools.ant.DirectoryScanner scanner,
int logIndex)
Retrieves all matched files from the given scanner.
|
protected java.util.List<java.io.File> |
scanFileSets()
Returns the list of files (full path name) to process.
|
private java.util.List<java.io.File> |
scanPath(org.apache.tools.ant.types.Path path,
int pathIndex)
Scans the given path and retrieves all files for the given path.
|
private java.util.List<java.io.File> |
scanPaths()
Retrieves all files from the defined paths.
|
void |
setClasspath(org.apache.tools.ant.types.Path classpath)
Set the class path.
|
void |
setClasspathRef(org.apache.tools.ant.types.Reference classpathRef)
Set the class path from a reference defined elsewhere.
|
void |
setConfig(java.lang.String configuration)
Sets configuration file.
|
void |
setExecuteIgnoredModules(boolean omit)
Sets flag - whether to execute ignored modules.
|
void |
setFailOnViolation(boolean fail)
Sets flag - whether to fail if a violation is found.
|
void |
setFailureProperty(java.lang.String propertyName)
Tells this task to write failure message to the named property when there
is a violation.
|
void |
setFile(java.io.File file)
Sets file to be checked.
|
void |
setMaxErrors(int maxErrors)
Sets the maximum number of errors allowed.
|
void |
setMaxWarnings(int maxWarnings)
Sets the maximum number of warnings allowed.
|
void |
setProperties(java.io.File props)
Sets a properties file for use instead
of individually setting them.
|
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
private static final java.lang.String E_XML
private static final java.lang.String E_PLAIN
private static final java.lang.String TIME_SUFFIX
private final java.util.List<org.apache.tools.ant.types.Path> paths
private final java.util.List<org.apache.tools.ant.types.FileSet> fileSets
private final java.util.List<CheckstyleAntTask.Formatter> formatters
private final java.util.List<CheckstyleAntTask.Property> overrideProps
private org.apache.tools.ant.types.Path classpath
private java.lang.String fileName
private java.lang.String config
private boolean failOnViolation
private java.lang.String failureProperty
private java.io.File properties
private int maxErrors
private int maxWarnings
private boolean executeIgnoredModules
public void setFailureProperty(java.lang.String propertyName)
propertyName
- the name of the property to set
in the event of an failure.public void setFailOnViolation(boolean fail)
fail
- whether to fail if a violation is foundpublic void setMaxErrors(int maxErrors)
maxErrors
- the maximum number of errors allowed.public void setMaxWarnings(int maxWarnings)
Integer.MAX_VALUE
.maxWarnings
- the maximum number of warnings allowed.public void addPath(org.apache.tools.ant.types.Path path)
path
- the path to add.public void addFileset(org.apache.tools.ant.types.FileSet fileSet)
fileSet
- the file set to addpublic void addFormatter(CheckstyleAntTask.Formatter formatter)
formatter
- the formatter to add for logging.public void addProperty(CheckstyleAntTask.Property property)
property
- the property to addpublic void setClasspath(org.apache.tools.ant.types.Path classpath)
classpath
- the path to locate classespublic void setClasspathRef(org.apache.tools.ant.types.Reference classpathRef)
classpathRef
- the reference to an instance defining the classpathpublic org.apache.tools.ant.types.Path createClasspath()
public void setFile(java.io.File file)
file
- the file to be checkedpublic void setConfig(java.lang.String configuration)
configuration
- the configuration file, URL, or resource to usepublic void setExecuteIgnoredModules(boolean omit)
omit
- whether to execute ignored modulespublic void setProperties(java.io.File props)
props
- the properties File to usepublic void execute()
execute
in class org.apache.tools.ant.Task
private void realExecute(java.lang.String checkstyleVersion)
checkstyleVersion
- Checkstyle compile version.private static void destroyRootModule(RootModule rootModule)
rootModule
- Root module that was used to process filesprivate void processFiles(RootModule rootModule, SeverityLevelCounter warningCounter, java.lang.String checkstyleVersion)
rootModule
- Root module to process fileswarningCounter
- Root Module's counter of warningscheckstyleVersion
- Checkstyle compile versionprivate RootModule createRootModule()
private java.util.Properties createOverridingProperties()
org.apache.tools.ant.BuildException
- if an error occursprivate AuditListener[] getListeners()
protected java.util.List<java.io.File> getFilesToCheck()
private java.util.List<java.io.File> scanPaths()
private java.util.List<java.io.File> scanPath(org.apache.tools.ant.types.Path path, int pathIndex)
path
- A path to scan.pathIndex
- The index of the given path. Used in log messages only.protected java.util.List<java.io.File> scanFileSets()
private java.util.List<java.io.File> retrieveAllScannedFiles(org.apache.tools.ant.DirectoryScanner scanner, int logIndex)
scanner
- A directory scanner. Note, that DirectoryScanner.scan()
must be called before calling this method.logIndex
- A log entry index. Used only for log messages.