Package nonapi.io.github.classgraph
Class WhiteBlackList
- java.lang.Object
-
- nonapi.io.github.classgraph.WhiteBlackList
-
- Direct Known Subclasses:
WhiteBlackList.WhiteBlackListPrefix
,WhiteBlackList.WhiteBlackListWholeString
public abstract class WhiteBlackList extends java.lang.Object
A class storing whitelist or blacklist criteria.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WhiteBlackList.WhiteBlackListLeafname
Whitelist/blacklist for prefix strings.static class
WhiteBlackList.WhiteBlackListPrefix
Whitelist/blacklist for prefix strings.static class
WhiteBlackList.WhiteBlackListWholeString
Whitelist/blacklist for whole-strings matches.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Set<java.lang.String>
blacklist
Blacklisted items (whole-string match)protected java.util.Set<java.lang.String>
blacklistGlobs
Blacklist glob strings.protected java.util.List<java.util.regex.Pattern>
blacklistPatterns
Blacklist regexp patterns.protected java.util.List<java.lang.String>
blacklistPrefixes
Blacklisted items (prefix match)protected java.util.Set<java.lang.String>
whitelist
Whitelisted items (whole-string match)protected java.util.Set<java.lang.String>
whitelistGlobs
Whitelist glob strings.protected java.util.List<java.util.regex.Pattern>
whitelistPatterns
Whitelist regexp patterns.protected java.util.List<java.lang.String>
whitelistPrefixes
Whitelisted items (prefix match)
-
Constructor Summary
Constructors Constructor Description WhiteBlackList()
Constructor for deserialization.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
addToBlacklist(java.lang.String str)
abstract void
addToWhitelist(java.lang.String str)
boolean
blacklistIsEmpty()
static java.lang.String
classNameToClassfilePath(java.lang.String className)
Convert a class name to a classfile path.static java.util.regex.Pattern
globToPattern(java.lang.String glob)
Convert a spec with a '*' glob character into a regular expression.abstract boolean
isBlacklisted(java.lang.String str)
boolean
isSpecificallyWhitelisted(java.lang.String str)
boolean
isSpecificallyWhitelistedAndNotBlacklisted(java.lang.String str)
abstract boolean
isWhitelisted(java.lang.String str)
abstract boolean
isWhitelistedAndNotBlacklisted(java.lang.String str)
static java.lang.String
normalizePackageOrClassName(java.lang.String packageOrClassName)
Remove initial and final '.' characters, if any.static java.lang.String
normalizePath(java.lang.String path)
Remove initial and final '/' characters, if any.static java.lang.String
packageNameToPath(java.lang.String packageName)
Convert a package name to a path.static java.lang.String
pathToPackageName(java.lang.String path)
Convert a path to a package name.void
sortPrefixes()
Need to sort prefixes to ensure correct whitelist/blacklist evaluation (see Issue #167).java.lang.String
toString()
boolean
whitelistAndBlacklistAreEmpty()
abstract boolean
whitelistHasPrefix(java.lang.String str)
boolean
whitelistIsEmpty()
-
-
-
Field Detail
-
whitelist
protected java.util.Set<java.lang.String> whitelist
Whitelisted items (whole-string match)
-
blacklist
protected java.util.Set<java.lang.String> blacklist
Blacklisted items (whole-string match)
-
whitelistPrefixes
protected java.util.List<java.lang.String> whitelistPrefixes
Whitelisted items (prefix match)
-
blacklistPrefixes
protected java.util.List<java.lang.String> blacklistPrefixes
Blacklisted items (prefix match)
-
whitelistGlobs
protected java.util.Set<java.lang.String> whitelistGlobs
Whitelist glob strings. (Serialized to JSON, for logging purposes.)
-
blacklistGlobs
protected java.util.Set<java.lang.String> blacklistGlobs
Blacklist glob strings. (Serialized to JSON, for logging purposes.)
-
whitelistPatterns
protected transient java.util.List<java.util.regex.Pattern> whitelistPatterns
Whitelist regexp patterns. (Not serialized to JSON.)
-
blacklistPatterns
protected transient java.util.List<java.util.regex.Pattern> blacklistPatterns
Blacklist regexp patterns. (Not serialized to JSON.)
-
-
Method Detail
-
addToWhitelist
public abstract void addToWhitelist(java.lang.String str)
- Parameters:
str
- The string to whitelist.
-
addToBlacklist
public abstract void addToBlacklist(java.lang.String str)
- Parameters:
str
- The string to blacklist.
-
isWhitelistedAndNotBlacklisted
public abstract boolean isWhitelistedAndNotBlacklisted(java.lang.String str)
- Parameters:
str
- The string to test.- Returns:
- true if the string is whitelisted and not blacklisted.
-
isWhitelisted
public abstract boolean isWhitelisted(java.lang.String str)
- Parameters:
str
- The string to test.- Returns:
- true if the string is whitelisted.
-
whitelistHasPrefix
public abstract boolean whitelistHasPrefix(java.lang.String str)
- Parameters:
str
- The string to test.- Returns:
- true if the string is a prefix of a whitelisted string.
-
isBlacklisted
public abstract boolean isBlacklisted(java.lang.String str)
- Parameters:
str
- The string to test.- Returns:
- true if the string is blacklisted.
-
normalizePath
public static java.lang.String normalizePath(java.lang.String path)
Remove initial and final '/' characters, if any.- Parameters:
path
- The path to normalize.- Returns:
- The normalized path.
-
normalizePackageOrClassName
public static java.lang.String normalizePackageOrClassName(java.lang.String packageOrClassName)
Remove initial and final '.' characters, if any.- Parameters:
packageOrClassName
- The package or class name.- Returns:
- The normalized package or class name.
-
pathToPackageName
public static java.lang.String pathToPackageName(java.lang.String path)
Convert a path to a package name.- Parameters:
path
- The path.- Returns:
- The package name.
-
packageNameToPath
public static java.lang.String packageNameToPath(java.lang.String packageName)
Convert a package name to a path.- Parameters:
packageName
- The package name.- Returns:
- The path.
-
classNameToClassfilePath
public static java.lang.String classNameToClassfilePath(java.lang.String className)
Convert a class name to a classfile path.- Parameters:
className
- The class name.- Returns:
- The classfile path (including a ".class" suffix).
-
globToPattern
public static java.util.regex.Pattern globToPattern(java.lang.String glob)
Convert a spec with a '*' glob character into a regular expression. Replaces "." with "\." and "*" with ".*", then compiles a regular expression.- Parameters:
glob
- The glob string.- Returns:
- The Pattern created from the glob string.
-
whitelistIsEmpty
public boolean whitelistIsEmpty()
- Returns:
- true if there were no whitelist criteria added.
-
blacklistIsEmpty
public boolean blacklistIsEmpty()
- Returns:
- true if there were no blacklist criteria added.
-
whitelistAndBlacklistAreEmpty
public boolean whitelistAndBlacklistAreEmpty()
- Returns:
- true if there were no whitelist or blacklist criteria added.
-
isSpecificallyWhitelistedAndNotBlacklisted
public boolean isSpecificallyWhitelistedAndNotBlacklisted(java.lang.String str)
- Parameters:
str
- The string to test.- Returns:
- true if the requested string is specifically whitelisted and not blacklisted, i.e. will not return true if the whitelist is empty, or if the string is blacklisted.
-
isSpecificallyWhitelisted
public boolean isSpecificallyWhitelisted(java.lang.String str)
- Parameters:
str
- The string to test.- Returns:
- true if the requested string is specifically whitelisted, i.e. will not return true if the whitelist is empty.
-
sortPrefixes
public void sortPrefixes()
Need to sort prefixes to ensure correct whitelist/blacklist evaluation (see Issue #167).
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-