Package nl.basjes.gitignore
Class GitIgnoreFileSet
java.lang.Object
nl.basjes.gitignore.GitIgnoreFileSet
- All Implemented Interfaces:
FileFilter
A class that holds a set of .gitignore files and also handles the interactions between them.
-
Constructor Summary
ConstructorsConstructorDescriptionGitIgnoreFileSet(File projectBaseDir) This will automatically find and load all gitignore files.GitIgnoreFileSet(File projectBaseDir, boolean autoload) -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidvoidAutomatically find all .gitignore files starting in the projects root and add them all to the set.voidaddGitIgnoreFile(File gitIgnoreFile) Add a .gitignore file to the set.Sets the default assumption on how to interpret the filenames that must be checked to "all queries are assumed to be project relative"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"booleanignoreFile(String filename) Checks if the file matches the stored expressions.booleanignoreFile(String filename, boolean isProjectRelative) Checks if the file matches the stored expressions.booleanbooleanbooleanisEmpty()isIgnoredFile(String filename) Checks if the file matches the stored expressions.isIgnoredFile(String filename, boolean isRelative) Checks if the file matches the stored expressions.booleanChecks if the file matches the stored expressions.booleanChecks if the file matches the stored expressions.setAssumeProjectRelativeQueries(boolean assumeProjectRelativeQueries) Sets the default assumption on how to interpret the filenames that must be checked.setVerbose(boolean verbose) Make all currently loaded gitignore files become verbose when used.toString()
-
Constructor Details
-
GitIgnoreFileSet
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
- 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
Make all currently loaded gitignore files become verbose when used.- Parameters:
verbose- True: be verbose, False: be silent
-
setAssumeProjectRelativeQueries
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
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
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
-
addGitIgnoreFile
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
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
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
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
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
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
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
- Specified by:
acceptin interfaceFileFilter
-
toString
-