APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.internal.module

public Class ModulePath

extends Object
implements ModuleFinder
Class Inheritance
All Implemented Interfaces
java.lang.module.ModuleFinder
Imports
java.io.BufferedInputStream, .BufferedReader, .File, .IOException, .InputStream, .InputStreamReader, .UncheckedIOException, java.lang.module.FindException, .InvalidModuleDescriptorException, .ModuleDescriptor, .ModuleDescriptor.Builder, .ModuleFinder, .ModuleReference, java.net.URI, java.nio.file.DirectoryStream, .Files, .NoSuchFileException, .Path, java.nio.file.attribute.BasicFileAttributes, java.util.ArrayList, .HashMap, .List, .Map, .Objects, .Optional, .Set, java.util.jar.Attributes, .JarEntry, .JarFile, .Manifest, java.util.regex.Matcher, .Pattern, java.util.stream.Collectors, .Stream, java.util.zip.ZipException, .ZipFile, sun.nio.cs.UTF_8, jdk.internal.jmod.JmodFile, .JmodFile.Section, jdk.internal.perf.PerfCounter

A ModuleFinder that locates modules on the file system by searching a sequence of directories or packaged modules. The ModuleFinder can be created to work in either the run-time or link-time phases. In both cases it locates modular JAR and exploded modules. When created for link-time then it additionally locates modules in JMOD files. The ModuleFinder can also optionally patch any modules that it locates with a ModulePatcher.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
ModulePath.Patterns

Patterns used to derive the module name from a JAR file name.

Field Summary

Modifier and TypeField and Description
private static final Attributes.Name
private final Map<String, ModuleReference>
private final Path[]
private final boolean
private static final String
private static final PerfCounter
private int
private final ModulePatcher
private final Runtime.Version
private static final PerfCounter
private static final String

Constructor Summary

AccessConstructor and Description
private
ModulePath(Runtime.Version version, boolean isLinkPhase, ModulePatcher patcher, Path... entries)

Method Summary

Modifier and TypeMethod and Description
private static String
cleanModuleName(String mn)

Clean up candidate module name derived from a JAR file name.

private ModuleDescriptor
deriveModuleDescriptor(JarFile jf)

Treat the given JAR file as a module as follows: 1.

private Set<String>
private String
fileName(ModuleReference mref)

Returns a string with the file name of the module if possible.

public Optional<ModuleReference>
find(String name)

Implements java.lang.module.ModuleFinder.find.

Finds a reference to a module of a given name.

public Set<ModuleReference>
findAll()

Implements java.lang.module.ModuleFinder.findAll.

Returns the set of all module references that this finder can locate.

private boolean
hasNextEntry()

Returns true if there are additional entries to scan

private boolean
isDefaultFileSystem(Path path)

Return true if a path locates a path in the default file system

private boolean
isHidden(Path file)

Returns true if the given file exists and is a hidden file

private Set<String>
private Set<String>
private String
nextLine(BufferedReader reader)

Reads the next line from the given reader and trims it of comments and leading/trailing white space.

public static ModuleFinder
of(ModulePatcher patcher, Path... entries)

Returns a ModuleFinder that locates modules on the file system by searching a sequence of directories and/or packaged modules.

public static ModuleFinder
of(Path... entries)

Hides java.lang.module.ModuleFinder.of.

Returns a ModuleFinder that locates modules on the file system by searching a sequence of directories and/or packaged modules.

public static ModuleFinder
of(Runtime.Version
The release version to use for multi-release JAR files
version
,
boolean
true if the link phase to locate JMOD files
isLinkPhase
,
Path... entries)

Returns a ModuleFinder that locates modules on the file system by searching a sequence of directories and/or packaged modules.

private static String
packageName(String cn)

Maps a type name to its package name.

private ModuleReference
readExplodedModule(Path dir)

Returns a ModuleReference to an exploded module on the file system or null if module-info.class not found.

private ModuleReference
readJar(Path file)

Returns a ModuleReference to a module in modular JAR file on the file system.

private ModuleReference
readJMod(Path file)

Returns a ModuleReference to a module in JMOD file on the file system.

private ModuleReference
readModule(Path entry, BasicFileAttributes attrs)

