From 1bd678c494009f2707b3cdf48ed10cd95b7e3fd5 Mon Sep 17 00:00:00 2001 From: Jason <11360596+jpenilla@users.noreply.github.com> Date: Mon, 27 Jun 2022 15:41:59 -0700 Subject: [PATCH] [ci skip] Scan built jars for bad method usages (#8051) --- Paper-MojangAPI/build.gradle.kts | 9 ++++ patches/api/0002-Build-system-changes.patch | 41 ++++++++++++++++++- .../server/0003-Build-system-changes.patch | 20 ++++++++- ...ktraces-in-log-messages-crash-report.patch | 6 +-- 4 files changed, 71 insertions(+), 5 deletions(-) diff --git a/Paper-MojangAPI/build.gradle.kts b/Paper-MojangAPI/build.gradle.kts index 3275a3bf46..a278ee93d7 100644 --- a/Paper-MojangAPI/build.gradle.kts +++ b/Paper-MojangAPI/build.gradle.kts @@ -25,3 +25,12 @@ configure { from(components["java"]) } } + +val scanJar = tasks.register("scanJarForBadCalls", io.papermc.paperweight.tasks.ScanJarForBadCalls::class) { + badAnnotations.add("Lio/papermc/paper/annotation/DoNotUse;") + jarToScan.set(tasks.jar.flatMap { it.archiveFile }) + classpath.from(configurations.compileClasspath) +} +tasks.check { + dependsOn(scanJar) +} diff --git a/patches/api/0002-Build-system-changes.patch b/patches/api/0002-Build-system-changes.patch index ed022f5f4e..677a85f5ec 100644 --- a/patches/api/0002-Build-system-changes.patch +++ b/patches/api/0002-Build-system-changes.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Build system changes diff --git a/build.gradle.kts b/build.gradle.kts -index b81a893bd5418779544872eb4006adc6b3017a43..044b7c49b569e1170108c912e9307f7fec278762 100644 +index b81a893bd5418779544872eb4006adc6b3017a43..0b30b1f1be8818934ba530dd263fe6c9484983e8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,15 +14,27 @@ dependencies { @@ -46,3 +46,42 @@ index b81a893bd5418779544872eb4006adc6b3017a43..044b7c49b569e1170108c912e9307f7f "https://javadoc.io/doc/net.md-5/bungeecord-chat/1.16-R0.4/", ) +@@ -78,3 +90,14 @@ tasks.withType { + } + } + } ++ ++// Paper start ++val scanJar = tasks.register("scanJarForBadCalls", io.papermc.paperweight.tasks.ScanJarForBadCalls::class) { ++ badAnnotations.add("Lio/papermc/paper/annotation/DoNotUse;") ++ jarToScan.set(tasks.jar.flatMap { it.archiveFile }) ++ classpath.from(configurations.compileClasspath) ++} ++tasks.check { ++ dependsOn(scanJar) ++} ++// Paper end +diff --git a/src/main/java/io/papermc/paper/annotation/DoNotUse.java b/src/main/java/io/papermc/paper/annotation/DoNotUse.java +new file mode 100644 +index 0000000000000000000000000000000000000000..4766e49d819e75e5c2127c698b44078bf2fd6219 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/annotation/DoNotUse.java +@@ -0,0 +1,18 @@ ++package io.papermc.paper.annotation; ++ ++import java.lang.annotation.ElementType; ++import java.lang.annotation.Retention; ++import java.lang.annotation.RetentionPolicy; ++import java.lang.annotation.Target; ++import org.jetbrains.annotations.ApiStatus; ++ ++/** ++ * Annotation used to mark methods or constructors which should not be called. ++ * ++ *

Separate from {@link Deprecated} to differentiate from the large amount of deprecations.

++ */ ++@ApiStatus.Internal ++@Retention(RetentionPolicy.RUNTIME) ++@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) ++public @interface DoNotUse { ++} diff --git a/patches/server/0003-Build-system-changes.patch b/patches/server/0003-Build-system-changes.patch index 7ce0076cbb..72af6596d9 100644 --- a/patches/server/0003-Build-system-changes.patch +++ b/patches/server/0003-Build-system-changes.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Build system changes diff --git a/build.gradle.kts b/build.gradle.kts -index d10ff4a52c22033e2adb2a4e7f2cee98a13ea6c5..e4e9df9283c1a0fd7fff38a5d9b6a51f15e06b7a 100644 +index d10ff4a52c22033e2adb2a4e7f2cee98a13ea6c5..5d8a84341ab5be52b5c37737e3f82590f06f6073 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,10 +9,9 @@ plugins { @@ -48,6 +48,24 @@ index d10ff4a52c22033e2adb2a4e7f2cee98a13ea6c5..e4e9df9283c1a0fd7fff38a5d9b6a51f ) for (tld in setOf("net", "com", "org")) { attributes("$tld/bukkit", "Sealed" to true) +@@ -75,6 +80,17 @@ tasks.shadowJar { + } + } + ++// Paper start ++val scanJar = tasks.register("scanJarForBadCalls", io.papermc.paperweight.tasks.ScanJarForBadCalls::class) { ++ badAnnotations.add("Lio/papermc/paper/annotation/DoNotUse;") ++ jarToScan.set(tasks.shadowJar.flatMap { it.archiveFile }) ++ classpath.from(configurations.compileClasspath) ++} ++tasks.check { ++ dependsOn(scanJar) ++} ++// Paper end ++ + tasks.test { + exclude("org/bukkit/craftbukkit/inventory/ItemStack*Test.class") + } diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java index 95da14060be14c5ed8ffbdc65b405cb346e56f6e..80a8872b927ed9de61f1ee36b7769ce104793443 100644 --- a/src/main/java/org/bukkit/craftbukkit/Main.java diff --git a/patches/server/0408-Deobfuscate-stacktraces-in-log-messages-crash-report.patch b/patches/server/0408-Deobfuscate-stacktraces-in-log-messages-crash-report.patch index 16bf727363..981e5c6969 100644 --- a/patches/server/0408-Deobfuscate-stacktraces-in-log-messages-crash-report.patch +++ b/patches/server/0408-Deobfuscate-stacktraces-in-log-messages-crash-report.patch @@ -6,7 +6,7 @@ Subject: [PATCH] Deobfuscate stacktraces in log messages, crash reports, and diff --git a/build.gradle.kts b/build.gradle.kts -index 708915dfc740360752e7e93b185f469481fdf6e5..6def770d18acc25b9bda1917688039448b36309d 100644 +index e260462933a9f7065b2360e6bf9e4ee56069a705..a1a8c4778742584125d6084fa761b1bc86f6a842 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,6 @@ @@ -31,9 +31,9 @@ index 708915dfc740360752e7e93b185f469481fdf6e5..6def770d18acc25b9bda191768803944 runtimeOnly("org.xerial:sqlite-jdbc:3.36.0.3") runtimeOnly("mysql:mysql-connector-java:8.0.29") runtimeOnly("com.lmax:disruptor:3.4.4") // Paper -@@ -93,6 +97,45 @@ tasks.shadowJar { - } +@@ -104,6 +108,45 @@ tasks.check { } + // Paper end +// Paper start - include reobf mappings in jar for stacktrace deobfuscation +abstract class IncludeMappings : BaseTask() {