Class CheckstyleAntTask

  • All Implemented Interfaces:

    public class CheckstyleAntTask
    An implementation of an ANT task for calling checkstyle. See the documentation of the task for usage.
    • Method Detail

      • setFailureProperty

        public void setFailureProperty​(String propertyName)
        Tells this task to write failure message to the named property when there is a violation.
        propertyName - the name of the property to set in the event of a failure.
      • setFailOnViolation

        public void setFailOnViolation​(boolean fail)
        Sets flag - whether to fail if a violation is found.
        fail - whether to fail if a violation is found
      • setMaxErrors

        public void setMaxErrors​(int maxErrors)
        Sets the maximum number of errors allowed. Default is 0.
        maxErrors - the maximum number of errors allowed.
      • setMaxWarnings

        public void setMaxWarnings​(int maxWarnings)
        Sets the maximum number of warnings allowed. Default is Integer.MAX_VALUE.
        maxWarnings - the maximum number of warnings allowed.
      • addPath

        public void addPath​( path)
        Adds a path.
        path - the path to add.
      • addFileset

        public void addFileset​( fileSet)
        Adds set of files (nested fileset attribute).
        fileSet - the file set to add
      • createClasspath

        public createClasspath()
        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.
        a created path for locating classes
      • setFile

        public void setFile​(File file)
        Sets file to be checked.
        file - the file to be checked
      • setConfig

        public void setConfig​(String configuration)
        Sets configuration file.
        configuration - the configuration file, URL, or resource to use
        Throws: - when config was already set
      • setExecuteIgnoredModules

        public void setExecuteIgnoredModules​(boolean omit)
        Sets flag - whether to execute ignored modules.
        omit - whether to execute ignored modules
      • setProperties

        public void setProperties​(File props)
        Sets a properties file for use instead of individually setting them.
        props - the properties File to use
      • execute

        public void execute()
        execute in class
      • realExecute

        private void realExecute​(String checkstyleVersion)
        Helper implementation to perform execution.
        checkstyleVersion - Checkstyle compile version.
      • processFiles

        private void processFiles​(RootModule rootModule,
                                  SeverityLevelCounter warningCounter,
                                  String checkstyleVersion)
        Scans and processes files by means given root module.
        rootModule - Root module to process files
        warningCounter - Root Module's counter of warnings
        checkstyleVersion - Checkstyle compile version
        Throws: - if the files could not be processed, or if the build failed due to violations.
      • createRootModule

        private RootModule createRootModule()
        Creates new instance of the root module.
        new instance of the root module
        Throws: - if the root module could not be created.
      • createOverridingProperties

        private Properties createOverridingProperties()
        Create the Properties object based on the arguments specified to the ANT task.
        the properties for property expansion
        Throws: - if the properties file could not be loaded.
      • getListeners

        private AuditListener[] getListeners()
        Return the array of listeners set in this task.
        the array of listeners.
        Throws: - if the listeners could not be created.
      • getFilesToCheck

        private List<FilegetFilesToCheck()
        Returns the list of files (full path name) to process.
        the list of files included via the fileName, filesets and paths.
      • scanPaths

        private List<FilescanPaths()
        Retrieves all files from the defined paths.
        a list of files defined via paths.
      • scanPath

        private List<FilescanPath​( path,
                                    int pathIndex)
        Scans the given path and retrieves all files for the given path.
        path - A path to scan.
        pathIndex - The index of the given path. Used in log messages only.
        A list of files, extracted from the given path.
      • scanFileSets

        protected List<FilescanFileSets()
        Returns the list of files (full path name) to process.
        the list of files included via the filesets.
      • retrieveAllScannedFiles

        private List<FileretrieveAllScannedFiles​( scanner,
                                                   int logIndex)
        Retrieves all matched files from the given scanner.
        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.
        A list of files, retrieved from the given scanner.