From 8921042fdb495a2d8054dc5219c41c68771274dd Mon Sep 17 00:00:00 2001 From: piexel Date: Sat, 10 Oct 2026 18:15:44 +0200 Subject: [PATCH] registerHeldType: a pack module may describe a class the host loads (an exposed package), not one of its own jar --- DESIGN.md | 6 ++++-- src/main/java/com/volmit/FeatureRegistry.java | 5 +++-- src/main/java/com/volmit/host/ModuleRegistry.java | 6 +++--- src/test/java/com/volmit/host/PackSchemaTest.java | 15 ++++++++++++++- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/DESIGN.md b/DESIGN.md index b4478d4bd..e9980b45e 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -650,9 +650,11 @@ core engine is modules as well. The host's own JSON fields are not in it; no key inlined copy, so a class used in many places is described once, and a class that contains itself, directly or through others, ends the walk at its own name. Two different classes with one name fail the load; only a built-in class and a pack class can collide that way. -- Built-in modules may also register a class that Iris's own classes hold (`registerHeldType`, `FeatureCatalog.heldTypes()`): +- Modules may also register a class that Iris's own classes hold (`registerHeldType`, `FeatureCatalog.heldTypes()`): it is described like any settings class reachable from a feature, but no `FeatureSchema` names it. This is for - settings that live in a host class until their feature owns them, such as the clamp of an object placement. + settings that live in a host class until their feature owns them, such as the clamp of an object placement. The class + must be loaded by the host: a built-in module's, or one of a package the host exposes (the built-ins jar's modules + register the classes of `art.arcane.iris.builtin`); a class from the registering pack module's own jar fails the load. - A `SchemaOption` per field that `OptionsMetadata` selects, which means instance fields that are not transient, inherited ones included, in declaration order. Each has its name, `ValueKind`, `@Desc`, `@Required`, `@MinNumber`/`@MaxNumber`, `@MinItems` and the default value. diff --git a/src/main/java/com/volmit/FeatureRegistry.java b/src/main/java/com/volmit/FeatureRegistry.java index 4d51e0f96..fa16f55f0 100644 --- a/src/main/java/com/volmit/FeatureRegistry.java +++ b/src/main/java/com/volmit/FeatureRegistry.java @@ -40,8 +40,9 @@ public interface FeatureRegistry { void registerSettings(Class settingsType); /** Describes a class that Iris's own classes hold, such as the clamp of an object placement, so studio shows - * its fields as this class declares them. Only built-in modules may register one: the host classes that hold - * the class are Iris's, so a pack module's class could never be a field of one. The host reads the class + * its fields as this class declares them. The class must be one the host loads: a built-in module's class, or a + * class of a package the host exposes to pack modules (a pack module's own classes could never be a field of + * one of the host's classes, so registering one fails the load). The host reads the class * with its fields in pack JSON, and the class follows the rules of settings classes. Registering a class twice * changes nothing. */ diff --git a/src/main/java/com/volmit/host/ModuleRegistry.java b/src/main/java/com/volmit/host/ModuleRegistry.java index 08ce94eb6..065ce288e 100644 --- a/src/main/java/com/volmit/host/ModuleRegistry.java +++ b/src/main/java/com/volmit/host/ModuleRegistry.java @@ -129,9 +129,9 @@ public final class ModuleRegistry implements FeatureRegistry { checkOpen(); Objects.requireNonNull(type, "type"); requireRegistering("Held type " + type.getName()); - if (registering.source() != DiscoveredModule.Source.HOST) { - throw new IllegalArgumentException("Held type " + type.getName() + " of module " + registering + " is registered by a" - + " pack module; only built-in modules may describe a class that Iris's own classes hold"); + if (registering.source() != DiscoveredModule.Source.HOST && type.getClassLoader() == registering.module().getClass().getClassLoader()) { + throw new IllegalArgumentException("Held type " + type.getName() + " of module " + registering + " is a class of the pack module's" + + " own jar; only a class the host loads, such as one of an exposed package, can be held by Iris's own classes"); } heldTypes.putIfAbsent(type, new HeldTypeRegistration(type, registering)); } diff --git a/src/test/java/com/volmit/host/PackSchemaTest.java b/src/test/java/com/volmit/host/PackSchemaTest.java index 964b0e995..99002fc9c 100644 --- a/src/test/java/com/volmit/host/PackSchemaTest.java +++ b/src/test/java/com/volmit/host/PackSchemaTest.java @@ -387,10 +387,23 @@ class PackSchemaTest { jar.writeInto(pack, "flora.jar"); var failure = assertThrows(IllegalArgumentException.class, () -> LoadedPack.load(pack, NO_BUILT_INS)); - assertTrue(failure.getMessage().contains("Held type pack.flora.Clamp") && failure.getMessage().contains("only built-in modules"), + assertTrue(failure.getMessage().contains("Held type pack.flora.Clamp") && failure.getMessage().contains("own jar"), failure.getMessage()); } + @Test + void packModulesMayDescribeAHostClassOfAnExposedPackage() { + var jar = module("pack.flora.FloraModule", FLORA, + "public void register(com.volmit.FeatureRegistry registry) { registry.registerHeldType(com.volmit.example.held.ClampSettings.class); }", NO_STAGES) + .compileAgainstHostOf(ClampSettings.class); + var pack = pack("held-exposed"); + jar.writeInto(pack, "flora.jar"); + + var schema = LoadedPack.load(pack, NO_BUILT_INS.exposing("com.volmit.example.held")).schema(); + + assertEquals("Limits a placement by height", schema.type(ClampSettings.class.getName()).description()); + } + @Test void packModulesCannotUseHostTypes() { var host = NO_BUILT_INS.exposing(HOST_TYPES).describingHostTypesIn(HOST_TYPES);