Let the host expose extra packages, such as built-in modules, to packs

A single API_PACKAGE_PREFIX made built-in modules in Iris packages
(art.arcane.iris...) invisible, so pack jars could not require their
stages. ExposedPackages now holds the packages packs may use: always
the API (IrisModule's package), plus what the host passes to the new
PackModules.load(packRoot, exposedHostPackages). Names must be package
names (trailing dot accepted) and match whole packages only.

ApiAndJdkClassLoader becomes ExposedHostClassLoader and routes classes
and resources of every exposed package to the host loader. A jar that
ships a class of any exposed package fails; the compileOnly API hint
stays for the API, other packages get their own message. That check
moves from ModuleJar to PackClassCheck. A reference missing from any
exposed package is the "different build" error.

Tests use a built-in module in example.builtin, outside com.volmit.,
which a pack jar can require only when that package is exposed.
This commit is contained in:
piexel committed 2026-10-05 20:30:20 +02:00
1 parent 98bd9a9c12
commit 13a9300ab4
11 files changed
+396 -121

No files matched your search

@@ -0,0 +1,64 @@
package com.volmit.host;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
class ExposedPackagesTest {
@Test
void apiIsAlwaysExposedWithItsSubpackages() {
var exposed = ExposedPackages.apiOnly();
assertEquals("com.volmit", ExposedPackages.API_PACKAGE);
assertTrue(exposed.exposes("com.volmit.IrisModule"));
assertTrue(exposed.exposes("com.volmit.host.PackModules"));
assertTrue(ExposedPackages.apiAnd(List.of("example.builtin")).exposes("com.volmit.IrisModule"));
}
@Test
void onlyWholePackageNamesMatch() {
var exposed = ExposedPackages.apiAnd(List.of("example.builtin"));
assertTrue(exposed.exposes("example.builtin.CarveModule"));
assertTrue(exposed.exposes("example.builtin.deep.Stage"));
assertFalse(exposed.exposes("example.builtinx.CarveModule"));
assertFalse(exposed.exposes("example.Other"));
assertFalse(exposed.exposes("com.volmitx.Fake"));
assertFalse(exposed.exposes("com.volmit"));
}
@Test
void resourcesMatchByPath() {
var exposed = ExposedPackages.apiAnd(List.of("example.builtin"));
assertTrue(exposed.exposesResource("example/builtin/CarveModule.class"));
assertTrue(exposed.exposesResource("example/builtin/carve.json"));
assertTrue(exposed.exposesResource("com/volmit/IrisModule.class"));
assertFalse(exposed.exposesResource("example/builtinx/carve.json"));
assertFalse(exposed.exposesResource("META-INF/services/com.volmit.IrisModule"));
}
@Test
void trailingDotIsAccepted() {
assertTrue(ExposedPackages.apiAnd(List.of("example.builtin.")).exposes("example.builtin.CarveModule"));
}
@ParameterizedTest
@ValueSource(strings = {"", " ", ".", "example..builtin", ".example", "example.*", "example.builtin.**", "1example", "example builtin"})
void rejectsWhatIsNotAPackageName(String name) {
var message = assertThrows(IllegalArgumentException.class, () -> ExposedPackages.apiAnd(List.of(name))).getMessage();
assertTrue(message.startsWith("Exposed package '" + name + "' is not a package name"), message);
}
@Test
void namesTheMostSpecificExposedPackageOfAClass() {
var exposed = ExposedPackages.apiAnd(List.of("example", "example.builtin"));
assertEquals("example.builtin", exposed.packageOf("example.builtin.CarveModule"));
assertEquals("example", exposed.packageOf("example.Other"));
assertEquals("com.volmit", exposed.packageOf("com.volmit.IrisModule"));
}
}