Class AbstractScanner
- java.lang.Object
-
- org.codehaus.plexus.util.AbstractScanner
-
- All Implemented Interfaces:
Scanner
- Direct Known Subclasses:
DirectoryScanner
public abstract class AbstractScanner extends java.lang.Object implements Scanner
Scan a directory tree for files, with specified inclusions and exclusions.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String[]DEFAULTEXCLUDESPatterns which should be excluded by default, like SCM files Misc: **/*~, **/#*#, **/.#*, **/%*%, **/._* CVS: **/CVS, **/CVS/**, **/.cvsignore RCS: **/RCS, **/RCS/** SCCS: **/SCCS, **/SCCS/** VSSercer: **/vssver.scc MKS: **/project.pj SVN: **/.svn, **/.svn/** GNU: **/.arch-ids, **/.arch-ids/** Bazaar: **/.bzr, **/.bzr/** SurroundSCM: **/.MySCMServerInfo Mac: **/.DS_Store Serena Dimension: **/.metadata, **/.metadata/** Mercurial: **/.hg, **/.hg/**, **/.hgignore GIT: **/.git, **/.gitignore, **/.gitattributes, **/.git/** Bitkeeper: **/BitKeeper, **/BitKeeper/**, **/ChangeSet, **/ChangeSet/** Darcs: **/_darcs, **/_darcs/**, **/.darcsrepo, **/.darcsrepo/****/-darcs-backup*, **/.darcs-temp-mailprotected java.lang.String[]excludesThe patterns for the files to be excluded.private MatchPatternsexcludesPatternsprotected java.util.Comparator<java.lang.String>filenameComparatorprotected java.lang.String[]includesThe patterns for the files to be included.private MatchPatternsincludesPatternsprotected booleanisCaseSensitiveWhether or not the file system should be treated as a case sensitive one.
-
Constructor Summary
Constructors Constructor Description AbstractScanner()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDefaultExcludes()Adds default exclusions to the current exclusions set.protected booleancouldHoldIncluded(java.lang.String name)Tests whether or not a name matches the start of at least one include pattern.protected booleanisExcluded(java.lang.String name)Tests whether or not a name matches against at least one exclude pattern.protected booleanisExcluded(java.lang.String name, java.lang.String[] tokenizedName)protected booleanisIncluded(java.lang.String name)Tests whether or not a name matches against at least one include pattern.protected booleanisIncluded(java.lang.String name, java.lang.String[] tokenizedName)static booleanmatch(java.lang.String pattern, java.lang.String str)Tests whether or not a string matches against a pattern.protected static booleanmatch(java.lang.String pattern, java.lang.String str, boolean isCaseSensitive)Tests whether or not a string matches against a pattern.protected static booleanmatchPath(java.lang.String pattern, java.lang.String str)Tests whether or not a given path matches a given pattern.protected static booleanmatchPath(java.lang.String pattern, java.lang.String str, boolean isCaseSensitive)Tests whether or not a given path matches a given pattern.protected static booleanmatchPatternStart(java.lang.String pattern, java.lang.String str)Tests whether or not a given path matches the start of a given pattern up to the first "**".protected static booleanmatchPatternStart(java.lang.String pattern, java.lang.String str, boolean isCaseSensitive)Tests whether or not a given path matches the start of a given pattern up to the first "**".private java.lang.StringnormalizePattern(java.lang.String pattern)Normalizes the pattern, e.g.voidsetCaseSensitive(boolean isCaseSensitive)Sets whether or not the file system should be regarded as case sensitive.voidsetExcludes(java.lang.String[] excludes)Sets the list of exclude patterns to use.voidsetFilenameComparator(java.util.Comparator<java.lang.String> filenameComparator)Use a filename comparator in each directory when scanning.voidsetIncludes(java.lang.String[] includes)Sets the list of include patterns to use.protected voidsetupDefaultFilters()protected voidsetupMatchPatterns()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.codehaus.plexus.util.Scanner
getBasedir, getIncludedDirectories, getIncludedFiles, scan
-
-
-
-
Field Detail
-
DEFAULTEXCLUDES
public static final java.lang.String[] DEFAULTEXCLUDES
Patterns which should be excluded by default, like SCM files- Misc: **/*~, **/#*#, **/.#*, **/%*%, **/._*
- CVS: **/CVS, **/CVS/**, **/.cvsignore
- RCS: **/RCS, **/RCS/**
- SCCS: **/SCCS, **/SCCS/**
- VSSercer: **/vssver.scc
- MKS: **/project.pj
- SVN: **/.svn, **/.svn/**
- GNU: **/.arch-ids, **/.arch-ids/**
- Bazaar: **/.bzr, **/.bzr/**
- SurroundSCM: **/.MySCMServerInfo
- Mac: **/.DS_Store
- Serena Dimension: **/.metadata, **/.metadata/**
- Mercurial: **/.hg, **/.hg/**, **/.hgignore
- GIT: **/.git, **/.gitignore, **/.gitattributes, **/.git/**
- Bitkeeper: **/BitKeeper, **/BitKeeper/**, **/ChangeSet, **/ChangeSet/**
- Darcs: **/_darcs, **/_darcs/**, **/.darcsrepo, **/.darcsrepo/****/-darcs-backup*, **/.darcs-temp-mail
- See Also:
addDefaultExcludes()
-
includes
protected java.lang.String[] includes
The patterns for the files to be included.
-
includesPatterns
private MatchPatterns includesPatterns
-
excludes
protected java.lang.String[] excludes
The patterns for the files to be excluded.
-
excludesPatterns
private MatchPatterns excludesPatterns
-
isCaseSensitive
protected boolean isCaseSensitive
Whether or not the file system should be treated as a case sensitive one.
-
filenameComparator
protected java.util.Comparator<java.lang.String> filenameComparator
- Since:
- 3.3.0
-
-
Method Detail
-
setCaseSensitive
public void setCaseSensitive(boolean isCaseSensitive)
Sets whether or not the file system should be regarded as case sensitive.- Parameters:
isCaseSensitive- whether or not the file system should be regarded as a case sensitive one
-
matchPatternStart
protected static boolean matchPatternStart(java.lang.String pattern, java.lang.String str)Tests whether or not a given path matches the start of a given pattern up to the first "**".
This is not a general purpose test and should only be used if you can live with false positives. For example,
pattern=**\aandstr=bwill yieldtrue.- Parameters:
pattern- The pattern to match against. Must not benull.str- The path to match, as a String. Must not benull.- Returns:
- whether or not a given path matches the start of a given pattern up to the first "**".
-
matchPatternStart
protected static boolean matchPatternStart(java.lang.String pattern, java.lang.String str, boolean isCaseSensitive)Tests whether or not a given path matches the start of a given pattern up to the first "**".
This is not a general purpose test and should only be used if you can live with false positives. For example,
pattern=**\aandstr=bwill yieldtrue.- Parameters:
pattern- The pattern to match against. Must not benull.str- The path to match, as a String. Must not benull.isCaseSensitive- Whether or not matching should be performed case sensitively.- Returns:
- whether or not a given path matches the start of a given pattern up to the first "**".
-
matchPath
protected static boolean matchPath(java.lang.String pattern, java.lang.String str)Tests whether or not a given path matches a given pattern.- Parameters:
pattern- The pattern to match against. Must not benull.str- The path to match, as a String. Must not benull.- Returns:
trueif the pattern matches against the string, orfalseotherwise.
-
matchPath
protected static boolean matchPath(java.lang.String pattern, java.lang.String str, boolean isCaseSensitive)Tests whether or not a given path matches a given pattern.- Parameters:
pattern- The pattern to match against. Must not benull.str- The path to match, as a String. Must not benull.isCaseSensitive- Whether or not matching should be performed case sensitively.- Returns:
trueif the pattern matches against the string, orfalseotherwise.
-
match
public static boolean match(java.lang.String pattern, java.lang.String str)Tests whether or not a string matches against a pattern. The pattern may contain two special characters:
'*' means zero or more characters
'?' means one and only one character- Parameters:
pattern- The pattern to match against. Must not benull.str- The string which must be matched against the pattern. Must not benull.- Returns:
trueif the string matches against the pattern, orfalseotherwise.
-
match
protected static boolean match(java.lang.String pattern, java.lang.String str, boolean isCaseSensitive)Tests whether or not a string matches against a pattern. The pattern may contain two special characters:
'*' means zero or more characters
'?' means one and only one character- Parameters:
pattern- The pattern to match against. Must not benull.str- The string which must be matched against the pattern. Must not benull.isCaseSensitive- Whether or not matching should be performed case sensitively.- Returns:
trueif the string matches against the pattern, orfalseotherwise.
-
setIncludes
public void setIncludes(java.lang.String[] includes)
Sets the list of include patterns to use. All '/' and '\' characters are replaced by
File.separatorChar, so the separator used need not matchFile.separatorChar.When a pattern ends with a '/' or '\', "**" is appended.
- Specified by:
setIncludesin interfaceScanner- Parameters:
includes- A list of include patterns. May benull, indicating that all files should be included. If a non-nulllist is given, all elements must be non-null.
-
setExcludes
public void setExcludes(java.lang.String[] excludes)
Sets the list of exclude patterns to use. All '/' and '\' characters are replaced by
File.separatorChar, so the separator used need not matchFile.separatorChar.When a pattern ends with a '/' or '\', "**" is appended.
- Specified by:
setExcludesin interfaceScanner- Parameters:
excludes- A list of exclude patterns. May benull, indicating that no files should be excluded. If a non-nulllist is given, all elements must be non-null.
-
normalizePattern
private java.lang.String normalizePattern(java.lang.String pattern)
Normalizes the pattern, e.g. converts forward and backward slashes to the platform-specific file separator.- Parameters:
pattern- The pattern to normalize, must not benull.- Returns:
- The normalized pattern, never
null.
-
isIncluded
protected boolean isIncluded(java.lang.String name)
Tests whether or not a name matches against at least one include pattern.- Parameters:
name- The name to match. Must not benull.- Returns:
truewhen the name matches against at least one include pattern, orfalseotherwise.
-
isIncluded
protected boolean isIncluded(java.lang.String name, java.lang.String[] tokenizedName)
-
couldHoldIncluded
protected boolean couldHoldIncluded(java.lang.String name)
Tests whether or not a name matches the start of at least one include pattern.- Parameters:
name- The name to match. Must not benull.- Returns:
truewhen the name matches against the start of at least one include pattern, orfalseotherwise.
-
isExcluded
protected boolean isExcluded(java.lang.String name)
Tests whether or not a name matches against at least one exclude pattern.- Parameters:
name- The name to match. Must not benull.- Returns:
truewhen the name matches against at least one exclude pattern, orfalseotherwise.
-
isExcluded
protected boolean isExcluded(java.lang.String name, java.lang.String[] tokenizedName)
-
addDefaultExcludes
public void addDefaultExcludes()
Adds default exclusions to the current exclusions set.- Specified by:
addDefaultExcludesin interfaceScanner
-
setupDefaultFilters
protected void setupDefaultFilters()
-
setupMatchPatterns
protected void setupMatchPatterns()
-
setFilenameComparator
public void setFilenameComparator(java.util.Comparator<java.lang.String> filenameComparator)
Description copied from interface:ScannerUse a filename comparator in each directory when scanning.- Specified by:
setFilenameComparatorin interfaceScanner
-
-