mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 16:25:36 +00:00
Stop reserving namespaces, let a jar list several modules and add ModuleJarCheck for builds that write module jars
ReservedNamespaces and ModuleHost.reservingNamespaces are gone: a pack module may use any namespace, iris included. A module id is still loaded once, and the duplicate error now names the origin and class of both modules, so two modules of one jar can be told apart. A jar lists one module class per line in META-INF/services/com.volmit.IrisModule and loads all of them in that order; each class must still be defined in the jar. A jar with several modules is excused by the optional packages of all of them. ModuleJarCheck runs the load's class checks on one jar without loading it.
This commit is contained in:
1 parent
ef4b640867
commit
42d31a9ce4
21 files changed
+330
-208
No files matched your search
@@ -2,6 +2,7 @@ package com.volmit.host;
|
||||
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.example.placement.AnchorModule;
|
||||
import com.volmit.example.placement.MossModule;
|
||||
import com.volmit.example.placement.PlacementModules;
|
||||
import com.volmit.support.TestModuleJar;
|
||||
import example.builtin.CarveModule;
|
||||
@@ -32,8 +33,6 @@ class PackModulesTest {
|
||||
private static final String REQUIRES_BUILT_IN_STAGE =
|
||||
"graph.define(Stage.placement(\"user:core/carved\")).requires(example.builtin.CarveModule.CLEAR).run(context -> {});";
|
||||
|
||||
private static final Set<String> RESERVED_NAMESPACES = Set.of("iris");
|
||||
|
||||
@TempDir
|
||||
Path pack;
|
||||
|
||||
@@ -44,7 +43,7 @@ class PackModulesTest {
|
||||
private static LoadedModules loadWithBuiltIns(PackModules packModules) {
|
||||
var modules = new ArrayList<>(PlacementModules.builtIns());
|
||||
modules.addAll(packModules.modules());
|
||||
return LoadedModules.load(modules, Map.of(), Set.of(), Set.of(), Set.of());
|
||||
return LoadedModules.load(modules, Map.of(), Set.of(), Set.of());
|
||||
}
|
||||
|
||||
/** Versioned entries of a multi-release jar are read like any class, so they must be real class files. */
|
||||
@@ -145,14 +144,50 @@ class PackModulesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void jarNamingSeveralEntryPointsFails() {
|
||||
void jarNamingSeveralEntryPointsLoadsEachModuleInListedOrder() {
|
||||
module("pack.First", "first:core", NO_MEMBERS, NO_STAGES)
|
||||
.source("pack.Second", "package pack; public final class Second {}")
|
||||
.entryPoint("pack.Second")
|
||||
.alsoModule("pack.Second", "second:core", NO_MEMBERS, NO_STAGES)
|
||||
.writeInto(pack, "two.jar");
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
assertEquals(List.of("first:core", "second:core"),
|
||||
packModules.modules().stream().map(found -> found.info().id().toString()).toList());
|
||||
assertEquals(List.of(origin("two.jar"), origin("two.jar")),
|
||||
packModules.modules().stream().map(DiscoveredModule::origin).toList());
|
||||
assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void secondEntryPointOfAJarThatBreaksNamesItsClass() {
|
||||
module("pack.First", "first:core", NO_MEMBERS, NO_STAGES)
|
||||
.entryPoint("pack.Missing")
|
||||
.writeInto(pack, "two.jar");
|
||||
|
||||
assertMentions(failure(() -> PackModules.load(pack)),
|
||||
"Module jar " + origin("two.jar") + " names 2 entry points [pack.First, pack.Second]");
|
||||
"Module jar " + origin("two.jar") + " has a broken entry point pack.Missing: class cannot be loaded");
|
||||
}
|
||||
|
||||
@Test
|
||||
void entryPointOfAnotherJarFailsNamingTheJarThatListsIt() {
|
||||
module("pack.First", "first:core", NO_MEMBERS, NO_STAGES).writeInto(pack, "first.jar");
|
||||
new TestModuleJar().entryPoint("pack.First").writeInto(pack, "second.jar");
|
||||
|
||||
assertMentions(failure(() -> PackModules.load(pack)),
|
||||
"Module jar " + origin("second.jar") + " has a broken entry point pack.First",
|
||||
"loaded from " + origin("first.jar") + ", not from this jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
void optionalPackagesOfAnyModuleOfAJarExcuseItsMissingClasses(@TempDir Path build) {
|
||||
module("pack.First", "first:core", List.of("org.optional"), NO_MEMBERS, NO_STAGES)
|
||||
.alsoModule("pack.Second", "second:core", using(OPTIONAL_CLASS), NO_STAGES)
|
||||
.compileAgainst(library(build, "optional.jar", OPTIONAL_CLASS))
|
||||
.writeInto(pack, "two.jar");
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
assertEquals(List.of(), packModules.missingClasses());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -343,7 +378,7 @@ class PackModulesTest {
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
assertEquals(List.of(new MissingClasses(origin("user.jar"), List.of(OPTIONAL_CLASS))), packModules.missingClasses());
|
||||
assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of(), Set.of()));
|
||||
assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -477,7 +512,7 @@ class PackModulesTest {
|
||||
.writeInto(pack, "beta.jar");
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
var loaded = LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of(), Set.of());
|
||||
var loaded = LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of());
|
||||
assertTrue(loaded.placement().stages().stream().anyMatch(stage -> stage.stage().id().toString().equals("beta:core/size")));
|
||||
var beta = packModules.modules().getLast().module().getClass();
|
||||
assertEquals(0, beta.getDeclaredField("SHARED").getAnnotations().length,
|
||||
@@ -494,7 +529,7 @@ class PackModulesTest {
|
||||
try (var packModules = PackModules.load(pack, List.of(BUILT_IN_PACKAGE))) {
|
||||
var modules = new ArrayList<>(List.of(DiscoveredModule.builtIn(new CarveModule())));
|
||||
modules.addAll(packModules.modules());
|
||||
var order = LoadedModules.load(modules, Map.of(), Set.of(), Set.of(), Set.of()).placement().stages().stream()
|
||||
var order = LoadedModules.load(modules, Map.of(), Set.of(), Set.of()).placement().stages().stream()
|
||||
.map(stage -> stage.stage().id().toString()).toList();
|
||||
assertEquals(List.of("iris:carve/clear", "user:core/carved"), order);
|
||||
}
|
||||
@@ -572,7 +607,7 @@ class PackModulesTest {
|
||||
.writeInto(pack, "once.jar");
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
var loaded = assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of(), Set.of()));
|
||||
var loaded = assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of()));
|
||||
assertEquals("once:core", packModules.modules().getFirst().info().id().toString());
|
||||
assertEquals(1, loaded.placement().stages().size());
|
||||
}
|
||||
@@ -591,7 +626,7 @@ class PackModulesTest {
|
||||
.writeInto(pack, "beta.jar");
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of(), Set.of())),
|
||||
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of())),
|
||||
"Module beta:core from " + origin("beta.jar") + " failed to link or initialize a class while installing",
|
||||
"java.lang.NoSuchMethodError", "pack.lib.Lib.added()");
|
||||
}
|
||||
@@ -603,8 +638,9 @@ class PackModulesTest {
|
||||
module("pack.two.Duplicate", "dup:core", NO_MEMBERS, NO_STAGES).writeInto(pack, "two.jar");
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of(), Set.of())),
|
||||
"Duplicate module dup:core from " + origin("two.jar") + "; already loaded from " + origin("one.jar"));
|
||||
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of())),
|
||||
"Duplicate module dup:core from " + origin("two.jar") + " (pack.two.Duplicate); already loaded from "
|
||||
+ origin("one.jar") + " (pack.one.Duplicate)");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -614,7 +650,8 @@ class PackModulesTest {
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
assertMentions(failure(() -> loadWithBuiltIns(packModules)),
|
||||
"Duplicate module example:moss from " + origin("moss.jar") + "; already loaded from host classpath");
|
||||
"Duplicate module example:moss from " + origin("moss.jar") + " (pack.Moss); already loaded from host classpath ("
|
||||
+ MossModule.class.getName() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -625,42 +662,32 @@ class PackModulesTest {
|
||||
.writeInto(pack, "foreign.jar");
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of(), Set.of())),
|
||||
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of())),
|
||||
"Stage mine:other/work must start with mine:core/, the id of its defining module mine:core from " + origin("foreign.jar"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void packModuleInAReservedNamespaceFailsNamingTheJarAndTheNamespace() {
|
||||
void duplicateModuleIdWithinOneJarFailsNamingBothClasses() {
|
||||
module("pack.One", "dup:core", NO_MEMBERS, NO_STAGES)
|
||||
.alsoModule("pack.Two", "dup:core", NO_MEMBERS, NO_STAGES)
|
||||
.writeInto(pack, "both.jar");
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of())),
|
||||
"Duplicate module dup:core from " + origin("both.jar") + " (pack.Two); already loaded from "
|
||||
+ origin("both.jar") + " (pack.One)");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void packModuleMayUseAnyNamespaceIncludingIris() {
|
||||
module("pack.Stilt", "iris:stilt", NO_MEMBERS,
|
||||
"graph.define(Stage.placement(\"iris:stilt/fill\")).run(context -> {});")
|
||||
.writeInto(pack, "stilt.jar");
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
assertEquals("Module iris:stilt from " + origin("stilt.jar") + " uses reserved namespace 'iris', which only "
|
||||
+ "modules that ship with the host may use; give the module a namespace of its own, which its stages, "
|
||||
+ "settings ids and mantle keys then use too",
|
||||
failure(() -> LoadedModules.load(packModules.modules(), Map.of(), RESERVED_NAMESPACES, Set.of(), Set.of())));
|
||||
assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of(), Set.of()));
|
||||
assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void builtInModulesMayUseReservedNamespaces() {
|
||||
module("pack.user.User", "user:core", NO_MEMBERS, REQUIRES_BUILT_IN_STAGE)
|
||||
.compileAgainstHostOf(CarveModule.class)
|
||||
.writeInto(pack, "user.jar");
|
||||
|
||||
try (var packModules = PackModules.load(pack, List.of(BUILT_IN_PACKAGE))) {
|
||||
var modules = new ArrayList<>(List.of(DiscoveredModule.builtIn(new CarveModule())));
|
||||
modules.addAll(packModules.modules());
|
||||
assertDoesNotThrow(() -> LoadedModules.load(modules, Map.of(), RESERVED_NAMESPACES, Set.of(), Set.of()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidReservedNamespaceFails() {
|
||||
assertEquals("Reserved namespace 'iris:core' is not a namespace; name one such as iris, without ':' or a path",
|
||||
failure(() -> LoadedModules.load(List.of(), Map.of(), Set.of("iris:core"), Set.of(), Set.of())));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user