Class ScanResult
- All Implemented Interfaces:
Closeable, AutoCloseable
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classA class to hold a serialized ScanResult along with the ScanSpec that was used to scan. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ResourceListA list of all files that were found in accepted packages.private ClassGraphClassLoaderA custom ClassLoader that can load classes found during the scan.The map from class name toClassInfo.(package private) ClasspathFinderTheClasspathFinder.private List<ClasspathElement> The order of classpath elements, after inner jars have been extracted to temporary files, etc.private final AtomicBooleanIf true, this ScanResult has already been closed.private static final StringThe current serialization format.The file, directory and jarfile resources timestamped during a scan, along with their timestamp at the time of the scan.private final AtomicIntegerThe number of timesgetResourcesWithPath(String)has been called.private static final AtomicBooleanIf true, ScanResult#staticInit() has been run.private booleanIf true, thisScanResultwas produced byfromJSON(String).private Map<String, ModuleInfo> The map from class name toClassInfo.private NestedJarHandlerThe nested jar handler instance.private static Set<WeakReference<ScanResult>> The set of WeakReferences to non-closed ScanResult objects.private Map<String, PackageInfo> The map from package name toPackageInfo.private Map<String, ResourceList> The map from path (relative to package root) to a list ofResourceelements with the matching path.The order of raw classpath elements.protected ReflectionUtils(package private) ScanSpecThe scan spec.private final LogNodeThe toplevel log.private final WeakReference<ScanResult> TheWeakReferencefor this ScanResult. -
Constructor Summary
ConstructorsConstructorDescriptionScanResult(ScanSpec scanSpec, List<ClasspathElement> classpathOrder, List<String> rawClasspathEltOrderStrs, ClasspathFinder classpathFinder, Map<String, ClassInfo> classNameToClassInfo, Map<String, PackageInfo> packageNameToPackageInfo, Map<String, ModuleInfo> moduleNameToModuleInfo, Map<File, Long> fileToLastModified, NestedJarHandler nestedJarHandler, LogNode topLevelLog) The result of a scan. -
Method Summary
Modifier and TypeMethodDescriptionlongFind the maximum last-modified timestamp of any accepted file/directory/jarfile encountered during the scan.booleanDetermine whether the classpath contents have been modified since the last scan.voidclose()Free any temporary files created by extracting jars or files from within jars.static voidcloseAll()Close allScanResultinstances that have not yet been closed.static ScanResultDeserialize a ScanResult from previously-serialized JSON.Get all annotation classes found during the scan.Get all classes, interfaces and annotations found during the scan.Get a map from class name toClassInfoobject for all classes, interfaces and annotations found during the scan.Get allEnumclasses found during the scan.Get all interface classes found during the scan (not including annotations, which are also technically interfaces).Get all interface or annotation classes found during the scan.Get allrecordclasses found during the scan (JDK 14+).Get the list of all resources.Get a map from resource path toResourcefor all resources (including classfiles and non-classfiles) found in accepted packages.Get all standard (non-interface/non-annotation) classes found during the scan.getAnnotationsOnClass(String className) Get annotations on the named class.Get a map from theClassInfoobject for each accepted class to a list of the classes referenced by that class (i.e.getClassesImplementing(Class<?> interfaceClass) Get all classes that implement (or have superclasses that implement) the interface (or one of its subinterfaces).getClassesImplementing(String interfaceName) Get all classes that implement (or have superclasses that implement) the named interface (or one of its subinterfaces).getClassesWithAllAnnotations(Class<? extends Annotation>... annotations) Get classes with all of the specified class annotations or meta-annotation.getClassesWithAllAnnotations(String... annotationNames) Get classes with all of the named class annotations or meta-annotation.getClassesWithAnnotation(Class<? extends Annotation> annotation) Get classes with the class annotation or meta-annotation.getClassesWithAnnotation(String annotationName) Get classes with the named class annotation or meta-annotation.getClassesWithAnyAnnotation(Class<? extends Annotation>... annotations) Get classes with any of the specified class annotations or meta-annotation.getClassesWithAnyAnnotation(String... annotationNames) Get classes with any of the named class annotations or meta-annotation.getClassesWithFieldAnnotation(Class<? extends Annotation> fieldAnnotation) Get classes that have a field with an annotation of the named type.getClassesWithFieldAnnotation(String fieldAnnotationName) Get classes that have a field with an annotation of the named type.getClassesWithMethodAnnotation(Class<? extends Annotation> methodAnnotation) Get classes that have a method with an annotation of the named type.getClassesWithMethodAnnotation(String methodAnnotationName) Get classes that have a method with an annotation of the named type.getClassesWithMethodParameterAnnotation(Class<? extends Annotation> methodParameterAnnotation) Get classes that have a method with a parameter that is annotated with an annotation of the named type.getClassesWithMethodParameterAnnotation(String methodParameterAnnotationName) Get classes that have a method with a parameter that is annotated with an annotation of the named type.getClassInfo(String className) Get theClassInfoobject for the named class, or null if no class of the requested name was found in an accepted/non-rejected package during the scan.(package private) ClassLoader[]Get the ClassLoader order, respecting parent-first/parent-last delegation order.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 the list of File objects for unique classpath elements (directories or jarfiles), in classloader resolution order.Returns an ordered list of unique classpath element and module URIs.Returns an ordered list of unique classpath element and module URLs.getInterfaces(Class<?> classRef) Get all interfaces implemented by the class or by one of its superclasses, if the given class is a standard class, or the superinterfaces extended by this interface, if it is an interface.getInterfaces(String className) Get all interfaces implemented by the named class or by one of its superclasses, if the named class is a standard class, or the superinterfaces extended by this interface, if it is an interface.Get all modules found during the scan.getModuleInfo(String moduleName) Get theModuleInfoobject for the named module, or null if no module of the requested name was found during the scan.Get the module path info provided on the commandline with--module-path,--add-modules,--patch-module,--add-exports,--add-opens, and--add-reads, and also theAdd-ExportsandAdd-Opensentries from jarfile manifest files encountered during scanning.GetModuleRefreferences for all visible modules.Get all packages found during the scan.getPackageInfo(String packageName) Get thePackageInfoobject for the named package, or null if no package of the requested name was found during the scan.getResourcesMatchingPattern(Pattern pattern) Get the list of all resources found in accepted packages that have a path matching the requested regex pattern.getResourcesMatchingWildcard(String wildcardString) Get the list of all resources found in accepted packages that have a path matching the requested wildcard string.getResourcesWithExtension(String extension) Get the list of all resources found in accepted packages that have the requested filename extension.getResourcesWithLeafName(String leafName) Get the list of all resources found in accepted packages that have the requested leafname.getResourcesWithPath(String resourcePath) Get the list of all resources found in accepted packages that have the given path, relative to the package root of the classpath element.getResourcesWithPathIgnoringAccept(String resourcePath) Get the list of all resources found in any classpath element, whether in accepted packages or not (as long as the resource is not rejected), that have the given path, relative to the package root of the classpath element.getResourcesWithPathIgnoringWhitelist(String resourcePath) Deprecated.Get the reverse class dependency map, i.e.getSubclasses(Class<?> superclass) Get all subclasses of the superclass.getSubclasses(String superclassName) Get all subclasses of the named superclass.getSuperclasses(Class<?> subclass) Get superclasses of the subclass.getSuperclasses(String subclassName) Get superclasses of the named subclass.private void(package private) static voidinit(ReflectionUtils reflectionUtils) Static initialization (warm up classloading), called when the ClassGraph class is initialized.booleanisClosed()Returns whether this ScanResult has been closed yet or not.booleanChecks if thisScanResultwas obtained from JSON by deserialization, by callingfromJSON(String).Class<?> Load a class given a class name.<T> Class<T> Load a class given a class name.toJSON()Serialize a ScanResult to minified (un-indented) JSON.toJSON(int indentWidth) Serialize a ScanResult to JSON.
-
Field Details
-
rawClasspathEltOrderStrs
-
classpathOrder
The order of classpath elements, after inner jars have been extracted to temporary files, etc. -
allAcceptedResourcesCached
A list of all files that were found in accepted packages. -
getResourcesWithPathCallCount
The number of timesgetResourcesWithPath(String)has been called. -
pathToAcceptedResourcesCached
The map from path (relative to package root) to a list ofResourceelements with the matching path. -
classNameToClassInfo
-
packageNameToPackageInfo
The map from package name toPackageInfo. -
moduleNameToModuleInfo
The map from class name toClassInfo. -
fileToLastModified
The file, directory and jarfile resources timestamped during a scan, along with their timestamp at the time of the scan. For jarfiles, the timestamp represents the timestamp of all files within the jar. May be null, if this ScanResult object is the result of a call to ClassGraph#getUniqueClasspathElementsAsync(). -
isObtainedFromDeserialization
private boolean isObtainedFromDeserializationIf true, thisScanResultwas produced byfromJSON(String). -
classGraphClassLoader
A custom ClassLoader that can load classes found during the scan. -
classpathFinder
ClasspathFinder classpathFinderTheClasspathFinder. -
nestedJarHandler
The nested jar handler instance. -
scanSpec
ScanSpec scanSpecThe scan spec. -
closed
If true, this ScanResult has already been closed. -
reflectionUtils
-
topLevelLog
The toplevel log. -
weakReference
TheWeakReferencefor this ScanResult. -
nonClosedWeakReferences
The set of WeakReferences to non-closed ScanResult objects. Uses WeakReferences so that garbage collection is not blocked. (Bug #233) -
initialized
If true, ScanResult#staticInit() has been run. -
CURRENT_SERIALIZATION_FORMAT
The current serialization format.- See Also:
-
-
Constructor Details
-
ScanResult
ScanResult(ScanSpec scanSpec, List<ClasspathElement> classpathOrder, List<String> rawClasspathEltOrderStrs, ClasspathFinder classpathFinder, Map<String, ClassInfo> classNameToClassInfo, Map<String, PackageInfo> packageNameToPackageInfo, Map<String, ModuleInfo> moduleNameToModuleInfo, Map<File, Long> fileToLastModified, NestedJarHandler nestedJarHandler, LogNode topLevelLog) The result of a scan. Make sure you call complete() after calling the constructor.- Parameters:
scanSpec- the scan specclasspathOrder- the classpath orderrawClasspathEltOrderStrs- the raw classpath element orderclasspathFinder- theClasspathFinderclassNameToClassInfo- a map from class name to class infopackageNameToPackageInfo- a map from package name to package infomoduleNameToModuleInfo- a map from module name to module infofileToLastModified- a map from file to last modified timenestedJarHandler- the nested jar handlertopLevelLog- the toplevel log
-
-
Method Details
-
init
Static initialization (warm up classloading), called when the ClassGraph class is initialized. -
indexResourcesAndClassInfo
-
getClasspathFiles
-
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.
-
getClasspathURIs
-
getClasspathURLs
-
getModules
-
getModulePathInfo
Get the module path info provided on the commandline with--module-path,--add-modules,--patch-module,--add-exports,--add-opens, and--add-reads, and also theAdd-ExportsandAdd-Opensentries from jarfile manifest files encountered during scanning.Note that the returned
ModulePathInfoobject does not include classpath entries from the traditional classpath or system modules. UsegetModules()to get all visible modules, including anonymous, automatic and system modules.- Returns:
- The
ModulePathInfo.
-
getAllResources
Get the list of all resources.- Returns:
- A list of all resources (including classfiles and non-classfiles) found in accepted packages.
-
getAllResourcesAsMap
-
getResourcesWithPath
Get the list of all resources found in accepted 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.- Parameters:
resourcePath- A complete resource path, relative to the classpath entry package root.- Returns:
- A list of all resources found in accepted 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.
-
getResourcesWithPathIgnoringAccept
Get the list of all resources found in any classpath element, whether in accepted packages or not (as long as the resource is not rejected), that have the given path, relative to the package root of the classpath element. May match several resources, up to one per classpath element. Note that this may not return a non-accepted resource, particularly when scanning directory classpath elements, because recursive scanning terminates once there are no possible accepted resources below a given directory. However, resources in ancestral directories of accepted directories can be found using this method.- Parameters:
resourcePath- A complete resource path, relative to the classpath entry package root.- Returns:
- A list of all resources found in any classpath element, whether in accepted packages or not (as long as the resource is not rejected), that have the given path, relative to the package root of the classpath element. May match several resources, up to one per classpath element.
-
getResourcesWithPathIgnoringWhitelist
Deprecated.UsegetResourcesWithPathIgnoringAccept(String)instead.UsegetResourcesWithPathIgnoringAccept(String)instead.- Parameters:
resourcePath- A complete resource path, relative to the classpath entry package root.- Returns:
- A list of all resources found in any classpath element, whether in accepted packages or not (as long as the resource is not rejected), 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
Get the list of all resources found in accepted packages that have the requested leafname.- Parameters:
leafName- A resource leaf filename.- Returns:
- A list of all resources found in accepted packages that have the requested leafname.
-
getResourcesWithExtension
Get the list of all resources found in accepted packages that have the requested filename extension.- Parameters:
extension- A filename extension, e.g. "xml" to match all resources ending in ".xml".- Returns:
- A list of all resources found in accepted packages that have the requested filename extension.
-
getResourcesMatchingPattern
Get the list of all resources found in accepted packages that have a path matching the requested regex pattern. See also {getResourcesMatchingWildcard(String).- Parameters:
pattern- A pattern to matchResourcepaths with.- Returns:
- A list of all resources found in accepted packages that have a path matching the requested pattern.
-
getResourcesMatchingWildcard
Get the list of all resources found in accepted packages that have a path matching the requested wildcard string.The wildcard string may contain:
- Single asterisks, to match zero or more of any character other than '/'
- Double asterisks, to match zero or more of any character
- Question marks, to match one character
- Any other regexp-style syntax, such as character sets (denoted by square brackets) -- the remainder of the expression is passed through to the Java regex parser, after escaping dot characters.
The wildcard string is translated in a simplistic way into a regex. If you need more complex pattern matching, use a regex directly, via
getResourcesMatchingPattern(Pattern).- Parameters:
wildcardString- A wildcard (glob) pattern to matchResourcepaths with.- Returns:
- A list of all resources found in accepted packages that have a path matching the requested wildcard string.
-
getModuleInfo
Get theModuleInfoobject for the named module, or null if no module of the requested name was found during the scan.- Parameters:
moduleName- The module name.- Returns:
- The
ModuleInfoobject for the named module, or null if the module was not found.
-
getModuleInfo
Get all modules found during the scan.- Returns:
- A list of all modules found during the scan, or the empty list if none.
-
getPackageInfo
Get thePackageInfoobject for the named package, or null if no package of the requested name was found during the scan.- Parameters:
packageName- The package name.- Returns:
- The
PackageInfoobject for the named package, or null if the package was not found.
-
getPackageInfo
Get all packages found during the scan.- Returns:
- A list of all packages found during the scan, or the empty list if none.
-
getClassDependencyMap
Get a map from theClassInfoobject for each accepted class to a list of the classes referenced by that class (i.e. returns a map from dependents to dependencies). Note that you need to callClassGraph.enableInterClassDependencies()beforeClassGraph.scan()for this method to work. You should also callClassGraph.enableExternalClasses()beforeClassGraph.scan()if you want non-accepted classes to appear in the result. See alsogetReverseClassDependencyMap(), which inverts the map.- Returns:
- A map from a
ClassInfoobject for each accepted class to a list of the classes referenced by that class (i.e. returns a map from dependents to dependencies). Each map value is the result of callingClassInfo.getClassDependencies()on the corresponding key.
-
getReverseClassDependencyMap
Get the reverse class dependency map, i.e. a map from theClassInfoobject for each dependency class (accepted or not) to a list of the accepted classes that referenced that class as a dependency (i.e. returns a map from dependencies to dependents). Note that you need to callClassGraph.enableInterClassDependencies()beforeClassGraph.scan()for this method to work. You should also callClassGraph.enableExternalClasses()beforeClassGraph.scan()if you want non-accepted classes to appear in the result. See alsogetClassDependencyMap().- Returns:
- A map from a
ClassInfoobject for each dependency class (accepted or not) to a list of the accepted classes that referenced that class as a dependency (i.e. returns a map from dependencies to dependents).
-
getClassInfo
-
getAllClasses
Get all classes, interfaces and annotations found during the scan.- Returns:
- A list of all accepted classes found during the scan, or the empty list if none.
-
getAllEnums
-
getAllRecords
Get allrecordclasses found during the scan (JDK 14+).- Returns:
- A list of all
recordclasses found during the scan, or the empty list if none.
-
getAllClassesAsMap
-
getAllStandardClasses
Get all standard (non-interface/non-annotation) classes found during the scan.- Returns:
- A list of all accepted standard classes found during the scan, or the empty list if none.
-
getSubclasses
Get all subclasses of the superclass.- Parameters:
superclass- The superclass.- Returns:
- A list of subclasses of the superclass, or the empty list if none.
-
getSubclasses
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
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.
-
getSuperclasses
Get superclasses of the subclass.- Parameters:
subclass- The subclass.- Returns:
- A list of superclasses of the named subclass, or the empty list if none.
-
getClassesWithMethodAnnotation
Get classes that have a method with an annotation of the named type.- Parameters:
methodAnnotation- 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.
-
getClassesWithMethodAnnotation
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.
-
getClassesWithMethodParameterAnnotation
public ClassInfoList getClassesWithMethodParameterAnnotation(Class<? extends Annotation> methodParameterAnnotation) Get classes that have a method with a parameter that is annotated with an annotation of the named type.- Parameters:
methodParameterAnnotation- the method parameter annotation.- Returns:
- A list of classes that have a method with a parameter annotated with the named annotation type, or the empty list if none.
-
getClassesWithMethodParameterAnnotation
Get classes that have a method with a parameter that is annotated with an annotation of the named type.- Parameters:
methodParameterAnnotationName- the name of the method parameter annotation.- Returns:
- A list of classes that have a method with a parameter annotated with the named annotation type, or the empty list if none.
-
getClassesWithFieldAnnotation
Get classes that have a field with an annotation of the named type.- Parameters:
fieldAnnotation- 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.
-
getClassesWithFieldAnnotation
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
Get all interface classes found during the scan (not including annotations, which are also technically interfaces). See alsogetAllInterfacesAndAnnotations().- Returns:
- A list of all accepted interfaces found during the scan, or the empty list if none.
-
getInterfaces
Get all interfaces implemented by the named class or by one of its superclasses, if the named class is a standard class, or the superinterfaces extended by this interface, if it 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.
-
getInterfaces
Get all interfaces implemented by the class or by one of its superclasses, if the given class is a standard class, or the superinterfaces extended by this interface, if it is an interface.- Parameters:
classRef- The class.- Returns:
- A list of interfaces implemented by the given class (or superinterfaces extended by the given interface), or the empty list if none.
-
getClassesImplementing
Get all classes that implement (or have superclasses that implement) the interface (or one of its subinterfaces).- Parameters:
interfaceClass- The interface class.- Returns:
- A list of all classes that implement the interface, or the empty list if none.
-
getClassesImplementing
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
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
Get all interface or annotation classes found during the scan. (Annotations are technically interfaces, and they can be implemented.)- Returns:
- A list of all accepted interfaces found during the scan, or the empty list if none.
-
getClassesWithAnnotation
Get classes with the class annotation or meta-annotation.- Parameters:
annotation- The class annotation or meta-annotation.- Returns:
- A list of all non-annotation classes that were found with the class annotation during the scan, or the empty list if none.
-
getClassesWithAllAnnotations
Get classes with all of the specified class annotations or meta-annotation.- Parameters:
annotations- The class annotations or meta-annotations.- Returns:
- A list of all non-annotation classes that were found with any of the class annotations during the scan, or the empty list if none.
-
getClassesWithAnyAnnotation
Get classes with any of the specified class annotations or meta-annotation.- Parameters:
annotations- The class annotations or meta-annotations.- Returns:
- A list of all non-annotation classes that were found with any of the class annotations during the scan, or the empty list if none.
-
getClassesWithAnnotation
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.
-
getClassesWithAllAnnotations
Get classes with all of the named class annotations or meta-annotation.- Parameters:
annotationNames- The name of the class annotations or meta-annotations.- Returns:
- A list of all non-annotation classes that were found with all of the named class annotations during the scan, or the empty list if none.
-
getClassesWithAnyAnnotation
Get classes with any of the named class annotations or meta-annotation.- Parameters:
annotationNames- The name of the class annotations or meta-annotations.- Returns:
- A list of all non-annotation classes that were found with any of the named class annotations during the scan, or the empty list if none.
-
getAnnotationsOnClass
Get annotations on the named class. This only returns the annotating classes; to read annotation parameters, callgetClassInfo(String)to get theClassInfoobject for the named class, then if theClassInfoobject 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.
-
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 accept 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 accepted file/directory/jarfile encountered during the scan. Checks the current timestamps, so this should increase between calls if something changes in accepted 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 accepted files/directories/jars encountered during the scan.
-
getClassLoaderOrderRespectingParentDelegation
ClassLoader[] getClassLoaderOrderRespectingParentDelegation()Get the ClassLoader order, respecting parent-first/parent-last delegation order.- Returns:
- the class loader order.
-
loadClass
public Class<?> loadClass(String className, boolean returnNullIfClassNotFound) 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.returnNullIfClassNotFound- 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 withClassGraph#initializeLoadedClasses(true).) Otherwise exceptions are suppressed, and null is returned if any of these problems occurs.
-
loadClass
public <T> Class<T> loadClass(String className, Class<T> superclassOrInterfaceType, boolean returnNullIfClassNotFound) 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.
- Type Parameters:
T- the superclass or interface type.- Parameters:
className- the class to load.superclassOrInterfaceType- The class type to cast the result to.returnNullIfClassNotFound- 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 the class, initializing the class, or casting it to the requested type. (Note that class initialization on load is disabled by default, you can enable it withClassGraph#initializeLoadedClasses(true).) Otherwise exceptions are suppressed, and null is returned if any of these problems occurs.
-
fromJSON
Deserialize a ScanResult from previously-serialized JSON.- Parameters:
json- The JSON string for the serializedScanResult.- Returns:
- The deserialized
ScanResult.
-
toJSON
Serialize a ScanResult to JSON.- Parameters:
indentWidth- If greater than 0, JSON will be formatted (indented), otherwise it will be minified (un-indented).- Returns:
- This
ScanResult, serialized as a JSON string.
-
toJSON
Serialize a ScanResult to minified (un-indented) JSON.- Returns:
- This
ScanResult, serialized as a JSON string.
-
isObtainedFromDeserialization
public boolean isObtainedFromDeserialization()Checks if thisScanResultwas obtained from JSON by deserialization, by callingfromJSON(String).- Returns:
- True if this
ScanResultwas obtained from JSON by deserialization.
-
close
public void close()Free any temporary files created by extracting jars or files from within jars. Without calling this method, the temporary files created by extracting the inner jars will be removed in a finalizer, called by the garbage collector (or at JVM shutdown). If you don't want to experience long GC pauses, make sure you call this close method when you have finished with theScanResult.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
isClosed
public boolean isClosed()Returns whether this ScanResult has been closed yet or not.- Returns:
trueif this ScanResult has been closed
-
closeAll
public static void closeAll()Close allScanResultinstances that have not yet been closed. Note that this will close all openScanResultinstances for any class that uses the classloader that theScanResultclass is cached in -- so if you call this method, you need to ensure that the lifecycle of the classloader matches the lifecycle of your application, or that two concurrent applications don't share the same classloader, otherwise one application might close another application'sScanResultinstances while they are still in use.
-
getResourcesWithPathIgnoringAccept(String)instead.