< 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.
+ * 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
import jdk.internal.jmod.JmodFile.Section;
import jdk.internal.perf.PerfCounter;
/**
* A {@code 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.
+ * a sequence of directories or packaged modules.
+ *
+ * <p> A ModulePath can be created to locate modules on a module path at run-time or
+ * link-time. In both cases it supports modular JARs and exploded modules. At link-time
+ * it additionally locates modules in JMOD files. The ModuleFinder can also optionally
+ * patch the modules that it locates with a ModulePatcher.
+ *
+ * <p> A ModulePath can also be created to locate modules in a JDK exploded image. It
+ * can optionally patch any modules that it locates with a ModulePatcher, and it can
+ * support preview classes in META-INF/preview when running with preview features enabled.
*/
public class ModulePath implements ModuleFinder {
private static final String MODULE_INFO = "module-info.class";
private final boolean isLinkPhase;
// for patching modules, can be null
private final ModulePatcher patcher;
+ // true for a module path to a JDK exploded image and preview features are enabled
+ private final boolean previewMode;
+
// the entries on this module path
private final Path[] entries;
private int next;
- // map of module name to module reference map for modules already located
+ // map of module name to module reference for modules already located
private final Map<String, ModuleReference> cachedModules = new HashMap<>();
private ModulePath(Runtime.Version version,
boolean isLinkPhase,
ModulePatcher patcher,
+ boolean previewMode,
Path... entries) {
this.releaseVersion = version;
this.isLinkPhase = isLinkPhase;
this.patcher = patcher;
+ this.previewMode = previewMode;
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);
+ return new ModulePath(JarFile.runtimeVersion(), false, patcher, false, 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) {
- return of((ModulePatcher)null, entries);
+ return of(null, 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);
+ return new ModulePath(version, isLinkPhase, null, false, entries);
}
+ /**
+ * Returns a ModuleFinder that locates modules in a JDK exploded image.
+ * @param modulesDir the modules directory ($JAVA_HOME/modules)
+ * @param patcher the ModulePatcher or null
+ * @param previewMode true if preview features are enabled
+ */
+ public static ModuleFinder ofExplodedImage(Path modulesDir,
+ ModulePatcher patcher,
+ boolean previewMode) {
+ return new ModulePath(JarFile.runtimeVersion(), // not used for exploded image
+ false,
+ patcher,
+ previewMode,
+ modulesDir);
+ }
@Override
public Optional<ModuleReference> find(String name) {
Objects.requireNonNull(name);
() -> explodedPackages(dir));
} catch (NoSuchFileException e) {
// for now
return null;
}
- return ModuleReferences.newExplodedModule(attrs, patcher, dir);
+ return ModuleReferences.newExplodedModule(attrs, patcher, previewMode, dir);
}
/**
* Maps a type name to its package name.
*/
< prev index next >