public final class Main extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
private static class |
Main.CliOptions
Command line options.
|
private static class |
Main.OnlyCheckstyleLoggersFilter
Log Filter used in debug mode.
|
(package private) static class |
Main.OutputFormat
Enumeration over the possible output formats.
|
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
CREATE_LISTENER_EXCEPTION
A key pointing to the create listener exception
message in the "messages.properties" file.
|
static java.lang.String |
ERROR_COUNTER
A key pointing to the error counter
message in the "messages.properties" file.
|
private static int |
EXIT_WITH_CHECKSTYLE_EXCEPTION_CODE
Exit code returned when execution finishes with
CheckstyleException. |
private static int |
EXIT_WITH_INVALID_USER_INPUT_CODE
Exit code returned when user specified invalid command line arguments.
|
static java.lang.String |
LOAD_PROPERTIES_EXCEPTION
A key pointing to the load properties exception
message in the "messages.properties" file.
|
private static org.apache.commons.logging.Log |
LOG
Logger for Main.
|
| Modifier | Constructor and Description |
|---|---|
private |
Main()
Client code should not create instances of this class, but use
main(String[]) method instead. |
| Modifier and Type | Method and Description |
|---|---|
private static AuditListener |
createListener(Main.OutputFormat format,
java.nio.file.Path outputLocation)
This method creates in AuditListener an open stream for validation data, it must be
closed by
RootModule (default implementation is Checker) by calling
AuditListener.auditFinished(AuditEvent). |
private static int |
execute(picocli.CommandLine.ParseResult parseResult,
Main.CliOptions options)
Validates the user input and returns -1 if
invalid, otherwise executes CheckStyle and returns the number of violations.
|
private static java.util.List<java.io.File> |
getFilesToProcess(Main.CliOptions options)
Determines the files to process.
|
private static java.io.OutputStream |
getOutputStream(java.nio.file.Path outputPath)
Create output stream or return System.out
|
private static AutomaticBean.OutputStreamOptions |
getOutputStreamOptions(java.nio.file.Path outputPath)
Create
AutomaticBean.OutputStreamOptions for the given location. |
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 Configuration |
getTreeWalkerConfig(Configuration config)
Returns
TreeWalker module configuration. |
private static java.lang.String |
getVersionString()
Returns the version string printed when the user requests version help (--version or -V).
|
private static boolean |
isPathExcluded(java.lang.String path,
java.util.List<java.util.regex.Pattern> patternsToExclude)
Checks if a directory/file
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 int |
runCheckstyle(Main.CliOptions options,
java.util.List<java.io.File> filesToProcess)
Executes required Checkstyle actions based on passed parameters.
|
private static int |
runCli(Main.CliOptions options,
java.util.List<java.io.File> filesToProcess)
Do execution of CheckStyle based on Command line options.
|
public static final java.lang.String ERROR_COUNTER
public static final java.lang.String LOAD_PROPERTIES_EXCEPTION
public static final java.lang.String CREATE_LISTENER_EXCEPTION
private static final org.apache.commons.logging.Log LOG
private static final int EXIT_WITH_INVALID_USER_INPUT_CODE
private static final int EXIT_WITH_CHECKSTYLE_EXCEPTION_CODE
CheckstyleException.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 java.lang.String getVersionString()
private static int execute(picocli.CommandLine.ParseResult parseResult, Main.CliOptions options) throws java.io.IOException, CheckstyleException
parseResult - generic access to options and parameters found on the command lineoptions - encapsulates options and parameters specified on the command linejava.io.IOException - if a file could not be read.CheckstyleException - if something happens processing the files.private static java.util.List<java.io.File> getFilesToProcess(Main.CliOptions options)
options - the user-specified optionsprivate 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 patterns to exclude from searching or being added as
files.private static boolean isPathExcluded(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/file to checkpatternsToExclude - The list of patterns to exclude from searching or being added as
files.private static int runCli(Main.CliOptions options, java.util.List<java.io.File> filesToProcess) throws java.io.IOException, CheckstyleException
options - user-specified optionsfilesToProcess - the list of files whose style to checkjava.io.IOException - if a file could not be read.CheckstyleException - if something happens processing the files.private static int runCheckstyle(Main.CliOptions options, java.util.List<java.io.File> filesToProcess) throws CheckstyleException, java.io.IOException
options - user-specified optionsfilesToProcess - the list of files whose style to checkjava.io.IOException - when output file could not be foundCheckstyleException - when properties file could not be loadedprivate static java.util.Properties loadProperties(java.io.File file) throws CheckstyleException
file - the properties fileCheckstyleException - when could not load properties fileprivate 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 Configuration getTreeWalkerConfig(Configuration config)
TreeWalker module configuration.config - The configuration object.TreeWalker module configuration.private static AuditListener createListener(Main.OutputFormat format, java.nio.file.Path outputLocation) throws java.io.IOException
RootModule (default implementation is Checker) by calling
AuditListener.auditFinished(AuditEvent).format - format of the audit listeneroutputLocation - the location of outputAuditListenerjava.io.IOException - when provided output location is not foundprivate static java.io.OutputStream getOutputStream(java.nio.file.Path outputPath) throws java.io.IOException
outputPath - output locationjava.io.IOException - might happenprivate static AutomaticBean.OutputStreamOptions getOutputStreamOptions(java.nio.file.Path outputPath)
AutomaticBean.OutputStreamOptions for the given location.outputPath - output locationCopyright © 2001-2022. All Rights Reserved.