The plugin bundles iris-builtins.jar and every pack loads it

A world's pack copy carried its own modules/iris-builtins.jar, which
went stale with every plugin update and, since a used pack that cannot
load stops startup, would stop the server. Now :core:builtinModulesJar
packages the jar from core's own compiled classes (moved here from
IrisModule's build, with IrisApi's ModuleJarCheck), and core's jar and
the Bukkit shadowJar carry it as iris-builtins.jar, leaving its classes
out of the plugin's own. IrisModuleHost unpacks it to a temporary
folder and bundles it (ModuleHost.bundlingJars), so every pack loads
it as if it were in its modules folder.

A pack's own copy is left out; Iris warns once with its path.
MissingBuiltInModules now only fires for an Iris build without the jar
(Iris's own tests), and says so.
This commit is contained in:
piexel committed 2026-10-22 09:45:47 +02:00
1 parent 91b251b352
commit 72c3d662c1
6 files changed
+167 -10

No files matched your search

@@ -25,7 +25,12 @@ import com.volmit.ModuleLog;
import com.volmit.host.ModuleHost;
import com.volmit.host.PackModules;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.List;
import java.util.stream.Stream;
@@ -35,8 +40,8 @@ import java.util.stream.Stream;
* model as host types, the pack folders Iris reads itself, a jar copy directory under the plugin's cache, and
* Iris's log.
* <p>
* The built-in modules that are already ported ship in the built-ins jar ({@code IrisModule/builtin-modules.txt}), which a
* pack puts into its {@code modules} folder like any pack module; they are not listed here.
* The built-in modules that are already ported ship in the built-ins jar ({@code IrisModule/builtin-modules.txt}), which the
* plugin bundles and every pack loads as if it were in its {@code modules} folder; they are not listed here.
*/
public final class IrisModuleHost {
/** Exposed to pack modules, with its subpackages; see its package documentation. */
@@ -50,8 +55,8 @@ public final class IrisModuleHost {
public static final List<String> EXPOSED_PACKAGES = Stream.concat(Stream.of(BUILT_IN_API_PACKAGE), SHARED_LIBRARY_PACKAGES.stream()).toList();
/**
* The ids of the built-in modules that ship in the built-ins jar ({@code iris-builtins.jar}, listed in
* {@code IrisModule/builtin-modules.txt}) instead of being compiled into Iris. A pack loads them from its {@code modules}
* folder, and {@link MissingBuiltInModules} warns when it loads none; a test keeps this equal to the jar's list.
* {@code IrisModule/builtin-modules.txt}) instead of being compiled into Iris. Every pack loads them from the jar Iris
* bundles, and {@link MissingBuiltInModules} warns when it loads none; a test keeps this equal to the jar's list.
*/
public static final List<String> JAR_MODULE_IDS = List.of("iris:post", "iris:perfection", "iris:matter", "iris:loot",
"iris:spawn", "iris:prepare", "iris:anchor", "iris:validate", "iris:bore", "iris:blocks", "iris:stilt", "iris:vacuum",
@@ -60,6 +65,8 @@ public final class IrisModuleHost {
/** Iris's pack object model: built-in settings may hold these classes, which Iris reads and describes itself. */
public static final String HOST_TYPE_PACKAGE = "art.arcane.iris.engine.object";
private static final String[] JAR_COPY_FOLDER = {"cache", "module-jars"};
private static final String BUNDLED_JAR_RESOURCE = "/" + MissingBuiltInModules.JAR_NAME;
private static final String BUNDLED_JAR_TEMPORARY_PREFIX = "iris-built-in-modules-";
private static final String TEMPORARY_DIRECTORY_PROPERTY = "java.io.tmpdir";
private IrisModuleHost() {
@@ -95,10 +102,36 @@ public final class IrisModuleHost {
.reservingFields(ModuleTargets.reservedFields())
.describingHostTypesIn(HOST_TYPE_PACKAGE)
.reservingFolders(IrisData.ownFolderNames().toArray(String[]::new))
.bundlingJars(bundledJars())
.copyingJarsTo(jarCopyRoot())
.loggingTo(new IrisApiLogger(PackModules.class.getName()));
}
/**
* The built-ins jar this build of Iris carries, unpacked to a file the pack loader can copy; none when the classpath
* holds no such jar, as in Iris's own tests, which put a copy into the pack instead.
*/
private static Path[] bundledJars() {
try (InputStream bundled = IrisModuleHost.class.getResourceAsStream(BUNDLED_JAR_RESOURCE)) {
if (bundled == null) {
return new Path[0];
}
Path unpacked = bundledJarFolder().resolve(MissingBuiltInModules.JAR_NAME);
Files.copy(bundled, unpacked, StandardCopyOption.REPLACE_EXISTING);
return new Path[]{unpacked};
} catch (IOException exception) {
throw new UncheckedIOException("Cannot unpack Iris's built-in modules jar", exception);
}
}
/** A fresh temporary folder, removed when the JVM exits; the host is built before a platform may be bound. */
private static Path bundledJarFolder() throws IOException {
Path folder = Files.createTempDirectory(BUNDLED_JAR_TEMPORARY_PREFIX);
folder.toFile().deleteOnExit();
folder.resolve(MissingBuiltInModules.JAR_NAME).toFile().deleteOnExit();
return folder;
}
/** Under the plugin's cache folder when a platform is bound; tests and the standalone probe use the JDK's temporary directory. */
private static Path jarCopyRoot() {
if (!IrisPlatforms.isBound()) {
@@ -25,8 +25,8 @@ import java.util.Collection;
import java.util.Optional;
/**
* Notices a pack that loads without the built-in modules jar. Such a pack still loads and generates, but quietly without
* what the jar's modules do, so the owner is told once, with the fix.
* Notices a pack that loads without the built-in modules jar, which happens only when this build of Iris does not bundle
* it. Such a pack still loads and generates, but quietly without what the jar's modules do, so the owner is told once.
*/
final class MissingBuiltInModules {
static final String JAR_NAME = "iris-builtins.jar";
@@ -44,7 +44,7 @@ final class MissingBuiltInModules {
}
return Optional.of("Pack " + packFolder.getName() + " loads without the built-in modules (" + JAR_NAME + "): its world gets"
+ " only its layout (biomes and heights), with no terrain blocks, ores, caves, decorations, objects or vanilla features,"
+ " and no loot, block drops, entity spawns or ambient effects. Copy " + JAR_NAME
+ " into " + new File(packFolder, PackModuleSet.MODULES_FOLDER).getPath() + " to fix it.");
+ " and no loot, block drops, entity spawns or ambient effects. This build of Iris does not bundle " + JAR_NAME
+ "; use a complete build, or copy the jar into " + new File(packFolder, PackModuleSet.MODULES_FOLDER).getPath() + ".");
}
}
@@ -40,6 +40,7 @@ public final class PackModuleSet implements AutoCloseable {
static final String MODULES_FOLDER = "modules";
private static final String JAR_EXTENSION = ".jar";
private static final String MISSING_BUILT_INS_KEY = "missing-built-in-modules:";
private static final String REPLACED_JAR_KEY = "replaced-module-jar:";
private final File packFolder;
private final Supplier<Gson> irisGson;
@@ -124,6 +125,7 @@ public final class PackModuleSet implements AutoCloseable {
pack = loaded;
state = State.LOADED;
warnWhenBuiltInModulesAreMissing(loaded);
warnAboutReplacedJars(loaded);
} catch (RuntimeException loadFailure) {
failure = new PackModulesException(packFolder, loadFailure);
state = State.FAILED;
@@ -137,6 +139,14 @@ public final class PackModuleSet implements AutoCloseable {
.ifPresent(warning -> IrisLogging.warnOnce(MISSING_BUILT_INS_KEY + packFolder.getAbsolutePath(), "%s", warning));
}
/** A pack's own copy of a jar Iris bundles, such as an old {@code iris-builtins.jar}, is left out; its owner is told once. */
private void warnAboutReplacedJars(LoadedPack loaded) {
for (String jar : loaded.replacedJars()) {
String path = new File(packFolder, jar).getAbsolutePath();
IrisLogging.warnOnce(REPLACED_JAR_KEY + path, "%s is not loaded; Iris's own copy loads instead. Delete it.", path);
}
}
/** Each module jar's name, size and modification time, in name order. */
private List<String> jarFingerprint() {
File[] jars = new File(packFolder, MODULES_FOLDER).listFiles(file -> file.isFile() && file.getName().endsWith(JAR_EXTENSION));
@@ -39,7 +39,8 @@ public class MissingBuiltInModulesTest {
String warning = MissingBuiltInModules.warning(PACK, List.of()).orElseThrow();
assertTrue(warning, warning.startsWith("Pack overworld loads without the built-in modules (iris-builtins.jar)"));
assertTrue(warning, warning.contains("Copy iris-builtins.jar into " + new File(PACK, "modules").getPath() + " to fix it."));
assertTrue(warning, warning.contains("does not bundle iris-builtins.jar; use a complete build, or copy the jar into "
+ new File(PACK, "modules").getPath() + "."));
}
@Test
@@ -74,7 +74,7 @@ public class PackModuleSetTest {
String warnings = warningsWhile(() -> new PackModuleSet(pack, Gson::new).pack());
assertTrue(warnings, warnings.contains("[Iris/WARN] Pack without-builtins loads without the built-in modules (iris-builtins.jar)"));
assertTrue(warnings, warnings.contains("Copy iris-builtins.jar into " + new File(pack, "modules").getPath()));
assertTrue(warnings, warnings.contains("copy the jar into " + new File(pack, "modules").getPath()));
}
@Test