aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJason Penilla <[email protected]>2024-05-21 13:23:08 -0700
committerJason Penilla <[email protected]>2024-05-21 13:23:08 -0700
commitec5437b24ee7380f12f70ce1ad593e8c0538e3d2 (patch)
tree692bf832d87abde8b68e3dbcb5701c94b9da00cf
parent980cff9f298032f8670b20368851b8a7316a44d7 (diff)
downloadPaper-ec5437b24ee7380f12f70ce1ad593e8c0538e3d2.tar.gz
Paper-ec5437b24ee7380f12f70ce1ad593e8c0538e3d2.zip
Allow using PluginLoader classpath API from Bukkit plugins
-rw-r--r--patches/api/0478-Allow-Bukkit-plugin-to-use-Paper-PluginLoader-API.patch75
-rw-r--r--patches/server/1046-Allow-Bukkit-plugin-to-use-Paper-PluginLoader-API.patch186
2 files changed, 261 insertions, 0 deletions
diff --git a/patches/api/0478-Allow-Bukkit-plugin-to-use-Paper-PluginLoader-API.patch b/patches/api/0478-Allow-Bukkit-plugin-to-use-Paper-PluginLoader-API.patch
new file mode 100644
index 0000000000..a3aab59860
--- /dev/null
+++ b/patches/api/0478-Allow-Bukkit-plugin-to-use-Paper-PluginLoader-API.patch
@@ -0,0 +1,75 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Jason Penilla <[email protected]>
+Date: Tue, 21 May 2024 13:18:00 -0700
+Subject: [PATCH] Allow Bukkit plugin to use Paper PluginLoader API
+
+
+diff --git a/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java b/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java
+index c0691a849831f99268fdcb7b0f471f80a1a2a70e..95df45f4042f80f25e923c2a170a79906212f459 100644
+--- a/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java
++++ b/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java
+@@ -259,6 +259,13 @@ public final class PluginDescriptionFile implements io.papermc.paper.plugin.conf
+ private Set<PluginAwareness> awareness = ImmutableSet.of();
+ private String apiVersion = null;
+ private List<String> libraries = ImmutableList.of();
++ // Paper start - plugin loader api
++ private String paperPluginLoader;
++ @org.jetbrains.annotations.ApiStatus.Internal @org.jetbrains.annotations.Nullable
++ public String getPaperPluginLoader() {
++ return this.paperPluginLoader;
++ }
++ // Paper end - plugin loader api
+ // Paper start - oh my goddddd
+ /**
+ * Don't use this.
+@@ -1232,6 +1239,7 @@ public final class PluginDescriptionFile implements io.papermc.paper.plugin.conf
+ } else {
+ libraries = ImmutableList.<String>of();
+ }
++ if (map.containsKey("paper-plugin-loader")) this.paperPluginLoader = map.get("paper-plugin-loader").toString(); // Paper - plugin loader api
+
+ try {
+ lazyPermissions = (Map<?, ?>) map.get("permissions");
+diff --git a/src/main/java/org/bukkit/plugin/java/LibraryLoader.java b/src/main/java/org/bukkit/plugin/java/LibraryLoader.java
+index 8e1b6be2462aaa692efa1f72986921a6dc357196..fb0a6fb6c1b7dfdbc567cb250535479537a2cfbb 100644
+--- a/src/main/java/org/bukkit/plugin/java/LibraryLoader.java
++++ b/src/main/java/org/bukkit/plugin/java/LibraryLoader.java
+@@ -84,7 +84,13 @@ public class LibraryLoader
+ @Nullable
+ public ClassLoader createLoader(@NotNull PluginDescriptionFile desc)
+ {
+- if ( desc.getLibraries().isEmpty() )
++ // Paper start - plugin loader api
++ return this.createLoader(desc, null);
++ }
++ @Nullable
++ public ClassLoader createLoader(@NotNull PluginDescriptionFile desc, java.nio.file.Path @Nullable [] paperLibraryPaths) {
++ if ( desc.getLibraries().isEmpty() && paperLibraryPaths == null )
++ // Paper end - plugin loader api
+ {
+ return null;
+ }
+@@ -103,17 +109,20 @@ public class LibraryLoader
+ }
+
+ DependencyResult result;
+- try
++ if (!dependencies.isEmpty()) try // Paper - plugin loader api
+ {
+ result = repository.resolveDependencies( session, new DependencyRequest( new CollectRequest( (Dependency) null, dependencies, repositories ), null ) );
+ } catch ( DependencyResolutionException ex )
+ {
+ throw new RuntimeException( "Error resolving libraries", ex );
+- }
++ } else result = null; // Paper - plugin loader api
+
+ List<URL> jarFiles = new ArrayList<>();
+ List<java.nio.file.Path> jarPaths = new ArrayList<>(); // Paper - remap libraries
+- for ( ArtifactResult artifact : result.getArtifactResults() )
++ // Paper start - plugin loader api
++ if (paperLibraryPaths != null) jarPaths.addAll(Arrays.asList(paperLibraryPaths));
++ if (result != null) for ( ArtifactResult artifact : result.getArtifactResults() )
++ // Paper end - plugin loader api
+ {
+ // Paper start - remap libraries
+ jarPaths.add(artifact.getArtifact().getFile().toPath());
diff --git a/patches/server/1046-Allow-Bukkit-plugin-to-use-Paper-PluginLoader-API.patch b/patches/server/1046-Allow-Bukkit-plugin-to-use-Paper-PluginLoader-API.patch
new file mode 100644
index 0000000000..6df4617ba9
--- /dev/null
+++ b/patches/server/1046-Allow-Bukkit-plugin-to-use-Paper-PluginLoader-API.patch
@@ -0,0 +1,186 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Jason Penilla <[email protected]>
+Date: Tue, 21 May 2024 13:18:15 -0700
+Subject: [PATCH] Allow Bukkit plugin to use Paper PluginLoader API
+
+
+diff --git a/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperPluginClassLoader.java b/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperPluginClassLoader.java
+index 5a00e5c41274ded6b837fb81fa8f54616f2b7bc8..9374a53dd1c161ee383044b965966e1083de8edf 100644
+--- a/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperPluginClassLoader.java
++++ b/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperPluginClassLoader.java
+@@ -48,18 +48,22 @@ public class PaperPluginClassLoader extends PaperSimplePluginClassLoader impleme
+ @Nullable
+ private PluginClassLoaderGroup group;
+
++ private PaperPluginMeta configuration() {
++ return (PaperPluginMeta) this.configuration;
++ }
++
+ public PaperPluginClassLoader(Logger logger, Path source, JarFile file, PaperPluginMeta configuration, ClassLoader parentLoader, URLClassLoader libraryLoader) throws IOException {
+ super(source, file, configuration, parentLoader);
+ this.libraryLoader = libraryLoader;
+
+ this.logger = logger;
+- if (this.configuration.hasOpenClassloader()) {
++ if (this.configuration().hasOpenClassloader()) {
+ this.group = PaperClassLoaderStorage.instance().registerOpenGroup(this);
+ }
+ }
+
+ public void refreshClassloaderDependencyTree(DependencyContext dependencyContext) {
+- if (this.configuration.hasOpenClassloader()) {
++ if (this.configuration().hasOpenClassloader()) {
+ return;
+ }
+ if (this.group != null) {
+diff --git a/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperSimplePluginClassLoader.java b/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperSimplePluginClassLoader.java
+index a4c18063854e050bd0c54d488ceeda43c768b6df..967465e542483e93a736129b5f5c6622cefd33fa 100644
+--- a/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperSimplePluginClassLoader.java
++++ b/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperSimplePluginClassLoader.java
+@@ -1,6 +1,6 @@
+ package io.papermc.paper.plugin.entrypoint.classloader;
+
+-import io.papermc.paper.plugin.provider.configuration.PaperPluginMeta;
++import io.papermc.paper.plugin.configuration.PluginMeta;
+ import io.papermc.paper.plugin.util.NamespaceChecker;
+ import org.jetbrains.annotations.ApiStatus;
+
+@@ -26,13 +26,13 @@ public class PaperSimplePluginClassLoader extends URLClassLoader {
+ ClassLoader.registerAsParallelCapable();
+ }
+
+- protected final PaperPluginMeta configuration;
++ protected final PluginMeta configuration;
+ protected final Path source;
+ protected final Manifest jarManifest;
+ protected final URL jarUrl;
+ protected final JarFile jar;
+
+- public PaperSimplePluginClassLoader(Path source, JarFile file, PaperPluginMeta configuration, ClassLoader parentLoader) throws IOException {
++ public PaperSimplePluginClassLoader(Path source, JarFile file, PluginMeta configuration, ClassLoader parentLoader) throws IOException {
+ super(source.getFileName().toString(), new URL[]{source.toUri().toURL()}, parentLoader);
+
+ this.source = source;
+diff --git a/src/main/java/io/papermc/paper/plugin/loader/PaperClasspathBuilder.java b/src/main/java/io/papermc/paper/plugin/loader/PaperClasspathBuilder.java
+index f9d4b33050a6fe8c2dabe8e5eec075d95dc513e0..dc106685ecb483c33c06e4f83eda27be58251aad 100644
+--- a/src/main/java/io/papermc/paper/plugin/loader/PaperClasspathBuilder.java
++++ b/src/main/java/io/papermc/paper/plugin/loader/PaperClasspathBuilder.java
+@@ -41,15 +41,7 @@ public class PaperClasspathBuilder implements PluginClasspathBuilder {
+ }
+
+ public PaperPluginClassLoader buildClassLoader(Logger logger, Path source, JarFile jarFile, PaperPluginMeta configuration) {
+- PaperLibraryStore paperLibraryStore = new PaperLibraryStore();
+- for (ClassPathLibrary library : this.libraries) {
+- library.register(paperLibraryStore);
+- }
+-
+- List<Path> paths = paperLibraryStore.getPaths();
+- if (PluginInitializerManager.instance().pluginRemapper != null) {
+- paths = PluginInitializerManager.instance().pluginRemapper.remapLibraries(paths);
+- }
++ List<Path> paths = this.buildLibraryPaths(true);
+ URL[] urls = new URL[paths.size()];
+ for (int i = 0; i < paths.size(); i++) {
+ Path path = paths.get(i);
+@@ -69,4 +61,17 @@ public class PaperClasspathBuilder implements PluginClasspathBuilder {
+ throw new RuntimeException(exception);
+ }
+ }
++
++ public List<Path> buildLibraryPaths(final boolean remap) {
++ PaperLibraryStore paperLibraryStore = new PaperLibraryStore();
++ for (ClassPathLibrary library : this.libraries) {
++ library.register(paperLibraryStore);
++ }
++
++ List<Path> paths = paperLibraryStore.getPaths();
++ if (remap && PluginInitializerManager.instance().pluginRemapper != null) {
++ paths = PluginInitializerManager.instance().pluginRemapper.remapLibraries(paths);
++ }
++ return paths;
++ }
+ }
+diff --git a/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProvider.java b/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProvider.java
+index 75a2b687d58d76b94f8bec111df8613f120ff74b..8c44c091233aa6335791ed9b9aca62e1f98eccd9 100644
+--- a/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProvider.java
++++ b/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProvider.java
+@@ -40,15 +40,17 @@ public class SpigotPluginProvider implements PluginProvider<JavaPlugin>, Provide
+ private final PluginDescriptionFile description;
+ private final JarFile jarFile;
+ private final Logger logger;
++ private final Path[] paperLibraryPaths;
+ private final ComponentLogger componentLogger;
+ private ProviderStatus status;
+ private DependencyContext dependencyContext;
+
+- SpigotPluginProvider(Path path, JarFile file, PluginDescriptionFile description) {
++ SpigotPluginProvider(Path path, JarFile file, PluginDescriptionFile description, Path[] paperLibraryPaths) {
+ this.path = path;
+ this.jarFile = file;
+ this.description = description;
+ this.logger = PaperPluginLogger.getLogger(description);
++ this.paperLibraryPaths = paperLibraryPaths;
+ this.componentLogger = ComponentLogger.logger(this.logger.getName());
+ }
+
+@@ -120,7 +122,7 @@ public class SpigotPluginProvider implements PluginProvider<JavaPlugin>, Provide
+
+ final PluginClassLoader loader;
+ try {
+- loader = new PluginClassLoader(this.getClass().getClassLoader(), this.description, dataFolder, this.path.toFile(), LIBRARY_LOADER.createLoader(this.description), this.jarFile, this.dependencyContext); // Paper
++ loader = new PluginClassLoader(this.getClass().getClassLoader(), this.description, dataFolder, this.path.toFile(), LIBRARY_LOADER.createLoader(this.description, this.paperLibraryPaths), this.jarFile, this.dependencyContext); // Paper
+ } catch (InvalidPluginException ex) {
+ throw ex;
+ } catch (Throwable ex) {
+diff --git a/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProviderFactory.java b/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProviderFactory.java
+index fdb52ad85cfaa1d53aadcad72cec3d3c8c12c058..a79e38499388f3baecc9896d38a3c64c5923b426 100644
+--- a/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProviderFactory.java
++++ b/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProviderFactory.java
+@@ -1,9 +1,17 @@
+ package io.papermc.paper.plugin.provider.type.spigot;
+
++import com.destroystokyo.paper.utils.PaperPluginLogger;
++import io.papermc.paper.plugin.bootstrap.PluginProviderContextImpl;
+ import io.papermc.paper.plugin.entrypoint.classloader.BytecodeModifyingURLClassLoader;
++import io.papermc.paper.plugin.entrypoint.classloader.PaperSimplePluginClassLoader;
++import io.papermc.paper.plugin.loader.PaperClasspathBuilder;
++import io.papermc.paper.plugin.loader.PluginLoader;
+ import io.papermc.paper.plugin.provider.configuration.serializer.constraints.PluginConfigConstraints;
+ import io.papermc.paper.plugin.provider.type.PluginTypeFactory;
++import io.papermc.paper.plugin.provider.util.ProviderUtil;
+ import io.papermc.paper.util.MappingEnvironment;
++import java.util.logging.Logger;
++import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
+ import org.bukkit.plugin.InvalidDescriptionException;
+ import org.bukkit.plugin.PluginDescriptionFile;
+ import org.bukkit.plugin.java.LibraryLoader;
+@@ -36,7 +44,28 @@ class SpigotPluginProviderFactory implements PluginTypeFactory<SpigotPluginProvi
+ throw new InvalidDescriptionException("Restricted name, cannot use 0x20 (space character) in a plugin name.");
+ }
+
+- return new SpigotPluginProvider(source, file, configuration);
++ final Path[] paperLibraryPaths;
++ if (configuration.getPaperPluginLoader() != null) {
++ final Logger logger = PaperPluginLogger.getLogger(configuration);
++ PaperClasspathBuilder builder = new PaperClasspathBuilder(PluginProviderContextImpl.create(
++ configuration, ComponentLogger.logger(logger.getName()), source
++ ));
++
++ try (
++ PaperSimplePluginClassLoader simplePluginClassLoader = new PaperSimplePluginClassLoader(source, file, configuration, this.getClass().getClassLoader())
++ ) {
++ PluginLoader loader = ProviderUtil.loadClass(configuration.getPaperPluginLoader(), PluginLoader.class, simplePluginClassLoader);
++ loader.classloader(builder);
++ } catch (IOException e) {
++ throw new RuntimeException(e);
++ }
++
++ paperLibraryPaths = builder.buildLibraryPaths(false).toArray(Path[]::new);
++ } else {
++ paperLibraryPaths = null;
++ }
++
++ return new SpigotPluginProvider(source, file, configuration, paperLibraryPaths);
+ }
+
+ @Override