mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Add module display names, reject duplicate pack classes, log pack modules
ModuleInfo gains a required, non-blank display name next to id and version: ModuleInfo.of(id, name, version). PackModules now fails when a class is in two jars of one pack, naming the class and both jars. ModuleJar indexes class names while it reads the entry point, so the check runs before the pack class loader exists and nothing is half-loaded. Jars are read with the runtime's multi-release version, like the loader reads them: a versioned class counts once under its base name; module-info.class and anything under META-INF/ are ignored. A successful load logs one INFO summary through System.Logger with the display name, id, version and jar of each module, or a line saying the pack has no module jars. PackModulesSummary builds the text and is tested without a logging backend.
This commit is contained in:
1 parent
4fa6ddcd7a
commit
b137bc6d92
19 files changed
+328
-53
No files matched your search
@@ -18,6 +18,10 @@ class PackModulesTest {
|
||||
"public static final PlacementStage<Void> MARK = Stage.placement(\"alpha:core/mark\");";
|
||||
private static final String NO_MEMBERS = "";
|
||||
private static final String NO_STAGES = "";
|
||||
private static final String SHARED_CLASS = "pack.shared.Util";
|
||||
private static final String SHARED_SOURCE = "package pack.shared; public final class Util {}";
|
||||
private static final byte[] UNUSED_CLASS_BYTES = {(byte) 0xCA, (byte) 0xFE};
|
||||
private static final String DEFINED_PROPERTY = "irisapi.test.packModuleConstructed";
|
||||
|
||||
@TempDir
|
||||
Path pack;
|
||||
@@ -133,6 +137,76 @@ class PackModulesTest {
|
||||
"not from this jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
void sameClassInTwoJarsFailsBeforeAnyModuleIsConstructed() {
|
||||
var constructorMarker = "public %s() { System.setProperty(\"" + DEFINED_PROPERTY + "\", \"true\"); }";
|
||||
module("pack.alpha.Alpha", "alpha:core", constructorMarker.formatted("Alpha"), NO_STAGES)
|
||||
.source(SHARED_CLASS, SHARED_SOURCE).writeInto(pack, "alpha.jar");
|
||||
module("pack.beta.Beta", "beta:core", constructorMarker.formatted("Beta"), NO_STAGES)
|
||||
.source(SHARED_CLASS, SHARED_SOURCE).writeInto(pack, "beta.jar");
|
||||
|
||||
try {
|
||||
assertMentions(failure(() -> PackModules.load(pack)),
|
||||
"Class " + SHARED_CLASS + " is in both module jars " + origin("alpha.jar") + " and " + origin("beta.jar"));
|
||||
assertNull(System.getProperty(DEFINED_PROPERTY), "a module was constructed before the duplicate was found");
|
||||
} finally {
|
||||
System.clearProperty(DEFINED_PROPERTY);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void moduleDescriptorsMayRepeatAcrossJars() {
|
||||
module("pack.alpha.Alpha", "alpha:core", NO_MEMBERS, NO_STAGES)
|
||||
.resource("module-info.class", UNUSED_CLASS_BYTES).writeInto(pack, "alpha.jar");
|
||||
module("pack.beta.Beta", "beta:core", NO_MEMBERS, NO_STAGES)
|
||||
.resource("module-info.class", UNUSED_CLASS_BYTES).writeInto(pack, "beta.jar");
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
assertEquals(2, packModules.modules().size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void versionedClassOfAMultiReleaseJarCountsUnderItsBaseName() {
|
||||
module("pack.alpha.Alpha", "alpha:core", NO_MEMBERS, NO_STAGES)
|
||||
.source(SHARED_CLASS, SHARED_SOURCE).writeInto(pack, "alpha.jar");
|
||||
module("pack.beta.Beta", "beta:core", NO_MEMBERS, NO_STAGES)
|
||||
.multiRelease()
|
||||
.resource("META-INF/versions/9/pack/shared/Util.class", UNUSED_CLASS_BYTES)
|
||||
.writeInto(pack, "beta.jar");
|
||||
|
||||
assertMentions(failure(() -> PackModules.load(pack)),
|
||||
"Class " + SHARED_CLASS + " is in both module jars " + origin("alpha.jar") + " and " + origin("beta.jar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void versionedEntriesOutsideAMultiReleaseJarAreNotClasses() {
|
||||
module("pack.alpha.Alpha", "alpha:core", NO_MEMBERS, NO_STAGES)
|
||||
.source(SHARED_CLASS, SHARED_SOURCE)
|
||||
.resource("META-INF/versions/9/pack/shared/Util.class", UNUSED_CLASS_BYTES)
|
||||
.writeInto(pack, "alpha.jar");
|
||||
module("pack.beta.Beta", "beta:core", NO_MEMBERS, NO_STAGES)
|
||||
.resource("META-INF/versions/9/pack/shared/Util.class", UNUSED_CLASS_BYTES)
|
||||
.writeInto(pack, "beta.jar");
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
assertEquals(2, packModules.modules().size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void multiReleaseJarMayHoldAVersionedCopyOfItsOwnClass() {
|
||||
module("pack.alpha.Alpha", "alpha:core", NO_MEMBERS, NO_STAGES)
|
||||
.source(SHARED_CLASS, SHARED_SOURCE)
|
||||
.multiRelease()
|
||||
.resource("META-INF/versions/9/pack/shared/Util.class", UNUSED_CLASS_BYTES)
|
||||
.writeInto(pack, "alpha.jar");
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
assertEquals(1, packModules.modules().size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void duplicateModuleIdsAcrossJarsFailNamingBothJars() {
|
||||
module("pack.one.Duplicate", "dup:core", NO_MEMBERS, NO_STAGES).writeInto(pack, "one.jar");
|
||||
|
||||
Reference in new issue
Block a user