public class FastClasspathScanner extends Object
Constructor and Description |
---|
FastClasspathScanner(String... packagesToScan)
Constructs a FastClasspathScanner instance.
|
Modifier and Type | Method and Description |
---|---|
long |
classpathContentsLastModifiedTime()
Returns the maximum "last modified" timestamp in the classpath (in epoch millis), or zero if scan() has not yet
been called (or if nothing was found on the classpath).
|
boolean |
classpathContentsModifiedSinceScan()
Returns true if the classpath contents have been changed since scan() was last called.
|
FastClasspathScanner |
enableHashingClassfileContents()
Enable the hashing of classfile contents for all classfiles in whitelisted package prefixes.
|
HashMap<String,String> |
getClassNameToClassfileHash()
Get the mapping from class name to hash of classfile contents, assuming enableHashingClassfileContents() has been
called.
|
<T> Set<String> |
getNamesOfAllClasses()
Returns the names of all classes and interfaces processed during the scan, i.e.
|
<T> List<String> |
getNamesOfClassesImplementing(Class<T> implementedInterface)
Returns the names of classes on the classpath that implement the specified interface or a subinterface, or whose
superclasses implement the specified interface or a sub-interface.
|
List<String> |
getNamesOfClassesImplementing(String implementedInterfaceName)
Returns the names of classes on the classpath that implement the specified interface or a subinterface, or whose
superclasses implement the specified interface or a sub-interface.
|
<T> List<String> |
getNamesOfClassesWithAnnotation(Class<?> annotation)
Returns the names of classes on the classpath that have the specified annotation.
|
List<String> |
getNamesOfClassesWithAnnotation(String annotationName)
Returns the names of classes on the classpath that have the specified annotation.
|
<T> List<String> |
getNamesOfSubclassesOf(Class<T> superclass)
Returns the names of classes on the classpath that extend the specified superclass.
|
List<String> |
getNamesOfSubclassesOf(String superclassName)
Returns the names of classes on the classpath that extend the specified superclass.
|
<T> List<String> |
getNamesOfSubinterfacesOf(Class<T> superInterface)
Returns the names of interfaces on the classpath that extend a given superinterface.
|
List<String> |
getNamesOfSubinterfacesOf(String superInterfaceName)
Returns the names of interfaces on the classpath that extend a given superinterface.
|
<T> List<String> |
getNamesOfSuperclassesOf(Class<T> subclass)
Returns the names of classes on the classpath that are superclasses of the specified subclass.
|
List<String> |
getNamesOfSuperclassesOf(String subclassName)
Returns the names of classes on the classpath that are superclasses of the specified subclass.
|
<T> List<String> |
getNamesOfSuperinterfacesOf(Class<T> subInterface)
Returns the names of interfaces on the classpath that are superinterfaces of a given subinterface.
|
List<String> |
getNamesOfSuperinterfacesOf(String subInterfaceName)
Returns the names of interfaces on the classpath that are superinterfaces of a given subinterface.
|
static ArrayList<File> |
getUniqueClasspathElements()
Get a list of unique elements on the classpath (directories and files) as File objects, preserving order.
|
<T> Class<? extends T> |
loadClass(String className)
Call the classloader using Class.forName(className).
|
<T> FastClasspathScanner |
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.
|
FastClasspathScanner |
matchClassesWithAnnotation(Class<?> annotation,
ClassAnnotationMatchProcessor classAnnotationMatchProcessor)
Calls the provided ClassMatchProcessor if classes are found on the classpath that have 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,
FileMatchProcessor fileMatchProcessor)
Calls the given FileMatchProcessor 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,
FileMatchProcessor fileMatchProcessor)
Calls the given FileMatchProcessor 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,
FileMatchProcessor fileMatchProcessor)
Calls the given FileMatchProcessor 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,
FileMatchProcessor fileMatchProcessor)
Calls the given FileMatchProcessor if files are found on the classpath with the given regexp pattern in their
path.
|
FastClasspathScanner |
matchStaticFinalFieldNames(HashSet<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.
|
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.
|
<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 |
scan()
Scans the classpath for matching files, and calls any match processors if a match is identified.
|
public FastClasspathScanner(String... packagesToScan)
packagesToScan
- the whitelist of package prefixes to scan, e.g. "com.xyz.widget", "com.xyz.gizmo". If no whitelisted
packages are given (i.e. if the constructor is called with zero arguments), or a whitelisted package
is "", then all packages on the classpath are whitelisted. If a package name is prefixed with "-",
e.g. "-com.xyz.otherthing", then that package is blacklisted, rather than whitelisted. The final list
of packages scanned is the set of whitelisted packages minus the set of blacklisted packages.public <T> Class<? extends T> loadClass(String className)
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> List<String> getNamesOfSubclassesOf(Class<T> superclass)
superclass
- The superclass to match (i.e. the class that subclasses need to extend to match).public List<String> getNamesOfSubclassesOf(String superclassName)
superclassName
- The name of the superclass to match (i.e. the name of the class that subclasses need to extend).public <T> List<String> getNamesOfSuperclassesOf(Class<T> subclass)
subclass
- The subclass to match (i.e. the class that needs to extend a superclass for the superclass to match).public List<String> getNamesOfSuperclassesOf(String subclassName)
subclassName
- The subclass to match (i.e. the class that needs to extend a superclass for the superclass to match).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> List<String> getNamesOfSubinterfacesOf(Class<T> superInterface)
superInterface
- The superinterface to match (i.e. the interface that subinterfaces need to extend to match).public List<String> getNamesOfSubinterfacesOf(String superInterfaceName)
superInterfaceName
- The name of the superinterface to match (i.e. the name of the interface that subinterfaces need to
extend).public <T> List<String> getNamesOfSuperinterfacesOf(Class<T> subInterface)
subInterface
- The superinterface to match (i.e. the interface that subinterfaces need to extend to match).public List<String> getNamesOfSuperinterfacesOf(String subInterfaceName)
subInterfaceName
- The name of the superinterface to match (i.e. the name of the interface that subinterfaces need to
extend).public <T> FastClasspathScanner 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> List<String> getNamesOfClassesImplementing(Class<T> implementedInterface)
implementedInterface
- The interface that classes need to implement to match.public List<String> getNamesOfClassesImplementing(String implementedInterfaceName)
implementedInterfaceName
- The name of the interface that classes need to implement.public FastClasspathScanner matchClassesWithAnnotation(Class<?> annotation, ClassAnnotationMatchProcessor classAnnotationMatchProcessor)
annotation
- The class annotation to match.classAnnotationMatchProcessor
- the ClassAnnotationMatchProcessor to call when a match is found.public <T> List<String> getNamesOfClassesWithAnnotation(Class<?> annotation)
annotation
- The class annotation.public List<String> getNamesOfClassesWithAnnotation(String annotationName)
annotationName
- The name of the class annotation.public FastClasspathScanner matchStaticFinalFieldNames(HashSet<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 FastClasspathScanner matchStaticFinalFieldNames(String fullyQualifiedStaticFinalFieldName, StaticFinalFieldMatchProcessor staticFinalFieldMatchProcessor)
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)
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, 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 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 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 matchFilenameExtension(String extensionToMatch, FileMatchProcessor fileMatchProcessor)
extensionToMatch
- The extension to match, e.g. "html" matches "WidgetTemplate.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 <T> Set<String> getNamesOfAllClasses()
public FastClasspathScanner enableHashingClassfileContents()
public HashMap<String,String> getClassNameToClassfileHash()
public static ArrayList<File> getUniqueClasspathElements()
public FastClasspathScanner scan()
public boolean classpathContentsModifiedSinceScan()
public long classpathContentsLastModifiedTime()
Copyright © 2015. All rights reserved.