Class PropertyCacheFile

java.lang.Object
com.puppycrawl.tools.checkstyle.PropertyCacheFile

public final class PropertyCacheFile extends Object
This class maintains a persistent(on file-system) store of the files that have checked ok(no validation events) and their associated timestamp. It is used to optimize Checkstyle between few launches. It is mostly useful for plugin and extensions of Checkstyle. It uses a property file for storage. A hashcode of the Configuration is stored in the cache file to ensure the cache is invalidated when the configuration has changed.
  • Field Details

    • CONFIG_HASH_KEY

      public static final String CONFIG_HASH_KEY
      The property key to use for storing the hashcode of the configuration. To avoid name clashes with the files that are checked the key is chosen in such a way that it cannot be a valid file name.
      See Also:
    • EXTERNAL_RESOURCE_KEY_PREFIX

      public static final String EXTERNAL_RESOURCE_KEY_PREFIX
      The property prefix to use for storing the hashcode of an external resource. To avoid name clashes with the files that are checked the prefix is chosen in such a way that it cannot be a valid file name and makes it clear it is a resource.
      See Also:
  • Constructor Details

    • PropertyCacheFile

      public PropertyCacheFile(Configuration config, String fileName)
      Creates a new PropertyCacheFile instance.
      Parameters:
      config - the current configuration, not null
      fileName - the cache file
      Throws:
      IllegalArgumentException - when either arguments are null
  • Method Details

    • load

      public void load() throws IOException
      Load cached values from file.
      Throws:
      IOException - when there is a problems with file read
    • persist

      public void persist() throws IOException
      Cleans up the object and updates the cache file.
      Throws:
      IOException - when there is a problems with file save
    • reset

      public void reset()
      Resets the cache to be empty except for the configuration hash.
    • isInCache

      public boolean isInCache(String uncheckedFileName, long timestamp)
      Checks that file is in cache.
      Parameters:
      uncheckedFileName - the file to check
      timestamp - the timestamp of the file to check
      Returns:
      whether the specified file has already been checked ok
    • put

      public void put(String checkedFileName, long timestamp)
      Records that a file checked ok.
      Parameters:
      checkedFileName - name of the file that checked ok
      timestamp - the timestamp of the file
    • get

      public String get(String name)
      Retrieves the hash of a specific file.
      Parameters:
      name - The name of the file to retrieve.
      Returns:
      The has of the file or null.
    • remove

      public void remove(String checkedFileName)
      Removed a specific file from the cache.
      Parameters:
      checkedFileName - The name of the file to remove.
    • putExternalResources

      public void putExternalResources(Set<String> locations)
      Puts external resources in cache. If at least one external resource changed, clears the cache.
      Parameters:
      locations - locations of external resources.