Package io.github.classgraph.utils
Class WhiteBlackList
- java.lang.Object
-
- io.github.classgraph.utils.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 classWhiteBlackList.WhiteBlackListLeafnameWhitelist/blacklist for prefix strings.static classWhiteBlackList.WhiteBlackListPrefixWhitelist/blacklist for prefix strings.static classWhiteBlackList.WhiteBlackListWholeStringWhitelist/blacklist for whole-strings matches.
-
Field Summary
Fields Modifier and Type Field Description protected Set<String>blacklistBlacklisted items (whole-string match)protected Set<String>blacklistGlobsBlacklist glob strings.protected List<Pattern>blacklistPatternsBlacklist regexp patterns.protected List<String>blacklistPrefixesBlacklisted items (prefix match)protected Set<String>whitelistWhitelisted items (whole-string match)protected Set<String>whitelistGlobsWhitelist glob strings.protected List<Pattern>whitelistPatternsWhitelist regexp patterns.protected List<String>whitelistPrefixesWhitelisted 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 voidaddToBlacklist(String str)abstract voidaddToWhitelist(String str)static StringclassNameToClassfilePath(String className)Convert a class name to a classfile path.static PatternglobToPattern(String glob)Convert a spec with a '*' glob character into a regular expression.abstract booleanisBlacklisted(String str)booleanisSpecificallyWhitelisted(String str)booleanisSpecificallyWhitelistedAndNotBlacklisted(String str)abstract booleanisWhitelisted(String str)abstract booleanisWhitelistedAndNotBlacklisted(String str)static StringnormalizePackageOrClassName(String packageOrClassName)Remove initial and final '.' characters, if any.static StringnormalizePath(String path)Remove initial and final '/' characters, if any.static StringpackageNameToPath(String packageName)Convert a package name to a path.static StringpathToPackageName(String path)Convert a path to a package name.voidsortPrefixes()Need to sort prefixes to ensure correct whitelist/blacklist evaluation (see Issue #167).StringtoString()abstract booleanwhitelistHasPrefix(String str)booleanwhitelistIsEmpty()
-
-
-
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.
-
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).
-
-