Top Description Inners Fields Constructors Methods
io.github.classgraph

public final Class ScanResult

extends Object
implements Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable
Imports
java.io.Closeable, .File, java.lang.annotation.Annotation, java.lang.ref.WeakReference, java.net.MalformedURLException, .URI, .URL, java.nio.ByteBuffer, java.util.ArrayList, .Collection, .Collections, .HashMap, .HashSet, .List, .Map, .Map.Entry, .Set, java.util.concurrent.ConcurrentHashMap, java.util.concurrent.atomic.AtomicBoolean, .AtomicInteger, java.util.regex.Matcher, .Pattern, nonapi.io.github.classgraph.classpath.ClasspathFinder, nonapi.io.github.classgraph.concurrency.AutoCloseableExecutorService, nonapi.io.github.classgraph.fastzipfilereader.NestedJarHandler, nonapi.io.github.classgraph.json.JSONDeserializer, .JSONSerializer, nonapi.io.github.classgraph.reflection.ReflectionUtils, nonapi.io.github.classgraph.scanspec.AcceptReject, .ScanSpec, nonapi.io.github.classgraph.utils.Assert, .CollectionUtils, .FileUtils, .JarUtils, .LogNode

The result of a scan. You should assign a ScanResult in a try-with-resources block, or manually close it when you have finished with the result of a scan.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
ScanResult.SerializationFormat

A class to hold a serialized ScanResult along with the ScanSpec that was used to scan.

Field Summary

Modifier and TypeField and Description
private ResourceList
allAcceptedResourcesCached

A list of all files that were found in accepted packages.

private ClassGraphClassLoader
classGraphClassLoader

A custom ClassLoader that can load classes found during the scan.

pack-priv Map<String, ClassInfo>
classNameToClassInfo

The map from class name to ClassInfo.

pack-priv ClasspathFinder
private List<ClasspathElement>
classpathOrder

The order of classpath elements, after inner jars have been extracted to temporary files, etc.

private final AtomicBoolean
closed

If true, this ScanResult has already been closed.

private static final String
CURRENT_SERIALIZATION_FORMAT

The current serialization format.

private Map<File, Long>
fileToLastModified

The file, directory and jarfile resources timestamped during a scan, along with their timestamp at the time of the scan.

private final AtomicInteger
getResourcesWithPathCallCount

The number of times getResourcesWithPath(String) has been called.

private static final AtomicBoolean
initialized

If true, ScanResult#staticInit() has been run.

private boolean
private Map<String, ModuleInfo>
moduleNameToModuleInfo

The map from class name to ClassInfo.

private NestedJarHandler
nestedJarHandler

The nested jar handler instance.

private static Set<WeakReference<ScanResult>>
nonClosedWeakReferences

The set of WeakReferences to non-closed ScanResult objects.

private Map<String, PackageInfo>
packageNameToPackageInfo

The map from package name to PackageInfo.

private Map<String, ResourceList>
pathToAcceptedResourcesCached

The map from path (relative to package root) to a list of Resource elements with the matching path.

private List<String>
rawClasspathEltOrderStrs

The order of raw classpath elements.

protected ReflectionUtils
pack-priv ScanSpec
scanSpec

The scan spec.

private final LogNode
topLevelLog

The toplevel log.

private final WeakReference<ScanResult>
weakReference

The WeakReference for this ScanResult.

Constructor Summary

AccessConstructor and Description
pack-priv
ScanResult(final ScanSpec
the scan spec
scanSpec
,
final List<ClasspathElement>
the classpath order
classpathOrder
,
final List<String>
the raw classpath element order
rawClasspathEltOrderStrs
,
final ClasspathFinder classpathFinder, final Map<String, ClassInfo>
a map from class name to class info
classNameToClassInfo
,
final Map<String, PackageInfo>
a map from package name to package info
packageNameToPackageInfo
,
final Map<String, ModuleInfo>
a map from module name to module info
moduleNameToModuleInfo
,
final Map<File, Long>
a map from file to last modified time
fileToLastModified
,
final NestedJarHandler
the nested jar handler
nestedJarHandler
,
final LogNode
the toplevel log
topLevelLog
)

The result of a scan.

Method Summary

Modifier and TypeMethod and Description
public long

Returns:

the maximum last-modified time for accepted files/directories/jars encountered during the scan.
classpathContentsLastModifiedTime
()

