Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Luke Hutchison edited this page Aug 16, 2021 · 2 revisions

See also the ClassGraph API overview.

Contents

ModuleInfo

Holds information about a module encountered during scanning. Obtained by calling ScanResult#getModuleInfo(moduleName) or ScanResult#getModuleInfo().

  • Properties: (N.B. call .enableClassInfo() before .scan() to enable ModuleInfo, and call .ignoreClassVisibility() if you want to get modules for non-public classes.)
    • .getName() returns the name of the module as a String.
    • .getLocation() returns the location of the module as a URI.
    • .getModuleRef() returns the ModuleRef for the module.
  • Classes:
    • .getClassInfo() returns a ClassInfoList of ClassInfo objects for all classes found in this module.
    • .getClassInfo(String className) returns the ClassInfo object for the named class in this module, or null if the class was not found in this module. /wiki/PackageInfo-API#packageinfo) object for the named package in this module, or null if the package was not found in this module.
  • Annotations: (module annotations are annotations on the module-info.java module descriptor)
    • .getAnnotationInfo() returns the annotations on this module as an AnnotationInfoList.
    • .hasAnnotation(String annotationName | Class<? extends Annotation> annotationClass) returns true if the module has the given annotation.
    • .getAnnotationInfo(String annotationName | Class<? extends Annotation> annotationClass) returns the AnnotationInfo object for the given module annotation, or null if none.
  • Packages:
    • .getPackageInfo() returns a PackageInfoList of PackageInfo objects for all packages found in this module.
    • .getPackageInfo(String packageName) returns the PackageInfo object for the package of the given name in this module.

ModuleInfoList

Extends ArrayList<ModuleInfo> with the following convenience methods:

  • .asMap() returns the ModuleInfoList as a Map<String, ModuleInfo> mapping the module name to the corresponding ModuleInfo object.
  • .getNames() returns a list of the names of the modules in this list as a List<String>.
  • .getAsStrings() returns a list of the result of calling .toString() on each ModuleInfo object in this list, producing a List<string> of String representations of each module, including the module name and the module location URI.
  • .containsName(String moduleName) returns true if a module of the given name is contained in this list.
  • .get(String moduleName) returns the ModuleInfo object in this list with the requested name, if present, otherwise returns null.
  • .filter(ModuleInfoFilter filter) returns a ModuleInfoList that is a subset of the original list, obtained by applying the given filter predicate to each ModuleInfo object in the list.
    • ModuleInfoFilter is a FunctionalInterface with the single abstract method boolean accept(ModuleInfo moduleInfo).

ModulePathInfo

Provides information on the module path. Note that this will only include module system parameters actually listed in commandline arguments -- in particular this does not include classpath elements from the traditional classpath, or system modules.

Obtained by calling ClassGraph#getModulePathInfo() or ScanResult#getModulePathInfo (the ScanResult version includes any Add-Exports or Add-Opens entries found in jar manifest files while scanning). Note that the fields are all ordered sets (LinkedHashSet), so iterating through a set will return the original order, only deduplicated.

  • .modulePath contains the module path specified using the --module-path or -p commandline switch, as an ordered set of module names, in the order they were listed on the commandline. Note that some modules (such as system modules) will not be in this list, as they are added to the module system automatically by the runtime. Call ClassGraph#getModules() or ScanResult#getModules() get all modules visible at runtime.
  • .addModules contains modules added using the --add-modules commandline switch, as an ordered set of module names, in the order they were listed on the commandline. Note that valid module names include ALL-DEFAULT, ALL-SYSTEM, and ALL-MODULE-PATH (see JEP 261 for info).
  • .patchModules contains module patch directives specified using the --patch-module commandline switch, as an ordered set of strings in the format <module>=<file>(<pathsep><file>)*, in the order they were listed on the commandline.
  • .addExports contains module exports directives specified using the --add-exports commandline switch, as an ordered set of strings in the format <source-module>/<package>=<target-module>(,<target-module>)*, in the order they were listed on the commandline. Additionally, if this ModulePathInfo object was obtained from ScanResult#getModulePathInfo() rather than ClassGraph#getModulePathInfo(), any additional Add-Exports entries found in manifest files during classpath scanning will be appended to this list, in the format <source-module>/<package>=ALL-UNNAMED.
  • .addOpens contains module opens directives specified using the --add-opens commandline switch, as an ordered set of strings in the format <source-module>/<package>=<target-module>(,<target-module>)*, in the order they were listed on the commandline. Additionally, if this ModulePathInfo object was obtained from ScanResult#getModulePathInfo() rather than ClassGraph#getModulePathInfo(), any additional Add-Opens entries found in manifest files during classpath scanning will be appended to this list, in the format <source-module>/<package>=ALL-UNNAMED.
  • .addReads contains module reads directives specified using the --add-reads commandline switch, as an ordered set of strings in the format <source-module>=<target-module>, in the order they were listed on the commandline.
  • .toString() will return all of the above as a String, in commandline switch format.