public final class Main
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
Main.CliOptions
Helper structure to clear show what is required for Checker to run.
|
Modifier and Type | Field and Description |
---|---|
private static int |
EXIT_WITH_CHECKSTYLE_EXCEPTION_CODE
Exit code returned when execution finishes with
CheckstyleException . |
private static int |
HELP_WIDTH
Width of CLI help option.
|
private static org.apache.commons.logging.Log |
LOG
Logger for Main.
|
private static java.lang.String |
OPTION_C_NAME
Name for the option 'c'.
|
private static java.lang.String |
OPTION_CAPITAL_J_NAME
Name for the option '-J'.
|
private static java.lang.String |
OPTION_CAPITAL_T_NAME
Name for the option '-T'.
|
private static java.lang.String |
OPTION_D_NAME
Name for the option '-d'.
|
private static java.lang.String |
OPTION_DEBUG_NAME
Name for the option '--debug'.
|
private static java.lang.String |
OPTION_E_NAME
Name for the option 'e'.
|
private static java.lang.String |
OPTION_EXCLUDE_NAME
Name for the option '--exclude'.
|
private static java.lang.String |
OPTION_EXCLUDE_REGEXP_NAME
Name for the option '--exclude-regexp'.
|
private static java.lang.String |
OPTION_EXECUTE_IGNORED_MODULES_NAME
Name for the option '--executeIgnoredModules'.
|
private static java.lang.String |
OPTION_F_NAME
Name for the option 'f'.
|
private static java.lang.String |
OPTION_J_NAME
Name for the option '-j'.
|
private static java.lang.String |
OPTION_JAVADOC_TREE_NAME
Name for the option '--javadocTree'.
|
private static java.lang.String |
OPTION_O_NAME
Name for the option 'o'.
|
private static java.lang.String |
OPTION_P_NAME
Name for the option 'p'.
|
private static java.lang.String |
OPTION_T_NAME
Name for the option 't'.
|
private static java.lang.String |
OPTION_TREE_COMMENT_NAME
Name for the option '--treeWithComments'.
|
private static java.lang.String |
OPTION_TREE_JAVADOC_NAME
Name for the option '--treeWithJavadoc'.
|
private static java.lang.String |
OPTION_TREE_NAME
Name for the option '--tree'.
|
private static java.lang.String |
OPTION_V_NAME
Name for the option 'v'.
|
private static java.lang.String |
OPTION_X_NAME
Name for the option 'x'.
|
private static java.lang.String |
PLAIN_FORMAT_NAME
Name for 'plain' format.
|
private static java.lang.String |
XML_FORMAT_NAME
Name for 'xml' format.
|
Modifier | Constructor and Description |
---|---|
private |
Main()
Don't create instance of this class, use
main(String[]) method instead. |
Modifier and Type | Method and Description |
---|---|
private static org.apache.commons.cli.Options |
buildOptions()
Builds and returns list of parameters supported by cli Checkstyle.
|
private static Main.CliOptions |
convertCliToPojo(org.apache.commons.cli.CommandLine cmdLine,
java.util.List<java.io.File> filesToProcess)
Util method to convert CommandLine type to POJO object.
|
private static AuditListener |
createListener(java.lang.String format,
java.lang.String outputLocation)
Creates the audit listener.
|
private static java.util.List<java.util.regex.Pattern> |
getExclusions(org.apache.commons.cli.CommandLine commandLine)
Gets the list of exclusions provided through the command line argument.
|
private static java.util.List<java.io.File> |
getFilesToProcess(java.util.List<java.util.regex.Pattern> patternsToExclude,
java.lang.String... filesToProcess)
Determines the files to process.
|
private static RootModule |
getRootModule(java.lang.String name,
java.lang.ClassLoader moduleClassLoader)
Creates a new instance of the root module that will control and run
Checkstyle.
|
private static boolean |
isDirectoryExcluded(java.lang.String path,
java.util.List<java.util.regex.Pattern> patternsToExclude)
Checks if a directory
path should be excluded based on if it matches one of the
patterns supplied. |
private static java.util.List<java.io.File> |
listFiles(java.io.File node,
java.util.List<java.util.regex.Pattern> patternsToExclude)
Traverses a specified node looking for files to check.
|
private static java.util.Properties |
loadProperties(java.io.File file)
Loads properties from a File.
|
static void |
main(java.lang.String... args)
Loops over the files specified checking them for errors.
|
private static org.apache.commons.cli.CommandLine |
parseCli(java.lang.String... args)
Parses and executes Checkstyle based on passed arguments.
|
private static void |
printUsage()
Prints the usage information.
|
private static int |
runCheckstyle(Main.CliOptions cliOptions)
Executes required Checkstyle actions based on passed parameters.
|
private static int |
runCli(org.apache.commons.cli.CommandLine commandLine,
java.util.List<java.io.File> filesToProcess)
Do execution of CheckStyle based on Command line options.
|
private static java.util.List<java.lang.String> |
validateCli(org.apache.commons.cli.CommandLine cmdLine,
java.util.List<java.io.File> filesToProcess)
Do validation of Command line options.
|
private static final org.apache.commons.logging.Log LOG
private static final int HELP_WIDTH
private static final int EXIT_WITH_CHECKSTYLE_EXCEPTION_CODE
CheckstyleException
.private static final java.lang.String OPTION_V_NAME
private static final java.lang.String OPTION_C_NAME
private static final java.lang.String OPTION_F_NAME
private static final java.lang.String OPTION_P_NAME
private static final java.lang.String OPTION_O_NAME
private static final java.lang.String OPTION_T_NAME
private static final java.lang.String OPTION_TREE_NAME
private static final java.lang.String OPTION_CAPITAL_T_NAME
private static final java.lang.String OPTION_TREE_COMMENT_NAME
private static final java.lang.String OPTION_J_NAME
private static final java.lang.String OPTION_JAVADOC_TREE_NAME
private static final java.lang.String OPTION_CAPITAL_J_NAME
private static final java.lang.String OPTION_TREE_JAVADOC_NAME
private static final java.lang.String OPTION_D_NAME
private static final java.lang.String OPTION_DEBUG_NAME
private static final java.lang.String OPTION_E_NAME
private static final java.lang.String OPTION_EXCLUDE_NAME
private static final java.lang.String OPTION_EXECUTE_IGNORED_MODULES_NAME
private static final java.lang.String OPTION_X_NAME
private static final java.lang.String OPTION_EXCLUDE_REGEXP_NAME
private static final java.lang.String XML_FORMAT_NAME
private static final java.lang.String PLAIN_FORMAT_NAME
private Main()
main(String[])
method instead.public static void main(java.lang.String... args) throws java.io.IOException
args
- the command line arguments.java.io.IOException
- if there is a problem with files accessprivate static org.apache.commons.cli.CommandLine parseCli(java.lang.String... args) throws org.apache.commons.cli.ParseException
args
- command line parametersorg.apache.commons.cli.ParseException
- when passed arguments are not validprivate static java.util.List<java.util.regex.Pattern> getExclusions(org.apache.commons.cli.CommandLine commandLine)
commandLine
- command line objectprivate static java.util.List<java.lang.String> validateCli(org.apache.commons.cli.CommandLine cmdLine, java.util.List<java.io.File> filesToProcess)
cmdLine
- command line objectfilesToProcess
- List of files to process found from the command line.private static int runCli(org.apache.commons.cli.CommandLine commandLine, java.util.List<java.io.File> filesToProcess) throws java.io.IOException, CheckstyleException
commandLine
- command line objectfilesToProcess
- List of files to process found from the command line.java.io.IOException
- if a file could not be read.CheckstyleException
- if something happens processing the files.private static Main.CliOptions convertCliToPojo(org.apache.commons.cli.CommandLine cmdLine, java.util.List<java.io.File> filesToProcess)
cmdLine
- command line objectfilesToProcess
- List of files to process found from the command line.private static int runCheckstyle(Main.CliOptions cliOptions) throws CheckstyleException, java.io.FileNotFoundException
cliOptions
- pojo object that contains all optionsjava.io.FileNotFoundException
- when output file could not be foundCheckstyleException
- when properties file could not be loadedprivate static RootModule getRootModule(java.lang.String name, java.lang.ClassLoader moduleClassLoader) throws CheckstyleException
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.CheckstyleException
- if no module can be instantiated from nameprivate static java.util.Properties loadProperties(java.io.File file) throws CheckstyleException
file
- the properties fileCheckstyleException
- when could not load properties fileprivate static AuditListener createListener(java.lang.String format, java.lang.String outputLocation) throws java.io.FileNotFoundException
format
- format of the audit listeneroutputLocation
- the location of outputAuditListener
java.io.FileNotFoundException
- when provided output location is not foundprivate static java.util.List<java.io.File> getFilesToProcess(java.util.List<java.util.regex.Pattern> patternsToExclude, java.lang.String... filesToProcess)
patternsToExclude
- The list of directory patterns to exclude from searching.filesToProcess
- arguments that were not processed yet but shall beprivate static java.util.List<java.io.File> listFiles(java.io.File node, java.util.List<java.util.regex.Pattern> patternsToExclude)
node
- the node to processpatternsToExclude
- The list of directory patterns to exclude from searching.private static boolean isDirectoryExcluded(java.lang.String path, java.util.List<java.util.regex.Pattern> patternsToExclude)
path
should be excluded based on if it matches one of the
patterns supplied.path
- The path of the directory to checkpatternsToExclude
- The list of directory patterns to exclude from searching.private static void printUsage()
private static org.apache.commons.cli.Options buildOptions()