Class AbstractFileProcessorBuilder

java.lang.Object
org.apache.rat.config.exclusion.fileProcessors.AbstractFileProcessorBuilder
Direct Known Subclasses:
BazaarIgnoreBuilder, CVSIgnoreBuilder, GitIgnoreBuilder, HgIgnoreBuilder

public abstract class AbstractFileProcessorBuilder extends Object
Creates a List of MatcherSets that represent the inclusions and exclusions of this file processor.

By default this processor:

  • Creates a list of levels that correspond to the depth of the directories where the specific include/exclude file is located. Directory depth is relative to the initially discovered include/exclude file.
  • A MatcherSet is created for each include/exclude file located, and the MatcherSet is added to the proper level.
  • During the build:
    • Each level creates a MatcherSet for the level.
    • The MatcherSet for each level is returned in reverse order (deepest first). This ensures that most include/exclude files will be properly handled.
  • Field Details

    • REGEX_FMT

      protected static final String REGEX_FMT
      A String format pattern to print a regex string
      See Also:
    • fileName

      protected final String fileName
      The name of the file being processed
    • commentFilter

      protected final Predicate<String> commentFilter
      The predicate that will return false for any comment line in the file.
  • Constructor Details

    • AbstractFileProcessorBuilder

      protected AbstractFileProcessorBuilder(String fileName, Iterable<String> commentPrefixes, boolean includeProcessorFile)
      Constructor for multiple comment prefixes.
      Parameters:
      fileName - The name of the file being read.
      commentPrefixes - the collection of comment prefixes.
    • AbstractFileProcessorBuilder

      protected AbstractFileProcessorBuilder(String fileName, String commentPrefix, boolean includeProcessorFile)
      Constructor for single comment prefix
      Parameters:
      fileName - The name of the file to process.
      commentPrefix - the comment prefix
    • AbstractFileProcessorBuilder

      protected AbstractFileProcessorBuilder(String fileName, Predicate<String> commentFilter, boolean includeProcessorFile)
      Constructor for single comment prefix
      Parameters:
      fileName - The name of the file to process.
      commentFilter - the comment prefix filter.
  • Method Details

    • build

      public final List<MatcherSet> build(DocumentName root)
      Builder the list of MatcherSet that define the inclusions/exclusions for the file processor.
      Parameters:
      root - the directory against which name resolution should be made.
      Returns:
      the List of MatcherSet that represent this file processor.
    • process

      protected MatcherSet process(Consumer<MatcherSet> matcherSetConsumer, DocumentName root, DocumentName documentName)
      Process by reading the file, creating a MatcherSet, and adding it to the matcherSets.
      Parameters:
      matcherSetConsumer - the consumer to add the custom matcher sets to.
      root - The root against which to resolve names.
      documentName - the file to read.
      Returns:
      A matcher set based on the strings in the file.
    • modifyEntry

      protected Optional<String> modifyEntry(Consumer<MatcherSet> matcherSetConsumer, DocumentName documentName, String entry)
      Allows modification of the file entry to match the MatchPattern format. Default implementation returns the @{code entry} argument.
      Parameters:
      documentName - the name of the document that the file was read from.
      entry - the entry from that document.
      Returns:
      the modified string or an empty Optional to skip the string.
    • listFiles

      protected File[] listFiles(File dir, FileFilter filter)
      Create a list of files by applying the filter to the specified directory.
      Parameters:
      dir - the directory.
      filter - the filter.
      Returns:
      an array of files. May be empty but will not be null.