mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-03 19:51:49 +00:00
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
This commit is contained in:
7 files changed
+57
-67
No files matched your search
@@ -331,7 +331,6 @@ tasks.named('shadowJar', ShadowJar).configure {
|
|||||||
if ((int) irisModTarget.java == 21) {
|
if ((int) irisModTarget.java == 21) {
|
||||||
exclude(java21RuntimeExclusions)
|
exclude(java21RuntimeExclusions)
|
||||||
}
|
}
|
||||||
exclude('META-INF/maven/**')
|
|
||||||
exclude('META-INF/proguard/**')
|
exclude('META-INF/proguard/**')
|
||||||
exclude('META-INF/*.SF')
|
exclude('META-INF/*.SF')
|
||||||
exclude('META-INF/*.DSA')
|
exclude('META-INF/*.DSA')
|
||||||
@@ -415,6 +414,7 @@ tasks.named('assemble').configure {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pluginPackaging {
|
pluginPackaging {
|
||||||
|
nativeBoundaryChecks = true
|
||||||
artifacts {
|
artifacts {
|
||||||
create('distribution') {
|
create('distribution') {
|
||||||
taskName = irisModTarget.fabricRemap ? 'remapJar' : 'shadowJar'
|
taskName = irisModTarget.fabricRemap ? 'remapJar' : 'shadowJar'
|
||||||
|
|||||||
@@ -320,7 +320,6 @@ tasks.named('shadowJar', ShadowJar).configure {
|
|||||||
if ((int) irisModTarget.java == 21) {
|
if ((int) irisModTarget.java == 21) {
|
||||||
exclude(java21RuntimeExclusions)
|
exclude(java21RuntimeExclusions)
|
||||||
}
|
}
|
||||||
exclude('META-INF/maven/**')
|
|
||||||
exclude('META-INF/proguard/**')
|
exclude('META-INF/proguard/**')
|
||||||
exclude('META-INF/*.SF')
|
exclude('META-INF/*.SF')
|
||||||
exclude('META-INF/*.DSA')
|
exclude('META-INF/*.DSA')
|
||||||
@@ -377,6 +376,7 @@ tasks.named('assemble').configure {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pluginPackaging {
|
pluginPackaging {
|
||||||
|
nativeBoundaryChecks = true
|
||||||
artifacts {
|
artifacts {
|
||||||
create('distribution') {
|
create('distribution') {
|
||||||
taskName = 'shadowJar'
|
taskName = 'shadowJar'
|
||||||
|
|||||||
@@ -304,7 +304,6 @@ tasks.named('shadowJar', ShadowJar).configure {
|
|||||||
if ((int) irisModTarget.java == 21) {
|
if ((int) irisModTarget.java == 21) {
|
||||||
exclude(java21RuntimeExclusions)
|
exclude(java21RuntimeExclusions)
|
||||||
}
|
}
|
||||||
exclude('META-INF/maven/**')
|
|
||||||
exclude('META-INF/proguard/**')
|
exclude('META-INF/proguard/**')
|
||||||
exclude('META-INF/*.SF')
|
exclude('META-INF/*.SF')
|
||||||
exclude('META-INF/*.DSA')
|
exclude('META-INF/*.DSA')
|
||||||
@@ -361,6 +360,7 @@ tasks.named('assemble').configure {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pluginPackaging {
|
pluginPackaging {
|
||||||
|
nativeBoundaryChecks = true
|
||||||
artifacts {
|
artifacts {
|
||||||
create('distribution') {
|
create('distribution') {
|
||||||
taskName = 'shadowJar'
|
taskName = 'shadowJar'
|
||||||
|
|||||||
+7
-7
@@ -1,5 +1,4 @@
|
|||||||
import art.arcane.volmit.packaging.PackedJar
|
import art.arcane.volmit.packaging.PackedJar
|
||||||
import art.arcane.volmit.packaging.PackagingMode
|
|
||||||
import art.arcane.volmit.packaging.NativeDevelopmentTargets
|
import art.arcane.volmit.packaging.NativeDevelopmentTargets
|
||||||
import io.papermc.paperweight.userdev.PaperweightUser
|
import io.papermc.paperweight.userdev.PaperweightUser
|
||||||
import io.papermc.paperweight.userdev.PaperweightUserDependenciesExtension
|
import io.papermc.paperweight.userdev.PaperweightUserDependenciesExtension
|
||||||
@@ -758,12 +757,8 @@ pluginPackaging {
|
|||||||
packed = true
|
packed = true
|
||||||
packedJarAccessors = ['art/arcane/iris/platform/bukkit/plugin/VolmitPlugin#getJarFile']
|
packedJarAccessors = ['art/arcane/iris/platform/bukkit/plugin/VolmitPlugin#getJarFile']
|
||||||
packedPayloadOnlyPrefixes = ['iris-language-guides/', 'META-INF/iris/generation-kernels/abi-', 'iris/icons/views/', 'iris/datapack/']
|
packedPayloadOnlyPrefixes = ['iris-language-guides/', 'META-INF/iris/generation-kernels/abi-', 'iris/icons/views/', 'iris/datapack/']
|
||||||
|
packedCompactPayload = true
|
||||||
packedMaximumBootstrapClasses = 90
|
packedMaximumBootstrapClasses = 90
|
||||||
stripDirectories = true
|
|
||||||
stripLocalVariables = true
|
|
||||||
releaseCompression = providers.gradleProperty('compactRelease')
|
|
||||||
.map { String value -> value.toBoolean() }
|
|
||||||
.getOrElse(!PackagingMode.resolve(providers).development())
|
|
||||||
prunePrefixes = ['art/arcane/volmlib/']
|
prunePrefixes = ['art/arcane/volmlib/']
|
||||||
keepPrefixes = ['art/arcane/volmlib/util/matter/slices/', 'art/arcane/volmlib/nativelib/']
|
keepPrefixes = ['art/arcane/volmlib/util/matter/slices/', 'art/arcane/volmlib/nativelib/']
|
||||||
shrinkRules = [file('packaging/shrink.pro'), nativeRuntimeRules.get().asFile]
|
shrinkRules = [file('packaging/shrink.pro'), nativeRuntimeRules.get().asFile]
|
||||||
@@ -1010,7 +1005,12 @@ tasks.withType(PackedJar).configureEach {
|
|||||||
dependsOn(tasks.named('verifyBukkitArtifact'), nativeRuntime)
|
dependsOn(tasks.named('verifyBukkitArtifact'), nativeRuntime)
|
||||||
nativeArtifacts.set(providers.provider { embeddedNatives() })
|
nativeArtifacts.set(providers.provider { embeddedNatives() })
|
||||||
doLast { PackedJar task ->
|
doLast { PackedJar task ->
|
||||||
NativeRuntimeArtifacts.verifyPacked(task.outputJar.get().asFile, nativeRuntimeModules, embeddedNatives())
|
File artifact = task.outputJar.get().asFile
|
||||||
|
Map<String, byte[]> outer = NativeRuntimeArtifacts.entries(artifact)
|
||||||
|
Map<String, byte[]> runtime = outer.containsKey('META-INF/volmit/runtime.properties')
|
||||||
|
? PackedJar.readRuntime(artifact.toPath()) : outer
|
||||||
|
NativeRuntimeArtifacts.verifyPacked(runtime, outer.get(NativeRuntimeArtifacts.MANIFEST), nativeRuntimeModules,
|
||||||
|
embeddedNatives())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ dependencies {
|
|||||||
implementation(gradleApi())
|
implementation(gradleApi())
|
||||||
implementation('org.ow2.asm:asm:9.10.1')
|
implementation('org.ow2.asm:asm:9.10.1')
|
||||||
implementation('org.apache.commons:commons-compress:1.28.0')
|
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')
|
implementation('io.papermc.paperweight:paperweight-userdev:2.0.0-beta.21')
|
||||||
testImplementation('junit:junit:4.13.2')
|
testImplementation('junit:junit:4.13.2')
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import org.gradle.api.GradleException;
|
import org.gradle.api.GradleException;
|
||||||
import org.tukaani.xz.XZInputStream;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -28,7 +27,6 @@ import java.util.zip.ZipInputStream;
|
|||||||
public final class NativeRuntimeArtifacts {
|
public final class NativeRuntimeArtifacts {
|
||||||
public static final String MANIFEST = "META-INF/iris/native-runtime.properties";
|
public static final String MANIFEST = "META-INF/iris/native-runtime.properties";
|
||||||
public static final String RESOURCES = "META-INF/iris/native/";
|
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 GROUP = "com.github.VolmitSoftware.VolmLib";
|
||||||
private static final String NATIVE = "art/arcane/volmlib/nativelib/";
|
private static final String NATIVE = "art/arcane/volmlib/nativelib/";
|
||||||
|
|
||||||
@@ -99,35 +97,20 @@ public final class NativeRuntimeArtifacts {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void verifyPacked(File artifact, List<String> modules, Map<String, File> 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<String, byte[]> runtime, byte[] outerManifest, List<String> modules,
|
||||||
|
Map<String, File> natives) throws IOException {
|
||||||
requireModules(natives, modules);
|
requireModules(natives, modules);
|
||||||
Map<String, byte[]> contents;
|
byte[] manifest = runtime.get(MANIFEST);
|
||||||
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);
|
|
||||||
if (manifest == null) {
|
if (manifest == null) {
|
||||||
throw new GradleException("Missing native runtime dependency manifest");
|
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);
|
verifyManifest(manifest, natives);
|
||||||
for (String module : natives.keySet()) {
|
for (String module : natives.keySet()) {
|
||||||
byte[] provider = contents.get(RESOURCES + module + ".jar");
|
byte[] provider = runtime.get(RESOURCES + module + ".jar");
|
||||||
if (provider == null) {
|
if (provider == null) {
|
||||||
throw new GradleException("Missing embedded native provider: " + module);
|
throw new GradleException("Missing embedded native provider: " + module);
|
||||||
}
|
}
|
||||||
@@ -137,6 +120,18 @@ public final class NativeRuntimeArtifacts {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Map<String, byte[]> entries(File artifact) throws IOException {
|
||||||
|
Map<String, byte[]> 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<String, File> natives) throws IOException {
|
private static void verifyManifest(byte[] bytes, Map<String, File> natives) throws IOException {
|
||||||
Properties manifest = new Properties();
|
Properties manifest = new Properties();
|
||||||
manifest.load(new ByteArrayInputStream(bytes));
|
manifest.load(new ByteArrayInputStream(bytes));
|
||||||
@@ -163,18 +158,6 @@ public final class NativeRuntimeArtifacts {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<String, byte[]> read(InputStream source) throws IOException {
|
|
||||||
Map<String, byte[]> 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) {
|
private static boolean implementation(String name) {
|
||||||
if (!name.startsWith(NATIVE)) {
|
if (!name.startsWith(NATIVE)) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -4,13 +4,11 @@ import org.junit.Test;
|
|||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.rules.TemporaryFolder;
|
||||||
import org.objectweb.asm.ClassWriter;
|
import org.objectweb.asm.ClassWriter;
|
||||||
import org.objectweb.asm.Opcodes;
|
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.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
@@ -22,6 +20,7 @@ import java.util.TreeMap;
|
|||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarOutputStream;
|
import java.util.jar.JarOutputStream;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertThrows;
|
import static org.junit.Assert.assertThrows;
|
||||||
@@ -89,15 +88,35 @@ public class NativeRuntimeArtifactsTest {
|
|||||||
public void verifiesTheEmbeddedProviderBytesInsideThePackedRuntime() throws Exception {
|
public void verifiesTheEmbeddedProviderBytesInsideThePackedRuntime() throws Exception {
|
||||||
Map<String, File> natives = natives();
|
Map<String, File> natives = natives();
|
||||||
Map<String, byte[]> runtime = runtime(natives, natives);
|
Map<String, byte[]> runtime = runtime(natives, natives);
|
||||||
NativeRuntimeArtifacts.verifyPacked(packed(runtime), MODULES, natives);
|
byte[] manifest = runtime.get(NativeRuntimeArtifacts.MANIFEST);
|
||||||
NativeRuntimeArtifacts.verifyPacked(jar("ordinary.jar", runtime), MODULES, natives);
|
NativeRuntimeArtifacts.verifyPacked(runtime, manifest, MODULES, natives);
|
||||||
|
NativeRuntimeArtifacts.verifyPacked(runtime, null, MODULES, natives);
|
||||||
Map<String, File> rebuilt = new TreeMap<>(natives);
|
Map<String, File> rebuilt = new TreeMap<>(natives);
|
||||||
rebuilt.put("native-v26_2_R1", provider("rebuilt.jar", "art/arcane/volmlib/util/collection/KMap"));
|
rebuilt.put("native-v26_2_R1", provider("rebuilt.jar", "art/arcane/volmlib/util/collection/KMap"));
|
||||||
assertThrows(GradleException.class, () -> NativeRuntimeArtifacts.verifyPacked(packed(runtime(natives, rebuilt)),
|
assertThrows(GradleException.class, () -> NativeRuntimeArtifacts.verifyPacked(runtime(natives, rebuilt),
|
||||||
MODULES, natives));
|
manifest, MODULES, natives));
|
||||||
Map<String, byte[]> missing = new TreeMap<>(runtime);
|
Map<String, byte[]> missing = new TreeMap<>(runtime);
|
||||||
missing.remove(NativeRuntimeArtifacts.RESOURCES + "native-v26_2_R1.jar");
|
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<String, File> natives = natives();
|
||||||
|
Map<String, byte[]> 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<String, byte[]> runtime = runtime(natives(), natives());
|
||||||
|
Map<String, byte[]> read = NativeRuntimeArtifacts.entries(jar("ordinary.jar", runtime));
|
||||||
|
assertEquals(runtime.keySet(), read.keySet());
|
||||||
|
for (Map.Entry<String, byte[]> entry : runtime.entrySet()) {
|
||||||
|
assertArrayEquals(entry.getValue(), read.get(entry.getKey()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, File> natives() throws IOException {
|
private Map<String, File> natives() throws IOException {
|
||||||
@@ -137,17 +156,6 @@ public class NativeRuntimeArtifactsTest {
|
|||||||
return contents;
|
return contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
private File packed(Map<String, byte[]> 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<String, byte[]> 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<String, byte[]> contents) throws IOException {
|
private File jar(String name, Map<String, byte[]> contents) throws IOException {
|
||||||
Path file = temporary.newFolder().toPath().resolve(name);
|
Path file = temporary.newFolder().toPath().resolve(name);
|
||||||
try (JarOutputStream jar = new JarOutputStream(Files.newOutputStream(file))) {
|
try (JarOutputStream jar = new JarOutputStream(Files.newOutputStream(file))) {
|
||||||
|
|||||||
Reference in new issue
Block a user