Package bm.target

Class FileContentState

java.lang.Object
bm.target.FileContentState
All Implemented Interfaces:
StateProvider, FileState

public class FileContentState extends Object implements FileState
Provides file or directory states reading either the full content of files or only their last modified time, depending on the factory method used.
  • Constructor Details

    • FileContentState

      public FileContentState(Path targetPath, FileContentState.ByteSource bytes)
      Calls the 4 parameter constructor with predicates which always return true.
    • FileContentState

      public FileContentState(Path targetPath, FileContentState.ByteSource bytes, Predicate<Path> includeRelativeFilePath)
      Calls the 4 parameter constructor with a directory predicate which always returns true.
    • FileContentState

      public FileContentState(Path targetPath, FileContentState.ByteSource bytes, Predicate<Path> includeRelativeFilePath, Predicate<Path> includeRelativeDirPath)
      Creates an instance.
      Parameters:
      targetPath - we manage
      bytes - should add the relevant indicative bytes of the file to a digest
      includeRelativeFilePath - will be called with each file path relative to the targetPath and only if true is returned, the file is included in the state.
      includeRelativeDirPath - will be called with each directory path relative to the targetPath (except the empty path representing the target path itself). If false is returned, the directory is not traversed and no file in it can end up in the state.
  • Method Details

    • fromContent

      public static FileContentState fromContent(Path targetPath)
      Creates a file/directory state provider from full file contents.
      Parameters:
      targetPath - file path to the target we maintain, either file or directory
    • fromContent

      public static FileContentState fromContent(String targetPath)
      Creates a file/directory state provider from full file contents.
      Parameters:
      targetPath - file path to the target we maintain, either file or directory
    • fromLastModified

      public static FileContentState fromLastModified(Path targetPath)
      Creates a file/directory state provider from a file's last modified time.
      Parameters:
      targetPath - file path to the target we maintain, either file or directory
    • fromLastModified

      public static FileContentState fromLastModified(String targetPath)
      Creates a file/directory state provider from a file's last modified time.
      Parameters:
      targetPath - file path to the target we maintain, either file or directory
    • withFilePathFilter

      public FileContentState withFilePathFilter(Predicate<Path> newIncludeRelativePath)
      Creates a new FileState with the given filter for relative paths.
      Parameters:
      newIncludeRelativePath - see description for the constructor
      Returns:
      a new instance with the filter provided
    • withDirPathFilter

      public FileContentState withDirPathFilter(Predicate<Path> newIncludeRelativePath)
    • withPathFilters

      public FileContentState withPathFilters(PathPredicates predicates)
    • getTargetPath

      public Path getTargetPath()
      The path of the target this objects represents.
      Specified by:
      getTargetPath in interface FileState
      Returns:
      path of the target
    • getManagedFiles

      public List<Path> getManagedFiles()
      Provides known files.
      Specified by:
      getManagedFiles in interface FileState
      Returns:
      the list of files in the directory managed by this target or the single file it represents
    • addState

      public void addState(Consumer<byte[]> digest) throws BuildProblemException
      Adds the managed files' state to the given consumer.
      Specified by:
      addState in interface StateProvider
      Parameters:
      digest - into which to fill the state representing bytes
      Throws:
      BuildProblemException - as needed