Make PluginProviderContext#getLogger return ComponentLogger, remove PluginProviderContext#getSLF4JLogger (#8921)

This commit is contained in:
Jason 2023-02-26 12:13:15 -07:00 committed by GitHub
parent fc072c0954
commit 16fc1a175e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 42 deletions

View File

@ -5,7 +5,7 @@ Subject: [PATCH] Paper Plugins
diff --git a/build.gradle.kts b/build.gradle.kts
index 359e7bd7e3c76cec89d638f940006dc9c944f98b..f5f217a3a786bf4c95bea74c135289d12205cf7b 100644
index d54ed6f7c4fa7e287e8daf35f7ae978b5a0a0d51..5aa294bdc1251df8798709a04ce9d34c316c7a17 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -44,7 +44,7 @@ dependencies {
@ -243,18 +243,18 @@ index 0000000000000000000000000000000000000000..ea84b11e8682e73fcd563fec65e76b70
+}
diff --git a/src/main/java/io/papermc/paper/plugin/bootstrap/PluginProviderContext.java b/src/main/java/io/papermc/paper/plugin/bootstrap/PluginProviderContext.java
new file mode 100644
index 0000000000000000000000000000000000000000..a4467fe1ba0dc348eab681900dbcac1770963591
index 0000000000000000000000000000000000000000..8be416f01055d94b474ecc425fc0bec69a814815
--- /dev/null
+++ b/src/main/java/io/papermc/paper/plugin/bootstrap/PluginProviderContext.java
@@ -0,0 +1,53 @@
@@ -0,0 +1,44 @@
+package io.papermc.paper.plugin.bootstrap;
+
+import io.papermc.paper.plugin.configuration.PluginMeta;
+import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.NotNull;
+
+import java.nio.file.Path;
+import java.util.logging.Logger;
+
+/**
+ * Represents the context provided to a {@link PluginBootstrap} during both the bootstrapping and plugin
@ -288,17 +288,8 @@ index 0000000000000000000000000000000000000000..a4467fe1ba0dc348eab681900dbcac17
+ * @return the logger instance
+ */
+ @NotNull
+ Logger getLogger();
+ ComponentLogger getLogger();
+
+ /**
+ * Provides the SLF4J logger assigned to this plugin.
+ *
+ * @return SLF4J logger
+ */
+ @NotNull
+ default org.slf4j.Logger getSLF4JLogger() {
+ return org.slf4j.LoggerFactory.getLogger(this.getLogger().getName());
+ }
+}
diff --git a/src/main/java/io/papermc/paper/plugin/configuration/PluginMeta.java b/src/main/java/io/papermc/paper/plugin/configuration/PluginMeta.java
new file mode 100644

View File

