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 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 Set<String>
blacklist
Blacklisted items (whole-string match)protected Set<String>
blacklistGlobs
Blacklist glob strings.protected List<Pattern>
blacklistPatterns
Blacklist regexp patterns.protected List<String>
blacklistPrefixes
Blacklisted items (prefix match)protected Set<String>
whitelist
Whitelisted items (whole-string match)protected Set<String>
whitelistGlobs
Whitelist glob strings.protected List<Pattern>
whitelistPatterns
Whitelist regexp patterns.protected List<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(String str)
abstract void
addToWhitelist(String str)
boolean
blacklistIsEmpty()
static String
classNameToClassfilePath(String className)
Convert a class name to a classfile path.static Pattern
globToPattern(String glob)
Convert a spec with a '*' glob character into a regular expression.abstract boolean
isBlacklisted(String str)
boolean
isSpecificallyWhitelisted(String str)
boolean
isSpecificallyWhitelistedAndNotBlacklisted(String str)
abstract boolean
isWhitelisted(String str)
abstract boolean
isWhitelistedAndNotBlacklisted(String str)
static String
normalizePackageOrClassName(String packageOrClassName)
Remove initial and final '.' characters, if any.static String
normalizePath(String path)
Remove initial and final '/' characters, if any.static String
packageNameToPath(String packageName)
Convert a package name to a path.static String
pathToPackageName(String path)
Convert a path to a package name.void
sortPrefixes()
Need to sort prefixes to ensure correct whitelist/blacklist evaluation (see Issue #167).String
toString()
boolean
whitelistAndBlacklistAreEmpty()
abstract boolean
whitelistHasPrefix(String str)
boolean
whitelistIsEmpty()
-
-
-
Field Detail
-
whitelistGlobs
protected Set<String> whitelistGlobs
Whitelist glob strings. (Serialized to JSON, for logging purposes.)
-
blacklistGlobs
protected Set<String> blacklistGlobs
Blacklist glob strings. (Serialized to JSON, for logging purposes.)
-
whitelistPatterns
protected transient List<Pattern> whitelistPatterns
Whitelist regexp patterns. (Not serialized to JSON.)
-
-
Method Detail
-
addToWhitelist
public abstract void addToWhitelist(String str)
- Parameters:
str
- The string to whitelist.
-
addToBlacklist
public abstract void addToBlacklist(String str)
- Parameters:
str
- The string to blacklist.
-
isWhitelistedAndNotBlacklisted
public abstract boolean isWhitelistedAndNotBlacklisted(String str)
- Parameters:
str
- The string to test.- Returns:
- true if the string is whitelisted and not blacklisted.
-
isWhitelisted
public abstract boolean isWhitelisted(String str)
- Parameters:
str
- The string to test.- Returns:
- true if the string is whitelisted.
-
whitelistHasPrefix
public abstract boolean whitelistHasPrefix(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(String str)
- Parameters:
str
- The string to test.- Returns:
- true if the string is blacklisted.
-
normalizePath
public static String normalizePath(String path)
Remove initial and final '/' characters, if any.- Parameters:
path
- The path to normalize.- Returns:
- The normalized path.
-
normalizePackageOrClassName
public static String normalizePackageOrClassName(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 String pathToPackageName(String path)
Convert a path to a package name.- Parameters:
path
- The path.- Returns:
- The package name.
-
packageNameToPath
public static String packageNameToPath(String packageName)
Convert a package name to a path.- Parameters:
packageName
- The package name.- Returns:
- The path.
-
classNameToClassfilePath
public static String classNameToClassfilePath(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 Pattern globToPattern(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(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(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).
-
-