Find the maximum last-modified timestamp of any accepted file/directory/jarfile encountered during the scan.

public boolean

Returns:

true if the classpath contents have been modified since the last scan.
classpathContentsModifiedSinceScan
()

Determine whether the classpath contents have been modified since the last scan.

public void
close()

Implements java.io.Closeable.close.

Free any temporary files created by extracting jars or files from within jars.

public static void
closeAll()

Close all ScanResult instances that have not yet been closed.

public static ScanResult

Returns:

The deserialized ScanResult.
fromJSON
(final String
The JSON string for the serialized ScanResult.
json
)

Deserialize a ScanResult from previously-serialized JSON.

public ClassInfoList

Returns:

A list of all annotation classes found during the scan, or the empty list if none.
getAllAnnotations
()

Get all annotation classes found during the scan.

public ClassInfoList

Returns:

A list of all accepted classes found during the scan, or the empty list if none.
getAllClasses
()

Get all classes, interfaces and annotations found during the scan.

public Map<String, ClassInfo>

Returns:

The map from class name to ClassInfo object for all classes, interfaces and annotations found during the scan.
getAllClassesAsMap
()

Get a map from class name to ClassInfo object for all classes, interfaces and annotations found during the scan.

public ClassInfoList

Returns:

A list of all Enum classes found during the scan, or the empty list if none.
getAllEnums
()

Get all Enum classes found during the scan.

public ClassInfoList

Returns:

A list of all accepted interfaces found during the scan, or the empty list if none.
getAllInterfaces
()

Get all interface classes found during the scan (not including annotations, which are also technically interfaces).

public ClassInfoList

Returns:

A list of all accepted interfaces found during the scan, or the empty list if none.
getAllInterfacesAndAnnotations
()

Get all interface or annotation classes found during the scan.

public ClassInfoList

Returns:

A list of all record classes found during the scan, or the empty list if none.
getAllRecords
()

Get all record classes found during the scan (JDK 14+).

public ResourceList

Returns:

A list of all resources (including classfiles and non-classfiles) found in accepted packages.
getAllResources
()

Get the list of all resources.

public Map<String, ResourceList>

Returns:

The map from resource path to Resource for all resources (including classfiles and non-classfiles) found in accepted packages.
getAllResourcesAsMap
()

Get a map from resource path to Resource for all resources (including classfiles and non-classfiles) found in accepted packages.

public ClassInfoList

Returns:

A list of all accepted standard classes found during the scan, or the empty list if none.
getAllStandardClasses
()

Get all standard (non-interface/non-annotation) classes found during the scan.

public ClassInfoList

Returns:

A list of all annotation classes that were found with the named class annotation during the scan, or the empty list if none.
getAnnotationsOnClass
(final String
The name of the class.
className
)

Get annotations on the named class.

public Map<ClassInfo, ClassInfoList>

Returns:

A map from a ClassInfo object 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 calling ClassInfo#getClassDependencies() on the corresponding key.
getClassDependencyMap
()

Get a map from the ClassInfo object for each accepted class to a list of the classes referenced by that class (i.e. returns a map from dependents to dependencies).

public ClassInfoList

Returns:

A list of all classes that implement the interface, or the empty list if none.
getClassesImplementing
(final Class<?>
The interface class.
interfaceClass
)

Get all classes that implement (or have superclasses that implement) the interface (or one of its subinterfaces).

public ClassInfoList

Returns:

A list of all classes that implement the named interface, or the empty list if none.
getClassesImplementing
(final String
The interface name.
interfaceName
)

Get all classes that implement (or have superclasses that implement) the named interface (or one of its subinterfaces).

public ClassInfoList

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.
getClassesWithAllAnnotations
(final Class<? extends Annotation>...
The class annotations or meta-annotations.
annotations
)

Get classes with all of the specified class annotations or meta-annotation.

public ClassInfoList

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.
getClassesWithAllAnnotations
(final String...
The name of the class annotations or meta-annotations.
annotationNames
)

Get classes with all of the named class annotations or meta-annotation.

public ClassInfoList

Returns:

A list of all non-annotation classes that were found with the class annotation during the scan, or the empty list if none.
getClassesWithAnnotation
(final Class<? extends Annotation>
The class annotation or meta-annotation.
annotation
)

Get classes with the class annotation or meta-annotation.

