Class GitIgnoreFileSet

java.lang.Object
nl.basjes.gitignore.GitIgnoreFileSet
All Implemented Interfaces:
FileFilter

public class GitIgnoreFileSet extends Object implements FileFilter
A class that holds a set of .gitignore files and also handles the interactions between them.
  • Constructor Details

    • GitIgnoreFileSet

      public GitIgnoreFileSet(File projectBaseDir)
      This will automatically find and load all gitignore files.
      Parameters:
      projectBaseDir - The base directory of the project. The root gitignore rules are relative to this directory.
    • GitIgnoreFileSet

      public GitIgnoreFileSet(File projectBaseDir, boolean autoload)
      Parameters:
      projectBaseDir - The base directory of the project. The root gitignore rules are relative to this directory.
      autoload - Automatically find and load all gitignore files?
  • Method Details

    • setVerbose

      public GitIgnoreFileSet setVerbose(boolean verbose)
      Make all currently loaded gitignore files become verbose when used.
      Parameters:
      verbose - True: be verbose, False: be silent
    • setAssumeProjectRelativeQueries

      public GitIgnoreFileSet setAssumeProjectRelativeQueries(boolean assumeProjectRelativeQueries)
      Sets the default assumption on how to interpret the filenames that must be checked.
      Parameters:
      assumeProjectRelativeQueries - The new assumption: True = all queries are assumed to be project relative; False = all queries are assumed to start with the path to the project directory in the SAME form as used during construction of this class.
    • assumeQueriesAreProjectRelative

      public GitIgnoreFileSet assumeQueriesAreProjectRelative()
      Sets the default assumption on how to interpret the filenames that must be checked to "all queries are assumed to be project relative"
    • isAssumeQueriesAreProjectRelative

      public boolean isAssumeQueriesAreProjectRelative()
    • assumeQueriesIncludeProjectBaseDir

      public GitIgnoreFileSet assumeQueriesIncludeProjectBaseDir()
      Sets the default assumption on how to interpret the filenames that must be checked to "all queries are assumed to start with the path to the project directory"
    • isAssumeQueriesIncludeProjectBaseDir

      public boolean isAssumeQueriesIncludeProjectBaseDir()
    • add

      public void add(GitIgnore gitIgnore)
    • addGitIgnoreFile

      public void addGitIgnoreFile(File gitIgnoreFile)
      Add a .gitignore file to the set.
      Parameters:
      gitIgnoreFile - The handle of the file of a gitignore file to be added. This MUST be able to get the ABSOLUTE path within the project.
    • addAllGitIgnoreFiles

      public void addAllGitIgnoreFiles()
      Automatically find all .gitignore files starting in the projects root and add them all to the set.
    • isEmpty

      public boolean isEmpty()
    • isIgnoredFile

      public Boolean isIgnoredFile(String filename)
      Checks if the file matches the stored expressions. This is suitable for combining multiple sets of rules!
      Parameters:
      filename - The filename to be checked which follows the assumeProjectRelativeQueries flag.
      Returns:
      NULL: not matched, True: must be ignored, False: it must be UNignored
    • isIgnoredFile

      public Boolean isIgnoredFile(String filename, boolean isRelative)
      Checks if the file matches the stored expressions. This is suitable for combining multiple sets of rules!
      Parameters:
      filename - The filename to be checked.
      isRelative - True: The provided filename is a RELATIVE path (i.e. the project base directory is assumed to be the root). False: The provided filename is an ABSOLUTE path (i.e. it still includes the project base directory).
      Returns:
      NULL: not matched, True: must be ignored, False: it must be UNignored
    • ignoreFile

      public boolean ignoreFile(String filename)
      Checks if the file matches the stored expressions. This is NOT suitable for combining multiple sets of rules!
      Parameters:
      filename - The filename to be checked which follows the assumeProjectRelativeQueries flag.
      Returns:
      true: must be ignored, false: it must be not be ignored
    • ignoreFile

      public boolean ignoreFile(String filename, boolean isProjectRelative)
      Checks if the file matches the stored expressions. This is NOT suitable for combining multiple sets of rules!
      Parameters:
      filename - The filename to be checked.
      isProjectRelative - True: The provided filename is a project RELATIVE path (i.e. "/directory in project/filename"). False: The provided filename is a path that starts with the path used to initialize this class (i.e. "project base directory/directory in project/filename").
      Returns:
      true: must be ignored, false: it must be not be ignored
    • keepFile

      public boolean keepFile(String filename)
      Checks if the file matches the stored expressions. This is NOT suitable for combining multiple sets of rules!
      Parameters:
      filename - The filename to be checked which follows the assumeProjectRelativeQueries flag.
      Returns:
      true: must be kept, false: it must be ignored
    • keepFile

      public boolean keepFile(String filename, boolean isProjectRelative)
      Checks if the file matches the stored expressions. This is NOT suitable for combining multiple sets of rules!
      Parameters:
      filename - The filename to be checked.
      isProjectRelative - True: The provided filename is a project RELATIVE path (i.e. "/directory in project/filename"). False: The provided filename is a path that starts with the path used to initialize this class (i.e. "project base directory/directory in project/filename").
      Returns:
      true: must be kept, false: it must be ignored
    • accept

      public boolean accept(File pathname)
      Specified by:
      accept in interface FileFilter
    • toString

      public String toString()
      Overrides:
      toString in class Object