Reads a packaged or exploded module, returning a ModuleReference to the module.

private Map<String, ModuleReference>
scan(Path entry)

Scan the given module path entry.

private Map<String, ModuleReference>

Returns:

a map of module name to ModuleReference for the modules found in the directory
scanDirectory
(Path dir)

Scans the given directory for packaged or exploded modules.

private void
scanNextEntry()

Scans the next entry on the module path.

private Optional<String>
toPackageName(String name)

Maps the name of an entry in a JAR or ZIP file to a package name.

private Optional<String>
toPackageName(Path file, String separator)

Maps the relative path of an entry in an exploded module to a package name.

private Optional<String>
toServiceName(String cf)

Returns the service type corresponding to the name of a services configuration file if it is a legal type name.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

AUTOMATIC_MODULE_NAMEback to summary
private static final Attributes.Name AUTOMATIC_MODULE_NAME
cachedModulesback to summary
private final Map<String, ModuleReference> cachedModules
entriesback to summary
private final Path[] entries
isLinkPhaseback to summary
private final boolean isLinkPhase
MODULE_INFOback to summary
private static final String MODULE_INFO
moduleCountback to summary
private static final PerfCounter moduleCount
nextback to summary
private int next
patcherback to summary
private final ModulePatcher patcher
releaseVersionback to summary
private final Runtime.Version releaseVersion
scanTimeback to summary
private static final PerfCounter scanTime
SERVICES_PREFIXback to summary
private static final String SERVICES_PREFIX

Constructor Detail

ModulePathback to summary
private ModulePath(Runtime.Version version, boolean isLinkPhase, ModulePatcher patcher, Path... entries)

Method Detail

cleanModuleNameback to summary
private static String cleanModuleName(String mn)

Clean up candidate module name derived from a JAR file name.

deriveModuleDescriptorback to summary
private ModuleDescriptor deriveModuleDescriptor(JarFile jf) throws IOException

Treat the given JAR file as a module as follows: 1. The value of the Automatic-Module-Name attribute is the module name 2. The version, and the module name when the Automatic-Module-Name attribute is not present, is derived from the file ame of the JAR file 3. All packages are derived from the .class files in the JAR file 4. The contents of any META-INF/services configuration files are mapped to "provides" declarations 5. The Main-Class attribute in the main attributes of the JAR manifest is mapped to the module descriptor mainClass if possible

explodedPackagesback to summary
private Set<String> explodedPackages(Path dir)
fileNameback to summary
private String fileName(ModuleReference mref)

Returns a string with the file name of the module if possible. If the module location is not a file URI then return the URI as a string.

findback to summary
public Optional<ModuleReference> find(String name)

Implements java.lang.module.ModuleFinder.find.

Doc from java.lang.module.ModuleFinder.find.

Finds a reference to a module of a given name.

A ModuleFinder provides a consistent view of the modules that it locates. If find is invoked several times to locate the same module (by name) then it will return the same result each time. If a module is located then it is guaranteed to be a member of the set of modules returned by the findAll method.

Annotations
@Override
findAllback to summary
public Set<ModuleReference> findAll()

Implements java.lang.module.ModuleFinder.findAll.

Doc from java.lang.module.ModuleFinder.findAll.

Returns the set of all module references that this finder can locate.

A ModuleFinder provides a consistent view of the modules that it locates. If findAll is invoked several times then it will return the same (equals) result each time. For each ModuleReference element in the returned set then it is guaranteed that find will locate the ModuleReference if invoked to find that module.

Annotations
@Override
hasNextEntryback to summary
private boolean hasNextEntry()

Returns true if there are additional entries to scan

isDefaultFileSystemback to summary
private boolean isDefaultFileSystem(Path path)

Return true if a path locates a path in the default file system

isHiddenback to summary
private boolean isHidden(Path file)

Returns true if the given file exists and is a hidden file

jarPackagesback to summary
private Set<String> jarPackages(JarFile jf)
jmodPackagesback to summary
private Set<String> jmodPackages(JmodFile jf)
nextLineback to summary
private String nextLine(BufferedReader reader) throws IOException

Reads the next line from the given reader and trims it of comments and leading/trailing white space. Returns null if the reader is at EOF.

