< prev index next > src/java.base/share/classes/jdk/internal/module/ModulePath.java
Print this page
/*
! * Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
/*
! * Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
// the version to use for multi-release modular JARs
private final Runtime.Version releaseVersion;
// true for the link phase (supports modules packaged in JMOD format)
private final boolean isLinkPhase;
+ // true if the found modules should return preview versions of resources
+ // (this must only be set for system modules).
+ private final boolean previewMode;
// for patching modules, can be null
private final ModulePatcher patcher;
// the entries on this module path
private final Map<String, ModuleReference> cachedModules = new HashMap<>();
private ModulePath(Runtime.Version version,
boolean isLinkPhase,
ModulePatcher patcher,
Path... entries) {
this.releaseVersion = version;
this.isLinkPhase = isLinkPhase;
this.patcher = patcher;
this.entries = entries.clone();
for (Path entry : this.entries) {
Objects.requireNonNull(entry);
}
}
/**
* 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.
*/
public static ModuleFinder of(ModulePatcher patcher, Path... entries) {
! return new ModulePath(JarFile.runtimeVersion(), false, patcher, entries);
}
/**
* Returns a ModuleFinder that locates modules on the file system by
* searching a sequence of directories and/or packaged modules.
private final Map<String, ModuleReference> cachedModules = new HashMap<>();
private ModulePath(Runtime.Version version,
boolean isLinkPhase,
+ boolean previewMode,
ModulePatcher patcher,
Path... entries) {
this.releaseVersion = version;
this.isLinkPhase = isLinkPhase;
+ this.previewMode = previewMode;
this.patcher = patcher;
this.entries = entries.clone();
for (Path entry : this.entries) {
Objects.requireNonNull(entry);
}
}
+ /**
+ * Returns a ModuleFinder for an exploded JDK build where {@code moduleDir}
+ * is the $JAVA_HOME/modules directory. The modules may be patched by the
+ * given ModulePatcher.
+ *
+ * <p>Preview mode is only permitted for system modules, and this method
+ * should only be called from {@link SystemModuleFinders#ofSystem()}.
+ */
+ public static ModuleFinder of(ModulePatcher patcher, boolean previewMode, Path moduleDir) {
+ return new ModulePath(JarFile.runtimeVersion(), false, previewMode, patcher, moduleDir);
+ }
+
/**
* 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.
*/
public static ModuleFinder of(ModulePatcher patcher, Path... entries) {
! return new ModulePath(JarFile.runtimeVersion(), false, false, patcher, entries);
}
/**
* Returns a ModuleFinder that locates modules on the file system by
* searching a sequence of directories and/or packaged modules.
* @param isLinkPhase {@code true} if the link phase to locate JMOD files
*/
public static ModuleFinder of(Runtime.Version version,
boolean isLinkPhase,
Path... entries) {
! return new ModulePath(version, isLinkPhase, null, entries);
}
@Override
public Optional<ModuleReference> find(String name) {
* @param isLinkPhase {@code true} if the link phase to locate JMOD files
*/
public static ModuleFinder of(Runtime.Version version,
boolean isLinkPhase,
Path... entries) {
! return new ModulePath(version, isLinkPhase, false, null, entries);
}
@Override
public Optional<ModuleReference> find(String name) {
() -> explodedPackages(dir));
} catch (NoSuchFileException e) {
// for now
return null;
}
! return ModuleReferences.newExplodedModule(attrs, patcher, dir);
}
/**
* Maps a type name to its package name.
*/
() -> explodedPackages(dir));
} catch (NoSuchFileException e) {
// for now
return null;
}
! return ModuleReferences.newExplodedModule(attrs, patcher, previewMode, dir);
}
/**
* Maps a type name to its package name.
*/
< prev index next >