Class Checker

All Implemented Interfaces:
Configurable, Contextualizable, MessageDispatcher, RootModule

This class provides the functionality to check a set of files.
  • Field Details

  • Constructor Details

    • Checker

      public Checker()
      Creates a new Checker instance. The instance needs to be contextualized and configured.
  • Method Details

    • setCacheFile

      public void setCacheFile(String fileName) throws IOException
      Sets cache file.
      Parameters:
      fileName - the cache file.
      Throws:
      IOException - if there are some problems with file loading.
    • removeBeforeExecutionFileFilter

      Removes before execution file filter.
      Parameters:
      filter - before execution file filter to remove.
    • removeFilter

      public void removeFilter(Filter filter)
      Removes filter.
      Parameters:
      filter - filter to remove.
    • destroy

      public void destroy()
      Description copied from interface: RootModule
      Cleans up the object.
      Specified by:
      destroy in interface RootModule
    • removeListener

      public void removeListener(AuditListener listener)
      Removes a given listener.
      Parameters:
      listener - a listener to remove
    • setBasedir

      public void setBasedir(String basedir)
      Sets base directory.
      Parameters:
      basedir - the base directory to strip off in file names
    • process

      public int process(List<File> files) throws CheckstyleException
      Description copied from interface: RootModule
      Processes a set of files. Once this is done, it is highly recommended to call for the destroy method to close and remove the listeners.
      Specified by:
      process in interface RootModule
      Parameters:
      files - the list of files to be audited.
      Returns:
      the total number of audit events with error severity found
      Throws:
      CheckstyleException - if error condition within Checkstyle occurs
      See Also:
    • getExternalResourceLocations

      Returns a set of external configuration resource locations which are used by all file set checks and filters.
      Returns:
      a set of external configuration resource locations which are used by all file set checks and filters.
    • fireAuditStarted

      private void fireAuditStarted()
      Notify all listeners about the audit start.
    • fireAuditFinished

      private void fireAuditFinished()
      Notify all listeners about the audit end.
    • processFiles

      private void processFiles(List<File> files) throws CheckstyleException
      Processes a list of files with all FileSetChecks.
      Parameters:
      files - a list of files to process.
      Throws:
      CheckstyleException - if error condition within Checkstyle occurs.
      Error - wraps any java.lang.Error happened during execution
    • processFile

      Processes a file with all FileSetChecks.
      Parameters:
      file - a file to process.
      Returns:
      a sorted set of violations to be logged.
      Throws:
      CheckstyleException - if error condition within Checkstyle occurs.
    • acceptFileStarted

      private boolean acceptFileStarted(String fileName)
      Check if all before execution file filters accept starting the file.
      Parameters:
      fileName - the file to be audited
      Returns:
      true if the file is accepted.
    • fireFileStarted

      public void fireFileStarted(String fileName)
      Notify all listeners about the beginning of a file audit.
      Specified by:
      fireFileStarted in interface MessageDispatcher
      Parameters:
      fileName - the file to be audited
    • fireErrors

      public void fireErrors(String fileName, SortedSet<Violation> errors)
      Notify all listeners about the errors in a file.
      Specified by:
      fireErrors in interface MessageDispatcher
      Parameters:
      fileName - the audited file
      errors - the audit errors from the file
    • fireFileFinished

      public void fireFileFinished(String fileName)
      Notify all listeners about the end of a file audit.
      Specified by:
      fireFileFinished in interface MessageDispatcher
      Parameters:
      fileName - the audited file
    • finishLocalSetup

      protected void finishLocalSetup() throws CheckstyleException
      Description copied from class: AbstractAutomaticBean
      Provides a hook to finish the part of this component's setup that was not handled by the bean introspection.

      The default implementation does nothing.

      Specified by:
      finishLocalSetup in class AbstractAutomaticBean
      Throws:
      CheckstyleException - if there is a configuration error.
    • setupChild

      protected void setupChild(Configuration childConf) throws CheckstyleException
      Called by configure() for every child of this component's Configuration.

      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.

      Creates child module.
      Overrides:
      setupChild in class AbstractAutomaticBean
      Parameters:
      childConf - a child of this component's Configuration
      Throws:
      CheckstyleException - if there is a configuration error.
      See Also:
    • addFileSetCheck

      public void addFileSetCheck(FileSetCheck fileSetCheck)
      Adds a FileSetCheck to the list of FileSetChecks that is executed in process().
      Parameters:
      fileSetCheck - the additional FileSetCheck
    • addBeforeExecutionFileFilter

      Adds a before execution file filter to the end of the event chain.
      Parameters:
      filter - the additional filter
    • addFilter

      public void addFilter(Filter filter)
      Adds a filter to the end of the audit event filter chain.
      Parameters:
      filter - the additional filter
    • addListener

      public final void addListener(AuditListener listener)
      Description copied from interface: RootModule
      Add the listener that will be used to receive events from the audit.
      Specified by:
      addListener in interface RootModule
      Parameters:
      listener - the nosy thing
    • setFileExtensions

      public final void setFileExtensions(String... extensions)
      Sets the file extensions that identify the files that pass the filter of this FileSetCheck.
      Parameters:
      extensions - the set of file extensions. A missing initial '.' character of an extension is automatically added.
    • setModuleFactory

      public void setModuleFactory(ModuleFactory moduleFactory)
      Sets the factory for creating submodules.
      Parameters:
      moduleFactory - the factory for creating FileSetChecks
    • setLocaleCountry

      public void setLocaleCountry(String localeCountry)
      Sets locale country.
      Parameters:
      localeCountry - the country to report messages
    • setLocaleLanguage

      public void setLocaleLanguage(String localeLanguage)
      Sets locale language.
      Parameters:
      localeLanguage - the language to report messages
    • setSeverity

      public final void setSeverity(String severity)
      Sets the severity level. The string should be one of the names defined in the SeverityLevel class.
      Parameters:
      severity - The new severity level
      See Also:
    • setModuleClassLoader

      public final void setModuleClassLoader(ClassLoader moduleClassLoader)
      Description copied from interface: RootModule
      Sets the classloader used to load Checkstyle core and custom module classes when the module tree is being built up. If no custom ModuleFactory is being set for the root module then this module classloader must be specified.
      Specified by:
      setModuleClassLoader in interface RootModule
      Parameters:
      moduleClassLoader - the classloader used to load module classes
    • setCharset

      public void setCharset(String charset) throws UnsupportedEncodingException
      Sets a named charset.
      Parameters:
      charset - the name of a charset
      Throws:
      UnsupportedEncodingException - if charset is unsupported.
    • setHaltOnException

      public void setHaltOnException(boolean haltOnException)
      Sets the field haltOnException.
      Parameters:
      haltOnException - the new value.
    • setTabWidth

      public final void setTabWidth(int tabWidth)
      Set the tab width to report audit events with.
      Parameters:
      tabWidth - an int value
    • clearCache

      public void clearCache()
      Clears the cache.
    • getLocalizedMessage

      private String getLocalizedMessage(String messageKey, Object... args)
      Extracts localized messages from properties files.
      Parameters:
      messageKey - the key pointing to localized message in respective properties file.
      args - the arguments of message in respective properties file.
      Returns:
      a string containing extracted localized message