@ -589,7 +589,7 @@ index 0000000000000000000000000000000000000000..f7e43c693140b7a820b2432db312df8f
+}
diff --git a/src/main/java/io/papermc/paper/plugin/bootstrap/PluginProviderContextImpl.java b/src/main/java/io/papermc/paper/plugin/bootstrap/PluginProviderContextImpl.java
new file mode 100644
index 0000000000000000000000000000000000000000..8249a7024537fccd99735b92abb1368e6647b5ae
index 0000000000000000000000000000000000000000..7bf5daaeec4e4e3911741fa482def13b6044ce97
--- /dev/null
+++ b/src/main/java/io/papermc/paper/plugin/bootstrap/PluginProviderContextImpl.java
@@ -0,0 +1,40 @@
@ -598,15 +598,15 @@ index 0000000000000000000000000000000000000000..8249a7024537fccd99735b92abb1368e
+import io.papermc.paper.plugin.PluginInitializerManager;
+import io.papermc.paper.plugin.configuration.PluginMeta;
+import io.papermc.paper.plugin.provider.PluginProvider;
+import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
+import org.jetbrains.annotations.NotNull;
+
+import java.nio.file.Path;
+import java.util.logging.Logger;
+
+public record PluginProviderContextImpl(PluginMeta config, Path dataFolder,
+ Logger logger) implements PluginProviderContext {
+ ComponentLogger logger) implements PluginProviderContext {
+
+ public static PluginProviderContextImpl of(PluginMeta config, Logger logger) {
+ public static PluginProviderContextImpl of(PluginMeta config, ComponentLogger logger) {
+ Path dataFolder = PluginInitializerManager.instance().pluginDirectoryPath().resolve(config.getDisplayName());
+
+ return new PluginProviderContextImpl(config, dataFolder, logger);
@ -629,7 +629,7 @@ index 0000000000000000000000000000000000000000..8249a7024537fccd99735b92abb1368e
+ }
+
+ @Override
+ public @NotNull Logger getLogger() {
+ public @NotNull ComponentLogger getLogger() {
+ return this.logger;
+ }
+}
@ -2127,7 +2127,7 @@ index 0000000000000000000000000000000000000000..22189a1c42459c00d3e8bdeb980d15a6
+}
diff --git a/src/main/java/io/papermc/paper/plugin/entrypoint/strategy/LegacyPluginLoadingStrategy.java b/src/main/java/io/papermc/paper/plugin/entrypoint/strategy/LegacyPluginLoadingStrategy.java
new file mode 100644
index 0000000000000000000000000000000000000000..746272e0f8fb5311d5408175abe08db8aa356376
index 0000000000000000000000000000000000000000..779f6980a71db8df68c9cf20784976409d13929e
--- /dev/null
+++ b/src/main/java/io/papermc/paper/plugin/entrypoint/strategy/LegacyPluginLoadingStrategy.java
@@ -0,0 +1,269 @@
@ -2396,7 +2396,7 @@ index 0000000000000000000000000000000000000000..746272e0f8fb5311d5408175abe08db8
+
+ private void warnIfPaperPlugin(PluginProvider<T> provider) {
+ if (provider instanceof PaperPluginParent.PaperServerPluginProvider) {
+ provider.getLogger().warning("Loading Paper plugin in the legacy plugin loading logic. This is not recommended and may introduce some differences into load order. It's highly recommended you move away from this if you are wanting to use Paper plugins.");
+ provider.getLogger().warn("Loading Paper plugin in the legacy plugin loading logic. This is not recommended and may introduce some differences into load order. It's highly recommended you move away from this if you are wanting to use Paper plugins.");
+ }
+ }
+}
@ -4114,7 +4114,7 @@ index 0000000000000000000000000000000000000000..ea8cf22c35242eb9f3914b95df00e205
+}
diff --git a/src/main/java/io/papermc/paper/plugin/provider/PluginProvider.java b/src/main/java/io/papermc/paper/plugin/provider/PluginProvider.java
new file mode 100644
index 0000000000000000000000000000000000000000..a97ec947bc6cecf9d9183b236263fd4407e5fd7e
index 0000000000000000000000000000000000000000..3fc9246c111f862438f2cebda7d429c1c0b9582e
--- /dev/null
+++ b/src/main/java/io/papermc/paper/plugin/provider/PluginProvider.java
@@ -0,0 +1,55 @@
@ -4122,6 +4122,7 @@ index 0000000000000000000000000000000000000000..a97ec947bc6cecf9d9183b236263fd44
+
+import io.papermc.paper.plugin.configuration.PluginMeta;
+import io.papermc.paper.plugin.provider.configuration.LoadOrderConfiguration;
+import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.NotNull;
+
@ -4129,7 +4130,6 @@ index 0000000000000000000000000000000000000000..a97ec947bc6cecf9d9183b236263fd44
+import java.util.List;
+import java.util.Map;
+import java.util.jar.JarFile;
+import java.util.logging.Logger;
+
+/**
+ * PluginProviders are created by a {@link io.papermc.paper.plugin.provider.source.ProviderSource},
@ -4165,7 +4165,7 @@ index 0000000000000000000000000000000000000000..a97ec947bc6cecf9d9183b236263fd44
+
+ PluginMeta getMeta();
+
+ Logger getLogger();
+ ComponentLogger getLogger();
+
+ LoadOrderConfiguration createConfiguration(@NotNull Map<String, PluginProvider<?>> toLoad);
+
@ -5353,7 +5353,7 @@ index 0000000000000000000000000000000000000000..b7e8a5ba375a558e0442aa9facf96954
+}
diff --git a/src/main/java/io/papermc/paper/plugin/provider/type/paper/PaperPluginParent.java b/src/main/java/io/papermc/paper/plugin/provider/type/paper/PaperPluginParent.java
new file mode 100644
index 0000000000000000000000000000000000000000..a0773c6d24de1f2ce1f0d949cba26b9997b696e6
index 0000000000000000000000000000000000000000..884ddb16ee6a5b182e932abb53fdf38a4444d765
--- /dev/null
+++ b/src/main/java/io/papermc/paper/plugin/provider/type/paper/PaperPluginParent.java
@@ -0,0 +1,258 @@
@ -5374,6 +5374,7 @@ index 0000000000000000000000000000000000000000..a0773c6d24de1f2ce1f0d949cba26b99
+import io.papermc.paper.plugin.provider.configuration.PaperPluginMeta;
+import io.papermc.paper.plugin.provider.type.PluginTypeFactory;
+import io.papermc.paper.plugin.provider.util.ProviderUtil;
+import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
+import org.bukkit.plugin.java.JavaPlugin;
+import org.jetbrains.annotations.NotNull;
+
@ -5382,7 +5383,6 @@ index 0000000000000000000000000000000000000000..a0773c6d24de1f2ce1f0d949cba26b99
+import java.util.List;
+import java.util.Map;
+import java.util.jar.JarFile;
+import java.util.logging.Logger;
+
+public class PaperPluginParent {
+
@ -5392,7 +5392,7 @@ index 0000000000000000000000000000000000000000..a0773c6d24de1f2ce1f0d949cba26b99
+ private final PaperPluginMeta description;
+ private final PaperPluginClassLoader classLoader;
+ private final PluginProviderContext context;
+ private final Logger logger;
+ private final ComponentLogger logger;
+
+ public PaperPluginParent(Path path, JarFile jarFile, PaperPluginMeta description, PaperPluginClassLoader classLoader, PluginProviderContext context) {
+ this.path = path;
@ -5445,7 +5445,7 @@ index 0000000000000000000000000000000000000000..a0773c6d24de1f2ce1f0d949cba26b99
+ }
+
+ @Override
+ public Logger getLogger() {
+ public ComponentLogger getLogger() {
+ return PaperPluginParent.this.logger;
+ }
+
@ -5552,7 +5552,7 @@ index 0000000000000000000000000000000000000000..a0773c6d24de1f2ce1f0d949cba26b99
+ }
+
+ @Override
+ public Logger getLogger() {
+ public ComponentLogger getLogger() {
+ return PaperPluginParent.this.logger;
+ }
+
@ -5617,10 +5617,10 @@ index 0000000000000000000000000000000000000000..a0773c6d24de1f2ce1f0d949cba26b99
+}
diff --git a/src/main/java/io/papermc/paper/plugin/provider/type/paper/PaperPluginProviderFactory.java b/src/main/java/io/papermc/paper/plugin/provider/type/paper/PaperPluginProviderFactory.java
new file mode 100644
index 0000000000000000000000000000000000000000..db343a2f482ac375078610f0875692861f412ee2
index 0000000000000000000000000000000000000000..eb0464a52d99a916bca8f93cd9294cdc30893671
--- /dev/null
+++ b/src/main/java/io/papermc/paper/plugin/provider/type/paper/PaperPluginProviderFactory.java
@@ -0,0 +1,54 @@
@@ -0,0 +1,56 @@
+package io.papermc.paper.plugin.provider.type.paper;
+
+import com.destroystokyo.paper.utils.PaperPluginLogger;
@ -5641,12 +5641,14 @@ index 0000000000000000000000000000000000000000..db343a2f482ac375078610f087569286
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.logging.Logger;
+import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
+
+class PaperPluginProviderFactory implements PluginTypeFactory<PaperPluginParent, PaperPluginMeta> {
+
+ @Override
+ public PaperPluginParent build(JarFile file, PaperPluginMeta configuration, Path source) throws Exception {
+ Logger logger = PaperPluginLogger.getLogger(configuration);
+ Logger jul = PaperPluginLogger.getLogger(configuration);
+ ComponentLogger logger = ComponentLogger.logger(jul.getName());
+ PluginProviderContext context = PluginProviderContextImpl.of(configuration, logger);
+
+ PaperClasspathBuilder builder = new PaperClasspathBuilder(context);
@ -5662,7 +5664,7 @@ index 0000000000000000000000000000000000000000..db343a2f482ac375078610f087569286
+ }
+ }
+
+ PaperPluginClassLoader classLoader = builder.buildClassLoader(logger, source, file, configuration);
+ PaperPluginClassLoader classLoader = builder.buildClassLoader(jul, source, file, configuration);
+ return new PaperPluginParent(source, file, configuration, classLoader, context);
+ }
+
@ -5755,16 +5757,15 @@ index 0000000000000000000000000000000000000000..b2a6544e321fa61c58bdf5684231de10
+}
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
new file mode 100644
index 0000000000000000000000000000000000000000..600023770e19f02258327816122298f58d73e4ab
index 0000000000000000000000000000000000000000..9a19abaccec91df9b2614dd6638d7bc199bdac2c
--- /dev/null
+++ b/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProvider.java
@@ -0,0 +1,188 @@
@@ -0,0 +1,190 @@
+package io.papermc.paper.plugin.provider.type.spigot;
+
+import com.destroystokyo.paper.util.SneakyThrow;
+import com.destroystokyo.paper.utils.PaperPluginLogger;
+import io.papermc.paper.plugin.entrypoint.dependency.DependencyUtil;
+import io.papermc.paper.plugin.manager.PaperPluginManagerImpl;
+import io.papermc.paper.plugin.provider.configuration.LoadOrderConfiguration;
+import io.papermc.paper.plugin.provider.entrypoint.DependencyContext;
+import io.papermc.paper.plugin.entrypoint.dependency.DependencyContextHolder;
@ -5772,6 +5773,7 @@ index 0000000000000000000000000000000000000000..600023770e19f02258327816122298f5
+import io.papermc.paper.plugin.provider.ProviderStatus;
+import io.papermc.paper.plugin.provider.ProviderStatusHolder;
+import io.papermc.paper.plugin.provider.type.PluginTypeFactory;
+import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
+import org.bukkit.Bukkit;
+import org.bukkit.Server;
+import org.bukkit.plugin.InvalidPluginException;
@ -5800,6 +5802,7 @@ index 0000000000000000000000000000000000000000..600023770e19f02258327816122298f5
+ private final PluginDescriptionFile description;
+ private final JarFile jarFile;
+ private final Logger logger;
+ private final ComponentLogger componentLogger;
+ private ProviderStatus status;
+ private DependencyContext dependencyContext;
+
@ -5808,6 +5811,7 @@ index 0000000000000000000000000000000000000000..600023770e19f02258327816122298f5
+ this.jarFile = file;
+ this.description = description;
+ this.logger = PaperPluginLogger.getLogger(description);
+ this.componentLogger = ComponentLogger.logger(this.logger.getName());
+ }
+
+ @Override
@ -5907,8 +5911,8 @@ index 0000000000000000000000000000000000000000..600023770e19f02258327816122298f5
+ }
+
+ @Override
+ public Logger getLogger() {
+ return this.logger;
+ public ComponentLogger getLogger() {
+ return this.componentLogger;
+ }
+
+ @Override
@ -7029,7 +7033,7 @@ index 0000000000000000000000000000000000000000..04903794a8ee4dd73162ae240862ff6d
+}
diff --git a/src/test/java/io/papermc/paper/plugin/TestJavaPluginProvider.java b/src/test/java/io/papermc/paper/plugin/TestJavaPluginProvider.java
new file mode 100644
index 0000000000000000000000000000000000000000..ea2854172968abea40c39eb05faf76ed1191c353
index 0000000000000000000000000000000000000000..e3871de8a5e1c04b915927d852157c48b0f6612f
--- /dev/null
+++ b/src/test/java/io/papermc/paper/plugin/TestJavaPluginProvider.java
@@ -0,0 +1,76 @@
@ -7039,6 +7043,7 @@ index 0000000000000000000000000000000000000000..ea2854172968abea40c39eb05faf76ed
+import io.papermc.paper.plugin.entrypoint.dependency.DependencyUtil;
+import io.papermc.paper.plugin.provider.PluginProvider;
+import io.papermc.paper.plugin.provider.configuration.LoadOrderConfiguration;
+import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
+import org.jetbrains.annotations.NotNull;
+
+import java.nio.file.Path;
@ -7046,7 +7051,6 @@ index 0000000000000000000000000000000000000000..ea2854172968abea40c39eb05faf76ed
+import java.util.List;
+import java.util.Map;
+import java.util.jar.JarFile;
+import java.util.logging.Logger;
+
+public class TestJavaPluginProvider implements PluginProvider<PaperTestPlugin> {
+
@ -7077,8 +7081,8 @@ index 0000000000000000000000000000000000000000..ea2854172968abea40c39eb05faf76ed
+ }
+
+ @Override
+ public Logger getLogger() {
+ return Logger.getLogger("TestPlugin");
+ public ComponentLogger getLogger() {
+ return ComponentLogger.logger("TestPlugin");
+ }
+
+ @Override