public ClassInfoList

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.
getClassesWithAnnotation
(final String
The name of the class annotation or meta-annotation.
annotationName
)

Get classes with the named class annotation or meta-annotation.

public ClassInfoList

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
(final Class<? extends Annotation>...
The class annotations or meta-annotations.
annotations
)

Get classes with any of the specified class annotations or meta-annotation.

public ClassInfoList

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.
getClassesWithAnyAnnotation
(final String...
The name of the class annotations or meta-annotations.
annotationNames
)

Get classes with any of the named class annotations or meta-annotation.

public ClassInfoList

Returns:

A list of classes that have a field with an annotation of the named type, or the empty list if none.
getClassesWithFieldAnnotation
(final Class<? extends Annotation>
the field annotation.
fieldAnnotation
)

Get classes that have a field with an annotation of the named type.

public ClassInfoList

Returns:

A list of classes that have a field with an annotation of the named type, or the empty list if none.
getClassesWithFieldAnnotation
(final String
the name of the field annotation.
fieldAnnotationName
)

Get classes that have a field with an annotation of the named type.

public ClassInfoList

Returns:

A list of classes with a method that has an annotation of the named type, or the empty list if none.
getClassesWithMethodAnnotation
(final Class<? extends Annotation>
the method annotation.
methodAnnotation
)

Get classes that have a method with an annotation of the named type.

public ClassInfoList

Returns:

A list of classes with a method that has an annotation of the named type, or the empty list if none.
getClassesWithMethodAnnotation
(final String
the name of the method annotation.
methodAnnotationName
)

Get classes that have a method with an annotation of the named type.

public ClassInfoList

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
(final Class<? extends Annotation>
the method parameter annotation.
methodParameterAnnotation
)

Get classes that have a method with a parameter that is annotated with an annotation of the named type.

public ClassInfoList

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
(final String
the name of the method parameter annotation.
methodParameterAnnotationName
)

Get classes that have a method with a parameter that is annotated with an annotation of the named type.

public ClassInfo

Returns:

The ClassInfo object for the named class, or null if the class was not found.
getClassInfo
(final String
The class name.
className
)

Get the ClassInfo object for the named class, or null if no class of the requested name was found in an accepted/non-rejected package during the scan.

pack-priv ClassLoader[]

Returns:

the class loader order.
getClassLoaderOrderRespectingParentDelegation
()

Get the ClassLoader order, respecting parent-first/parent-last delegation order.

public String

Returns:

a the unique directories and jarfiles on the classpath, in classpath resolution order, as a path 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.

public List<File>

Returns:

The unique classpath elements.
getClasspathFiles
()

Returns the list of File objects for unique classpath elements (directories or jarfiles), in classloader resolution order.

public List<URI>

Returns:

The unique classpath element and module URIs.
getClasspathURIs
()

Returns an ordered list of unique classpath element and module URIs.

public List<URL>

Returns:

The unique classpath element and module URLs.
getClasspathURLs
()

Returns an ordered list of unique classpath element and module URLs.

public ClassInfoList

Returns:

