mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Document exposed host packages and optional pack dependencies
README, DESIGN and CONTRACTS now say that modules may use any library they ship in the pack but never Iris's copy, that classes nobody has only warn, how each missing reference is classified, and that the host chooses which packages besides the always-exposed API pack modules can see, meant for built-in modules' stage constants.
This commit is contained in:
1 parent
13a9300ab4
commit
3873894a22
3 files changed
+141
-79
No files matched your search
+13
-7
@@ -8,7 +8,7 @@ types that carry them and lists what the Iris adapter still owes.
|
||||
| Requirement | Contract |
|
||||
| --- | --- |
|
||||
| Module identity and composition | `IrisModule`, `ModuleInfo`, `StageGraph` |
|
||||
| Module jars in a pack | `META-INF/services/com.volmit.IrisModule`, host `PackModules`, `DiscoveredModule` |
|
||||
| Module jars in a pack | `META-INF/services/com.volmit.IrisModule`, host `PackModules`, `DiscoveredModule`, `MissingClasses` |
|
||||
| Module-owned work and ordering | `Stage`, `StageRef`, stage definitions, `requires`/`softAfter`/`softBefore` |
|
||||
| Activation by configuration | `when(settingsType)`, host `ConfiguredSettings` |
|
||||
| Typed results between modules | stage outputs, `StageContext.output` |
|
||||
@@ -28,9 +28,11 @@ types that carry them and lists what the Iris adapter still owes.
|
||||
Stage bodies hold no invocation state. Everything per placement or chunk travels through the
|
||||
context, outputs and accumulators.
|
||||
|
||||
Modules compile against the API `compileOnly` and never ship it. At runtime they can use only the
|
||||
API (`com.volmit.*`), the JDK and the classes in their own pack's jars; anything else fails the
|
||||
pack load, naming the jar and the classes.
|
||||
Modules compile against the API `compileOnly` and never ship it. At runtime they can use the API
|
||||
(`com.volmit.*`), the host packages the host chooses to expose, the JDK and the classes in their
|
||||
own pack's jars. They may use any library they ship in the pack, never Iris's copy. A class Iris has
|
||||
but hides, or one missing from an exposed package, fails the pack load, naming the jar and the
|
||||
classes. A class nobody has (an optional dependency) only warns.
|
||||
|
||||
There is no API version gating. Packs ship their module jars, so their compatibility with the
|
||||
running Iris is the pack publisher's responsibility.
|
||||
@@ -50,11 +52,15 @@ running Iris is the pack publisher's responsibility.
|
||||
- Load each pack's jars with `PackModules`, pass them with the built-in modules to
|
||||
`LoadedModules.load`, and close `PackModules` only after nothing built from it is in use.
|
||||
- Route `System.Logger` output (logger `com.volmit.host.PackModules`) to the server log, so the
|
||||
per-pack module summary is visible.
|
||||
per-pack module summary and missing-classes warning are visible.
|
||||
- Provide the API at runtime from the plugin's class loader, for example by shading it into the
|
||||
Iris plugin jar. Pack jars must not ship it.
|
||||
- Pack jars see only `com.volmit.` classes of that loader. Built-in modules whose stages packs may
|
||||
require must be in such a package on that loader, or pack jars cannot require their stages.
|
||||
- Pass the packages of built-in modules whose stages packs may require to
|
||||
`PackModules.load(packRoot, exposedHostPackages)`. They must be on the loader that defines the
|
||||
API. Keep them narrow: everything in an exposed package and its subpackages becomes visible to
|
||||
packs and is part of what packs can break on. Stage output types and settings types that pack
|
||||
code uses through those stages must be in exposed packages too. The API is always exposed.
|
||||
- Consider showing `PackModules.missingClasses()` in studio.
|
||||
|
||||
## Open
|
||||
|
||||
|
||||
@@ -48,25 +48,28 @@ which jar a broken provider came from. The rejected alternatives:
|
||||
- A descriptor file with id and version. It duplicates `info()`, so the two can disagree, and
|
||||
parsing it needs a format the JDK does not ship.
|
||||
|
||||
`PackModules.load(packRoot)`:
|
||||
`PackModules.load(packRoot, exposedHostPackages)` (or `load(packRoot)`, which exposes only the
|
||||
API):
|
||||
|
||||
1. Lists regular files ending in `.jar` in `<pack>/modules`, sorted by file name. A missing
|
||||
1. Validates the exposed packages. The API's package is always one of them.
|
||||
2. Lists regular files ending in `.jar` in `<pack>/modules`, sorted by file name. A missing
|
||||
directory means no modules.
|
||||
2. Reads each jar's entry point file and its class files. Comments (`#`) and blank lines are
|
||||
ignored; zero or more than one entry class name fails. A class in a `com.volmit.` package
|
||||
fails, naming the jar and the first such class.
|
||||
3. Fails if a class is in two jars, naming the class and both jars.
|
||||
4. Fails if a class uses a class that is not in the API, the JDK or a jar of the pack, listing
|
||||
each referencing and referenced class per jar. Nothing has been defined up to here.
|
||||
5. Creates one `URLClassLoader` for all jars of the pack, parent = `ApiAndJdkClassLoader`.
|
||||
6. Loads each entry class, checks that it implements `IrisModule` and comes from its own jar,
|
||||
3. Reads each jar's entry point file and its class files. Comments (`#`) and blank lines are
|
||||
ignored; zero or more than one entry class name fails.
|
||||
4. Fails if a jar holds a class of an exposed package, naming the jar and the first such class.
|
||||
5. Fails if a class is in two jars, naming the class and both jars.
|
||||
6. Resolves every class each class uses (see below). A class that Iris has but hides, or that is
|
||||
missing from an exposed package, fails the load, listing each referencing and referenced class
|
||||
per jar. Classes that nobody has are collected per jar. Nothing has been defined up to here.
|
||||
7. Creates one `URLClassLoader` for all jars of the pack, parent = `ExposedHostClassLoader`.
|
||||
8. Loads each entry class, checks that it implements `IrisModule` and comes from its own jar,
|
||||
instantiates it with the public no-argument constructor and calls `info()`.
|
||||
7. Logs one INFO summary of the pack's modules.
|
||||
9. Logs one INFO summary of the pack's modules, and one WARNING if any classes are missing.
|
||||
|
||||
One loader per pack, not per jar, because `requires(...)` takes another module's stage constant.
|
||||
A pack jar that requires a stage of another pack jar must see its classes. Packs stay isolated
|
||||
from each other. The cost is a shared class namespace: with two copies of a class, the loader
|
||||
would silently use the one first in file name order. Step 3 turns that into a load error, so two
|
||||
would silently use the one first in file name order. Step 5 turns that into a load error, so two
|
||||
jars that shade the same library must relocate it, and shared code belongs in one module that the
|
||||
others require.
|
||||
|
||||
@@ -78,48 +81,73 @@ loader never reads `META-INF/versions`, so those entries are skipped.
|
||||
|
||||
### What a module can see
|
||||
|
||||
Modules depend only on the Iris API. They compile against it `compileOnly` and never ship it,
|
||||
because Iris provides it at runtime; in production it is shaded into the Iris plugin jar. The
|
||||
loader that defines the API therefore also sees Iris internals and the libraries Iris bundles, so
|
||||
it is not the pack loader's parent. `ApiAndJdkClassLoader` is: it delegates every class in a
|
||||
package starting with `com.volmit.` (`API_PACKAGE_PREFIX`) to the API's loader and everything else
|
||||
to the platform class loader, which holds the JDK. A module can use only the API, the JDK and the
|
||||
classes of its own pack's jars. The api/host split is deferred, so `com.volmit.host` is visible
|
||||
too.
|
||||
Modules depend on the Iris API. They compile against it `compileOnly` and never ship it, because
|
||||
Iris provides it at runtime; in production it is shaded into the Iris plugin jar. That loader also
|
||||
holds Iris internals and the libraries Iris bundles, so it is not the pack loader's parent.
|
||||
`ExposedHostClassLoader` is: it delegates every class in an exposed package, and its subpackages,
|
||||
to the host's loader (the loader that defines the API) and everything else to the platform class
|
||||
loader, which holds the JDK. The api/host split is deferred, so `com.volmit.host` is visible too.
|
||||
|
||||
Resources follow the same rule by path: `com/volmit/...` from the API's loader, everything else
|
||||
from the platform loader, then the pack's jars. A class and its class file come from the same
|
||||
place, and a pack never sees Iris's own resources such as `plugin.yml` or its service files.
|
||||
The exposed packages (`ExposedPackages`) are the API's package, `com.volmit` (the package of
|
||||
`IrisModule`), plus whatever the host passes to `PackModules.load`. The host decides those; the
|
||||
intended use is the packages that hold built-in modules' stage constants, so that a pack jar can
|
||||
`requires(...)` a stage of the core engine or a built-in feature. A pack jar then links against
|
||||
the host's class and the same stage constant, which resolution requires: a copy would be a second
|
||||
definition of the id. Names match whole packages: `com.volmit` does not expose `com.volmitx`. A
|
||||
trailing dot is accepted; anything that is not a package name, such as a blank string or a
|
||||
wildcard, is rejected.
|
||||
|
||||
The pack loader asks its parent first, so a packaged copy of an API class would be silently
|
||||
replaced by the host's, and a module class in a `com.volmit.` package could be replaced by a
|
||||
later API class of the same name. Step 2 rejects both; the prefix belongs to the API. A module
|
||||
class that shares a name with an Iris internal is harmless, because the pack loader cannot see
|
||||
Iris internals. A module class that shares a name with a JDK class is replaced by the JDK's; that
|
||||
is not checked.
|
||||
A module may use any library, but it ships that library itself, inside its own jar or as another
|
||||
jar of the pack. It never borrows Iris's copy: Iris's libraries can change with any Iris update,
|
||||
and two modules would otherwise depend on whatever version Iris happens to bundle.
|
||||
|
||||
Step 4 reads every class file with the JDK's `java.lang.classfile` API. A class uses every class
|
||||
Resources follow the same rule by path: `com/volmit/...` and the paths of other exposed packages
|
||||
from the host's loader, everything else from the platform loader, then the pack's jars. A class
|
||||
and its class file come from the same place, and a pack never sees Iris's own resources such as
|
||||
`plugin.yml` or its service files.
|
||||
|
||||
The pack loader asks its parent first, so a packaged copy of a host class would be silently
|
||||
replaced by the host's, and a module class in an exposed package could be replaced by a later host
|
||||
class of the same name. Step 4 rejects both; exposed packages belong to the host. For the API the
|
||||
message points at `compileOnly`, the usual cause. A module class that shares a name with a hidden
|
||||
Iris internal is harmless, because the pack loader cannot see it. A module class that shares a name
|
||||
with a JDK class is replaced by the JDK's; that is not checked.
|
||||
|
||||
Step 6 reads every class file with the JDK's `java.lang.classfile` API. A class uses every class
|
||||
in its constant pool (supertypes, and instantiated, cast, caught, called-on and class-literal
|
||||
types) and every type in the descriptors of its own fields and methods and of the members and
|
||||
call sites it uses. Arrays count as their element type; primitives do not count. A class counts
|
||||
as present when the pack has it or the parent has its class file, so nothing is loaded or
|
||||
initialized by the check. Annotations and generic signatures are left out: the JVM never resolves
|
||||
them while linking, and reflection skips an annotation whose type is missing, so a `compileOnly`
|
||||
annotation library such as JetBrains annotations needs nothing at runtime.
|
||||
call sites it uses. Arrays count as their element type; primitives do not count. Annotations and
|
||||
generic signatures are left out: the JVM never resolves them while linking, and reflection skips an
|
||||
annotation whose type is missing, so a `compileOnly` annotation library such as JetBrains
|
||||
annotations needs nothing at runtime. Each used class outside the pack is judged by its class
|
||||
file, so nothing is loaded or initialized:
|
||||
|
||||
The check is stricter than the JVM, which resolves a class only when code first uses it. A
|
||||
shaded library with optional dependencies that are absent from the pack is therefore rejected,
|
||||
even if those code paths would never run; the jar must leave such classes out or ship the
|
||||
dependency. In exchange, a missing class shows up at load, with the jar and both class names,
|
||||
instead of as a `NoClassDefFoundError` during install or generation. A missing `com.volmit.`
|
||||
class means the jar was built against a different API, and the error says so.
|
||||
| The class is | Result |
|
||||
| --- | --- |
|
||||
| in a jar of the pack, an exposed package of the host, or the JDK | resolves |
|
||||
| in an exposed package, but the host does not have it | load error: the jar was built against a different Iris API or Iris version |
|
||||
| not exposed, but the host's loader has it (Iris internals, Iris's copy of a library) | load error: modules cannot use Iris's classes; ship the library in the pack or use the API |
|
||||
| nowhere | the pack loads, with a warning |
|
||||
|
||||
The JVM resolves a class only when code first needs it, so a class that nobody has is usually an
|
||||
optional dependency of a bundled library, used only when present. Rejecting those would be stricter
|
||||
than the JVM and would make many ordinary libraries unusable. Instead the pack loads,
|
||||
`PackModules.missingClasses()` lists the missing classes per jar (`MissingClasses`), and the load
|
||||
logs one WARNING for the pack, one line per jar with at most five class names
|
||||
(`MissingClassesWarning`), so a large shaded library cannot flood the log. Code that needs a missing
|
||||
class throws `NoClassDefFoundError` when it runs; the verifier may also need it while linking a
|
||||
class that uses it, which then fails when that class is first used.
|
||||
|
||||
A class the host hides fails, even though the pack might never run that code, because it exists:
|
||||
the module was written against Iris's copy, and the error says to ship the library or use the API
|
||||
instead of leaving the author with a `NoClassDefFoundError` during install or generation.
|
||||
|
||||
There is no version gating. Packs ship their module jars and Iris never downloads any, so whether
|
||||
a jar works with the running Iris is the pack publisher's responsibility. The class check catches
|
||||
API classes that no longer exist. It does not check methods and fields: a jar built against an API
|
||||
whose methods have changed fails with a linkage error, which `LoadedModules.load` reports with the
|
||||
module's jar when it happens during install, and which surfaces at generation time when it
|
||||
happens only in a stage body.
|
||||
API and exposed classes that no longer exist. It does not check methods and fields: a jar built
|
||||
against an API whose methods have changed fails with a linkage error, which `LoadedModules.load`
|
||||
reports with the module's jar when it happens during install, and which surfaces at generation
|
||||
time when it happens only in a stage body.
|
||||
|
||||
Closing `PackModules` closes the loader. Classes loaded before that keep working, so the host
|
||||
must drop `LoadedModules` and everything else built from the pack first.
|
||||
@@ -128,10 +156,11 @@ Each module reaches `LoadedModules.load` as a `DiscoveredModule`: the module and
|
||||
jar path relative to the pack or "host classpath" for built-ins. Duplicate module ids and foreign
|
||||
stage namespaces name the origin. Every jar error names the jar.
|
||||
|
||||
The load summary goes through `System.getLogger(PackModules.class.getName())`, so the host can
|
||||
route it with a `System.LoggerFinder`. It lists display name, id, version and jar for each module
|
||||
in load order, or says the pack has no module jars. `PackModulesSummary` builds the text and is
|
||||
tested on its own.
|
||||
The load summary and the missing-classes warning go through
|
||||
`System.getLogger(PackModules.class.getName())`, so the host can route them with a
|
||||
`System.LoggerFinder`. The summary lists display name, id, version and jar for each module in load
|
||||
order, or says the pack has no module jars. `PackModulesSummary` and `MissingClassesWarning` build
|
||||
the texts and are tested on their own.
|
||||
|
||||
## Stages
|
||||
|
||||
|
||||
@@ -60,12 +60,19 @@ every stage the module defines; the name is what logs show. Names and versions m
|
||||
line: line breaks and other control characters are rejected.
|
||||
|
||||
A module compiles against the Iris API as `compileOnly` (Maven: `provided`) and never ships it;
|
||||
Iris provides the API at runtime. At runtime a module can use only the Iris API (`com.volmit.*`),
|
||||
the JDK and the classes in its pack's module jars. Iris internals and the libraries Iris bundles
|
||||
are hidden, so a library the module needs goes inside one of the pack's jars. A class may appear
|
||||
in only one jar of a pack, so two jars that shade the same library must relocate it. The
|
||||
`com.volmit.` package prefix belongs to the API: module classes, and the libraries they shade,
|
||||
must not use it.
|
||||
Iris provides the API at runtime. At runtime a module can use the Iris API (`com.volmit.*`), the
|
||||
packages the host exposes besides it (meant for built-in modules, so packs can require their
|
||||
stages), the JDK and the classes in its pack's module jars. Iris internals and the libraries Iris
|
||||
bundles are hidden.
|
||||
|
||||
A module may use any library. It ships the library inside its own jar or as another jar of the
|
||||
pack, and never borrows Iris's copy. A class may appear in only one jar of a pack, so two jars that
|
||||
shade the same library must relocate it. The API's package and the other exposed packages belong
|
||||
to Iris: module classes, and the libraries they shade, must not use them.
|
||||
|
||||
Libraries often reference optional integrations they only use when present. A class that neither
|
||||
the pack, Iris nor the JDK has therefore does not fail the load: the pack loads, logs one warning
|
||||
listing such classes per jar, and code that needs one throws `NoClassDefFoundError` when it runs.
|
||||
|
||||
Iris never downloads modules and does not check which API version a jar was built for. A pack
|
||||
ships its module jars, and keeping them compatible with the Iris version it targets is the pack
|
||||
@@ -74,7 +81,7 @@ publisher's job.
|
||||
## Host side
|
||||
|
||||
```java
|
||||
try (var pack = PackModules.load(packRoot)) {
|
||||
try (var pack = PackModules.load(packRoot, builtInPackages)) { // exposed besides the API
|
||||
var modules = new ArrayList<>(builtIns); // DiscoveredModule.builtIn(...)
|
||||
modules.addAll(pack.modules());
|
||||
var loaded = LoadedModules.load(modules, reservedHostFields);
|
||||
@@ -87,21 +94,38 @@ try (var pack = PackModules.load(packRoot)) {
|
||||
} // drop everything built from the pack before it closes
|
||||
```
|
||||
|
||||
`PackModules.load` reads one entry point per jar, in jar file name order, and loads every jar
|
||||
of the pack through one class loader. Closing it closes that loader. A pack without a `modules`
|
||||
directory has no modules. Errors name the jar: no entry point, several entry points, a
|
||||
`com.volmit.` class in the jar, a class that is also in another jar of the pack (both jars are
|
||||
named), a class that uses a class outside the API, the JDK and the pack's jars, or an entry class
|
||||
that cannot be loaded, is not an `IrisModule`, is not in that jar, or fails to construct. All
|
||||
checks before the last run before any class of the pack is defined:
|
||||
`PackModules.load(packRoot, exposedHostPackages)` exposes the API plus the given host packages,
|
||||
each with its subpackages; `PackModules.load(packRoot)` exposes only the API. The host chooses
|
||||
those packages, such as the ones that hold built-in modules' stage constants. It reads one entry
|
||||
point per jar, in jar file name order, and loads every jar of the pack through one class loader.
|
||||
Closing it closes that loader. A pack without a `modules` directory has no modules. Errors name the
|
||||
jar: no entry point, several entry points, a class of an exposed package in the jar, a class that is
|
||||
also in another jar of the pack (both jars are named), a class that uses a class Iris has but hides
|
||||
or a class missing from an exposed package, or an entry class that cannot be loaded, is not an
|
||||
`IrisModule`, is not in that jar, or fails to construct. All checks before the last run before any
|
||||
class of the pack is defined:
|
||||
|
||||
```
|
||||
Module jar modules/alpha.jar contains Iris API class com.volmit.FeatureAttachment and 130 more; Iris provides the API at runtime, so mark the Iris API dependency compileOnly (Maven: provided) and keep module classes out of com.volmit.*
|
||||
|
||||
Module jar modules/moss.jar uses classes that are not in the Iris API, the JDK or the pack's module jars:
|
||||
Module jar modules/caves.jar contains class art.arcane.iris.engine.modules.CarveModule of package art.arcane.iris.engine.modules, which Iris provides to modules at runtime; compile against it compileOnly (Maven: provided) instead of shipping it, and keep module classes out of art.arcane.iris.engine.modules.*
|
||||
|
||||
Module jar modules/moss.jar uses classes that exist in Iris but are hidden from modules:
|
||||
com.example.moss.MossModule -> com.google.gson.Gson
|
||||
com.example.moss.MossSettings -> art.arcane.iris.engine.object.IrisBiome
|
||||
A module can use only the Iris API, the JDK and the classes in its pack's module jars; ship any library it needs inside a module jar of the pack.
|
||||
Modules cannot use Iris's own classes or its copies of libraries; ship the library in a module jar of the pack, or use the Iris API.
|
||||
|
||||
Module jar modules/moss.jar uses classes that this Iris does not have, in packages Iris provides to modules:
|
||||
com.example.moss.MossModule -> com.volmit.stage.NewerStage
|
||||
The jar was built against a different Iris API or Iris version.
|
||||
```
|
||||
|
||||
Classes that nobody has only produce a warning, also available as `pack.missingClasses()`:
|
||||
|
||||
```
|
||||
Pack overworld: module jars use classes that neither the pack, Iris nor the JDK has, usually optional dependencies of a bundled library. The jars load, but code that needs these classes throws NoClassDefFoundError when it runs:
|
||||
modules/moss.jar: org.slf4j.Logger, org.slf4j.LoggerFactory
|
||||
modules/stilt.jar: org.apache.logging.log4j.LogManager, org.apache.logging.log4j.Logger, org.slf4j.Logger, org.slf4j.LoggerFactory, org.slf4j.spi.LocationAwareLogger and 3 more
|
||||
```
|
||||
|
||||
A successful load logs one INFO summary through `System.Logger`:
|
||||
@@ -150,10 +174,13 @@ invocations and must not keep views or mutable state.
|
||||
The tests cover graph resolution and every error path, fusion, activation cascade, outputs,
|
||||
rejection and rollback, and install-order determinism. `PackModulesTest` compiles real module
|
||||
jars into a temporary pack and loads them, including every jar error, duplicate classes in plain
|
||||
and multi-release jars, API classes in a jar, references outside the pack, references that must
|
||||
still load (arrays, the JDK, other pack jars, missing annotation types) and linkage errors during
|
||||
install. `ApiAndJdkClassLoaderTest` checks what the pack loader's parent shows.
|
||||
`PackModulesSummaryTest` checks the log text. The example ports in
|
||||
`src/test/java/com/volmit/example` rebuild preparation, anchoring, block writes, stilt and snow
|
||||
as separate modules, add a third-party moss module, and add a two-module chunk pipeline. There is
|
||||
no Minecraft integration or production storage in these tests.
|
||||
and multi-release jars, API and other exposed classes in a jar, hidden host classes, classes missing
|
||||
from an exposed package, optional dependencies that only warn, references that must still load
|
||||
(arrays, the JDK, other pack jars, missing annotation types), linkage errors during install, and a
|
||||
pack jar that requires a stage of a built-in module in `example.builtin`, outside `com.volmit`,
|
||||
which loads only when the host exposes that package. `ExposedHostClassLoaderTest` checks what the
|
||||
pack loader's parent shows and `ExposedPackagesTest` which package names it accepts and how they
|
||||
match. `PackModulesSummaryTest` and `MissingClassesWarningTest` check the log texts. The example
|
||||
ports in `src/test/java/com/volmit/example` rebuild preparation, anchoring, block writes, stilt and
|
||||
snow as separate modules, add a third-party moss module, and add a two-module chunk pipeline. There
|
||||
is no Minecraft integration or production storage in these tests.
|
||||
Reference in new issue
Block a user