Class ScanResult
- java.lang.Object
-
- io.github.lukehutch.fastclasspathscanner.ScanResult
-
public class ScanResult extends Object
The result of a scan.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description long
classpathContentsLastModifiedTime()
Find the maximum last-modified timestamp of any whitelisted file/directory/jarfile encountered during the scan.boolean
classpathContentsModifiedSinceScan()
Determine whether the classpath contents have been modified since the last scan.protected void
finalize()
static ScanResult
fromJSON(String json)
Deserialize a ScanResult from previously-saved JSON.ClassInfoList
getAllAnnotations()
Get all annotation classes found during the scan.ClassInfoList
getAllClasses()
Get all classes, interfaces and annotations found during the scan.ClassInfoList
getAllInterfaces()
Get all interface classes found during the scan (not including annotations, which are also technically interfaces).ClassInfoList
getAllInterfacesAndAnnotations()
Get all interface or annotation classes found during the scan.ResourceList
getAllResources()
Get a list of all resources (including classfiles and non-classfiles) found in whitelisted packages.ClassInfoList
getAllStandardClasses()
Get all standard (non-interface/non-annotation) classes found during the scan.ClassInfoList
getAnnotationsOnClass(String className)
Get annotations on the named class.ClassInfoList
getClassesImplementing(String interfaceName)
Get all classes that implement (or have superclasses that implement) the named interface (or one of its subinterfaces).ClassInfoList
getClassesWithAnnotation(String annotationName)
Get classes with the named class annotation or meta-annotation.ClassInfoList
getClassesWithFieldAnnotation(String fieldAnnotationName)
Get classes that have a field with an annotation of the named type.ClassInfoList
getClassesWithMethodAnnotation(String methodAnnotationName)
Get classes that have a method with an annotation of the named type.ClassInfo
getClassInfo(String className)
Get the ClassInfo object for the named class, or null if no class of the requested name was found in a whitelisted/non-blacklisted package during scanning.String
getClasspath()
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.List<File>
getClasspathFiles()
Returns the list of File objects for unique classpath elements (directories or jarfiles), in classloader resolution order.List<URL>
getClasspathURLs()
Returns the list of unique classpath element paths as URLs, in classloader resolution order.ClassInfoList
getInterfaces(String className)
Get all interfaces implemented by the named class or by one of its superclasses, if this is a standard class, or the superinterfaces extended by this interface, if this is an interface.List<ModuleRef>
getModules()
Returns references for all the visible modules.ResourceList
getResourcesMatchingPattern(Pattern pattern)
Get a list of all resources found in whitelisted packages that have a path, relative to the classpath package root, matching the requested pattern.ResourceList
getResourcesWithExtension(String extension)
Get a list of all resources found in whitelisted packages that have the requested extension (e.g.ResourceList
getResourcesWithLeafName(String leafName)
Get a list of all resources found in whitelisted packages that have the requested leafname.ResourceList
getResourcesWithPath(String resourcePath)
Get a list of all resources found in whitelisted packages that have the given path, relative to the package root of the classpath element.ClassInfoList
getSubclasses(String superclassName)
Get all subclasses of the named superclass.ClassInfoList
getSuperclasses(String subclassName)
Get superclasses of the named subclass.Class<?>
loadClass(String className, boolean ignoreExceptions)
Load a class given a class name.void
removeTemporaryFiles()
Free any temporary files created by extracting jars from within jars.String
toJSON()
Serialize a ScanResult to minified (un-indented) JSON.String
toJSON(int indentWidth)
Serialize a ScanResult to JSON.
-
-
-
Method Detail
-
getClasspathFiles
public List<File> getClasspathFiles()
Returns the list of File objects for unique classpath elements (directories or jarfiles), in classloader resolution order.- Returns:
- The unique classpath elements.
-
getClasspath
public String getClasspath()
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.- Returns:
- a the unique directories and jarfiles on the classpath, in classpath resolution order, as a path string.
-
getClasspathURLs
public List<URL> getClasspathURLs()
Returns the list of unique classpath element paths as URLs, in classloader resolution order.- Returns:
- The unique classpath element URLs.
-
getAllResources
public ResourceList getAllResources()
Get a list of all resources (including classfiles and non-classfiles) found in whitelisted packages.
-
getResourcesWithPath
public ResourceList getResourcesWithPath(String resourcePath)
Get a list of all resources found in whitelisted packages that have the given path, relative to the package root of the classpath element. May match several resources, up to one per classpath element.
-
getResourcesWithLeafName
public ResourceList getResourcesWithLeafName(String leafName)
Get a list of all resources found in whitelisted packages that have the requested leafname.
-
getResourcesWithExtension
public ResourceList getResourcesWithExtension(String extension)
Get a list of all resources found in whitelisted packages that have the requested extension (e.g. "xml" to match all resources ending in ".xml").
-
getResourcesMatchingPattern
public ResourceList getResourcesMatchingPattern(Pattern pattern)
Get a list of all resources found in whitelisted packages that have a path, relative to the classpath package root, matching the requested pattern.
-
classpathContentsModifiedSinceScan
public boolean classpathContentsModifiedSinceScan()
Determine whether the classpath contents have been modified since the last scan. Checks the timestamps of files and jarfiles encountered during the previous scan to see if they have changed. Does not perform a full scan, so cannot detect the addition of directories that newly match whitelist criteria -- you need to perform a full scan to detect those changes.- Returns:
- true if the classpath contents have been modified since the last scan.
-
classpathContentsLastModifiedTime
public long classpathContentsLastModifiedTime()
Find the maximum last-modified timestamp of any whitelisted file/directory/jarfile encountered during the scan. Checks the current timestamps, so this should increase between calls if something changes in whitelisted paths. Assumes both file and system timestamps were generated from clocks whose time was accurate. Ignores timestamps greater than the system time.This method cannot in general tell if classpath has changed (or modules have been added or removed) if it is run twice during the same runtime session.
- Returns:
- the maximum last-modified time for whitelisted files/directories/jars encountered during the scan.
-
getClassInfo
public ClassInfo getClassInfo(String className)
Get the ClassInfo object for the named class, or null if no class of the requested name was found in a whitelisted/non-blacklisted package during scanning.- Returns:
- The ClassInfo object for the named class, or null if the class was not found.
-
getAllClasses
public ClassInfoList getAllClasses()
Get all classes, interfaces and annotations found during the scan.- Returns:
- A list of all whitelisted classes found during the scan, or the empty list if none.
-
getAllStandardClasses
public ClassInfoList getAllStandardClasses()
Get all standard (non-interface/non-annotation) classes found during the scan.- Returns:
- A list of all whitelisted standard classes found during the scan, or the empty list if none.
-
getSubclasses
public ClassInfoList getSubclasses(String superclassName)
Get all subclasses of the named superclass.- Parameters:
superclassName
- The name of the superclass.- Returns:
- A list of subclasses of the named superclass, or the empty list if none.
-
getSuperclasses
public ClassInfoList getSuperclasses(String subclassName)
Get superclasses of the named subclass.- Parameters:
subclassName
- The name of the subclass.- Returns:
- A list of superclasses of the named subclass, or the empty list if none.
-
getClassesWithMethodAnnotation
public ClassInfoList getClassesWithMethodAnnotation(String methodAnnotationName)
Get classes that have a method with an annotation of the named type.- Parameters:
methodAnnotationName
- the name of the method annotation.- Returns:
- A list of classes with a method that has an annotation of the named type, or the empty list if none.
-
getClassesWithFieldAnnotation
public ClassInfoList getClassesWithFieldAnnotation(String fieldAnnotationName)
Get classes that have a field with an annotation of the named type.- Parameters:
fieldAnnotationName
- the name of the field annotation.- Returns:
- A list of classes that have a field with an annotation of the named type, or the empty list if none.
-
getAllInterfaces
public ClassInfoList getAllInterfaces()
Get all interface classes found during the scan (not including annotations, which are also technically interfaces). See alsogetAllInterfacesAndAnnotations()
.- Returns:
- A list of all whitelisted interfaces found during the scan, or the empty list if none.
-
getInterfaces
public ClassInfoList getInterfaces(String className)
Get all interfaces implemented by the named class or by one of its superclasses, if this is a standard class, or the superinterfaces extended by this interface, if this is an interface.- Parameters:
className
- The class name.- Returns:
- A list of interfaces implemented by the named class (or superinterfaces extended by the named interface), or the empty list if none.
-
getClassesImplementing
public ClassInfoList getClassesImplementing(String interfaceName)
Get all classes that implement (or have superclasses that implement) the named interface (or one of its subinterfaces).- Parameters:
interfaceName
- The interface name.- Returns:
- A list of all classes that implement the named interface, or the empty list if none.
-
getAllAnnotations
public ClassInfoList getAllAnnotations()
Get all annotation classes found during the scan. See alsogetAllInterfacesAndAnnotations()
.- Returns:
- A list of all annotation classes found during the scan, or the empty list if none.
-
getAllInterfacesAndAnnotations
public ClassInfoList getAllInterfacesAndAnnotations()
Get all interface or annotation classes found during the scan. (Annotations are technically interfaces, and they can be implemented.)- Returns:
- A list of all whitelisted interfaces found during the scan, or the empty list if none.
-
getClassesWithAnnotation
public ClassInfoList getClassesWithAnnotation(String annotationName)
Get classes with the named class annotation or meta-annotation.- Parameters:
annotationName
- The name of the class annotation or meta-annotation.- Returns:
- A list of all non-annotation classes that were found with the named class annotation during the scan, or the empty list if none.
-
getAnnotationsOnClass
public ClassInfoList getAnnotationsOnClass(String className)
Get annotations on the named class. This only returns the annotating classes; to read annotation parameters, callgetClassInfo(String)
to get theClassInfo
object for the named class, then if theClassInfo
object is non-null, callClassInfo.getAnnotationInfo()
to get detailed annotation info.- Parameters:
className
- The name of the class.- Returns:
- A list of all annotation classes that were found with the named class annotation during the scan, or the empty list if none.
-
loadClass
public Class<?> loadClass(String className, boolean ignoreExceptions) throws IllegalArgumentException
Load a class given a class name. If ignoreExceptions is false, and the class cannot be loaded (due to classloading error, or due to an exception being thrown in the class initialization block), an IllegalArgumentException is thrown; otherwise, the class will simply be skipped if an exception is thrown.Enable verbose scanning to see details of any exceptions thrown during classloading, even if ignoreExceptions is false.
- Parameters:
className
- the class to load.ignoreExceptions
- If true, null is returned if there was an exception during classloading, otherwise IllegalArgumentException is thrown if a class could not be loaded.- Returns:
- a reference to the loaded class, or null if the class could not be loaded and ignoreExceptions is true.
- Throws:
IllegalArgumentException
- if ignoreExceptions is false, IllegalArgumentException is thrown if there were problems loading or initializing the class. (Note that class initialization on load is disabled by default, you can enable it withFastClasspathScanner#initializeLoadedClasses(true)
.) Otherwise exceptions are suppressed, and null is returned if any of these problems occurs.
-
fromJSON
public static ScanResult fromJSON(String json)
Deserialize a ScanResult from previously-saved JSON.
-
toJSON
public String toJSON(int indentWidth)
Serialize a ScanResult to JSON.- Parameters:
indentWidth
- If greater than 0, JSON will be formatted (indented), otherwise it will be minified (un-indented).
-
toJSON
public String toJSON()
Serialize a ScanResult to minified (un-indented) JSON.
-
removeTemporaryFiles
public void removeTemporaryFiles()
Free any temporary files created by extracting jars from within jars. By default, temporary files are removed at the end of a scan, after MatchProcessors have completed, so this typically does not need to be called. The case where it might need to be called is if the list of classpath elements has been fetched, and the classpath contained jars within jars. Without calling this method, the temporary files created by extracting the inner jars will not be removed until the temporary file system cleans them up (typically at reboot).
-
-