mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +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
@@ -135,7 +135,7 @@ class ChunkPipelineTest {
|
||||
|
||||
@Test
|
||||
void mantleStagesWriteBeyondTheirChunkAndChunkStagesReadTheirOwnPart() {
|
||||
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(new VeinModule())), Map.of(), Set.of(), Set.of(), Set.of());
|
||||
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(new VeinModule())), Map.of(), Set.of(), Set.of());
|
||||
var vein = new Entry<>(Target.BIOME, PLAINS, new VeinSettings(12, 4));
|
||||
int reach = loaded.mantle().stages().getFirst().reachBlocks(new DeclaredSettings(vein));
|
||||
assertEquals(3, reach, "a 12 block vein from the centre column runs 3 blocks into the next chunk");
|
||||
|
||||
@@ -202,7 +202,7 @@ class PlacementLifecyclePortTest {
|
||||
|
||||
@Test
|
||||
void loadingThePortCatalogsEveryConditioningSettingsType() {
|
||||
var loaded = LoadedModules.load(PlacementModules.builtIns(), Map.of(), Set.of(), Set.of(), Set.of());
|
||||
var loaded = LoadedModules.load(PlacementModules.builtIns(), Map.of(), Set.of(), Set.of());
|
||||
|
||||
assertEquals(List.of("example:moss", "iris:snow", "iris:stilt"),
|
||||
loaded.catalog().settings().stream().map(settings -> settings.id().toString()).toList());
|
||||
|
||||
@@ -30,7 +30,7 @@ class DiscoveredModuleTest {
|
||||
var module = new ShiftingIdentity();
|
||||
var discovered = DiscoveredModule.builtIn(module);
|
||||
|
||||
var loaded = LoadedModules.load(List.of(discovered), Map.of(), Set.of(), Set.of(), Set.of());
|
||||
var loaded = LoadedModules.load(List.of(discovered), Map.of(), Set.of(), Set.of());
|
||||
|
||||
assertEquals("first:core", discovered.info().id().toString());
|
||||
assertEquals(List.of("first:core/mark"),
|
||||
|
||||
@@ -19,8 +19,7 @@ class LoadedPackTest {
|
||||
private static final String NO_MEMBERS = "";
|
||||
private static final String NO_STAGES = "";
|
||||
private static final ModuleHost HOST = ModuleHost.of(List.of(new CarveModule()))
|
||||
.exposing(CarveModule.class.getPackageName())
|
||||
.reservingNamespaces("iris");
|
||||
.exposing(CarveModule.class.getPackageName());
|
||||
|
||||
@TempDir
|
||||
Path pack;
|
||||
@@ -72,11 +71,11 @@ class LoadedPackTest {
|
||||
|
||||
@Test
|
||||
void failedLoadLeavesNothingOpen() {
|
||||
writeModule("iris:stolen", NO_STAGES);
|
||||
writeModule("iris:carve", NO_STAGES);
|
||||
|
||||
var error = assertThrows(IllegalArgumentException.class, () -> LoadedPack.load(pack, HOST));
|
||||
|
||||
assertTrue(error.getMessage().contains("uses reserved namespace 'iris'"), error.getMessage());
|
||||
assertTrue(error.getMessage().contains("Duplicate module iris:carve"), error.getMessage());
|
||||
assertNotNull(packLoader(), "the module was constructed before installation failed");
|
||||
assertThrows(ClassNotFoundException.class, () -> packLoader().loadClass(UNUSED_CLASS));
|
||||
}
|
||||
@@ -85,7 +84,6 @@ class LoadedPackTest {
|
||||
void invalidHostConfigurationFailsWhenBuilt() {
|
||||
var host = ModuleHost.of(List.of());
|
||||
assertThrows(IllegalArgumentException.class, () -> host.exposing("org.*"));
|
||||
assertThrows(IllegalArgumentException.class, () -> host.reservingNamespaces("iris:core"));
|
||||
assertThrows(IllegalArgumentException.class, () -> host.reservingFields(Map.of(Target.BIOME, Set.of(" "))));
|
||||
assertEquals(List.of(), host.builtIns());
|
||||
assertEquals(Set.of(), host.exposedHostPackages());
|
||||
@@ -96,13 +94,10 @@ class LoadedPackTest {
|
||||
var host = ModuleHost.of(List.of())
|
||||
.exposing("example.first")
|
||||
.exposing("example.second")
|
||||
.reservingNamespaces("iris")
|
||||
.reservingNamespaces("vanilla")
|
||||
.reservingFields(Map.of(Target.BIOME, Set.of("carving"), Target.REGION, Set.of("spawns")))
|
||||
.reservingFields(Map.of(Target.BIOME, Set.of("objects")));
|
||||
|
||||
assertEquals(Set.of("example.first", "example.second"), host.exposedHostPackages());
|
||||
assertEquals(Set.of("iris", "vanilla"), host.reservedNamespaces());
|
||||
assertEquals(Map.of(Target.BIOME, Set.of("carving", "objects"), Target.REGION, Set.of("spawns")), host.reservedHostFields());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.volmit.host;
|
||||
|
||||
import com.volmit.support.TestModuleJar;
|
||||
import example.builtin.CarveModule;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.function.Executable;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import static com.volmit.support.TestModuleJar.module;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class ModuleJarCheckTest {
|
||||
private static final String NO_MEMBERS = "";
|
||||
private static final String NO_STAGES = "";
|
||||
private static final String USES_JUNIT = "static Object used() { return org.junit.jupiter.api.Test.class; }";
|
||||
private static final List<String> NO_EXPOSED_PACKAGES = List.of();
|
||||
|
||||
@TempDir
|
||||
Path build;
|
||||
|
||||
private static String failure(Executable check) {
|
||||
return assertThrows(IllegalArgumentException.class, check).getMessage();
|
||||
}
|
||||
|
||||
@Test
|
||||
void jarOfSeveralModulesPassesAndReturnsThemInListedOrder() {
|
||||
var jar = module("pack.First", "first:core", NO_MEMBERS, NO_STAGES)
|
||||
.alsoModule("pack.Second", "second:core", NO_MEMBERS, NO_STAGES)
|
||||
.writeInto(build, "two.jar");
|
||||
|
||||
assertEquals(List.of("pack.First", "pack.Second"), ModuleJarCheck.check(jar, NO_EXPOSED_PACKAGES));
|
||||
}
|
||||
|
||||
@Test
|
||||
void jarThatUsesAnExposedHostPackagePasses() {
|
||||
var jar = module("pack.User", "user:core", NO_MEMBERS,
|
||||
"graph.define(Stage.placement(\"user:core/carved\")).requires(example.builtin.CarveModule.CLEAR).run(context -> {});")
|
||||
.compileAgainstHostOf(CarveModule.class)
|
||||
.writeInto(build, "user.jar");
|
||||
|
||||
assertEquals(List.of("pack.User"), ModuleJarCheck.check(jar, List.of(CarveModule.class.getPackageName())));
|
||||
}
|
||||
|
||||
@Test
|
||||
void jarThatUsesAHiddenHostClassFailsNamingTheClass() {
|
||||
var jar = module("pack.User", "user:core", USES_JUNIT, NO_STAGES)
|
||||
.compileAgainstHostOf(Test.class)
|
||||
.writeInto(build, "user.jar");
|
||||
|
||||
var message = failure(() -> ModuleJarCheck.check(jar, NO_EXPOSED_PACKAGES));
|
||||
|
||||
assertTrue(message.contains("hidden from modules"), message);
|
||||
assertTrue(message.contains("pack.User -> org.junit.jupiter.api.Test"), message);
|
||||
}
|
||||
|
||||
@Test
|
||||
void jarThatUsesAHostClassItsHostDoesNotExposeFails() {
|
||||
var jar = module("pack.User", "user:core", NO_MEMBERS,
|
||||
"graph.define(Stage.placement(\"user:core/carved\")).requires(example.builtin.CarveModule.CLEAR).run(context -> {});")
|
||||
.compileAgainstHostOf(CarveModule.class)
|
||||
.writeInto(build, "user.jar");
|
||||
|
||||
var message = failure(() -> ModuleJarCheck.check(jar, NO_EXPOSED_PACKAGES));
|
||||
|
||||
assertTrue(message.contains("pack.User -> example.builtin.CarveModule"), message);
|
||||
}
|
||||
|
||||
@Test
|
||||
void moduleClassOutsideTheJarFailsNamingTheJarAndTheClass() {
|
||||
var jar = module("pack.User", "user:core", NO_MEMBERS, NO_STAGES)
|
||||
.entryPoint("pack.Elsewhere")
|
||||
.writeInto(build, "user.jar");
|
||||
|
||||
var message = failure(() -> ModuleJarCheck.check(jar, NO_EXPOSED_PACKAGES));
|
||||
|
||||
assertTrue(message.contains(jar.toString()), message);
|
||||
assertTrue(message.contains("lists pack.Elsewhere"), message);
|
||||
}
|
||||
|
||||
@Test
|
||||
void jarThatListsNoModuleFails() {
|
||||
var jar = new TestModuleJar().source("pack.Plain", "package pack; public final class Plain {}").writeInto(build, "plain.jar");
|
||||
|
||||
assertTrue(failure(() -> ModuleJarCheck.check(jar, NO_EXPOSED_PACKAGES)).contains("has no entry point"));
|
||||
}
|
||||
}
|
||||
@@ -130,14 +130,14 @@ class ModuleRegistryTest {
|
||||
public void install(StageGraph graph) { graph.define(WORK).when(One.class).run((context, one) -> {}); }
|
||||
public void register(FeatureRegistry registry) { registry.registerObject(Two.class, ignored -> context -> null); }
|
||||
};
|
||||
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(conditioned)), Map.of(), Set.of(), Set.of(), Set.of());
|
||||
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(conditioned)), Map.of(), Set.of(), Set.of());
|
||||
assertEquals(List.of("test:core/one"), loaded.catalog().settings().stream().map(value -> value.id().toString()).toList());
|
||||
assertEquals(1, loaded.catalog().objects().size());
|
||||
assertEquals(1, loaded.placement().stages().size());
|
||||
assertTrue(loaded.chunk().stages().isEmpty());
|
||||
|
||||
var reserved = Map.of(FeatureAttachment.Target.BIOME, Set.of("shared"));
|
||||
assertThrows(IllegalArgumentException.class, () -> LoadedModules.load(List.of(DiscoveredModule.builtIn(conditioned)), reserved, Set.of(), Set.of(), Set.of()));
|
||||
assertThrows(IllegalArgumentException.class, () -> LoadedModules.load(List.of(DiscoveredModule.builtIn(conditioned)), reserved, Set.of(), Set.of()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -182,11 +182,11 @@ class ModuleRegistryTest {
|
||||
public void install(StageGraph graph) { graph.define(WORK).when(One.class).run((context, one) -> {}); }
|
||||
};
|
||||
|
||||
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(owner), DiscoveredModule.builtIn(user)), Map.of(), Set.of(), Set.of(), Set.of());
|
||||
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(owner), DiscoveredModule.builtIn(user)), Map.of(), Set.of(), Set.of());
|
||||
assertEquals(List.of("test:core/one"), loaded.catalog().settings().stream().map(value -> value.id().toString()).toList());
|
||||
|
||||
var unowned = assertThrows(IllegalArgumentException.class,
|
||||
() -> LoadedModules.load(List.of(DiscoveredModule.builtIn(user)), Map.of(), Set.of(), Set.of(), Set.of()));
|
||||
() -> LoadedModules.load(List.of(DiscoveredModule.builtIn(user)), Map.of(), Set.of(), Set.of()));
|
||||
assertTrue(unowned.getMessage().contains("which none of the modules naming it in when(...) owns"), unowned.getMessage());
|
||||
}
|
||||
|
||||
|
||||
@@ -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())));
|
||||
}
|
||||
}
|
||||
@@ -478,7 +478,7 @@ class StageGraphTest {
|
||||
stages.define(plain).run(context -> {});
|
||||
stages.define(paint).reach(2).run(context -> {});
|
||||
});
|
||||
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(withMantle(reach, depth, marks))), Map.of(), Set.of(), Set.of(), Set.of());
|
||||
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(withMantle(reach, depth, marks))), Map.of(), Set.of(), Set.of());
|
||||
|
||||
assertEquals(new StageReach(24, List.of(depth)), loaded.mantle().stages().getFirst().reach());
|
||||
assertEquals(StageReach.NONE, loaded.mantle().stages().get(2).reach(), "an undeclared reach is 0 with no layers");
|
||||
@@ -496,7 +496,7 @@ class StageGraphTest {
|
||||
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(module("test:reach", stages -> {
|
||||
stages.define(carve).reach(settings -> settings.declared(Toggle.class).isEmpty() ? 4 : 40).run(context -> {});
|
||||
stages.define(mark).reach(2).run(context -> {});
|
||||
}))), Map.of(), Set.of(), Set.of(), Set.of());
|
||||
}))), Map.of(), Set.of(), Set.of());
|
||||
var computed = loaded.mantle().stages().getFirst();
|
||||
var toggled = new DeclaredSettings(new Entry<>(FeatureAttachment.Target.DIMENSION, ResourceId.parse("pack:dimension/main"), new Toggle()));
|
||||
|
||||
@@ -512,7 +512,7 @@ class StageGraphTest {
|
||||
@Test
|
||||
void onlyMantleStagesWorkOutTheirReachAndNeverANegativeOne() {
|
||||
var negative = LoadedModules.load(List.of(DiscoveredModule.builtIn(module("test:reach", stages ->
|
||||
stages.define(Stage.mantle("test:reach/carve")).reach(settings -> -1).run(context -> {})))), Map.of(), Set.of(), Set.of(), Set.of());
|
||||
stages.define(Stage.mantle("test:reach/carve")).reach(settings -> -1).run(context -> {})))), Map.of(), Set.of(), Set.of());
|
||||
var failure = assertThrows(IllegalStateException.class, () -> negative.mantle().stages().getFirst().reachBlocks(DeclaredSettings.NONE));
|
||||
assertEquals("Stage test:reach/carve of module test:reach worked out a negative reach of -1 blocks for this pack", failure.getMessage());
|
||||
|
||||
@@ -567,13 +567,13 @@ class StageGraphTest {
|
||||
module("test:reach", stages -> stages.define(carve).writesMantle(depth, depth).run(context -> {}))));
|
||||
|
||||
var unregistered = assertThrows(IllegalArgumentException.class, () -> LoadedModules.load(List.of(DiscoveredModule.builtIn(
|
||||
module("test:reach", stages -> stages.define(carve).writesMantle(depth).run(context -> {})))), Map.of(), Set.of(), Set.of(), Set.of()));
|
||||
module("test:reach", stages -> stages.define(carve).writesMantle(depth).run(context -> {})))), Map.of(), Set.of(), Set.of()));
|
||||
assertEquals("Stage test:reach/carve of module test:reach writes mantle layer test:reach/depth, which no module registers;"
|
||||
+ " its owner registers it with FeatureRegistry.registerMantle", unregistered.getMessage());
|
||||
|
||||
var asText = new MantleKey<>("test:reach/depth", String.class);
|
||||
var mismatch = assertThrows(IllegalArgumentException.class, () -> LoadedModules.load(List.of(DiscoveredModule.builtIn(withMantle(
|
||||
module("test:reach", stages -> stages.define(carve).writesMantle(asText).run(context -> {})), depth))), Map.of(), Set.of(), Set.of(), Set.of()));
|
||||
module("test:reach", stages -> stages.define(carve).writesMantle(asText).run(context -> {})), depth))), Map.of(), Set.of(), Set.of()));
|
||||
assertEquals("Stage test:reach/carve of module test:reach writes mantle layer test:reach/depth as java.lang.String,"
|
||||
+ " but it is registered as java.lang.Integer", mismatch.getMessage());
|
||||
}
|
||||
|
||||
@@ -49,6 +49,12 @@ public final class TestModuleJar {
|
||||
return new TestModuleJar().source(className, moduleSource(className, info, members, install)).entryPoint(className);
|
||||
}
|
||||
|
||||
/** Another entry class in the same jar, with the given module id; see {@link #module(String, String, String, String)}. */
|
||||
public TestModuleJar alsoModule(String className, String moduleId, String members, String install) {
|
||||
var info = moduleInfo(moduleId, List.of());
|
||||
return source(className, moduleSource(className, info, members, install)).entryPoint(className);
|
||||
}
|
||||
|
||||
/** Compiles one class on its own and returns its class file, for raw entries such as versioned classes. */
|
||||
public static byte[] compileClass(Path workDirectory, String className, String code) {
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user