A list of interfaces implemented by the named class (or superinterfaces extended by the named interface), or the empty list if none.
getInterfaces
(final String
The class name.
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.

public ClassInfoList

Returns:

A list of interfaces implemented by the given class (or superinterfaces extended by the given interface), or the empty list if none.
getInterfaces
(final Class<?>
The 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.

public ModuleInfo

Returns:

The ModuleInfo object for the named module, or null if the module was not found.
getModuleInfo
(final String
The module name.
moduleName
)

Get the ModuleInfo object for the named module, or null if no module of the requested name was found during the scan.

public ModuleInfoList

Returns:

A list of all modules found during the scan, or the empty list if none.
getModuleInfo
()

Get all modules found during the scan.

public ModulePathInfo

Returns:

The ModulePathInfo.
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 the Add-Exports and Add-Opens entries from jarfile manifest files encountered during scanning.

public List<ModuleRef>

Returns:

ModuleRef references for all visible modules.
getModules
()

Get ModuleRef references for all visible modules.

public PackageInfo

Returns:

The PackageInfo object for the named package, or null if the package was not found.
getPackageInfo
(final String
The package name.
packageName
)

Get the PackageInfo object for the named package, or null if no package of the requested name was found during the scan.

public PackageInfoList

Returns:

A list of all packages found during the scan, or the empty list if none.
getPackageInfo
()

Get all packages found during the scan.

public ResourceList

Returns:

A list of all resources found in accepted packages that have a path matching the requested pattern.
getResourcesMatchingPattern
(final Pattern
A pattern to match Resource paths with.
pattern
)

Get the list of all resources found in accepted packages that have a path matching the requested regex pattern.

public ResourceList

Returns:

A list of all resources found in accepted packages that have a path matching the requested wildcard string.
getResourcesMatchingWildcard
(final String
A wildcard (glob) pattern to match Resource paths with.
wildcardString
)

Get the list of all resources found in accepted packages that have a path matching the requested wildcard string.

public ResourceList

Returns:

A list of all resources found in accepted packages that have the requested filename extension.
getResourcesWithExtension
(final String
A filename extension, e.g. "xml" to match all resources ending in ".xml".
extension
)

Get the list of all resources found in accepted packages that have the requested filename extension.

public ResourceList

Returns:

A list of all resources found in accepted packages that have the requested leafname.
getResourcesWithLeafName
(final String
A resource leaf filename.
leafName
)

Get the list of all resources found in accepted packages that have the requested leafname.

public ResourceList

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.
getResourcesWithPath
(final String
A complete resource path, relative to the classpath entry package root.
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.

public ResourceList

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.
getResourcesWithPathIgnoringAccept
(final String
A complete resource path, relative to the classpath entry package root.
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.

public ResourceList

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
(final String
A complete resource path, relative to the classpath entry package root.
resourcePath
)

Use getResourcesWithPathIgnoringAccept(String) instead.

public Map<ClassInfo, ClassInfoList>

Returns:

A map from a ClassInfo object 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).
getReverseClassDependencyMap
()

Get the reverse class dependency map, i.e. a map from the ClassInfo object 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).

public ClassInfoList

Returns:

A list of subclasses of the superclass, or the empty list if none.
getSubclasses
(final Class<?>
The superclass.
superclass
)

Get all subclasses of the superclass.

public ClassInfoList

Returns:

A list of subclasses of the named superclass, or the empty list if none.
getSubclasses
(final String
The name of the superclass.
superclassName
)

Get all subclasses of the named superclass.

public ClassInfoList

Returns:

A list of superclasses of the named subclass, or the empty list if none.
getSuperclasses
(final String
The name of the subclass.
subclassName
)

Get superclasses of the named subclass.

public ClassInfoList

Returns:

A list of superclasses of the named subclass, or the empty list if none.
getSuperclasses
(final Class<?>
The subclass.
subclass
)

Get superclasses of the subclass.

private void
indexResourcesAndClassInfo(final LogNode
the log
log
)

Index Resource and ClassInfo objects.

pack-priv static void
init(final ReflectionUtils reflectionUtils)

Static initialization (warm up classloading), called when the ClassGraph class is initialized.

public boolean

Returns:

true if this ScanResult has been closed
isClosed
()

Returns whether this ScanResult has been closed yet or not.

public boolean

Returns:

True if this ScanResult was obtained from JSON by deserialization.
isObtainedFromDeserialization
()

Checks if this ScanResult was obtained from JSON by deserialization, by calling fromJSON(String).

public Class<?>

Returns:

a reference to the loaded class, or null if the class could not be loaded and ignoreExceptions is true.
loadClass
(final String
the class to load.
className
,
final boolean
If true, null is returned if there was an exception during classloading, otherwise IllegalArgumentException is thrown if a class could not be loaded.
returnNullIfClassNotFound
)

Load a class given a class name.

public <
the superclass or interface type.
T
>
Class<T>

Returns:

a reference to the loaded class, or null if the class could not be loaded and ignoreExceptions is true.
loadClass
(final String
the class to load.
className
,
final Class<T>
The class type to cast the result to.
superclassOrInterfaceType
,
final boolean
If true, null is returned if there was an exception during classloading, otherwise IllegalArgumentException is thrown if a class could not be loaded.
returnNullIfClassNotFound
)

Load a class given a class name.

public String

Returns:

This ScanResult, serialized as a JSON string.
toJSON
(final int
If greater than 0, JSON will be formatted (indented), otherwise it will be minified (un-indented).
indentWidth
)

Serialize a ScanResult to JSON.

public String

Returns:

This ScanResult, serialized as a JSON string.
toJSON
()

Serialize a ScanResult to minified (un-indented) JSON.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait