mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
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:
1 parent
91b251b352
commit
72c3d662c1
6 files changed
+167
-10
No files matched your search
@@ -310,8 +310,121 @@ List<String> dependencyBuildMetadata = [
|
||||
'META-INF/versions/*/OSGI-INF/**'
|
||||
]
|
||||
|
||||
// The built-in modules as a pack module jar, iris-builtins.jar, packaged from these compiled classes so it always fits this
|
||||
// build of Iris, checked as a pack load would check it, and bundled into the plugin (IrisModuleHost loads it with every pack).
|
||||
// What goes in is listed in IrisModule/builtin-modules.txt: "module <class>" (an entry point) or "include <ant pattern>".
|
||||
String builtinModulesJarName = 'iris-builtins.jar'
|
||||
String builtinModuleEntryFile = 'com.volmit.IrisModule'
|
||||
File builtinModulesFile = rootProject.file('../IrisModule/builtin-modules.txt')
|
||||
// The packages pack modules may use besides the IrisApi; IrisModuleHost.EXPOSED_PACKAGES lists the same.
|
||||
List<String> builtinExposedPackages = ['art.arcane.iris.builtin', 'art.arcane.volmlib', 'com.google.gson']
|
||||
List<String> builtinModuleClasses = []
|
||||
List<String> builtinClassPatterns = []
|
||||
builtinModulesFile.readLines()
|
||||
.collect { String line -> line.contains('#') ? line.substring(0, line.indexOf('#')).trim() : line.trim() }
|
||||
.findAll { String line -> !line.isEmpty() }
|
||||
.each { String line ->
|
||||
List<String> parts = line.split(/\s+/, 2) as List<String>
|
||||
if (parts.size() < 2 || parts[1].isBlank()) {
|
||||
throw new GradleException("${builtinModulesFile.name}: '${line}' needs a value after '${parts[0]}'")
|
||||
}
|
||||
if (parts[0] == 'module') {
|
||||
builtinModuleClasses.add(parts[1].trim())
|
||||
} else if (parts[0] == 'include') {
|
||||
builtinClassPatterns.add(parts[1].trim())
|
||||
} else {
|
||||
throw new GradleException("${builtinModulesFile.name}: unknown line '${line}'; start it with 'module' or 'include'")
|
||||
}
|
||||
}
|
||||
List<String> builtinPackagedPatterns = builtinModuleClasses.collectMany { String moduleClass ->
|
||||
String path = moduleClass.replace('.', '/')
|
||||
[path + '.class', path + '$*.class']
|
||||
} + builtinClassPatterns
|
||||
Provider<Directory> builtinModulesBuild = layout.buildDirectory.dir('builtin-modules')
|
||||
|
||||
configurations {
|
||||
// What the jar check sees besides Iris's classes: the IrisApi and the libraries Iris shares with pack modules.
|
||||
builtinModulesCheckClasspath {
|
||||
canBeConsumed = false
|
||||
transitive = false
|
||||
attributes {
|
||||
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
builtinModulesCheckClasspath('com.volmit:IrisApi')
|
||||
builtinModulesCheckClasspath(volmLibCoordinate)
|
||||
builtinModulesCheckClasspath(libs.gson)
|
||||
}
|
||||
|
||||
def writeBuiltinModuleEntries = tasks.register('writeBuiltinModuleEntries') {
|
||||
description = "Writes the built-ins jar's META-INF/services/${builtinModuleEntryFile}, one module class per line."
|
||||
Provider<RegularFile> entries = builtinModulesBuild.map { it.file("services/${builtinModuleEntryFile}") }
|
||||
inputs.file(builtinModulesFile)
|
||||
outputs.file(entries)
|
||||
doLast {
|
||||
File entriesFile = entries.get().asFile
|
||||
entriesFile.parentFile.mkdirs()
|
||||
entriesFile.text = builtinModuleClasses.join('\n') + '\n'
|
||||
}
|
||||
}
|
||||
|
||||
def packageBuiltinModules = tasks.register('packageBuiltinModules', Jar) {
|
||||
description = 'Packages the listed built-in modules and classes before they are checked.'
|
||||
archiveFileName.set(builtinModulesJarName)
|
||||
destinationDirectory.set(builtinModulesBuild.map { it.dir('unchecked') })
|
||||
inputs.file(builtinModulesFile)
|
||||
from(sourceSets.main.java.classesDirectory) {
|
||||
include(builtinPackagedPatterns)
|
||||
}
|
||||
from(writeBuiltinModuleEntries) {
|
||||
into('META-INF/services')
|
||||
}
|
||||
}
|
||||
|
||||
def builtinModulesJar = tasks.register('builtinModulesJar', JavaExec) {
|
||||
group = 'build'
|
||||
description = "Builds build/builtin-modules/${builtinModulesJarName}, the built-in modules as a pack module jar, checked with" +
|
||||
" IrisApi's pack class and reference checks as a pack load would."
|
||||
dependsOn(packageBuiltinModules)
|
||||
Provider<RegularFile> unchecked = packageBuiltinModules.flatMap { it.archiveFile }
|
||||
Provider<RegularFile> checked = builtinModulesBuild.map { it.file(builtinModulesJarName) }
|
||||
classpath = configurations.builtinModulesCheckClasspath + files(sourceSets.main.java.classesDirectory)
|
||||
mainClass.set('com.volmit.host.ModuleJarCheck')
|
||||
inputs.file(unchecked)
|
||||
inputs.file(volmLibLeftOutFile)
|
||||
outputs.file(checked)
|
||||
argumentProviders.add({
|
||||
[unchecked.get().asFile.absolutePath, "--left-out=${volmLibLeftOutFile.absolutePath}".toString()] + builtinExposedPackages
|
||||
} as CommandLineArgumentProvider)
|
||||
ignoreExitValue = true
|
||||
ByteArrayOutputStream problems = new ByteArrayOutputStream()
|
||||
errorOutput = problems
|
||||
doFirst {
|
||||
// A jar from an earlier run that passed must not survive a run that fails.
|
||||
checked.get().asFile.delete()
|
||||
}
|
||||
doLast {
|
||||
if (executionResult.get().exitValue != 0) {
|
||||
throw new GradleException("The built-in modules jar breaks the rules of a pack module jar:\n" + problems.toString().trim() +
|
||||
"\nFix the classes listed in ${builtinModulesFile.name}, or move what they use into the jar or into art.arcane.iris.builtin.")
|
||||
}
|
||||
java.nio.file.Files.copy(unchecked.get().asFile.toPath(), checked.get().asFile.toPath())
|
||||
}
|
||||
}
|
||||
|
||||
// The jar's classes load from the bundled jar only, in each pack's class loader, so the plugin's own classes leave them out.
|
||||
tasks.named('jar', Jar).configure {
|
||||
exclude(builtinPackagedPatterns)
|
||||
from(builtinModulesJar)
|
||||
}
|
||||
|
||||
tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar).configure {
|
||||
dependsOn(embeddedAgentJar)
|
||||
exclude(builtinPackagedPatterns)
|
||||
from(builtinModulesJar)
|
||||
mergeServiceFiles()
|
||||
// minimize() stays off. Caffeine reaches its 520 generated cache and node classes through
|
||||
// MethodHandles.Lookup.findClass on a computed name, and the VolmLib command, GUI and hotload
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user