public class ScanSpec extends Object
Modifier and Type | Class and Description |
---|---|
static class |
ScanSpec.FilePathTesterAndMatchProcessorWrapper |
static class |
ScanSpec.ScanSpecPathMatch
Whether a path is a descendant of a blacklisted path, or an ancestor or descendant of a whitelisted path.
|
Modifier and Type | Field and Description |
---|---|
boolean |
blacklistSystemJars
True if JRE system jarfiles (rt.jar etc.) should not be scanned.
|
boolean |
blacklistSystemPackages
By default, blacklist all java.* and sun.* packages.
|
HashSet<ClassLoaderHandler> |
extraClassLoaderHandlers
Manually-registered ClassLoaderHandlers.
|
boolean |
ignoreFieldVisibility
If true, ignore field visibility (affects finding classes with fields of a given type, and matching of static
final fields with constant initializers).
|
String |
overrideClasspath
If non-null, specifies a classpath to override the default one.
|
boolean |
scanJars
True if jarfiles should be scanned.
|
boolean |
scanNonJars
True if non-jarfiles (directories) should be scanned.
|
Modifier and Type | Method and Description |
---|---|
void |
addFilePathMatcher(io.github.lukehutch.fastclasspathscanner.scanner.FilePathTester filePathTester,
io.github.lukehutch.fastclasspathscanner.scanner.FileMatchProcessorWrapper fileMatchProcessorWrapper) |
boolean |
blacklistSystemJars()
True if JRE system jarfiles (rt.jar etc.) should not be scanned.
|
void |
callMatchProcessors(ScanResult scanResult,
LinkedBlockingQueue<io.github.lukehutch.fastclasspathscanner.scanner.ClasspathResource> matchingFiles,
Map<String,ClassInfo> classNameToClassInfo,
ThreadLog log)
Run the MatchProcessors after a scan has completed.
|
void |
checkClassIsNotBlacklisted(String className)
Checks that the named class is not blacklisted.
|
boolean |
classIsNotBlacklisted(String className)
Returns true if the class is not specifically blacklisted, and is not within a blacklisted package.
|
String |
getAnnotationName(Class<?> annotation)
Check a class is an annotation, and that it is in a whitelisted package.
|
String[] |
getAnnotationNames(Class<?>[] annotations)
Check each element of an array of classes is an annotation, and that it is in a whitelisted package.
|
String |
getClassName(Class<?> cls)
Check a class is in a whitelisted package.
|
Map<String,HashSet<String>> |
getClassNameToStaticFinalFieldsToMatch() |
String |
getClassOrInterfaceName(Class<?> classOrInterface)
Check a class is a regular class or interface and not an annotation, and that it is in a whitelisted package.
|
String |
getInterfaceName(Class<?> iface)
Check a class is an interface, and that it is in a whitelisted package.
|
String[] |
getInterfaceNames(Class<?>[] interfaces)
Check each element of an array of classes is an interface, and that it is in a whitelisted package.
|
String |
getStandardClassName(Class<?> cls)
Check a class is a standard class (not an interface or annotation), and that it is in a whitelisted package.
|
boolean |
isSpecificallyWhitelistedClass(String relativePath)
Returns true if the given relative path (for a classfile name, including ".class") matches a
specifically-whitelisted (and non-blacklisted) classfile's relative path.
|
boolean |
jarIsWhitelisted(String jarName)
Returns true if a jarfile is whitelisted and not blacklisted.
|
void |
log(ThreadLog log) |
void |
matchAllAnnotationClasses(ClassMatchProcessor ClassMatchProcessor)
Calls the provided ClassMatchProcessor for all annotation classes (annotation definitions) found in
whitelisted packages on the classpath.
|
void |
matchAllClasses(ClassMatchProcessor classMatchProcessor)
Calls the provided ClassMatchProcessor for all standard classes, interfaces and annotations found in
whitelisted packages on the classpath.
|
void |
matchAllInterfaceClasses(ClassMatchProcessor ClassMatchProcessor)
Calls the provided ClassMatchProcessor for all interface classes (interface definitions) found in whitelisted
packages on the classpath.
|
void |
matchAllStandardClasses(ClassMatchProcessor classMatchProcessor)
Calls the provided ClassMatchProcessor for all standard classes (i.e.
|
<T> void |
matchClassesImplementing(Class<T> implementedInterface,
InterfaceMatchProcessor<T> interfaceMatchProcessor)
Calls the provided InterfaceMatchProcessor for classes on the classpath that implement the specified
interface or a subinterface, or whose superclasses implement the specified interface or a sub-interface.
|
void |
matchClassesWithAnnotation(Class<?> annotation,
ClassAnnotationMatchProcessor classAnnotationMatchProcessor)
Calls the provided ClassMatchProcessor if classes are found on the classpath that have the specified
annotation.
|
<T> void |
matchClassesWithFieldOfType(Class<T> fieldType,
ClassMatchProcessor classMatchProcessor)
Calls the provided ClassMatchProcessor for classes on the classpath that have a field of the given type.
|
void |
matchFilenameExtension(String extensionToMatch,
FileMatchContentsProcessor fileMatchContentsProcessor)
Calls the given FileMatchProcessor if files are found on the classpath that have the given file extension.
|
void |
matchFilenameExtension(String extensionToMatch,
FileMatchContentsProcessorWithContext fileMatchContentsProcessorWithContext)
Calls the given FileMatchProcessorWithContext if files are found on the classpath that have the given file
extension.
|
void |
matchFilenameExtension(String extensionToMatch,
FileMatchProcessor fileMatchProcessor)
Calls the given FileMatchProcessor if files are found on the classpath that have the given file extension.
|
void |
matchFilenameExtension(String extensionToMatch,
FileMatchProcessorWithContext fileMatchProcessorWithContext)
Calls the given FileMatchProcessorWithContext if files are found on the classpath that have the given file
extension.
|
void |
matchFilenamePath(String relativePathToMatch,
FileMatchContentsProcessor fileMatchContentsProcessor)
Calls the given FileMatchContentsProcessor if files are found on the classpath that exactly match the given
relative path.
|
void |
matchFilenamePath(String relativePathToMatch,
FileMatchContentsProcessorWithContext fileMatchContentsProcessorWithContext)
Calls the given FileMatchContentsProcessorWithContext if files are found on the classpath that exactly match
the given relative path.
|
void |
matchFilenamePath(String relativePathToMatch,
FileMatchProcessor fileMatchProcessor)
Calls the given FileMatchProcessor if files are found on the classpath that exactly match the given relative
path.
|
void |
matchFilenamePath(String relativePathToMatch,
FileMatchProcessorWithContext fileMatchProcessorWithContext)
Calls the given FileMatchProcessorWithContext if files are found on the classpath that exactly match the
given relative path.
|
void |
matchFilenamePathLeaf(String pathLeafToMatch,
FileMatchContentsProcessor fileMatchContentsProcessor)
Calls the given FileMatchContentsProcessor if files are found on the classpath that exactly match the given
path leafname.
|
void |
matchFilenamePathLeaf(String pathLeafToMatch,
FileMatchContentsProcessorWithContext fileMatchContentsProcessorWithContext)
Calls the given FileMatchContentsProcessorWithContext if files are found on the classpath that exactly match
the given path leafname.
|
void |
matchFilenamePathLeaf(String pathLeafToMatch,
FileMatchProcessor fileMatchProcessor)
Calls the given FileMatchProcessor if files are found on the classpath that exactly match the given path
leafname.
|
void |
matchFilenamePathLeaf(String pathLeafToMatch,
FileMatchProcessorWithContext fileMatchProcessorWithContext)
Calls the given FileMatchProcessorWithContext if files are found on the classpath that exactly match the
given path leafname.
|
void |
matchFilenamePattern(String pathRegexp,
FileMatchContentsProcessor fileMatchContentsProcessor)
Calls the given FileMatchContentsProcessor if files are found on the classpath with the given regexp pattern
in their path.
|
void |
matchFilenamePattern(String pathRegexp,
FileMatchContentsProcessorWithContext fileMatchContentsProcessorWithContext)
Calls the given FileMatchContentsProcessorWithContext if files are found on the classpath with the given
regexp pattern in their path.
|
void |
matchFilenamePattern(String pathRegexp,
FileMatchProcessor fileMatchProcessor)
Calls the given FileMatchProcessor if files are found on the classpath with the given regexp pattern in their
path.
|
void |
matchFilenamePattern(String pathRegexp,
FileMatchProcessorWithContext fileMatchProcessorWithContext)
Calls the given FileMatchProcessorWithContext if files are found on the classpath with the given regexp
pattern in their path.
|
void |
matchStaticFinalFieldNames(Set<String> fullyQualifiedStaticFinalFieldNames,
StaticFinalFieldMatchProcessor staticFinalFieldMatchProcessor)
Calls the given StaticFinalFieldMatchProcessor if classes are found on the classpath that contain static
final fields that match one of a set of fully-qualified field names, e.g.
|
void |
matchStaticFinalFieldNames(String[] fullyQualifiedStaticFinalFieldNames,
StaticFinalFieldMatchProcessor staticFinalFieldMatchProcessor)
Calls the given StaticFinalFieldMatchProcessor if classes are found on the classpath that contain static
final fields that match one of a list of fully-qualified field names, e.g.
|
void |
matchStaticFinalFieldNames(String fullyQualifiedStaticFinalFieldName,
StaticFinalFieldMatchProcessor staticFinalFieldMatchProcessor)
Calls the given StaticFinalFieldMatchProcessor if classes are found on the classpath that contain static
final fields that match a fully-qualified field name, e.g.
|
<T> void |
matchSubclassesOf(Class<T> superclass,
SubclassMatchProcessor<T> subclassMatchProcessor)
Calls the provided SubclassMatchProcessor if classes are found on the classpath that extend the specified
superclass.
|
<T> void |
matchSubinterfacesOf(Class<T> superinterface,
SubinterfaceMatchProcessor<T> subinterfaceMatchProcessor)
Calls the provided SubinterfaceMatchProcessor if an interface that extends a given superinterface is found on
the classpath.
|
ScanSpec.ScanSpecPathMatch |
pathWhitelistMatchStatus(String relativePath)
Returns true if the given directory path is a descendant of a blacklisted path, or an ancestor or descendant
of a whitelisted path.
|
public final boolean scanJars
public final boolean scanNonJars
public String overrideClasspath
public final HashSet<ClassLoaderHandler> extraClassLoaderHandlers
public boolean blacklistSystemJars
public boolean blacklistSystemPackages
public boolean ignoreFieldVisibility
public ScanSpec(String[] scanSpec)
public Map<String,HashSet<String>> getClassNameToStaticFinalFieldsToMatch()
public void log(ThreadLog log)
public void callMatchProcessors(ScanResult scanResult, LinkedBlockingQueue<io.github.lukehutch.fastclasspathscanner.scanner.ClasspathResource> matchingFiles, Map<String,ClassInfo> classNameToClassInfo, ThreadLog log) throws InterruptedException
InterruptedException
public ScanSpec.ScanSpecPathMatch pathWhitelistMatchStatus(String relativePath)
public boolean isSpecificallyWhitelistedClass(String relativePath)
public boolean classIsNotBlacklisted(String className)
public void checkClassIsNotBlacklisted(String className)
public boolean jarIsWhitelisted(String jarName)
public boolean blacklistSystemJars()
public String getAnnotationName(Class<?> annotation)
public String[] getAnnotationNames(Class<?>[] annotations)
public String getInterfaceName(Class<?> iface)
public String[] getInterfaceNames(Class<?>[] interfaces)
public String getClassOrInterfaceName(Class<?> classOrInterface)
public String getStandardClassName(Class<?> cls)
public String getClassName(Class<?> cls)
public void matchAllClasses(ClassMatchProcessor classMatchProcessor)
classMatchProcessor
- the ClassMatchProcessor to call when a match is found.public void matchAllStandardClasses(ClassMatchProcessor classMatchProcessor)
classMatchProcessor
- the ClassMatchProcessor to call when a match is found.public void matchAllInterfaceClasses(ClassMatchProcessor ClassMatchProcessor)
ClassMatchProcessor
- the ClassMatchProcessor to call when a match is found.public void matchAllAnnotationClasses(ClassMatchProcessor ClassMatchProcessor)
ClassMatchProcessor
- the ClassMatchProcessor to call when a match is found.public <T> void matchSubclassesOf(Class<T> superclass, SubclassMatchProcessor<T> subclassMatchProcessor)
superclass
- The superclass to match (i.e. the class that subclasses need to extend to match).subclassMatchProcessor
- the SubclassMatchProcessor to call when a match is found.public <T> void matchSubinterfacesOf(Class<T> superinterface, SubinterfaceMatchProcessor<T> subinterfaceMatchProcessor)
superinterface
- The superinterface to match (i.e. the interface that subinterfaces need to extend to match).subinterfaceMatchProcessor
- the SubinterfaceMatchProcessor to call when a match is found.public <T> void matchClassesImplementing(Class<T> implementedInterface, InterfaceMatchProcessor<T> interfaceMatchProcessor)
implementedInterface
- The interface that classes need to implement.interfaceMatchProcessor
- the ClassMatchProcessor to call when a match is found.public <T> void matchClassesWithFieldOfType(Class<T> fieldType, ClassMatchProcessor classMatchProcessor)
fieldType
- The type of the field to match..classMatchProcessor
- the ClassMatchProcessor to call when a match is found.public void matchClassesWithAnnotation(Class<?> annotation, ClassAnnotationMatchProcessor classAnnotationMatchProcessor)
annotation
- The class annotation to match.classAnnotationMatchProcessor
- the ClassAnnotationMatchProcessor to call when a match is found.public void matchStaticFinalFieldNames(Set<String> fullyQualifiedStaticFinalFieldNames, StaticFinalFieldMatchProcessor staticFinalFieldMatchProcessor)
fullyQualifiedStaticFinalFieldNames
- The set of fully-qualified static field names to match.staticFinalFieldMatchProcessor
- the StaticFinalFieldMatchProcessor to call when a match is found.public void matchStaticFinalFieldNames(String fullyQualifiedStaticFinalFieldName, StaticFinalFieldMatchProcessor staticFinalFieldMatchProcessor)
fullyQualifiedStaticFinalFieldName
- The fully-qualified static field name to matchstaticFinalFieldMatchProcessor
- the StaticFinalFieldMatchProcessor to call when a match is found.public void matchStaticFinalFieldNames(String[] fullyQualifiedStaticFinalFieldNames, StaticFinalFieldMatchProcessor staticFinalFieldMatchProcessor)
fullyQualifiedStaticFinalFieldNames
- The list of fully-qualified static field names to match.staticFinalFieldMatchProcessor
- the StaticFinalFieldMatchProcessor to call when a match is found.public void addFilePathMatcher(io.github.lukehutch.fastclasspathscanner.scanner.FilePathTester filePathTester, io.github.lukehutch.fastclasspathscanner.scanner.FileMatchProcessorWrapper fileMatchProcessorWrapper)
public void matchFilenamePattern(String pathRegexp, FileMatchProcessorWithContext fileMatchProcessorWithContext)
pathRegexp
- The regexp to match, e.g. "app/templates/.\*\.html"fileMatchProcessorWithContext
- The FileMatchProcessorWithContext to call when each match is found.public void matchFilenamePattern(String pathRegexp, FileMatchProcessor fileMatchProcessor)
pathRegexp
- The regexp to match, e.g. "app/templates/.\*\.html"fileMatchProcessor
- The FileMatchProcessor to call when each match is found.public void matchFilenamePattern(String pathRegexp, FileMatchContentsProcessorWithContext fileMatchContentsProcessorWithContext)
pathRegexp
- The regexp to match, e.g. "app/templates/.\*\.html"fileMatchContentsProcessorWithContext
- The FileMatchContentsProcessorWithContext to call when each match is found.public void matchFilenamePattern(String pathRegexp, FileMatchContentsProcessor fileMatchContentsProcessor)
pathRegexp
- The regexp to match, e.g. "app/templates/.\*\.html"fileMatchContentsProcessor
- The FileMatchContentsProcessor to call when each match is found.public void matchFilenamePath(String relativePathToMatch, FileMatchProcessorWithContext fileMatchProcessorWithContext)
relativePathToMatch
- The complete path to match relative to the classpath entry, e.g.
"app/templates/WidgetTemplate.html"fileMatchProcessorWithContext
- The FileMatchProcessorWithContext to call when each match is found.public void matchFilenamePath(String relativePathToMatch, FileMatchProcessor fileMatchProcessor)
relativePathToMatch
- The complete path to match relative to the classpath entry, e.g.
"app/templates/WidgetTemplate.html"fileMatchProcessor
- The FileMatchProcessor to call when each match is found.public void matchFilenamePath(String relativePathToMatch, FileMatchContentsProcessorWithContext fileMatchContentsProcessorWithContext)
relativePathToMatch
- The complete path to match relative to the classpath entry, e.g.
"app/templates/WidgetTemplate.html"fileMatchContentsProcessorWithContext
- The FileMatchContentsProcessorWithContext to call when each match is found.public void matchFilenamePath(String relativePathToMatch, FileMatchContentsProcessor fileMatchContentsProcessor)
relativePathToMatch
- The complete path to match relative to the classpath entry, e.g.
"app/templates/WidgetTemplate.html"fileMatchContentsProcessor
- The FileMatchContentsProcessor to call when each match is found.public void matchFilenamePathLeaf(String pathLeafToMatch, FileMatchProcessorWithContext fileMatchProcessorWithContext)
pathLeafToMatch
- The complete path leaf to match, e.g. "WidgetTemplate.html"fileMatchProcessorWithContext
- The FileMatchProcessorWithContext to call when each match is found.public void matchFilenamePathLeaf(String pathLeafToMatch, FileMatchProcessor fileMatchProcessor)
pathLeafToMatch
- The complete path leaf to match, e.g. "WidgetTemplate.html"fileMatchProcessor
- The FileMatchProcessor to call when each match is found.public void matchFilenamePathLeaf(String pathLeafToMatch, FileMatchContentsProcessorWithContext fileMatchContentsProcessorWithContext)
pathLeafToMatch
- The complete path leaf to match, e.g. "WidgetTemplate.html"fileMatchContentsProcessorWithContext
- The FileMatchContentsProcessorWithContext to call when each match is found.public void matchFilenamePathLeaf(String pathLeafToMatch, FileMatchContentsProcessor fileMatchContentsProcessor)
pathLeafToMatch
- The complete path leaf to match, e.g. "WidgetTemplate.html"fileMatchContentsProcessor
- The FileMatchContentsProcessor to call when each match is found.public void matchFilenameExtension(String extensionToMatch, FileMatchProcessorWithContext fileMatchProcessorWithContext)
extensionToMatch
- The extension to match, e.g. "html" matches "WidgetTemplate.html" and "WIDGET.HTML".fileMatchProcessorWithContext
- The FileMatchProcessorWithContext to call when each match is found.public void matchFilenameExtension(String extensionToMatch, FileMatchProcessor fileMatchProcessor)
extensionToMatch
- The extension to match, e.g. "html" matches "WidgetTemplate.html" and "WIDGET.HTML".fileMatchProcessor
- The FileMatchProcessor to call when each match is found.public void matchFilenameExtension(String extensionToMatch, FileMatchContentsProcessorWithContext fileMatchContentsProcessorWithContext)
extensionToMatch
- The extension to match, e.g. "html" matches "WidgetTemplate.html".fileMatchContentsProcessorWithContext
- The FileMatchContentsProcessorWithContext to call when each match is found.public void matchFilenameExtension(String extensionToMatch, FileMatchContentsProcessor fileMatchContentsProcessor)
extensionToMatch
- The extension to match, e.g. "html" matches "WidgetTemplate.html".fileMatchContentsProcessor
- The FileMatchContentsProcessor to call when each match is found.Copyright © 2016. All rights reserved.