Class Main


  • public final class Main
    extends Object
    Wrapper command line program for the Checker.
    • Constructor Detail

      • Main

        private Main()
        Client code should not create instances of this class, but use main(String[]) method instead.
    • Method Detail

      • main

        public static void main​(String... args)
                         throws IOException
        Loops over the files specified checking them for errors. The exit code is the number of errors found in all the files.
        Parameters:
        args - the command line arguments.
        Throws:
        IOException - if there is a problem with files access
      • getVersionString

        private static String getVersionString()
        Returns the version string printed when the user requests version help (--version or -V).
        Returns:
        a version string based on the package implementation version
      • execute

        private static int execute​(picocli.CommandLine.ParseResult parseResult,
                                   Main.CliOptions options)
                            throws IOException,
                                   CheckstyleException
        Validates the user input and returns -1 if invalid, otherwise executes CheckStyle and returns the number of violations.
        Parameters:
        parseResult - generic access to options and parameters found on the command line
        options - encapsulates options and parameters specified on the command line
        Returns:
        number of violations
        Throws:
        IOException - if a file could not be read.
        CheckstyleException - if something happens processing the files.
      • getFilesToProcess

        private static List<FilegetFilesToProcess​(Main.CliOptions options)
        Determines the files to process.
        Parameters:
        options - the user-specified options
        Returns:
        list of files to process
      • listFiles

        private static List<FilelistFiles​(File node,
                                            List<Pattern> patternsToExclude)
        Traverses a specified node looking for files to check. Found files are added to a specified list. Subdirectories are also traversed.
        Parameters:
        node - the node to process
        patternsToExclude - The list of patterns to exclude from searching or being added as files.
        Returns:
        found files
      • isPathExcluded

        private static boolean isPathExcluded​(String path,
                                              List<Pattern> patternsToExclude)
        Checks if a directory/file path should be excluded based on if it matches one of the patterns supplied.
        Parameters:
        path - The path of the directory/file to check
        patternsToExclude - The list of patterns to exclude from searching or being added as files.
        Returns:
        True if the directory/file matches one of the patterns.
      • getRootModule

        private static RootModule getRootModule​(String name,
                                                ClassLoader moduleClassLoader)
                                         throws CheckstyleException
        Creates a new instance of the root module that will control and run Checkstyle.
        Parameters:
        name - The name of the module. This will either be a short name that will have to be found or the complete package name.
        moduleClassLoader - Class loader used to load the root module.
        Returns:
        The new instance of the root module.
        Throws:
        CheckstyleException - if no module can be instantiated from name
      • getTreeWalkerConfig

        private static Configuration getTreeWalkerConfig​(Configuration config)
        Returns TreeWalker module configuration.
        Parameters:
        config - The configuration object.
        Returns:
        The TreeWalker module configuration.