Add module display names, reject duplicate pack classes, log pack modules

ModuleInfo gains a required, non-blank display name next to id and
version: ModuleInfo.of(id, name, version).

PackModules now fails when a class is in two jars of one pack, naming
the class and both jars. ModuleJar indexes class names while it reads
the entry point, so the check runs before the pack class loader exists
and nothing is half-loaded. Jars are read with the runtime's
multi-release version, like the loader reads them: a versioned class
counts once under its base name; module-info.class and anything under
META-INF/ are ignored.

A successful load logs one INFO summary through System.Logger with the
display name, id, version and jar of each module, or a line saying the
pack has no module jars. PackModulesSummary builds the text and is
tested without a logging backend.
This commit is contained in:
piexel committed 2026-10-05 18:02:31 +02:00
1 parent 4fa6ddcd7a
commit b137bc6d92
19 files changed
+328 -53

No files matched your search

+10 -4
View File
@@ -3,17 +3,23 @@ package com.volmit;
import com.volmit.resource.ResourceId;
import java.util.Objects;
/** Module identity. Stages a module defines must use the namespace of its id. */
public record ModuleInfo(ResourceId id, String version) {
/** Module identity. Stages a module defines must use the namespace of its id. The name is for
* people, for example in load logs; the id is what the host and other modules match on.
*/
public record ModuleInfo(ResourceId id, String name, String version) {
public ModuleInfo {
Objects.requireNonNull(id, "id");
Objects.requireNonNull(name, "name");
Objects.requireNonNull(version, "version");
if (name.isBlank()) {
throw new IllegalArgumentException("Blank module name: " + id);
}
if (version.isBlank()) {
throw new IllegalArgumentException("Blank module version: " + id);
}
}
public static ModuleInfo of(String id, String version) {
return new ModuleInfo(ResourceId.parse(id), version);
public static ModuleInfo of(String id, String name, String version) {
return new ModuleInfo(ResourceId.parse(id), name, version);
}
}
+70 -26
View File
@@ -13,38 +13,42 @@ import java.nio.file.Path;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.zip.ZipFile;
/** One jar in a pack's modules directory and the entry class it names.
/** One jar in a pack's modules directory, the entry class it names and the classes it holds.
*
* <p>The entry point is the jar's own {@code META-INF/services/com.volmit.IrisModule} file, in
* the format {@link java.util.ServiceLoader} reads. The host reads that file from this jar only:
* {@code ServiceLoader} would also return providers from parent class loaders and could not tell
* which jar a broken entry came from.
*/
record ModuleJar(Path path, String origin, String entryClass) {
record ModuleJar(Path path, String origin, String entryClass, List<String> classNames) {
static final String ENTRY_POINT_FILE = "META-INF/services/" + IrisModule.class.getName();
private static final String COMMENT_START = "#";
private static final String CLASS_FILE_SUFFIX = ".class";
private static final String MODULE_DESCRIPTOR = "module-info" + CLASS_FILE_SUFFIX;
private static final String META_INF = "META-INF/";
ModuleJar {
Objects.requireNonNull(path, "path");
Objects.requireNonNull(origin, "origin");
Objects.requireNonNull(entryClass, "entryClass");
classNames = List.copyOf(classNames);
}
/** Reads the single entry class a jar names. The origin is the jar path relative to its pack. */
/** Reads the single entry class a jar names and the classes it holds. The origin is the jar
* path relative to its pack.
*/
static ModuleJar read(Path packRoot, Path jar) {
var origin = packRoot.relativize(jar).toString();
var entryClasses = readEntryClasses(jar, origin);
if (entryClasses.isEmpty()) {
throw new IllegalArgumentException("Module jar " + origin + " has no entry point; name its "
+ IrisModule.class.getSimpleName() + " class in " + ENTRY_POINT_FILE);
try (var file = openAsClassLoaderSeesIt(jar)) {
var entryClass = requireSingleEntryClass(origin, readEntryClasses(file));
return new ModuleJar(jar, origin, entryClass, readClassNames(file));
} catch (IOException exception) {
throw new UncheckedIOException("Module jar " + origin + " is not a readable jar", exception);
}
if (entryClasses.size() > 1) {
throw new IllegalArgumentException("Module jar " + origin + " names " + entryClasses.size()
+ " entry points " + entryClasses + "; one jar holds exactly one module");
}
return new ModuleJar(jar, origin, entryClasses.getFirst());
}
URL url() {
@@ -66,21 +70,61 @@ record ModuleJar(Path path, String origin, String entryClass) {
return new DiscoveredModule(module, origin);
}
private static List<String> readEntryClasses(Path jar, String origin) {
try (var file = new JarFile(jar.toFile())) {
var entry = file.getJarEntry(ENTRY_POINT_FILE);
if (entry == null) return List.of();
try (var reader = new BufferedReader(new InputStreamReader(file.getInputStream(entry), StandardCharsets.UTF_8))) {
return reader.lines()
.map(ModuleJar::withoutComment)
.map(String::strip)
.filter(Predicate.not(String::isEmpty))
.distinct()
.toList();
}
} catch (IOException exception) {
throw new UncheckedIOException("Module jar " + origin + " is not a readable jar", exception);
/** Opens the jar with the runtime's multi-release version, like the pack class loader does, so
* class names below match the classes that loader can define.
*/
private static JarFile openAsClassLoaderSeesIt(Path jar) throws IOException {
return new JarFile(jar.toFile(), true, ZipFile.OPEN_READ, JarFile.runtimeVersion());
}
private static String requireSingleEntryClass(String origin, List<String> entryClasses) {
if (entryClasses.isEmpty()) {
throw new IllegalArgumentException("Module jar " + origin + " has no entry point; name its "
+ IrisModule.class.getSimpleName() + " class in " + ENTRY_POINT_FILE);
}
if (entryClasses.size() > 1) {
throw new IllegalArgumentException("Module jar " + origin + " names " + entryClasses.size()
+ " entry points " + entryClasses + "; one jar holds exactly one module");
}
return entryClasses.getFirst();
}
private static List<String> readEntryClasses(JarFile file) throws IOException {
var entry = file.getJarEntry(ENTRY_POINT_FILE);
if (entry == null) return List.of();
try (var reader = new BufferedReader(new InputStreamReader(file.getInputStream(entry), StandardCharsets.UTF_8))) {
return reader.lines()
.map(ModuleJar::withoutComment)
.map(String::strip)
.filter(Predicate.not(String::isEmpty))
.distinct()
.toList();
}
}
/** Binary names of the classes in the jar, sorted. A multi-release jar contributes each class
* once, under its base name, in the version this runtime would load. Anything left below
* {@code META-INF/}, such as versioned entries of a jar that is not multi-release, cannot be
* loaded as a class: {@code META-INF} is not a valid package name.
*/
private static List<String> readClassNames(JarFile file) {
return file.versionedStream()
.filter(Predicate.not(JarEntry::isDirectory))
.map(JarEntry::getName)
.filter(ModuleJar::isClassFile)
.map(ModuleJar::toBinaryName)
.sorted()
.toList();
}
private static boolean isClassFile(String entryName) {
return entryName.endsWith(CLASS_FILE_SUFFIX)
&& !entryName.equals(MODULE_DESCRIPTOR)
&& !entryName.startsWith(META_INF);
}
private static String toBinaryName(String entryName) {
return entryName.substring(0, entryName.length() - CLASS_FILE_SUFFIX.length()).replace('/', '.');
}
private static String withoutComment(String line) {
+47 -9
View File
@@ -3,11 +3,13 @@ package com.volmit.host;
import com.volmit.IrisModule;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.lang.System.Logger.Level;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
@@ -16,7 +18,11 @@ import java.util.Objects;
*
* <p>All jars of a pack share one class loader whose parent is the loader of the API. A pack jar
* can therefore name another pack jar's stage constants in {@code requires(...)}, as well as
* those of built-in modules visible to the API. Packs do not see each other's classes.
* those of built-in modules visible to the API. Packs do not see each other's classes, and no class
* may appear in two jars of one pack.
*
* <p>A successful load logs one INFO summary of the pack's modules through {@link System.Logger},
* which the host can route to its own logging.
*
* <p>Close this when the pack unloads, after dropping everything built from its modules, such as
* {@link LoadedModules}. Classes not loaded before then can no longer be loaded.
@@ -24,6 +30,7 @@ import java.util.Objects;
public final class PackModules implements AutoCloseable {
public static final String MODULES_DIRECTORY = "modules";
static final String JAR_EXTENSION = ".jar";
private static final System.Logger LOGGER = System.getLogger(PackModules.class.getName());
private final List<DiscoveredModule> modules;
private final URLClassLoader loader;
@@ -41,13 +48,10 @@ public final class PackModules implements AutoCloseable {
var jars = findModuleJars(packRoot).stream()
.map(jar -> ModuleJar.read(packRoot, jar))
.toList();
var loader = newPackClassLoader(packRoot, jars);
try {
return new PackModules(createModules(jars, loader), loader);
} catch (RuntimeException | Error failure) {
closeAfterFailure(loader, failure);
throw failure;
}
requireDistinctClasses(jars);
var packModules = defineModules(packRoot, jars);
LOGGER.log(Level.INFO, () -> PackModulesSummary.describe(packName(packRoot), packModules.modules()));
return packModules;
}
/** One module per jar, in jar file name order. */
@@ -81,9 +85,43 @@ public final class PackModules implements AutoCloseable {
return Files.isRegularFile(path) && path.getFileName().toString().endsWith(JAR_EXTENSION);
}
/** Fails before any class is defined when two jars hold the same class. The shared loader would
* otherwise silently use whichever copy comes first in file name order.
*/
private static void requireDistinctClasses(List<ModuleJar> jars) {
var owners = new HashMap<String, ModuleJar>();
for (var jar : jars) {
for (var className : jar.classNames()) {
var owner = owners.putIfAbsent(className, jar);
if (owner != null) throw duplicateClass(className, owner, jar);
}
}
}
private static IllegalArgumentException duplicateClass(String className, ModuleJar first, ModuleJar second) {
return new IllegalArgumentException("Class " + className + " is in both module jars " + first.origin()
+ " and " + second.origin() + "; every class of a pack must come from one jar, so relocate"
+ " shaded libraries or keep shared classes in one module");
}
private static PackModules defineModules(Path packRoot, List<ModuleJar> jars) {
var loader = newPackClassLoader(packRoot, jars);
try {
return new PackModules(createModules(jars, loader), loader);
} catch (RuntimeException | Error failure) {
closeAfterFailure(loader, failure);
throw failure;
}
}
private static URLClassLoader newPackClassLoader(Path packRoot, List<ModuleJar> jars) {
var urls = jars.stream().map(ModuleJar::url).toArray(URL[]::new);
return new URLClassLoader("pack:" + packRoot.getFileName(), urls, IrisModule.class.getClassLoader());
return new URLClassLoader("pack:" + packName(packRoot), urls, IrisModule.class.getClassLoader());
}
private static String packName(Path packRoot) {
var name = packRoot.getFileName();
return name == null ? packRoot.toString() : name.toString();
}
private static List<DiscoveredModule> createModules(List<ModuleJar> jars, ClassLoader loader) {
@@ -0,0 +1,29 @@
package com.volmit.host;
import java.util.List;
/** The one log message a pack load writes: which modules the pack uses and which jar each comes
* from.
*/
final class PackModulesSummary {
private static final String INDENT = " ";
private PackModulesSummary() {}
static String describe(String packName, List<DiscoveredModule> modules) {
if (modules.isEmpty()) {
return "Pack " + packName + " uses no modules: no jars in its " + PackModules.MODULES_DIRECTORY + " directory";
}
var text = new StringBuilder("Pack ").append(packName).append(" uses ").append(modules.size())
.append(modules.size() == 1 ? " module:" : " modules:");
for (var module : modules) {
text.append('\n').append(INDENT).append(describe(module));
}
return text.toString();
}
private static String describe(DiscoveredModule discovered) {
var info = discovered.module().info();
return info.name() + " (" + info.id() + " " + info.version() + ") from " + discovered.origin();
}
}
@@ -31,6 +31,16 @@ class ApiValuesTest {
assertThrows(IllegalArgumentException.class, () -> new ResourceKey<>("test:value", int.class));
}
@Test
void moduleInfoRequiresANameAndVersion() {
var info = ModuleInfo.of("example:moss", "Moss", "1.0.0");
assertEquals(ResourceId.parse("example:moss"), info.id());
assertEquals("Moss", info.name());
assertThrows(IllegalArgumentException.class, () -> ModuleInfo.of("example:moss", " ", "1.0.0"));
assertThrows(IllegalArgumentException.class, () -> ModuleInfo.of("example:moss", "Moss", ""));
assertThrows(NullPointerException.class, () -> ModuleInfo.of("example:moss", null, "1.0.0"));
}
@Test
void sparseObjectsCopySortAndRejectDuplicateOrOutOfBoundsBlocks() {
var a = new ObjectBlock(new BlockPosition(-1, 0, 0), new BlockState("minecraft:stone"));
@@ -177,7 +177,7 @@ class PlacementLifecyclePortTest {
void inactiveRequirementDeactivatesThirdPartyDependents() {
var capModule = new IrisModule() {
static final PlacementStage<Void> CAP = Stage.placement("example:cap/top");
public ModuleInfo info() { return ModuleInfo.of("example:cap", "1"); }
public ModuleInfo info() { return ModuleInfo.of("example:cap", "Cap", "1"); }
public void install(StageGraph graph) {
graph.define(CAP).requires(StiltModule.FILL).run(context -> context.access().set(
new PlacedBlock(new BlockPosition(5, 20, 5), PLANKS, Optional.empty())));
@@ -14,7 +14,7 @@ public final class GrassModule implements IrisModule {
@Override
public ModuleInfo info() {
return ModuleInfo.of("example:grass", "1.0.0");
return ModuleInfo.of("example:grass", "Grass", "1.0.0");
}
@Override
@@ -17,7 +17,7 @@ public final class TerrainModule implements IrisModule {
@Override
public ModuleInfo info() {
return ModuleInfo.of("iris:terrain", "test");
return ModuleInfo.of("iris:terrain", "Terrain", "test");
}
@Override
@@ -15,7 +15,7 @@ public final class AnchorModule implements IrisModule {
@Override
public ModuleInfo info() {
return ModuleInfo.of("iris:anchor", "test");
return ModuleInfo.of("iris:anchor", "Anchor", "test");
}
@Override
@@ -17,7 +17,7 @@ public final class BlocksModule implements IrisModule {
@Override
public ModuleInfo info() {
return ModuleInfo.of("iris:blocks", "test");
return ModuleInfo.of("iris:blocks", "Blocks", "test");
}
@Override
@@ -21,7 +21,7 @@ public final class MossModule implements IrisModule {
@Override
public ModuleInfo info() {
return ModuleInfo.of("example:moss", "1.0.0");
return ModuleInfo.of("example:moss", "Moss", "1.0.0");
}
@Override
@@ -17,7 +17,7 @@ public final class PrepareModule implements IrisModule {
@Override
public ModuleInfo info() {
return ModuleInfo.of("iris:prepare", "test");
return ModuleInfo.of("iris:prepare", "Prepare", "test");
}
@Override
@@ -23,7 +23,7 @@ public final class SnowModule implements IrisModule {
@Override
public ModuleInfo info() {
return ModuleInfo.of("iris:snow", "test");
return ModuleInfo.of("iris:snow", "Snow", "test");
}
@Override
@@ -19,7 +19,7 @@ public final class StiltModule implements IrisModule {
@Override
public ModuleInfo info() {
return ModuleInfo.of("iris:stilt", "test");
return ModuleInfo.of("iris:stilt", "Stilts", "test");
}
@Override
@@ -69,7 +69,7 @@ class ModuleRegistryTest {
void loadingModulesCatalogsStageSettingsAndRegistrationsTogether() {
var conditioned = new IrisModule() {
static final PlacementStage<Void> WORK = Stage.placement("test:conditioned/work");
public ModuleInfo info() { return ModuleInfo.of("test:conditioned", "1"); }
public ModuleInfo info() { return ModuleInfo.of("test:conditioned", "Conditioned", "1"); }
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); }
};
@@ -0,0 +1,38 @@
package com.volmit.host;
import com.volmit.example.placement.MossModule;
import com.volmit.example.placement.SnowModule;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
class PackModulesSummaryTest {
@Test
void listsNameIdVersionAndJarOfEveryModuleInLoadOrder() {
var modules = List.of(
new DiscoveredModule(new MossModule(), "modules/moss.jar"),
new DiscoveredModule(new SnowModule(), "modules/snow.jar"));
assertEquals("""
Pack overworld uses 2 modules:
Moss (example:moss 1.0.0) from modules/moss.jar
Snow (iris:snow test) from modules/snow.jar""",
PackModulesSummary.describe("overworld", modules));
}
@Test
void singleModuleReadsAsOneModule() {
var modules = List.of(new DiscoveredModule(new MossModule(), "modules/moss.jar"));
assertEquals("""
Pack overworld uses 1 module:
Moss (example:moss 1.0.0) from modules/moss.jar""",
PackModulesSummary.describe("overworld", modules));
}
@Test
void packWithoutModulesSaysSo() {
assertEquals("Pack overworld uses no modules: no jars in its modules directory",
PackModulesSummary.describe("overworld", List.of()));
}
}
@@ -18,6 +18,10 @@ class PackModulesTest {
"public static final PlacementStage<Void> MARK = Stage.placement(\"alpha:core/mark\");";
private static final String NO_MEMBERS = "";
private static final String NO_STAGES = "";
private static final String SHARED_CLASS = "pack.shared.Util";
private static final String SHARED_SOURCE = "package pack.shared; public final class Util {}";
private static final byte[] UNUSED_CLASS_BYTES = {(byte) 0xCA, (byte) 0xFE};
private static final String DEFINED_PROPERTY = "irisapi.test.packModuleConstructed";
@TempDir
Path pack;
@@ -133,6 +137,76 @@ class PackModulesTest {
"not from this jar");
}
@Test
void sameClassInTwoJarsFailsBeforeAnyModuleIsConstructed() {
var constructorMarker = "public %s() { System.setProperty(\"" + DEFINED_PROPERTY + "\", \"true\"); }";
module("pack.alpha.Alpha", "alpha:core", constructorMarker.formatted("Alpha"), NO_STAGES)
.source(SHARED_CLASS, SHARED_SOURCE).writeInto(pack, "alpha.jar");
module("pack.beta.Beta", "beta:core", constructorMarker.formatted("Beta"), NO_STAGES)
.source(SHARED_CLASS, SHARED_SOURCE).writeInto(pack, "beta.jar");
try {
assertMentions(failure(() -> PackModules.load(pack)),
"Class " + SHARED_CLASS + " is in both module jars " + origin("alpha.jar") + " and " + origin("beta.jar"));
assertNull(System.getProperty(DEFINED_PROPERTY), "a module was constructed before the duplicate was found");
} finally {
System.clearProperty(DEFINED_PROPERTY);
}
}
@Test
void moduleDescriptorsMayRepeatAcrossJars() {
module("pack.alpha.Alpha", "alpha:core", NO_MEMBERS, NO_STAGES)
.resource("module-info.class", UNUSED_CLASS_BYTES).writeInto(pack, "alpha.jar");
module("pack.beta.Beta", "beta:core", NO_MEMBERS, NO_STAGES)
.resource("module-info.class", UNUSED_CLASS_BYTES).writeInto(pack, "beta.jar");
try (var packModules = PackModules.load(pack)) {
assertEquals(2, packModules.modules().size());
}
}
@Test
void versionedClassOfAMultiReleaseJarCountsUnderItsBaseName() {
module("pack.alpha.Alpha", "alpha:core", NO_MEMBERS, NO_STAGES)
.source(SHARED_CLASS, SHARED_SOURCE).writeInto(pack, "alpha.jar");
module("pack.beta.Beta", "beta:core", NO_MEMBERS, NO_STAGES)
.multiRelease()
.resource("META-INF/versions/9/pack/shared/Util.class", UNUSED_CLASS_BYTES)
.writeInto(pack, "beta.jar");
assertMentions(failure(() -> PackModules.load(pack)),
"Class " + SHARED_CLASS + " is in both module jars " + origin("alpha.jar") + " and " + origin("beta.jar"));
}
@Test
void versionedEntriesOutsideAMultiReleaseJarAreNotClasses() {
module("pack.alpha.Alpha", "alpha:core", NO_MEMBERS, NO_STAGES)
.source(SHARED_CLASS, SHARED_SOURCE)
.resource("META-INF/versions/9/pack/shared/Util.class", UNUSED_CLASS_BYTES)
.writeInto(pack, "alpha.jar");
module("pack.beta.Beta", "beta:core", NO_MEMBERS, NO_STAGES)
.resource("META-INF/versions/9/pack/shared/Util.class", UNUSED_CLASS_BYTES)
.writeInto(pack, "beta.jar");
try (var packModules = PackModules.load(pack)) {
assertEquals(2, packModules.modules().size());
}
}
@Test
void multiReleaseJarMayHoldAVersionedCopyOfItsOwnClass() {
module("pack.alpha.Alpha", "alpha:core", NO_MEMBERS, NO_STAGES)
.source(SHARED_CLASS, SHARED_SOURCE)
.multiRelease()
.resource("META-INF/versions/9/pack/shared/Util.class", UNUSED_CLASS_BYTES)
.writeInto(pack, "alpha.jar");
try (var packModules = PackModules.load(pack)) {
assertEquals(1, packModules.modules().size());
}
}
@Test
void duplicateModuleIdsAcrossJarsFailNamingBothJars() {
module("pack.one.Duplicate", "dup:core", NO_MEMBERS, NO_STAGES).writeInto(pack, "one.jar");
@@ -41,7 +41,7 @@ class StageGraphTest {
private static IrisModule module(String id, Consumer<StageGraph> install) {
return new IrisModule() {
public ModuleInfo info() { return ModuleInfo.of(id, "1"); }
public ModuleInfo info() { return ModuleInfo.of(id, "Test module " + id, "1"); }
public void install(StageGraph graph) { install.accept(graph); }
};
}
@@ -14,6 +14,7 @@ import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
@@ -30,6 +31,8 @@ public final class TestModuleJar {
private static final String SERVICES_FILE = "META-INF/services/" + IrisModule.class.getName();
private final Map<String, String> sources = new LinkedHashMap<>();
private final Map<String, byte[]> resources = new LinkedHashMap<>();
private boolean multiRelease;
private final List<String> entryPoints = new ArrayList<>();
private final List<Path> classpath = new ArrayList<>(List.of(classesOf(IrisModule.class), classesOf(AnchorModule.class)));
@@ -49,6 +52,18 @@ public final class TestModuleJar {
return this;
}
/** Adds a raw jar entry, such as a versioned class file, without compiling anything. */
public TestModuleJar resource(String entryName, byte[] content) {
resources.put(entryName, content.clone());
return this;
}
/** Marks the jar {@code Multi-Release: true}, so its {@code META-INF/versions} entries count. */
public TestModuleJar multiRelease() {
multiRelease = true;
return this;
}
public TestModuleJar compileAgainst(Path jar) {
classpath.add(jar);
return this;
@@ -59,8 +74,9 @@ public final class TestModuleJar {
try {
var jar = Files.createDirectories(packRoot.resolve("modules")).resolve(jarName);
var classes = compile(Files.createTempDirectory(packRoot, "classes"));
try (var output = new JarOutputStream(Files.newOutputStream(jar), new Manifest())) {
try (var output = new JarOutputStream(Files.newOutputStream(jar), manifest())) {
writeClasses(output, classes);
writeResources(output);
writeEntryPoints(output);
}
return jar;
@@ -92,6 +108,21 @@ public final class TestModuleJar {
}
}
private Manifest manifest() {
var manifest = new Manifest();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
if (multiRelease) manifest.getMainAttributes().put(Attributes.Name.MULTI_RELEASE, "true");
return manifest;
}
private void writeResources(JarOutputStream output) throws IOException {
for (var resource : resources.entrySet()) {
output.putNextEntry(new JarEntry(resource.getKey()));
output.write(resource.getValue());
output.closeEntry();
}
}
private void writeEntryPoints(JarOutputStream output) throws IOException {
if (entryPoints.isEmpty()) return;
output.putNextEntry(new JarEntry(SERVICES_FILE));
@@ -111,11 +142,16 @@ public final class TestModuleJar {
public final class %s implements IrisModule {
%s
public ModuleInfo info() { return ModuleInfo.of("%s", "1.0.0"); }
public ModuleInfo info() { return ModuleInfo.of("%s", "%s", "1.0.0"); }
public void install(StageGraph graph) { %s }
}
""".formatted(className.substring(0, dot), className.substring(dot + 1), members, moduleId, install);
""".formatted(className.substring(0, dot), className.substring(dot + 1), members, moduleId, displayName(moduleId), install);
}
/** The display name test modules get, so assertions can predict it from the id. */
public static String displayName(String moduleId) {
return "Test " + moduleId;
}
private static Path classesOf(Class<?> type) {