public class FastClasspathScanner extends Object
Documentation:
https://github.com/lukehutch/fast-classpath-scanner/wiki
Modifier and Type | Class | Description |
---|---|---|
static interface |
FastClasspathScanner.ClasspathElementFilter |
Add a classpath element filter.
|
Constructor | Description |
---|---|
FastClasspathScanner(String... scanSpec) |
Construct a FastClasspathScanner instance.
|
Modifier and Type | Method | Description |
---|---|---|
FastClasspathScanner |
addClassLoader(ClassLoader classLoader) |
Add a ClassLoader to the list of ClassLoaders to scan.
|
FastClasspathScanner |
alwaysScanClasspathElementRoot() |
Allows you to scan default packages (with package name "") without scanning sub-packages unless they are
whitelisted.
|
FastClasspathScanner |
alwaysScanClasspathElementRoot(boolean alwaysScanClasspathElementRoot) |
Allows you to scan default packages (with package name "") without scanning sub-packages unless they are
whitelisted.
|
FastClasspathScanner |
disableRecursiveScanning() |
Disable recursive scanning.
|
FastClasspathScanner |
disableRecursiveScanning(boolean disableRecursiveScanning) |
If true, disable recursive scanning.
|
FastClasspathScanner |
enableFieldAnnotationIndexing() |
Enables field annotation indexing, which allows you to call
ScanResult#getNamesOfClassesWithFieldAnnotation(annotation).
|
FastClasspathScanner |
enableFieldAnnotationIndexing(boolean enableFieldAnnotationIndexing) |
If enableFieldAnnotationIndexing is true, enables field annotation indexing, which allows you to call
ScanResult#getNamesOfClassesWithFieldAnnotation(annotation).
|
FastClasspathScanner |
enableFieldInfo() |
Enables the saving of field info during the scan.
|
FastClasspathScanner |
enableFieldInfo(boolean enableFieldInfo) |
If enableFieldInfo is true, enables the saving of field info during the scan.
|
FastClasspathScanner |
enableMethodAnnotationIndexing() |
Enables method annotation indexing, which allows you to call
ScanResult#getNamesOfClassesWithMethodAnnotation(annotation).
|
FastClasspathScanner |
enableMethodAnnotationIndexing(boolean enableMethodAnnotationIndexing) |
If enableMethodAnnotationIndexing is true, enables method annotation indexing, which allows you to call
ScanResult#getNamesOfClassesWithMethodAnnotation(annotation).
|
FastClasspathScanner |
enableMethodInfo() |
Enables the saving of method info during the scan.
|
FastClasspathScanner |
enableMethodInfo(boolean enableMethodInfo) |
If enableMethodInfo is true, enables the saving of method info during the scan.
|
FastClasspathScanner |
filterClasspathElements(FastClasspathScanner.ClasspathElementFilter classpathElementFilter) |
Add a classpath element filter.
|
ClassLoader[] |
findBestClassLoader() |
Find the classloader or classloaders most likely to represent the order that classloaders are used to resolve
classes in the current context.
|
List<File> |
getUniqueClasspathElements() |
Returns the list of all unique File objects representing directories or zip/jarfiles on the classpath, in
classloader resolution order.
|
List<File> |
getUniqueClasspathElements(ExecutorService executorService,
int numParallelTasks) |
Returns the list of all unique File objects representing directories or zip/jarfiles on the classpath, in
classloader resolution order.
|
String |
getUniqueClasspathElementsAsPathStr() |
Returns all unique directories or zip/jarfiles on the classpath, in classloader resolution order, as a
classpath string, delineated with the standard path separator character.
|
Future<List<File>> |
getUniqueClasspathElementsAsync(ExecutorService executorService,
int numParallelTasks) |
Asynchronously returns the list of all unique File objects representing directories or zip/jarfiles on the
classpath, in classloader resolution order.
|
List<URL> |
getUniqueClasspathElementURLs() |
Returns the list of all unique URL objects representing directories or zip/jarfiles on the classpath, in
classloader resolution order.
|
List<URL> |
getUniqueClasspathElementURLs(ExecutorService executorService,
int numParallelTasks) |
Returns the list of all unique URL objects representing directories or zip/jarfiles on the classpath, in
classloader resolution order.
|
Future<List<URL>> |
getUniqueClasspathElementURLsAsync(ExecutorService executorService,
int numParallelTasks) |
Asynchronously returns the list of all unique URLs representing directories or zip/jarfiles on the classpath,
in classloader resolution order.
|
static String |
getVersion() |
Get the version number of FastClasspathScanner.
|
FastClasspathScanner |
ignoreFieldVisibility() |
This method causes FastClasspathScanner to ignore field visibility, enabling it to see private,
package-private and protected fields.
|
FastClasspathScanner |
ignoreFieldVisibility(boolean ignoreFieldVisibility) |
If ignoreFieldVisibility is true, causes FastClasspathScanner to ignore field visibility, enabling it to see
private, package-private and protected fields.
|
FastClasspathScanner |
ignoreMethodVisibility() |
This method causes FastClasspathScanner to ignore method visibility, enabling it to see private,
package-private and protected methods.
|
FastClasspathScanner |
ignoreMethodVisibility(boolean ignoreMethodVisibility) |
If ignoreMethodVisibility is true, causes FastClasspathScanner to ignore method visibility, enabling it to
see private, package-private and protected methods.
|
FastClasspathScanner |
ignoreParentClassLoaders() |
Ignore parent classloaders (i.e.
|
FastClasspathScanner |
ignoreParentClassLoaders(boolean ignoreParentClassLoaders) |
Ignore parent classloaders (i.e.
|
FastClasspathScanner |
initializeLoadedClasses(boolean initializeLoadedClasses) |
If initializeLoadedClasses is true, classes loaded with Class.forName() are initialized before passing class
references to MatchProcessors.
|
FastClasspathScanner |
matchAllAnnotationClasses(ClassMatchProcessor annotationClassMatchProcessor) |
Calls the provided ClassMatchProcessor for all annotation classes (annotation definitions) found in
whitelisted packages on the classpath.
|
FastClasspathScanner |
matchAllClasses(ClassMatchProcessor classMatchProcessor) |
Calls the provided ClassMatchProcessor for all standard classes, interfaces and annotations found in
whitelisted packages on the classpath.
|
FastClasspathScanner |
matchAllInterfaceClasses(ClassMatchProcessor interfaceClassMatchProcessor) |
Calls the provided ClassMatchProcessor for all interface classes (interface definitions) found in whitelisted
packages on the classpath.
|
FastClasspathScanner |
matchAllStandardClasses(ClassMatchProcessor standardClassMatchProcessor) |
Calls the provided ClassMatchProcessor for all standard classes (i.e.
|
<T> FastClasspathScanner |
matchClassesImplementing(Class<T> implementedInterface,
ImplementingClassMatchProcessor<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.
|
FastClasspathScanner |
matchClassesWithAnnotation(Class<?> annotation,
ClassAnnotationMatchProcessor classAnnotationMatchProcessor) |
Calls the provided ClassAnnotationMatchProcessor if classes are found on the classpath that have the
specified annotation.
|
FastClasspathScanner |
matchClassesWithFieldAnnotation(Class<? extends Annotation> annotation,
FieldAnnotationMatchProcessor fieldAnnotationMatchProcessor) |
Calls the provided FieldAnnotationMatchProcessor if classes are found on the classpath that have one or more
fields with the specified annotation.
|
FastClasspathScanner |
matchClassesWithMethodAnnotation(Class<? extends Annotation> annotation,
MethodAnnotationMatchProcessor methodAnnotationMatchProcessor) |
Calls the provided MethodAnnotationMatchProcessor if classes are found on the classpath that have one or more
methods with the specified annotation.
|
FastClasspathScanner |
matchFilenameExtension(String extensionToMatch,
FileMatchContentsProcessor fileMatchContentsProcessor) |
Calls the given FileMatchProcessor if files are found on the classpath that have the given file extension.
|
FastClasspathScanner |
matchFilenameExtension(String extensionToMatch,
FileMatchContentsProcessorWithContext fileMatchContentsProcessorWithContext) |
Calls the given FileMatchProcessorWithContext if files are found on the classpath that have the given file
extension.
|
FastClasspathScanner |
matchFilenameExtension(String extensionToMatch,
FileMatchProcessor fileMatchProcessor) |
Calls the given FileMatchProcessor if files are found on the classpath that have the given file extension.
|
FastClasspathScanner |
matchFilenameExtension(String extensionToMatch,
FileMatchProcessorWithContext fileMatchProcessorWithContext) |
Calls the given FileMatchProcessorWithContext if files are found on the classpath that have the given file
extension.
|
FastClasspathScanner |
matchFilenameExtension(String extensionToMatch,
FilenameMatchProcessor filenameMatchProcessor) |
Calls the given FilenameMatchProcessor if files are found on the classpath that have the given file
extension.
|
FastClasspathScanner |
matchFilenamePath(String relativePathToMatch,
FileMatchContentsProcessor fileMatchContentsProcessor) |
Calls the given FileMatchContentsProcessor if files are found on the classpath that exactly match the given
relative path.
|
FastClasspathScanner |
matchFilenamePath(String relativePathToMatch,
FileMatchContentsProcessorWithContext fileMatchContentsProcessorWithContext) |
Calls the given FileMatchContentsProcessorWithContext if files are found on the classpath that exactly match
the given relative path.
|
FastClasspathScanner |
matchFilenamePath(String relativePathToMatch,
FileMatchProcessor fileMatchProcessor) |
Calls the given FileMatchProcessor if files are found on the classpath that exactly match the given relative
path.
|
FastClasspathScanner |
matchFilenamePath(String relativePathToMatch,
FileMatchProcessorWithContext fileMatchProcessorWithContext) |
Calls the given FileMatchProcessorWithContext if files are found on the classpath that exactly match the
given relative path.
|
FastClasspathScanner |
matchFilenamePath(String relativePathToMatch,
FilenameMatchProcessor filenameMatchProcessor) |
Calls the given FilenameMatchProcessor if files are found on the classpath that exactly match the given
relative path.
|
FastClasspathScanner |
matchFilenamePathLeaf(String pathLeafToMatch,
FileMatchContentsProcessor fileMatchContentsProcessor) |
Calls the given FileMatchContentsProcessor if files are found on the classpath that exactly match the given
path leafname.
|
FastClasspathScanner |
matchFilenamePathLeaf(String pathLeafToMatch,
FileMatchContentsProcessorWithContext fileMatchContentsProcessorWithContext) |
Calls the given FileMatchContentsProcessorWithContext if files are found on the classpath that exactly match
the given path leafname.
|
FastClasspathScanner |
matchFilenamePathLeaf(String pathLeafToMatch,
FileMatchProcessor fileMatchProcessor) |
Calls the given FileMatchProcessor if files are found on the classpath that exactly match the given path
leafname.
|
FastClasspathScanner |
matchFilenamePathLeaf(String pathLeafToMatch,
FileMatchProcessorWithContext fileMatchProcessorWithContext) |
Calls the given FileMatchProcessorWithContext if files are found on the classpath that exactly match the
given path leafname.
|
FastClasspathScanner |
matchFilenamePathLeaf(String pathLeafToMatch,
FilenameMatchProcessor filenameMatchProcessor) |
Calls the given FilenameMatchProcessor if files are found on the classpath that exactly match the given path
leafname.
|
FastClasspathScanner |
matchFilenamePattern(String pathRegexp,
FileMatchContentsProcessor fileMatchContentsProcessor) |
Calls the given FileMatchContentsProcessor if files are found on the classpath with the given regexp pattern
in their path.
|
FastClasspathScanner |
matchFilenamePattern(String pathRegexp,
FileMatchContentsProcessorWithContext fileMatchContentsProcessorWithContext) |
Calls the given FileMatchContentsProcessorWithContext if files are found on the classpath with the given
regexp pattern in their path.
|
FastClasspathScanner |
matchFilenamePattern(String pathRegexp,
FileMatchProcessor fileMatchProcessor) |
Calls the given FileMatchProcessor if files are found on the classpath with the given regexp pattern in their
path.
|
FastClasspathScanner |
matchFilenamePattern(String pathRegexp,
FileMatchProcessorWithContext fileMatchProcessorWithContext) |
Calls the given FileMatchProcessorWithContext if files are found on the classpath with the given regexp
pattern in their path.
|
FastClasspathScanner |
matchFilenamePattern(String pathRegexp,
FilenameMatchProcessor filenameMatchProcessor) |
Calls the given FilenameMatchProcessor if files are found on the classpath with the given regexp pattern in
their path.
|
FastClasspathScanner |
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.
|
FastClasspathScanner |
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.
|
FastClasspathScanner |
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.
|
<T> FastClasspathScanner |
matchSubclassesOf(Class<T> superclass,
SubclassMatchProcessor<T> subclassMatchProcessor) |
Calls the provided SubclassMatchProcessor if classes are found on the classpath that extend the specified
superclass.
|
<T> FastClasspathScanner |
matchSubinterfacesOf(Class<T> superinterface,
SubinterfaceMatchProcessor<T> subinterfaceMatchProcessor) |
Calls the provided SubinterfaceMatchProcessor if an interface that extends a given superinterface is found on
the classpath.
|
FastClasspathScanner |
overrideClassLoaders(ClassLoader... overrideClassLoaders) |
Completely override (and ignore) system ClassLoaders and the java.class.path system property.
|
FastClasspathScanner |
overrideClasspath(Iterable<?> overrideClasspathElements) |
Override the automatically-detected classpath with a custom path.
|
FastClasspathScanner |
overrideClasspath(Object... overrideClasspathElements) |
Override the automatically-detected classpath with a custom path.
|
FastClasspathScanner |
overrideClasspath(String overrideClasspath) |
Override the automatically-detected classpath with a custom path, with path elements separated by
File.pathSeparatorChar.
|
FastClasspathScanner |
registerClassLoaderHandler(Class<? extends ClassLoaderHandler> classLoaderHandlerClass) |
Register an extra ClassLoaderHandler.
|
FastClasspathScanner |
removeTemporaryFilesAfterScan(boolean removeTemporaryFilesAfterScan) |
If true (the default), nested jarfiles (jarfiles within jarfiles, which have to be extracted during scanning
in order to be read) are removed from their temporary directory after the scan has completed.
|
ScanResult |
scan() |
Scans the classpath for matching files, and calls any MatchProcessors if a match is identified.
|
ScanResult |
scan(int numThreads) |
Scans the classpath for matching files, and calls any MatchProcessors if a match is identified.
|
ScanResult |
scan(ExecutorService executorService,
int numParallelTasks) |
Scans the classpath for matching files, and calls any MatchProcessors if a match is identified.
|
Future<ScanResult> |
scanAsync(ExecutorService executorService,
int numParallelTasks) |
Asynchronously scans the classpath for matching files, and calls any MatchProcessors if a match is
identified.
|
void |
scanAsync(ExecutorService executorService,
int numParallelTasks,
ScanResultProcessor scanResultProcessor,
FailureHandler failureHandler) |
Asynchronously scans the classpath for matching files, and if runAsynchronously is true, also calls any
MatchProcessors if a match is identified.
|
FastClasspathScanner |
setAnnotationVisibility(RetentionPolicy annotationVisibility) |
Set annotation visibility (to match the annotation retention policy).
|
FastClasspathScanner |
strictWhitelist() |
Switches FastClasspathScanner to strict mode, which disallows searching/matching based on blacklisted
classes, and removes "external" classes from result lists returned by ScanSpec#get...() methods.
|
FastClasspathScanner |
strictWhitelist(boolean strictWhitelist) |
If strictWhitelist is true, switches FastClasspathScanner to strict mode, which disallows searching/matching
based on blacklisted classes, and removes "external" classes from result lists returned by ScanSpec#get...()
methods.
|
FastClasspathScanner |
stripZipSFXHeaders() |
Manually strip the self extracting executable header from zipfiles (i.e.
|
FastClasspathScanner |
suppressMatchProcessorExceptions() |
Causes exceptions thrown inside MatchProcessors to not be re-thrown, wrapped in a MatchProcessorException, at
the end of a synchronous scan.
|
FastClasspathScanner |
suppressMatchProcessorExceptions(boolean suppressMatchProcessorExceptions) |
If suppressMatchProcessorExceptions is true, exceptions thrown inside MatchProcessors are not re-thrown
wrapped in a MatchProcessorException at the end of a synchronous scan, and any thrown exceptions can be
fetched using ScanResult.getMatchProcessorExceptions().
|
FastClasspathScanner |
verbose() |
Switches on verbose mode for debugging purposes.
|
FastClasspathScanner |
verbose(boolean verbose) |
Switches on verbose mode for debugging purposes if verbose == true.
|
public FastClasspathScanner(String... scanSpec)
https://github.com/lukehutch/fast-classpath-scanner/wiki/2.-Constructor
The scanSpec, if non-empty, prevents irrelevant classpath entries from being unecessarily scanned, which can be time-consuming.
Note that calling the constructor does not start the scan, you must separately call .scan() to perform the actual scan.
scanSpec
- The constructor accepts a list of whitelisted package prefixes / jar names to scan, as well as
blacklisted packages/jars not to scan, where blacklisted entries are prefixed with the '-'
character. See https://github.com/lukehutch/fast-classpath-scanner/wiki/2.-Constructor for info.public static final String getVersion()
public FastClasspathScanner verbose(boolean verbose)
verbose
- Whether or not to give verbose output.public FastClasspathScanner verbose()
public FastClasspathScanner ignoreFieldVisibility(boolean ignoreFieldVisibility)
ignoreFieldVisibility
- Whether or not to ignore the field visibility modifier.public FastClasspathScanner ignoreFieldVisibility()
public FastClasspathScanner ignoreMethodVisibility(boolean ignoreMethodVisibility)
ignoreMethodVisibility
- Whether or not to ignore the method visibility modifier.public FastClasspathScanner ignoreMethodVisibility()
public FastClasspathScanner enableMethodAnnotationIndexing(boolean enableMethodAnnotationIndexing)
enableMethodAnnotationIndexing
- Whether or not to enable method annotation indexing.public FastClasspathScanner enableMethodAnnotationIndexing()
public FastClasspathScanner enableFieldAnnotationIndexing(boolean enableFieldAnnotationIndexing)
enableFieldAnnotationIndexing
- Whether to enable field annotation indexing.public FastClasspathScanner enableFieldAnnotationIndexing()
public FastClasspathScanner enableFieldInfo(boolean enableFieldInfo)
enableFieldInfo
- If true, save field info while scanning. (Default false.)public FastClasspathScanner enableFieldInfo()
public FastClasspathScanner enableMethodInfo(boolean enableMethodInfo)
enableMethodInfo
- If true, save method info while scanning. (Default false.)public FastClasspathScanner enableMethodInfo()
public FastClasspathScanner alwaysScanClasspathElementRoot(boolean alwaysScanClasspathElementRoot)
alwaysScanClasspathElementRoot
- If true, always scan the classpath element root, regardless of the whitelist or blacklist.public FastClasspathScanner alwaysScanClasspathElementRoot()
public FastClasspathScanner strictWhitelist(boolean strictWhitelist)
See the following for info on external classes, and strict mode vs. non-strict mode:
https://github.com/lukehutch/fast-classpath-scanner/wiki/2.-Constructor#external-classes
strictWhitelist
- Whether or not to switch to strict mode.public FastClasspathScanner strictWhitelist()
See the following for info on external classes, and strict mode vs. non-strict mode:
https://github.com/lukehutch/fast-classpath-scanner/wiki/2.-Constructor#external-classes
public FastClasspathScanner initializeLoadedClasses(boolean initializeLoadedClasses)
initializeLoadedClasses
- Whether or not to initialize classes before passing class references to MatchProcessors. (The
default value is false.)public FastClasspathScanner removeTemporaryFilesAfterScan(boolean removeTemporaryFilesAfterScan)
This method should be called if you need to access nested jarfiles (e.g. from a Spring classpath) after scanning has completed. In particular, if you use ClasspathUtils.getClasspathResourceURL() in a FileMatchProcessor and you need to use the returned URLs after scanning has completed, then you should call FastClasspathScanner#removeTemporaryFilesAfterScan(false) before calling scan().
removeTemporaryFilesAfterScan
- Whether or not to remove temporary files after scanning. (The default value is true.)public FastClasspathScanner disableRecursiveScanning()
public FastClasspathScanner disableRecursiveScanning(boolean disableRecursiveScanning)
disableRecursiveScanning
- Whether or not to disable recursive scanning. (The default value is false.)public FastClasspathScanner stripZipSFXHeaders()
public FastClasspathScanner registerClassLoaderHandler(Class<? extends ClassLoaderHandler> classLoaderHandlerClass)
https://github.com/lukehutch/fast-classpath-scanner/wiki/4.-Working-with-nonstandard-ClassLoaders
classLoaderHandlerClass
- The ClassLoaderHandler class to register.public FastClasspathScanner overrideClasspath(String overrideClasspath)
If this method is called, nothing but the provided classpath will be scanned, i.e. this causes ClassLoaders to be ignored, as well as the java.class.path system property.
overrideClasspath
- The custom classpath to use for scanning, with path elements separated by File.pathSeparatorChar.public FastClasspathScanner overrideClasspath(Iterable<?> overrideClasspathElements)
If this method is called, nothing but the provided classpath will be scanned, i.e. this causes ClassLoaders to be ignored, as well as the java.class.path system property.
overrideClasspathElements
- The custom classpath to use for scanning, with path elements separated by File.pathSeparatorChar.public FastClasspathScanner overrideClasspath(Object... overrideClasspathElements)
overrideClasspathElements
- The custom classpath to use for scanning, with path elements separated by File.pathSeparatorChar.public FastClasspathScanner filterClasspathElements(FastClasspathScanner.ClasspathElementFilter classpathElementFilter)
classpathElementFilter
- The filter function to use. This function should return true if the classpath element path should
be scanned, and false if not.public FastClasspathScanner addClassLoader(ClassLoader classLoader)
This call is ignored if overrideClasspath() is also called, or if this method is called before overrideClassLoaders().
This call is ignored if overrideClasspath() is called.
classLoader
- The additional ClassLoader to scan.public FastClasspathScanner overrideClassLoaders(ClassLoader... overrideClassLoaders)
This call is ignored if overrideClasspath() is called.
overrideClassLoaders
- The ClassLoaders to scan instead of the automatically-detected ClassLoaders.public FastClasspathScanner ignoreParentClassLoaders(boolean ignoreParentClassLoaders)
This call is ignored if overrideClasspath() is called.
ignoreParentClassLoaders
- If true, do not fetch paths from parent classloaders.public FastClasspathScanner ignoreParentClassLoaders()
This call is ignored if overrideClasspath() is called.
public FastClasspathScanner suppressMatchProcessorExceptions()
public FastClasspathScanner suppressMatchProcessorExceptions(boolean suppressMatchProcessorExceptions)
suppressMatchProcessorExceptions
- Whether to suppress MatchProcessorExceptions.public ClassLoader[] findBestClassLoader()
Generally this will return exactly one ClassLoader, but if it returns more than one, the classloaders are listed in the order they should be called in until one of them is able to load the named class. If you can call only one ClassLoader, use the first element of the list.
If you have overridden the ClassLoader(s), then the override ClassLoader(s) will be returned instead.
public FastClasspathScanner matchAllClasses(ClassMatchProcessor classMatchProcessor)
classMatchProcessor
- the ClassMatchProcessor to call when a match is found.public FastClasspathScanner matchAllStandardClasses(ClassMatchProcessor standardClassMatchProcessor)
standardClassMatchProcessor
- the ClassMatchProcessor to call when a match is found.public FastClasspathScanner matchAllInterfaceClasses(ClassMatchProcessor interfaceClassMatchProcessor)
interfaceClassMatchProcessor
- the ClassMatchProcessor to call when a match is found.public FastClasspathScanner matchAllAnnotationClasses(ClassMatchProcessor annotationClassMatchProcessor)
annotationClassMatchProcessor
- the ClassMatchProcessor to call when a match is found.public <T> FastClasspathScanner 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> FastClasspathScanner 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> FastClasspathScanner matchClassesImplementing(Class<T> implementedInterface, ImplementingClassMatchProcessor<T> interfaceMatchProcessor)
implementedInterface
- The interface that classes need to implement.interfaceMatchProcessor
- the ClassMatchProcessor to call when a match is found.public FastClasspathScanner matchClassesWithAnnotation(Class<?> annotation, ClassAnnotationMatchProcessor classAnnotationMatchProcessor)
annotation
- The class annotation to match.classAnnotationMatchProcessor
- the ClassAnnotationMatchProcessor to call when a match is found.public FastClasspathScanner matchClassesWithMethodAnnotation(Class<? extends Annotation> annotation, MethodAnnotationMatchProcessor methodAnnotationMatchProcessor)
Calls enableMethodAnnotationIndexing() for you.
annotation
- The method annotation to match.methodAnnotationMatchProcessor
- the MethodAnnotationMatchProcessor to call when a match is found.public FastClasspathScanner matchClassesWithFieldAnnotation(Class<? extends Annotation> annotation, FieldAnnotationMatchProcessor fieldAnnotationMatchProcessor)
Calls enableFieldAnnotationIndexing() for you.
annotation
- The field annotation to match.fieldAnnotationMatchProcessor
- the FieldAnnotationMatchProcessor to call when a match is found.public FastClasspathScanner setAnnotationVisibility(RetentionPolicy annotationVisibility)
annotationVisibility
- The annotation visibility: RetentionPolicy.RUNTIME matches only runtime-visible annotations. The
default value, RetentionPolicy.CLASS, matches all annotations (both runtime-visible and
runtime-invisible). RetentionPolicy.SOURCE will cause an IllegalArgumentException to be thrown,
since SOURCE-annotated annotations are not retained in classfiles.public FastClasspathScanner matchStaticFinalFieldNames(Set<String> fullyQualifiedStaticFinalFieldNames, StaticFinalFieldMatchProcessor staticFinalFieldMatchProcessor)
Field values are obtained from the constant pool in classfiles, not from a loaded class using reflection. This allows you to detect changes to the classpath and then run another scan that picks up the new values of selected static constants without reloading the class. (Class reloading is fraught with issues, see: http://tutorials.jenkov.com/java-reflection/dynamic-class-loading-reloading.html )
Note: Only static final fields with constant-valued literals are matched, not fields with initializer values that are the result of an expression or reference, except for cases where the compiler is able to simplify an expression into a single constant at compiletime, such as in the case of string concatenation.
Note that the visibility of the fields is not checked if ignoreFieldVisibility() was called before scan().
fullyQualifiedStaticFinalFieldNames
- The set of fully-qualified static field names to match.staticFinalFieldMatchProcessor
- the StaticFinalFieldMatchProcessor to call when a match is found.public FastClasspathScanner matchStaticFinalFieldNames(String fullyQualifiedStaticFinalFieldName, StaticFinalFieldMatchProcessor staticFinalFieldMatchProcessor)
Field values are obtained from the constant pool in classfiles, *not* from a loaded class using reflection. This allows you to detect changes to the classpath and then run another scan that picks up the new values of selected static constants without reloading the class. (Class reloading is fraught with issues, see: http://tutorials.jenkov.com/java-reflection/dynamic-class-loading-reloading.html )
Note: Only static final fields with constant-valued literals are matched, not fields with initializer values that are the result of an expression or reference, except for cases where the compiler is able to simplify an expression into a single constant at compiletime, such as in the case of string concatenation.
Note that the visibility of the fields is not checked if ignoreFieldVisibility() was called before scan().
fullyQualifiedStaticFinalFieldName
- The fully-qualified static field name to matchstaticFinalFieldMatchProcessor
- the StaticFinalFieldMatchProcessor to call when a match is found.public FastClasspathScanner matchStaticFinalFieldNames(String[] fullyQualifiedStaticFinalFieldNames, StaticFinalFieldMatchProcessor staticFinalFieldMatchProcessor)
Field values are obtained from the constant pool in classfiles, *not* from a loaded class using reflection. This allows you to detect changes to the classpath and then run another scan that picks up the new values of selected static constants without reloading the class. (Class reloading is fraught with issues, see: http://tutorials.jenkov.com/java-reflection/dynamic-class-loading-reloading.html )
Note: Only static final fields with constant-valued literals are matched, not fields with initializer values that are the result of an expression or reference, except for cases where the compiler is able to simplify an expression into a single constant at compiletime, such as in the case of string concatenation.
Note that the visibility of the fields is not checked if ignoreFieldVisibility() was called before scan().
fullyQualifiedStaticFinalFieldNames
- The list of fully-qualified static field names to match.staticFinalFieldMatchProcessor
- the StaticFinalFieldMatchProcessor to call when a match is found.public FastClasspathScanner matchFilenamePattern(String pathRegexp, FilenameMatchProcessor filenameMatchProcessor)
pathRegexp
- The regexp to match, e.g. "app/templates/.*\\.html"filenameMatchProcessor
- The FilenameMatchProcessor to call when each match is found.public FastClasspathScanner 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 FastClasspathScanner 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 FastClasspathScanner 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 FastClasspathScanner 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 FastClasspathScanner matchFilenamePath(String relativePathToMatch, FilenameMatchProcessor filenameMatchProcessor)
relativePathToMatch
- The complete path to match relative to the classpath entry, e.g.
"app/templates/WidgetTemplate.html"filenameMatchProcessor
- The FilenameMatchProcessor to call when each match is found.public FastClasspathScanner 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 FastClasspathScanner 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 FastClasspathScanner 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 FastClasspathScanner 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 FastClasspathScanner matchFilenamePathLeaf(String pathLeafToMatch, FilenameMatchProcessor filenameMatchProcessor)
pathLeafToMatch
- The complete path leaf to match, e.g. "WidgetTemplate.html"filenameMatchProcessor
- The FilenameMatchProcessor to call when each match is found.public FastClasspathScanner 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 FastClasspathScanner 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 FastClasspathScanner 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 FastClasspathScanner 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 FastClasspathScanner matchFilenameExtension(String extensionToMatch, FilenameMatchProcessor filenameMatchProcessor)
extensionToMatch
- The extension to match, e.g. "html" matches "WidgetTemplate.html" and "WIDGET.HTML".filenameMatchProcessor
- The FilenameMatchProcessor to call when each match is found.public FastClasspathScanner 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 FastClasspathScanner 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.public FastClasspathScanner 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 FastClasspathScanner 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 scanAsync(ExecutorService executorService, int numParallelTasks, ScanResultProcessor scanResultProcessor, FailureHandler failureHandler)
executorService
- A custom ExecutorService to use for scheduling worker tasks.numParallelTasks
- The number of parallel tasks to break the work into during the most CPU-intensive stage of
classpath scanning. Ideally the ExecutorService will have at least this many threads available.scanResultProcessor
- A callback to run on successful scan. Passed the ScanResult after asynchronous scanning has
completed and MatchProcessors have been run. (If null, throws IllegalArgumentException.)failureHandler
- A callback to run on failed scan. Passed any Throwable thrown during the scan. (If null, throws
IllegalArgumentException.)public Future<ScanResult> scanAsync(ExecutorService executorService, int numParallelTasks)
Note on thread safety: MatchProcessors are all run on a separate thread from the thread that calls this method (although the MatchProcessors are all run on one thread). You will need to add your own synchronization logic if MatchProcessors interact with the main thread. See the following for more info:
https://github.com/lukehutch/fast-classpath-scanner/wiki/1.-Usage#multithreading-issues
executorService
- A custom ExecutorService to use for scheduling worker tasks.numParallelTasks
- The number of parallel tasks to break the work into during the most CPU-intensive stage of
classpath scanning. Ideally the ExecutorService will have at least this many threads available.public ScanResult scan(ExecutorService executorService, int numParallelTasks)
executorService
- A custom ExecutorService to use for scheduling worker tasks. This ExecutorService should start
tasks in FIFO order to avoid a deadlock during scan, i.e. be sure to construct the ExecutorService
with a LinkedBlockingQueue as its task queue. (This is the default for
Executors.newFixedThreadPool().)numParallelTasks
- The number of parallel tasks to break the work into during the most CPU-intensive stage of
classpath scanning. Ideally the ExecutorService will have at least this many threads available.MatchProcessorException
- if classloading fails for any of the classes matched by a MatchProcessor, or if a MatchProcessor
throws an exception. If suppressMatchProcessorExceptions()
is called
before scan()
, then MatchProcessorException
will not be
thrown at the end of scanning, and instead, any exceptions that were thrown by MatchProcessors
can be fetched using ScanResult.getMatchProcessorExceptions()
.ScanInterruptedException
- if any of the worker threads are interrupted during the scan. If you care about thread
interruption, you should catch this exception. If you don't plan to interrupt the scan, you
probably don't need to catch this.RuntimeException
- if any of the worker threads throws an uncaught exception. (Should not happen, this would
indicate a bug in FastClasspathScanner.)public ScanResult scan(int numThreads)
numThreads
- The number of worker threads to start up.MatchProcessorException
- if classloading fails for any of the classes matched by a MatchProcessor, or if a MatchProcessor
throws an exception. If suppressMatchProcessorExceptions()
is called
before scan()
, then MatchProcessorException
will not be
thrown at the end of scanning, and instead, any exceptions that were thrown by MatchProcessors
can be fetched using ScanResult.getMatchProcessorExceptions()
.ScanInterruptedException
- if any of the worker threads are interrupted during the scan (shouldn't happen under normal
circumstances).RuntimeException
- if any of the worker threads throws an uncaught exception. (Should not happen, this would
indicate a bug in FastClasspathScanner.)public ScanResult scan()
MatchProcessorException
- if classloading fails for any of the classes matched by a MatchProcessor, or if a MatchProcessor
throws an exception. If suppressMatchProcessorExceptions()
is called
before scan()
, then MatchProcessorException
will not be
thrown at the end of scanning, and instead, any exceptions that were thrown by MatchProcessors
can be fetched using ScanResult.getMatchProcessorExceptions()
.ScanInterruptedException
- if any of the worker threads are interrupted during the scan (shouldn't happen under normal
circumstances).RuntimeException
- if any of the worker threads throws an uncaught exception. (Should not happen, this would
indicate a bug in FastClasspathScanner.)public Future<List<File>> getUniqueClasspathElementsAsync(ExecutorService executorService, int numParallelTasks)
See the following for info on thread safety:
https://github.com/lukehutch/fast-classpath-scanner/wiki/1.-Usage#multithreading-issues
Note that if there are nested jarfiles on the classpath, e.g.
file:///path/to/jar1.jar!/path/to/jar2.jar
, then both FastClasspathScanner#scanAsync() and
FastClasspathScanner#getUniqueClasspathElementsAsync() will cause jar2.jar to be extracted to a temporary
file, however FastClasspathScanner#getUniqueClasspathElementsAsync() will not remove this temporary file
after the scan (so that the file is still accessible to the caller -- each of the File objects in the
returned list of classpath elements should exist). These extracted temporary files are marked for deletion on
JVM exit, however.
executorService
- A custom ExecutorService to use for scheduling worker tasks.numParallelTasks
- The number of parallel tasks to break the work into during the most CPU-intensive stage of
classpath scanning. Ideally the ExecutorService will have at least this many threads available.Future<List<File>>
, that when resolved with get() returns a list of the unique directories
and jarfiles on the classpath, in classpath resolution order. You can call cancel(true) on this
Future if you want to interrupt the process (although the result is typically returned quickly).public List<File> getUniqueClasspathElements(ExecutorService executorService, int numParallelTasks)
Note that if there are nested jarfiles on the classpath, e.g.
file:///path/to/jar1.jar!/path/to/jar2.jar
, then both FastClasspathScanner#scan() and
FastClasspathScanner#getUniqueClasspathElements() will cause jar2.jar to be extracted to a temporary file,
however FastClasspathScanner#getUniqueClasspathElements() will not remove this temporary file after the scan
(so that the file is still accessible to the caller -- each of the File objects in the returned list of
classpath elements should exist). These extracted temporary files are marked for deletion on JVM exit,
however.
executorService
- A custom ExecutorService to use for scheduling worker tasks.numParallelTasks
- The number of parallel tasks to break the work into during the most CPU-intensive stage of
classpath scanning. Ideally the ExecutorService will have at least this many threads available.List<File>
consisting of the unique directories and jarfiles on the classpath, in classpath
resolution order.ScanInterruptedException
- if any of the worker threads are interrupted during the scan. If you care about thread
interruption, you should catch this exception. If you don't plan to interrupt the scan, you
probably don't need to catch this.public List<File> getUniqueClasspathElements()
Note that if there are nested jarfiles on the classpath, e.g.
file:///path/to/jar1.jar!/path/to/jar2.jar
, then both FastClasspathScanner#scan() and
FastClasspathScanner#getUniqueClasspathElements() will cause jar2.jar to be extracted to a temporary file,
however FastClasspathScanner#getUniqueClasspathElements() will not remove this temporary file after the scan
(so that the file is still accessible to the caller -- each of the File objects in the returned list of
classpath elements should exist). These extracted temporary files are marked for deletion on JVM exit,
however.
List<File>
consisting of the unique directories and jarfiles on the classpath, in classpath
resolution order.ScanInterruptedException
- if any of the worker threads are interrupted during the scan (shouldn't happen under normal
circumstances).public String getUniqueClasspathElementsAsPathStr()
Note that if there are nested jarfiles on the classpath, e.g.
file:///path/to/jar1.jar!/path/to/jar2.jar
, then both FastClasspathScanner#scan() and
FastClasspathScanner#getUniqueClasspathElements() will cause jar2.jar to be extracted to a temporary file,
however FastClasspathScanner#getUniqueClasspathElements() will not remove this temporary file after the scan
(so that the file is still accessible to the caller -- each of the File objects in the returned list of
classpath elements should exist). These extracted temporary files are marked for deletion on JVM exit,
however.
ScanInterruptedException
- if any of the worker threads are interrupted during the scan (shouldn't happen under normal
circumstances).public Future<List<URL>> getUniqueClasspathElementURLsAsync(ExecutorService executorService, int numParallelTasks)
See the following for info on thread safety:
https://github.com/lukehutch/fast-classpath-scanner/wiki/1.-Usage#multithreading-issues
Note that if there are nested jarfiles on the classpath, e.g.
file:///path/to/jar1.jar!/path/to/jar2.jar
, then both FastClasspathScanner#scanAsync() and
FastClasspathScanner#getUniqueClasspathElementsAsync() will cause jar2.jar to be extracted to a temporary
file, however FastClasspathScanner#getUniqueClasspathElementURLsAsync() will not remove this temporary file
after the scan (so that the file is still accessible to the caller -- each of the File objects in the
returned list of classpath elements should exist). These extracted temporary files are marked for deletion on
JVM exit, however.
executorService
- A custom ExecutorService to use for scheduling worker tasks.numParallelTasks
- The number of parallel tasks to break the work into during the most CPU-intensive stage of
classpath scanning. Ideally the ExecutorService will have at least this many threads available.Future<List<URL>>
, that when resolved with get() returns a list of URLs for the unique
directories and jarfiles on the classpath, in classpath resolution order. You can call cancel(true)
on this Future if you want to interrupt the process (although the result is typically returned
quickly).public List<URL> getUniqueClasspathElementURLs(ExecutorService executorService, int numParallelTasks)
Note that if there are nested jarfiles on the classpath, e.g.
file:///path/to/jar1.jar!/path/to/jar2.jar
, then both FastClasspathScanner#scan() and
FastClasspathScanner#getUniqueClasspathElements() will cause jar2.jar to be extracted to a temporary file,
however FastClasspathScanner#getUniqueClasspathElementURLs() will not remove this temporary file after the
scan (so that the file is still accessible to the caller -- each of the File objects in the returned list of
classpath elements should exist). These extracted temporary files are marked for deletion on JVM exit,
however.
executorService
- A custom ExecutorService to use for scheduling worker tasks.numParallelTasks
- The number of parallel tasks to break the work into during the most CPU-intensive stage of
classpath scanning. Ideally the ExecutorService will have at least this many threads available.List<URL>
consisting of the unique directories and jarfiles on the classpath, in classpath
resolution order.ScanInterruptedException
- if any of the worker threads are interrupted during the scan. If you care about thread
interruption, you should catch this exception. If you don't plan to interrupt the scan, you
probably don't need to catch this.public List<URL> getUniqueClasspathElementURLs()
Note that if there are nested jarfiles on the classpath, e.g.
file:///path/to/jar1.jar!/path/to/jar2.jar
, then both FastClasspathScanner#scan() and
FastClasspathScanner#getUniqueClasspathElements() will cause jar2.jar to be extracted to a temporary file,
however FastClasspathScanner#getUniqueClasspathElementURLs() will not remove this temporary file after the
scan (so that the file is still accessible to the caller -- each of the File objects in the returned list of
classpath elements should exist). These extracted temporary files are marked for deletion on JVM exit,
however.
List<URL>
consisting of the unique directories and jarfiles on the classpath, in classpath
resolution order.ScanInterruptedException
- if any of the worker threads are interrupted during the scan (shouldn't happen under normal
circumstances).Copyright © 2018. All rights reserved.