public class Checker extends AutomaticBean implements MessageDispatcher, RootModule
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
basedir
The basedir to strip off in file names.
|
private BeforeExecutionFileFilterSet |
beforeExecutionFileFilters
The audit event before execution file filters.
|
private PropertyCacheFile |
cache
Cache file.
|
private java.lang.String |
charset
Name of a charset.
|
private Context |
childContext
The context of all child components.
|
private java.lang.ClassLoader |
classLoader
Class loader to resolve classes with.
|
private SeverityLevelCounter |
counter
Maintains error count.
|
static java.lang.String |
EXCEPTION_MSG
Message to use when an exception occurs and should be printed as a violation.
|
private java.lang.String[] |
fileExtensions
The file extensions that are accepted.
|
private java.util.List<FileSetCheck> |
fileSetChecks
Vector of fileset checks.
|
private FilterSet |
filters
The audit event filters.
|
private boolean |
haltOnException
Controls whether exceptions should halt execution or not.
|
private java.util.List<AuditListener> |
listeners
Vector of listeners.
|
private java.lang.String |
localeCountry
Locale country to report messages .
|
private java.lang.String |
localeLanguage
Locale language to report messages .
|
private static org.apache.commons.logging.Log |
LOG
Logger for Checker.
|
private java.lang.ClassLoader |
moduleClassLoader
The classloader used for loading Checkstyle module classes.
|
private ModuleFactory |
moduleFactory
The factory for instantiating submodules.
|
private SeverityLevel |
severityLevel
The severity level of any violations found by submodules.
|
Constructor and Description |
---|
Checker()
Creates a new
Checker instance. |
Modifier and Type | Method and Description |
---|---|
private boolean |
acceptFileStarted(java.lang.String fileName)
Check if all before execution file filters accept starting the file.
|
void |
addBeforeExecutionFileFilter(BeforeExecutionFileFilter filter)
Adds a before execution file filter to the end of the event chain.
|
void |
addFileSetCheck(FileSetCheck fileSetCheck)
Adds a FileSetCheck to the list of FileSetChecks
that is executed in process().
|
void |
addFilter(Filter filter)
Adds a filter to the end of the audit event filter chain.
|
void |
addListener(AuditListener listener)
Add the listener that will be used to receive events from the audit.
|
void |
clearCache()
Clears the cache.
|
void |
destroy()
Cleans up the object.
|
void |
finishLocalSetup()
Provides a hook to finish the part of this component's setup that
was not handled by the bean introspection.
|
private void |
fireAuditFinished()
Notify all listeners about the audit end.
|
private void |
fireAuditStarted()
Notify all listeners about the audit start.
|
void |
fireErrors(java.lang.String fileName,
java.util.SortedSet<LocalizedMessage> errors)
Notify all listeners about the errors in a file.
|
void |
fireFileFinished(java.lang.String fileName)
Notify all listeners about the end of a file audit.
|
void |
fireFileStarted(java.lang.String fileName)
Notify all listeners about the beginning of a file audit.
|
private java.util.Set<java.lang.String> |
getExternalResourceLocations()
Returns a set of external configuration resource locations which are used by all file set
checks and filters.
|
int |
process(java.util.List<java.io.File> files)
Processes a set of files.
|
private java.util.SortedSet<LocalizedMessage> |
processFile(java.io.File file)
Processes a file with all FileSetChecks.
|
private void |
processFiles(java.util.List<java.io.File> files)
Processes a list of files with all FileSetChecks.
|
void |
removeBeforeExecutionFileFilter(BeforeExecutionFileFilter filter)
Removes before execution file filter.
|
void |
removeFilter(Filter filter)
Removes filter.
|
void |
removeListener(AuditListener listener)
Removes a given listener.
|
void |
setBasedir(java.lang.String basedir)
Sets base directory.
|
void |
setCacheFile(java.lang.String fileName)
Sets cache file.
|
void |
setCharset(java.lang.String charset)
Sets a named charset.
|
void |
setClassLoader(java.lang.ClassLoader classLoader)
Sets the classloader that is used to contextualize fileset checks.
|
void |
setFileExtensions(java.lang.String... extensions)
Sets the file extensions that identify the files that pass the
filter of this FileSetCheck.
|
void |
setHaltOnException(boolean haltOnException)
Sets the field haltOnException.
|
void |
setLocaleCountry(java.lang.String localeCountry)
Sets locale country.
|
void |
setLocaleLanguage(java.lang.String localeLanguage)
Sets locale language.
|
void |
setModuleClassLoader(java.lang.ClassLoader moduleClassLoader)
Sets the classloader used to load Checkstyle core and custom module
classes when the module tree is being built up.
|
void |
setModuleFactory(ModuleFactory moduleFactory)
Sets the factory for creating submodules.
|
void |
setSeverity(java.lang.String severity)
Sets the severity level.
|
protected void |
setupChild(Configuration childConf)
Called by configure() for every child of this component's Configuration.
|
configure, contextualize, getConfiguration
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
configure
public static final java.lang.String EXCEPTION_MSG
private static final org.apache.commons.logging.Log LOG
private final SeverityLevelCounter counter
private final java.util.List<AuditListener> listeners
private final java.util.List<FileSetCheck> fileSetChecks
private final BeforeExecutionFileFilterSet beforeExecutionFileFilters
private final FilterSet filters
private java.lang.ClassLoader classLoader
private java.lang.String basedir
private java.lang.String localeCountry
private java.lang.String localeLanguage
private ModuleFactory moduleFactory
private java.lang.ClassLoader moduleClassLoader
private Context childContext
private java.lang.String[] fileExtensions
private SeverityLevel severityLevel
Note: Since the Checker is merely a container for modules it does not make sense to implement logging functionality here. Consequently Checker does not extend AbstractViolationReporter, leading to a bit of duplicated code for severity level setting.
private java.lang.String charset
private PropertyCacheFile cache
private boolean haltOnException
public Checker()
Checker
instance.
The instance needs to be contextualized and configured.public void setCacheFile(java.lang.String fileName) throws java.io.IOException
fileName
- the cache file.java.io.IOException
- if there are some problems with file loading.public void removeBeforeExecutionFileFilter(BeforeExecutionFileFilter filter)
filter
- before execution file filter to remove.public void removeFilter(Filter filter)
filter
- filter to remove.public void destroy()
RootModule
destroy
in interface RootModule
public void removeListener(AuditListener listener)
listener
- a listener to removepublic void setBasedir(java.lang.String basedir)
basedir
- the base directory to strip off in file namespublic int process(java.util.List<java.io.File> files) throws CheckstyleException
RootModule
process
in interface RootModule
files
- the list of files to be audited.CheckstyleException
- if error condition within Checkstyle occursRootModule.destroy()
private java.util.Set<java.lang.String> getExternalResourceLocations()
private void fireAuditStarted()
private void fireAuditFinished()
private void processFiles(java.util.List<java.io.File> files) throws CheckstyleException
files
- a list of files to process.CheckstyleException
- if error condition within Checkstyle occurs.private java.util.SortedSet<LocalizedMessage> processFile(java.io.File file) throws CheckstyleException
file
- a file to process.CheckstyleException
- if error condition within Checkstyle occurs.private boolean acceptFileStarted(java.lang.String fileName)
fileName
- the file to be auditedtrue
if the file is accepted.public void fireFileStarted(java.lang.String fileName)
fireFileStarted
in interface MessageDispatcher
fileName
- the file to be auditedpublic void fireErrors(java.lang.String fileName, java.util.SortedSet<LocalizedMessage> errors)
fireErrors
in interface MessageDispatcher
fileName
- the audited fileerrors
- the audit errors from the filepublic void fireFileFinished(java.lang.String fileName)
fireFileFinished
in interface MessageDispatcher
fileName
- the audited filepublic void finishLocalSetup() throws CheckstyleException
AutomaticBean
The default implementation does nothing.
finishLocalSetup
in class AutomaticBean
CheckstyleException
- if there is a configuration error.protected void setupChild(Configuration childConf) throws CheckstyleException
AutomaticBean
The default implementation throws CheckstyleException
if
childConf
is null
because it doesn't support children. It
must be overridden to validate and support children that are wanted.
setupChild
in class AutomaticBean
childConf
- a child of this component's ConfigurationCheckstyleException
- if there is a configuration error.Configuration.getChildren()
public void addFileSetCheck(FileSetCheck fileSetCheck)
fileSetCheck
- the additional FileSetCheckpublic void addBeforeExecutionFileFilter(BeforeExecutionFileFilter filter)
filter
- the additional filterpublic void addFilter(Filter filter)
filter
- the additional filterpublic final void addListener(AuditListener listener)
RootModule
addListener
in interface RootModule
listener
- the nosy thingpublic final void setFileExtensions(java.lang.String... extensions)
extensions
- the set of file extensions. A missing
initial '.' character of an extension is automatically added.public void setModuleFactory(ModuleFactory moduleFactory)
moduleFactory
- the factory for creating FileSetCheckspublic void setLocaleCountry(java.lang.String localeCountry)
localeCountry
- the country to report messagespublic void setLocaleLanguage(java.lang.String localeLanguage)
localeLanguage
- the language to report messagespublic final void setSeverity(java.lang.String severity)
SeverityLevel
class.severity
- The new severity levelSeverityLevel
public final void setClassLoader(java.lang.ClassLoader classLoader)
classLoader
- the new classloaderpublic final void setModuleClassLoader(java.lang.ClassLoader moduleClassLoader)
RootModule
setModuleClassLoader
in interface RootModule
moduleClassLoader
- the classloader used to load module classespublic void setCharset(java.lang.String charset) throws java.io.UnsupportedEncodingException
charset
- the name of a charsetjava.io.UnsupportedEncodingException
- if charset is unsupported.public void setHaltOnException(boolean haltOnException)
haltOnException
- the new value.public void clearCache()