From ba9694083b70c4dba226c0a13a4fc305c3a16e69 Mon Sep 17 00:00:00 2001 From: Brian Fopiano Date: Mon, 30 Nov 2026 13:56:08 -0500 Subject: [PATCH] Adopt packaging standard - Ship the Bukkit runtime as a compact payload - Drop packaging lines that now match the plugin defaults - Verify native providers from PackedJar.readRuntime entries - Remove the unused xz dependency from buildSrc - Drop hand-written META-INF/maven excludes in mod builds - Keep native boundary checks on in the mod adapters --- adapters/fabric/build.gradle | 2 +- adapters/forge/build.gradle | 2 +- adapters/neoforge/build.gradle | 2 +- build.gradle | 14 ++--- buildSrc/build.gradle | 1 - .../src/main/java/NativeRuntimeArtifacts.java | 57 +++++++------------ .../test/java/NativeRuntimeArtifactsTest.java | 46 ++++++++------- 7 files changed, 57 insertions(+), 67 deletions(-) diff --git a/adapters/fabric/build.gradle b/adapters/fabric/build.gradle index f1bbf72df..39cf57690 100644 --- a/adapters/fabric/build.gradle +++ b/adapters/fabric/build.gradle @@ -331,7 +331,6 @@ tasks.named('shadowJar', ShadowJar).configure { if ((int) irisModTarget.java == 21) { exclude(java21RuntimeExclusions) } - exclude('META-INF/maven/**') exclude('META-INF/proguard/**') exclude('META-INF/*.SF') exclude('META-INF/*.DSA') @@ -415,6 +414,7 @@ tasks.named('assemble').configure { } pluginPackaging { + nativeBoundaryChecks = true artifacts { create('distribution') { taskName = irisModTarget.fabricRemap ? 'remapJar' : 'shadowJar' diff --git a/adapters/forge/build.gradle b/adapters/forge/build.gradle index 2fdbe8f28..dd5271b4e 100644 --- a/adapters/forge/build.gradle +++ b/adapters/forge/build.gradle @@ -320,7 +320,6 @@ tasks.named('shadowJar', ShadowJar).configure { if ((int) irisModTarget.java == 21) { exclude(java21RuntimeExclusions) } - exclude('META-INF/maven/**') exclude('META-INF/proguard/**') exclude('META-INF/*.SF') exclude('META-INF/*.DSA') @@ -377,6 +376,7 @@ tasks.named('assemble').configure { } pluginPackaging { + nativeBoundaryChecks = true artifacts { create('distribution') { taskName = 'shadowJar' diff --git a/adapters/neoforge/build.gradle b/adapters/neoforge/build.gradle index 7a70a8991..abde9e61e 100644 --- a/adapters/neoforge/build.gradle +++ b/adapters/neoforge/build.gradle @@ -304,7 +304,6 @@ tasks.named('shadowJar', ShadowJar).configure { if ((int) irisModTarget.java == 21) { exclude(java21RuntimeExclusions) } - exclude('META-INF/maven/**') exclude('META-INF/proguard/**') exclude('META-INF/*.SF') exclude('META-INF/*.DSA') @@ -361,6 +360,7 @@ tasks.named('assemble').configure { } pluginPackaging { + nativeBoundaryChecks = true artifacts { create('distribution') { taskName = 'shadowJar' diff --git a/build.gradle b/build.gradle index df75070d8..d12fc5a94 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,4 @@ import art.arcane.volmit.packaging.PackedJar -import art.arcane.volmit.packaging.PackagingMode import art.arcane.volmit.packaging.NativeDevelopmentTargets import io.papermc.paperweight.userdev.PaperweightUser import io.papermc.paperweight.userdev.PaperweightUserDependenciesExtension @@ -758,12 +757,8 @@ pluginPackaging { packed = true packedJarAccessors = ['art/arcane/iris/platform/bukkit/plugin/VolmitPlugin#getJarFile'] packedPayloadOnlyPrefixes = ['iris-language-guides/', 'META-INF/iris/generation-kernels/abi-', 'iris/icons/views/', 'iris/datapack/'] + packedCompactPayload = true packedMaximumBootstrapClasses = 90 - stripDirectories = true - stripLocalVariables = true - releaseCompression = providers.gradleProperty('compactRelease') - .map { String value -> value.toBoolean() } - .getOrElse(!PackagingMode.resolve(providers).development()) prunePrefixes = ['art/arcane/volmlib/'] keepPrefixes = ['art/arcane/volmlib/util/matter/slices/', 'art/arcane/volmlib/nativelib/'] shrinkRules = [file('packaging/shrink.pro'), nativeRuntimeRules.get().asFile] @@ -1010,7 +1005,12 @@ tasks.withType(PackedJar).configureEach { dependsOn(tasks.named('verifyBukkitArtifact'), nativeRuntime) nativeArtifacts.set(providers.provider { embeddedNatives() }) doLast { PackedJar task -> - NativeRuntimeArtifacts.verifyPacked(task.outputJar.get().asFile, nativeRuntimeModules, embeddedNatives()) + File artifact = task.outputJar.get().asFile + Map outer = NativeRuntimeArtifacts.entries(artifact) + Map runtime = outer.containsKey('META-INF/volmit/runtime.properties') + ? PackedJar.readRuntime(artifact.toPath()) : outer + NativeRuntimeArtifacts.verifyPacked(runtime, outer.get(NativeRuntimeArtifacts.MANIFEST), nativeRuntimeModules, + embeddedNatives()) } } diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 6049e11e9..61dc535ca 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -35,7 +35,6 @@ dependencies { implementation(gradleApi()) implementation('org.ow2.asm:asm:9.10.1') implementation('org.apache.commons:commons-compress:1.28.0') - implementation('org.tukaani:xz:1.10') implementation('io.papermc.paperweight:paperweight-userdev:2.0.0-beta.21') testImplementation('junit:junit:4.13.2') } diff --git a/buildSrc/src/main/java/NativeRuntimeArtifacts.java b/buildSrc/src/main/java/NativeRuntimeArtifacts.java index f5aa0aaf5..506441988 100644 --- a/buildSrc/src/main/java/NativeRuntimeArtifacts.java +++ b/buildSrc/src/main/java/NativeRuntimeArtifacts.java @@ -1,5 +1,4 @@ import org.gradle.api.GradleException; -import org.tukaani.xz.XZInputStream; import java.io.ByteArrayInputStream; import java.io.File; @@ -28,7 +27,6 @@ import java.util.zip.ZipInputStream; public final class NativeRuntimeArtifacts { public static final String MANIFEST = "META-INF/iris/native-runtime.properties"; public static final String RESOURCES = "META-INF/iris/native/"; - private static final String PAYLOAD = "META-INF/volmit/runtime.jar.xz"; private static final String GROUP = "com.github.VolmitSoftware.VolmLib"; private static final String NATIVE = "art/arcane/volmlib/nativelib/"; @@ -99,35 +97,20 @@ public final class NativeRuntimeArtifacts { } } - public static void verifyPacked(File artifact, List modules, Map natives) throws IOException { + /** Checks the native providers inside {@code runtime}, the entries the plugin runs from, against the resolved build. */ + public static void verifyPacked(Map runtime, byte[] outerManifest, List modules, + Map natives) throws IOException { requireModules(natives, modules); - Map contents; - try (JarFile jar = new JarFile(artifact)) { - JarEntry payload = jar.getJarEntry(PAYLOAD); - if (payload == null) { - contents = read(Files.newInputStream(artifact.toPath())); - } else { - try (InputStream input = new XZInputStream(jar.getInputStream(payload))) { - contents = read(new ByteArrayInputStream(input.readAllBytes())); - } - JarEntry outer = jar.getJarEntry(MANIFEST); - byte[] embedded = contents.get(MANIFEST); - if (outer != null && embedded != null) { - try (InputStream input = jar.getInputStream(outer)) { - if (!Arrays.equals(input.readAllBytes(), embedded)) { - throw new GradleException("Packed native runtime manifests differ"); - } - } - } - } - } - byte[] manifest = contents.get(MANIFEST); + byte[] manifest = runtime.get(MANIFEST); if (manifest == null) { throw new GradleException("Missing native runtime dependency manifest"); } + if (outerManifest != null && !Arrays.equals(outerManifest, manifest)) { + throw new GradleException("Packed native runtime manifests differ"); + } verifyManifest(manifest, natives); for (String module : natives.keySet()) { - byte[] provider = contents.get(RESOURCES + module + ".jar"); + byte[] provider = runtime.get(RESOURCES + module + ".jar"); if (provider == null) { throw new GradleException("Missing embedded native provider: " + module); } @@ -137,6 +120,18 @@ public final class NativeRuntimeArtifacts { } } + public static Map entries(File artifact) throws IOException { + Map contents = new TreeMap<>(); + try (ZipInputStream archive = new ZipInputStream(Files.newInputStream(artifact.toPath()))) { + for (ZipEntry entry = archive.getNextEntry(); entry != null; entry = archive.getNextEntry()) { + if (!entry.isDirectory()) { + contents.put(entry.getName(), archive.readAllBytes()); + } + } + } + return contents; + } + private static void verifyManifest(byte[] bytes, Map natives) throws IOException { Properties manifest = new Properties(); manifest.load(new ByteArrayInputStream(bytes)); @@ -163,18 +158,6 @@ public final class NativeRuntimeArtifacts { } } - private static Map read(InputStream source) throws IOException { - Map contents = new TreeMap<>(); - try (ZipInputStream archive = new ZipInputStream(source)) { - for (ZipEntry entry = archive.getNextEntry(); entry != null; entry = archive.getNextEntry()) { - if (!entry.isDirectory()) { - contents.put(entry.getName(), archive.readAllBytes()); - } - } - } - return contents; - } - private static boolean implementation(String name) { if (!name.startsWith(NATIVE)) { return false; diff --git a/buildSrc/src/test/java/NativeRuntimeArtifactsTest.java b/buildSrc/src/test/java/NativeRuntimeArtifactsTest.java index fb4afa76b..108387136 100644 --- a/buildSrc/src/test/java/NativeRuntimeArtifactsTest.java +++ b/buildSrc/src/test/java/NativeRuntimeArtifactsTest.java @@ -4,13 +4,11 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Opcodes; -import org.tukaani.xz.LZMA2Options; -import org.tukaani.xz.XZOutputStream; -import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.Reader; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.security.MessageDigest; @@ -22,6 +20,7 @@ import java.util.TreeMap; import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; +import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThrows; @@ -89,15 +88,35 @@ public class NativeRuntimeArtifactsTest { public void verifiesTheEmbeddedProviderBytesInsideThePackedRuntime() throws Exception { Map natives = natives(); Map runtime = runtime(natives, natives); - NativeRuntimeArtifacts.verifyPacked(packed(runtime), MODULES, natives); - NativeRuntimeArtifacts.verifyPacked(jar("ordinary.jar", runtime), MODULES, natives); + byte[] manifest = runtime.get(NativeRuntimeArtifacts.MANIFEST); + NativeRuntimeArtifacts.verifyPacked(runtime, manifest, MODULES, natives); + NativeRuntimeArtifacts.verifyPacked(runtime, null, MODULES, natives); Map rebuilt = new TreeMap<>(natives); rebuilt.put("native-v26_2_R1", provider("rebuilt.jar", "art/arcane/volmlib/util/collection/KMap")); - assertThrows(GradleException.class, () -> NativeRuntimeArtifacts.verifyPacked(packed(runtime(natives, rebuilt)), - MODULES, natives)); + assertThrows(GradleException.class, () -> NativeRuntimeArtifacts.verifyPacked(runtime(natives, rebuilt), + manifest, MODULES, natives)); Map missing = new TreeMap<>(runtime); missing.remove(NativeRuntimeArtifacts.RESOURCES + "native-v26_2_R1.jar"); - assertThrows(GradleException.class, () -> NativeRuntimeArtifacts.verifyPacked(packed(missing), MODULES, natives)); + assertThrows(GradleException.class, () -> NativeRuntimeArtifacts.verifyPacked(missing, manifest, MODULES, natives)); + } + + @Test + public void rejectsAnOuterManifestThatDiffersFromTheRuntimeOne() throws Exception { + Map natives = natives(); + Map runtime = runtime(natives, natives); + byte[] outer = (new String(runtime.get(NativeRuntimeArtifacts.MANIFEST), StandardCharsets.UTF_8) + "extra=1\n") + .getBytes(StandardCharsets.UTF_8); + assertThrows(GradleException.class, () -> NativeRuntimeArtifacts.verifyPacked(runtime, outer, MODULES, natives)); + } + + @Test + public void readsEveryFileEntryOfAnOrdinaryJar() throws Exception { + Map runtime = runtime(natives(), natives()); + Map read = NativeRuntimeArtifacts.entries(jar("ordinary.jar", runtime)); + assertEquals(runtime.keySet(), read.keySet()); + for (Map.Entry entry : runtime.entrySet()) { + assertArrayEquals(entry.getValue(), read.get(entry.getKey())); + } } private Map natives() throws IOException { @@ -137,17 +156,6 @@ public class NativeRuntimeArtifactsTest { return contents; } - private File packed(Map runtime) throws IOException { - ByteArrayOutputStream compressed = new ByteArrayOutputStream(); - try (XZOutputStream xz = new XZOutputStream(compressed, new LZMA2Options(1))) { - xz.write(Files.readAllBytes(jar("payload.jar", runtime).toPath())); - } - Map outer = new TreeMap<>(); - outer.put(NativeRuntimeArtifacts.MANIFEST, runtime.get(NativeRuntimeArtifacts.MANIFEST)); - outer.put("META-INF/volmit/runtime.jar.xz", compressed.toByteArray()); - return jar("packed.jar", outer); - } - private File jar(String name, Map contents) throws IOException { Path file = temporary.newFolder().toPath().resolve(name); try (JarOutputStream jar = new JarOutputStream(Files.newOutputStream(file))) {