ofback to summary
public static ModuleFinder of(ModulePatcher patcher, Path... entries)

Returns a ModuleFinder that locates modules on the file system by searching a sequence of directories and/or packaged modules. The modules may be patched by the given ModulePatcher.

ofback to summary
public static ModuleFinder of(Path... entries)

Hides java.lang.module.ModuleFinder.of.

Returns a ModuleFinder that locates modules on the file system by searching a sequence of directories and/or packaged modules.

ofback to summary
public static ModuleFinder of(Runtime.Version version, boolean isLinkPhase, Path... entries)

Returns a ModuleFinder that locates modules on the file system by searching a sequence of directories and/or packaged modules.

Parameters
version:Runtime.Version

The release version to use for multi-release JAR files

isLinkPhase:boolean

true if the link phase to locate JMOD files

packageNameback to summary
private static String packageName(String cn)

Maps a type name to its package name.

readExplodedModuleback to summary
private ModuleReference readExplodedModule(Path dir) throws IOException

Returns a ModuleReference to an exploded module on the file system or null if module-info.class not found.

readJarback to summary
private ModuleReference readJar(Path file) throws IOException

Returns a ModuleReference to a module in modular JAR file on the file system.

readJModback to summary
private ModuleReference readJMod(Path file) throws IOException

Returns a ModuleReference to a module in JMOD file on the file system.

readModuleback to summary
private ModuleReference readModule(Path entry, BasicFileAttributes attrs) throws IOException

Reads a packaged or exploded module, returning a ModuleReference to the module. Returns null if the entry is not recognized.

Exceptions
IOException:
if an I/O error occurs
FindException:
if an error occurs parsing its module descriptor
scanback to summary
private Map<String, ModuleReference> scan(Path entry)

Scan the given module path entry. If the entry is a directory then it is a directory of modules or an exploded module. If the entry is a regular file then it is assumed to be a packaged module.

Exceptions
FindException:
if an error occurs scanning the entry
scanDirectoryback to summary
private Map<String, ModuleReference> scanDirectory(Path dir) throws IOException

Scans the given directory for packaged or exploded modules.

Returns:Map<String, ModuleReference>

a map of module name to ModuleReference for the modules found in the directory

Exceptions
IOException:
if an I/O error occurs
FindException:
if an error occurs scanning the entry or the directory contains two or more modules with the same name
scanNextEntryback to summary
private void scanNextEntry()

Scans the next entry on the module path. A no-op if all entries have already been scanned.

Exceptions
FindException:
if an error occurs scanning the next entry
toPackageNameback to summary
private Optional<String> toPackageName(String name)

Maps the name of an entry in a JAR or ZIP file to a package name.

Exceptions
InvalidModuleDescriptorException:
if the name is a class file in the top-level directory of the JAR/ZIP file (and it's not module-info.class)
toPackageNameback to summary
private Optional<String> toPackageName(Path file, String separator)

Maps the relative path of an entry in an exploded module to a package name.

Exceptions
InvalidModuleDescriptorException:
if the name is a class file in the top-level directory (and it's not module-info.class)
toServiceNameback to summary
private Optional<String> toServiceName(String cf)

Returns the service type corresponding to the name of a services configuration file if it is a legal type name. For example, if called with "META-INF/services/p.S" then this method returns a container with the value "p.S".

jdk.internal.module back to summary

private Class ModulePath.Patterns

extends Object
Class Inheritance

Patterns used to derive the module name from a JAR file name.

Field Summary

Modifier and TypeField and Description
pack-priv static final Pattern
pack-priv static final Pattern
pack-priv static final Pattern
pack-priv static final Pattern
pack-priv static final Pattern

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DASH_VERSIONback to summary
pack-priv static final Pattern DASH_VERSION
LEADING_DOTSback to summary
pack-priv static final Pattern LEADING_DOTS
NON_ALPHANUMback to summary
pack-priv static final Pattern NON_ALPHANUM
REPEATING_DOTSback to summary
pack-priv static final Pattern REPEATING_DOTS
TRAILING_DOTSback to summary
pack-priv static final Pattern TRAILING_DOTS

Constructor Detail

Patternsback to summary
private Patterns()