mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Let pack jars use classes nobody has, as optional dependencies
The class check was stricter than the JVM: a bundled library that references optional integrations failed the whole pack, although that code only runs when the classes exist. Each missing reference is now classified: - the host has the class but hides it (Iris internals, Iris's copy of a library): load error, saying modules cannot use Iris's classes; - missing from the API: load error, as before (different Iris build); - nobody has it: the pack loads. PackModules.missingClasses() lists the classes per jar and the load logs one capped WARNING per pack, formatted by MissingClassesWarning. Reference resolution moves from PackClassCheck to PackReferenceCheck.
This commit is contained in:
1 parent
b7b3993a8d
commit
98bd9a9c12
9 files changed
+326
-91
No files matched your search
@@ -19,10 +19,12 @@ import java.util.Objects;
|
||||
* stage constants in {@code requires(...)}. Besides the pack's own classes, that loader sees only
|
||||
* the Iris API and the JDK ({@link ApiAndJdkClassLoader}); packs do not see each other or Iris
|
||||
* internals. Before the loader exists, the load fails if a jar holds API classes, if a class is in
|
||||
* two jars, or if a class uses a class the loader would not find.
|
||||
* two jars, or if a class uses a class that Iris hides from modules or that is missing from the API.
|
||||
* Classes that nobody has are not an error, because the JVM only needs them when code that uses
|
||||
* them runs; they are reported as {@link #missingClasses()}.
|
||||
*
|
||||
* <p>A successful load logs one INFO summary of the pack's modules through {@link System.Logger},
|
||||
* which the host can route to its own logging.
|
||||
* which the host can route to its own logging, and one WARNING listing the missing classes, if any.
|
||||
*
|
||||
* <p>Close this when the pack unloads, after dropping everything built from its modules, such as
|
||||
* {@link LoadedModules}. Classes not loaded before then can no longer be loaded.
|
||||
@@ -33,10 +35,12 @@ public final class PackModules implements AutoCloseable {
|
||||
private static final System.Logger LOGGER = System.getLogger(PackModules.class.getName());
|
||||
|
||||
private final List<DiscoveredModule> modules;
|
||||
private final List<MissingClasses> missingClasses;
|
||||
private final URLClassLoader loader;
|
||||
|
||||
private PackModules(List<DiscoveredModule> modules, URLClassLoader loader) {
|
||||
private PackModules(List<DiscoveredModule> modules, List<MissingClasses> missingClasses, URLClassLoader loader) {
|
||||
this.modules = List.copyOf(modules);
|
||||
this.missingClasses = List.copyOf(missingClasses);
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
@@ -49,9 +53,9 @@ public final class PackModules implements AutoCloseable {
|
||||
.map(jar -> ModuleJar.read(packRoot, jar))
|
||||
.toList();
|
||||
var apiAndJdk = new ApiAndJdkClassLoader(IrisModule.class.getClassLoader());
|
||||
PackClassCheck.requireLinkable(jars, apiAndJdk);
|
||||
var packModules = defineModules(packRoot, jars, apiAndJdk);
|
||||
LOGGER.log(Level.INFO, () -> PackModulesSummary.describe(packName(packRoot), packModules.modules()));
|
||||
var missingClasses = PackClassCheck.requireLinkable(jars, apiAndJdk);
|
||||
var packModules = defineModules(packRoot, jars, missingClasses, apiAndJdk);
|
||||
logLoad(packName(packRoot), packModules);
|
||||
return packModules;
|
||||
}
|
||||
|
||||
@@ -60,6 +64,13 @@ public final class PackModules implements AutoCloseable {
|
||||
return modules;
|
||||
}
|
||||
|
||||
/** Per jar that uses any, in jar file name order, the classes that neither the pack, Iris nor the
|
||||
* JDK has. Empty when every class the jars use exists.
|
||||
*/
|
||||
public List<MissingClasses> missingClasses() {
|
||||
return missingClasses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
try {
|
||||
@@ -86,10 +97,11 @@ public final class PackModules implements AutoCloseable {
|
||||
return Files.isRegularFile(path) && path.getFileName().toString().endsWith(JAR_EXTENSION);
|
||||
}
|
||||
|
||||
private static PackModules defineModules(Path packRoot, List<ModuleJar> jars, ClassLoader apiAndJdk) {
|
||||
private static PackModules defineModules(
|
||||
Path packRoot, List<ModuleJar> jars, List<MissingClasses> missingClasses, ClassLoader apiAndJdk) {
|
||||
var loader = newPackClassLoader(packRoot, jars, apiAndJdk);
|
||||
try {
|
||||
return new PackModules(createModules(jars, loader), loader);
|
||||
return new PackModules(createModules(jars, loader), missingClasses, loader);
|
||||
} catch (RuntimeException | Error failure) {
|
||||
closeAfterFailure(loader, failure);
|
||||
throw failure;
|
||||
@@ -101,6 +113,12 @@ public final class PackModules implements AutoCloseable {
|
||||
return new URLClassLoader("pack:" + packName(packRoot), urls, apiAndJdk);
|
||||
}
|
||||
|
||||
private static void logLoad(String packName, PackModules packModules) {
|
||||
LOGGER.log(Level.INFO, () -> PackModulesSummary.describe(packName, packModules.modules()));
|
||||
if (packModules.missingClasses().isEmpty()) return;
|
||||
LOGGER.log(Level.WARNING, () -> MissingClassesWarning.describe(packName, packModules.missingClasses()));
|
||||
}
|
||||
|
||||
private static String packName(Path packRoot) {
|
||||
var name = packRoot.getFileName();
|
||||
return name == null ? packRoot.toString() : name.toString();
|
||||
|
||||
Reference in new issue
Block a user