mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-30 16:19:03 +01:00
Split rewriting flag into paper.disableOldApiSupport
and paper.disablePluginRemapping
(#11108)
This commit is contained in:
parent
4c38b7496b
commit
203314faf8
3 changed files with 39 additions and 31 deletions
|
@ -915,8 +915,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
- visitor = new LimitedClassRemapper(cw, new SimpleRemapper(Commodore.ENUM_RENAMES));
|
- visitor = new LimitedClassRemapper(cw, new SimpleRemapper(Commodore.ENUM_RENAMES));
|
||||||
- }
|
- }
|
||||||
|
|
||||||
cr.accept(new ClassRemapper(new ClassVisitor(Opcodes.ASM9, io.papermc.paper.pluginremap.reflect.ReflectionRemapper.visitor(visitor)) { // Paper
|
visitor = io.papermc.paper.pluginremap.reflect.ReflectionRemapper.visitor(visitor); // Paper
|
||||||
final Set<RerouteMethodData> rerouteMethodData = new HashSet<>();
|
cr.accept(new ClassRemapper(new ClassVisitor(Opcodes.ASM9, visitor) {
|
||||||
@@ -0,0 +0,0 @@ public class Commodore {
|
@@ -0,0 +0,0 @@ public class Commodore {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -92,7 +92,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
PluginInitializerManager(final Path pluginDirectory, final Path updateDirectory) {
|
PluginInitializerManager(final Path pluginDirectory, final Path updateDirectory) {
|
||||||
this.pluginDirectory = pluginDirectory;
|
this.pluginDirectory = pluginDirectory;
|
||||||
this.updateDirectory = updateDirectory;
|
this.updateDirectory = updateDirectory;
|
||||||
+ this.pluginRemapper = Boolean.getBoolean("paper.disable-plugin-rewriting")
|
+ this.pluginRemapper = Boolean.getBoolean("paper.disablePluginRemapping")
|
||||||
+ ? null
|
+ ? null
|
||||||
+ : PluginRemapper.create(pluginDirectory);
|
+ : PluginRemapper.create(pluginDirectory);
|
||||||
+ LibraryLoader.REMAPPER = this.pluginRemapper == null ? Function.identity() : this.pluginRemapper::remapLibraries;
|
+ LibraryLoader.REMAPPER = this.pluginRemapper == null ? Function.identity() : this.pluginRemapper::remapLibraries;
|
||||||
|
|
|
@ -240,23 +240,12 @@ diff --git a/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperC
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperClassloaderBytecodeModifier.java
|
--- a/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperClassloaderBytecodeModifier.java
|
||||||
+++ b/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperClassloaderBytecodeModifier.java
|
+++ b/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperClassloaderBytecodeModifier.java
|
||||||
@@ -0,0 +0,0 @@
|
@@ -0,0 +0,0 @@ public class PaperClassloaderBytecodeModifier implements ClassloaderBytecodeModi
|
||||||
package io.papermc.paper.plugin.entrypoint.classloader;
|
|
||||||
|
|
||||||
import io.papermc.paper.plugin.configuration.PluginMeta;
|
|
||||||
+import org.objectweb.asm.ClassReader;
|
|
||||||
+import org.objectweb.asm.ClassWriter;
|
|
||||||
|
|
||||||
// Stub, implement in future.
|
|
||||||
public class PaperClassloaderBytecodeModifier implements ClassloaderBytecodeModifier {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] modify(PluginMeta configuration, byte[] bytecode) {
|
public byte[] modify(PluginMeta configuration, byte[] bytecode) {
|
||||||
- return bytecode;
|
- return bytecode;
|
||||||
+ ClassReader classReader = new ClassReader(bytecode);
|
+ return io.papermc.paper.pluginremap.reflect.ReflectionRemapper.processClass(bytecode);
|
||||||
+ ClassWriter classWriter = new ClassWriter(classReader, 0);
|
|
||||||
+ classReader.accept(io.papermc.paper.pluginremap.reflect.ReflectionRemapper.visitor(classWriter), 0);
|
|
||||||
+ return classWriter.toByteArray();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
diff --git a/src/main/java/io/papermc/paper/plugin/loader/PaperClasspathBuilder.java b/src/main/java/io/papermc/paper/plugin/loader/PaperClasspathBuilder.java
|
diff --git a/src/main/java/io/papermc/paper/plugin/loader/PaperClasspathBuilder.java b/src/main/java/io/papermc/paper/plugin/loader/PaperClasspathBuilder.java
|
||||||
|
@ -292,7 +281,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
|
|
||||||
try {
|
try {
|
||||||
- return new PaperPluginClassLoader(logger, source, jarFile, configuration, this.getClass().getClassLoader(), new URLClassLoader(urls, getClass().getClassLoader()));
|
- return new PaperPluginClassLoader(logger, source, jarFile, configuration, this.getClass().getClassLoader(), new URLClassLoader(urls, getClass().getClassLoader()));
|
||||||
+ final URLClassLoader libraryLoader = MappingEnvironment.DISABLE_PLUGIN_REWRITING
|
+ final URLClassLoader libraryLoader = MappingEnvironment.DISABLE_PLUGIN_REMAPPING
|
||||||
+ ? new URLClassLoader(urls, this.getClass().getClassLoader())
|
+ ? new URLClassLoader(urls, this.getClass().getClassLoader())
|
||||||
+ : new BytecodeModifyingURLClassLoader(urls, this.getClass().getClassLoader());
|
+ : new BytecodeModifyingURLClassLoader(urls, this.getClass().getClassLoader());
|
||||||
+ return new PaperPluginClassLoader(logger, source, jarFile, configuration, this.getClass().getClassLoader(), libraryLoader);
|
+ return new PaperPluginClassLoader(logger, source, jarFile, configuration, this.getClass().getClassLoader(), libraryLoader);
|
||||||
|
@ -321,7 +310,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
class SpigotPluginProviderFactory implements PluginTypeFactory<SpigotPluginProvider, PluginDescriptionFile> {
|
class SpigotPluginProviderFactory implements PluginTypeFactory<SpigotPluginProvider, PluginDescriptionFile> {
|
||||||
|
|
||||||
+ static {
|
+ static {
|
||||||
+ if (!MappingEnvironment.DISABLE_PLUGIN_REWRITING) {
|
+ if (!MappingEnvironment.DISABLE_PLUGIN_REMAPPING) {
|
||||||
+ LibraryLoader.LIBRARY_LOADER_FACTORY = BytecodeModifyingURLClassLoader::new;
|
+ LibraryLoader.LIBRARY_LOADER_FACTORY = BytecodeModifyingURLClassLoader::new;
|
||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
|
@ -352,8 +341,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+import org.checkerframework.checker.nullness.qual.NonNull;
|
+import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
+import org.checkerframework.checker.nullness.qual.Nullable;
|
+import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
+import org.checkerframework.framework.qual.DefaultQualifier;
|
+import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
+import org.objectweb.asm.ClassReader;
|
|
||||||
+import org.objectweb.asm.ClassWriter;
|
|
||||||
+import org.slf4j.Logger;
|
+import org.slf4j.Logger;
|
||||||
+
|
+
|
||||||
+// todo proper inheritance handling
|
+// todo proper inheritance handling
|
||||||
|
@ -541,10 +528,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ // todo apply bytecode remap here as well
|
+ // todo apply bytecode remap here as well
|
||||||
+ private static byte[] processClass(final byte[] bytes) {
|
+ private static byte[] processClass(final byte[] bytes) {
|
||||||
+ try {
|
+ try {
|
||||||
+ final ClassReader reader = new ClassReader(bytes);
|
+ return ReflectionRemapper.processClass(bytes);
|
||||||
+ final ClassWriter writer = new ClassWriter(reader, 0);
|
|
||||||
+ reader.accept(ReflectionRemapper.visitor(writer), 0);
|
|
||||||
+ return writer.toByteArray();
|
|
||||||
+ } catch (final Exception ex) {
|
+ } catch (final Exception ex) {
|
||||||
+ LOGGER.warn("Failed to process class bytes", ex);
|
+ LOGGER.warn("Failed to process class bytes", ex);
|
||||||
+ return bytes;
|
+ return bytes;
|
||||||
|
@ -569,7 +553,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+import java.lang.reflect.Method;
|
+import java.lang.reflect.Method;
|
||||||
+import org.checkerframework.checker.nullness.qual.NonNull;
|
+import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
+import org.checkerframework.framework.qual.DefaultQualifier;
|
+import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
+import org.objectweb.asm.ClassReader;
|
||||||
+import org.objectweb.asm.ClassVisitor;
|
+import org.objectweb.asm.ClassVisitor;
|
||||||
|
+import org.objectweb.asm.ClassWriter;
|
||||||
+import org.objectweb.asm.Opcodes;
|
+import org.objectweb.asm.Opcodes;
|
||||||
+
|
+
|
||||||
+@DefaultQualifier(NonNull.class)
|
+@DefaultQualifier(NonNull.class)
|
||||||
|
@ -593,12 +579,22 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ public static ClassVisitor visitor(final ClassVisitor parent) {
|
+ public static ClassVisitor visitor(final ClassVisitor parent) {
|
||||||
+ if (MappingEnvironment.reobf()) {
|
+ if (MappingEnvironment.reobf() || MappingEnvironment.DISABLE_PLUGIN_REMAPPING) {
|
||||||
+ return parent;
|
+ return parent;
|
||||||
+ }
|
+ }
|
||||||
+ return VISITOR_FACTORY.createVisitor(parent);
|
+ return VISITOR_FACTORY.createVisitor(parent);
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
|
+ public static byte[] processClass(final byte[] bytes) {
|
||||||
|
+ if (MappingEnvironment.DISABLE_PLUGIN_REMAPPING) {
|
||||||
|
+ return bytes;
|
||||||
|
+ }
|
||||||
|
+ final ClassReader classReader = new ClassReader(bytes);
|
||||||
|
+ final ClassWriter classWriter = new ClassWriter(classReader, 0);
|
||||||
|
+ classReader.accept(ReflectionRemapper.visitor(classWriter), 0);
|
||||||
|
+ return classWriter.toByteArray();
|
||||||
|
+ }
|
||||||
|
+
|
||||||
+ private static void setupProxy() {
|
+ private static void setupProxy() {
|
||||||
+ try {
|
+ try {
|
||||||
+ final byte[] bytes = ProxyGenerator.generateProxy(PaperReflection.class, PAPER_REFLECTION_HOLDER_DESC);
|
+ final byte[] bytes = ProxyGenerator.generateProxy(PaperReflection.class, PAPER_REFLECTION_HOLDER_DESC);
|
||||||
|
@ -619,7 +615,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
|
|
||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
public final class MappingEnvironment {
|
public final class MappingEnvironment {
|
||||||
+ public static final boolean DISABLE_PLUGIN_REWRITING = Boolean.getBoolean("paper.disable-plugin-rewriting");
|
+ public static final boolean DISABLE_PLUGIN_REMAPPING = Boolean.getBoolean("paper.disablePluginRemapping");
|
||||||
+ public static final String LEGACY_CB_VERSION = "v1_21_R1";
|
+ public static final String LEGACY_CB_VERSION = "v1_21_R1";
|
||||||
private static final @Nullable String MAPPINGS_HASH = readMappingsHash();
|
private static final @Nullable String MAPPINGS_HASH = readMappingsHash();
|
||||||
private static final boolean REOBF = checkReobf();
|
private static final boolean REOBF = checkReobf();
|
||||||
|
@ -704,21 +700,28 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
visitor = new LimitedClassRemapper(cw, new SimpleRemapper(Commodore.ENUM_RENAMES));
|
visitor = new LimitedClassRemapper(cw, new SimpleRemapper(Commodore.ENUM_RENAMES));
|
||||||
}
|
}
|
||||||
|
|
||||||
- cr.accept(new ClassRemapper(new ClassVisitor(Opcodes.ASM9, visitor) {
|
+ visitor = io.papermc.paper.pluginremap.reflect.ReflectionRemapper.visitor(visitor); // Paper
|
||||||
+ cr.accept(new ClassRemapper(new ClassVisitor(Opcodes.ASM9, io.papermc.paper.pluginremap.reflect.ReflectionRemapper.visitor(visitor)) { // Paper
|
cr.accept(new ClassRemapper(new ClassVisitor(Opcodes.ASM9, visitor) {
|
||||||
final Set<RerouteMethodData> rerouteMethodData = new HashSet<>();
|
final Set<RerouteMethodData> rerouteMethodData = new HashSet<>();
|
||||||
String className;
|
String className;
|
||||||
boolean isInterface;
|
|
||||||
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||||
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||||
|
@@ -0,0 +0,0 @@ import org.bukkit.potion.PotionType;
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public final class CraftMagicNumbers implements UnsafeValues {
|
||||||
|
public static final UnsafeValues INSTANCE = new CraftMagicNumbers();
|
||||||
|
+ public static final boolean DISABLE_OLD_API_SUPPORT = Boolean.getBoolean("paper.disableOldApiSupport"); // Paper
|
||||||
|
|
||||||
|
private CraftMagicNumbers() {}
|
||||||
|
|
||||||
@@ -0,0 +0,0 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
@@ -0,0 +0,0 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||||
throw new InvalidPluginException("Plugin API version " + pdf.getAPIVersion() + " is lower than the minimum allowed version. Please update or replace it.");
|
throw new InvalidPluginException("Plugin API version " + pdf.getAPIVersion() + " is lower than the minimum allowed version. Please update or replace it.");
|
||||||
}
|
}
|
||||||
|
|
||||||
- if (toCheck.isOlderThan(ApiVersion.FLATTENING)) {
|
- if (toCheck.isOlderThan(ApiVersion.FLATTENING)) {
|
||||||
+ if (!io.papermc.paper.util.MappingEnvironment.DISABLE_PLUGIN_REWRITING && toCheck.isOlderThan(ApiVersion.FLATTENING)) { // Paper
|
+ if (!DISABLE_OLD_API_SUPPORT && toCheck.isOlderThan(ApiVersion.FLATTENING)) { // Paper
|
||||||
CraftLegacy.init();
|
CraftLegacy.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -726,7 +729,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] processClass(PluginDescriptionFile pdf, String path, byte[] clazz) {
|
public byte[] processClass(PluginDescriptionFile pdf, String path, byte[] clazz) {
|
||||||
+ if (io.papermc.paper.util.MappingEnvironment.DISABLE_PLUGIN_REWRITING) return clazz; // Paper
|
+ // Paper start
|
||||||
|
+ if (DISABLE_OLD_API_SUPPORT) {
|
||||||
|
+ // Make sure we still go through our reflection rewriting if needed
|
||||||
|
+ return io.papermc.paper.pluginremap.reflect.ReflectionRemapper.processClass(clazz);
|
||||||
|
+ }
|
||||||
|
+ // Paper end
|
||||||
try {
|
try {
|
||||||
clazz = Commodore.convert(clazz, pdf.getName(), ApiVersion.getOrCreateVersion(pdf.getAPIVersion()), ((CraftServer) Bukkit.getServer()).activeCompatibilities);
|
clazz = Commodore.convert(clazz, pdf.getName(), ApiVersion.getOrCreateVersion(pdf.getAPIVersion()), ((CraftServer) Bukkit.getServer()).activeCompatibilities);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
|
Loading…
Reference in a new issue