Redefine Cyclic Dependencies (#8873)
This commit is contained in:
parent
0e4f2cc527
commit
8427c88987
39 changed files with 566 additions and 317 deletions
|
@ -1942,7 +1942,7 @@ index 669a70faa95d0d6525a731d73499ed6fb0b48320..6175b04327b12e74140a0885f7326546
|
|||
|
||||
/**
|
||||
diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
||||
index 047c0304fd617cec990f80815b43916c6ef5a94c..d0ad072c832b8fc8a1cfdcafdd42c724531a2e29 100644
|
||||
index 047c0304fd617cec990f80815b43916c6ef5a94c..fa39c93d76ebb9eecce1f4b5203cb361e4778b4f 100644
|
||||
--- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
||||
+++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
||||
@@ -49,6 +49,7 @@ import org.yaml.snakeyaml.error.YAMLException;
|
||||
|
@ -1966,7 +1966,7 @@ index 047c0304fd617cec990f80815b43916c6ef5a94c..d0ad072c832b8fc8a1cfdcafdd42c724
|
|||
final PluginClassLoader loader;
|
||||
try {
|
||||
- loader = new PluginClassLoader(this, getClass().getClassLoader(), description, dataFolder, file, (libraryLoader != null) ? libraryLoader.createLoader(description) : null);
|
||||
+ loader = new PluginClassLoader(getClass().getClassLoader(), description, dataFolder, file, (libraryLoader != null) ? libraryLoader.createLoader(description) : null, null); // Paper
|
||||
+ loader = new PluginClassLoader(getClass().getClassLoader(), description, dataFolder, file, (libraryLoader != null) ? libraryLoader.createLoader(description) : null); // Paper
|
||||
} catch (InvalidPluginException ex) {
|
||||
throw ex;
|
||||
} catch (Throwable ex) {
|
||||
|
@ -1987,7 +1987,7 @@ index 6d634b0ea813ccb19f1562a7d0e5a59cea4eab21..f9e67e20133d349e43d126dbb48b34d4
|
|||
|
||||
private final Logger logger;
|
||||
diff --git a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
|
||||
index 2f74ec96ece706de23156ebabfe493211bc05391..2c3d2f60d3f2f55a1a90791d37521c61f96ab4b3 100644
|
||||
index 2f74ec96ece706de23156ebabfe493211bc05391..f92071617712a0f410475fae291fb85f668e8e8a 100644
|
||||
--- a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
|
||||
+++ b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
|
||||
@@ -29,7 +29,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
@ -2000,7 +2000,7 @@ index 2f74ec96ece706de23156ebabfe493211bc05391..2c3d2f60d3f2f55a1a90791d37521c61
|
|||
private final JavaPluginLoader loader;
|
||||
private final Map<String, Class<?>> classes = new ConcurrentHashMap<String, Class<?>>();
|
||||
private final PluginDescriptionFile description;
|
||||
@@ -39,20 +40,23 @@ final class PluginClassLoader extends URLClassLoader {
|
||||
@@ -39,20 +40,22 @@ final class PluginClassLoader extends URLClassLoader {
|
||||
private final Manifest manifest;
|
||||
private final URL url;
|
||||
private final ClassLoader libraryLoader;
|
||||
|
@ -2011,7 +2011,6 @@ index 2f74ec96ece706de23156ebabfe493211bc05391..2c3d2f60d3f2f55a1a90791d37521c61
|
|||
private final Set<String> seenIllegalAccess = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||
+ private java.util.logging.Logger logger; // Paper - add field
|
||||
+ private io.papermc.paper.plugin.provider.classloader.PluginClassLoaderGroup classLoaderGroup; // Paper
|
||||
+ public io.papermc.paper.plugin.provider.entrypoint.DependencyContext dependencyContext; // Paper
|
||||
|
||||
static {
|
||||
ClassLoader.registerAsParallelCapable();
|
||||
|
@ -2019,7 +2018,7 @@ index 2f74ec96ece706de23156ebabfe493211bc05391..2c3d2f60d3f2f55a1a90791d37521c61
|
|||
|
||||
- PluginClassLoader(@NotNull final JavaPluginLoader loader, @Nullable final ClassLoader parent, @NotNull final PluginDescriptionFile description, @NotNull final File dataFolder, @NotNull final File file, @Nullable ClassLoader libraryLoader) throws IOException, InvalidPluginException, MalformedURLException {
|
||||
+ @org.jetbrains.annotations.ApiStatus.Internal // Paper
|
||||
+ public PluginClassLoader(@Nullable final ClassLoader parent, @NotNull final PluginDescriptionFile description, @NotNull final File dataFolder, @NotNull final File file, @Nullable ClassLoader libraryLoader, io.papermc.paper.plugin.provider.entrypoint.DependencyContext dependencyContext) throws IOException, InvalidPluginException, MalformedURLException { // Paper
|
||||
+ public PluginClassLoader(@Nullable final ClassLoader parent, @NotNull final PluginDescriptionFile description, @NotNull final File dataFolder, @NotNull final File file, @Nullable ClassLoader libraryLoader) throws IOException, InvalidPluginException, MalformedURLException { // Paper
|
||||
super(new URL[] {file.toURI().toURL()}, parent);
|
||||
- Preconditions.checkArgument(loader != null, "Loader cannot be null");
|
||||
+ this.loader = null; // Paper - pass null into loader field
|
||||
|
@ -2028,19 +2027,18 @@ index 2f74ec96ece706de23156ebabfe493211bc05391..2c3d2f60d3f2f55a1a90791d37521c61
|
|||
this.description = description;
|
||||
this.dataFolder = dataFolder;
|
||||
this.file = file;
|
||||
@@ -61,6 +65,11 @@ final class PluginClassLoader extends URLClassLoader {
|
||||
@@ -61,6 +64,10 @@ final class PluginClassLoader extends URLClassLoader {
|
||||
this.url = file.toURI().toURL();
|
||||
this.libraryLoader = libraryLoader;
|
||||
|
||||
+
|
||||
+ // Paper start
|
||||
+ this.classLoaderGroup = io.papermc.paper.plugin.provider.classloader.PaperClassLoaderStorage.instance().registerSpigotGroup(this); // Paper
|
||||
+ this.dependencyContext = dependencyContext;
|
||||
+ // Paper end
|
||||
try {
|
||||
Class<?> jarClass;
|
||||
try {
|
||||
@@ -94,6 +103,22 @@ final class PluginClassLoader extends URLClassLoader {
|
||||
@@ -94,6 +101,22 @@ final class PluginClassLoader extends URLClassLoader {
|
||||
return findResources(name);
|
||||
}
|
||||
|
||||
|
@ -2063,7 +2061,7 @@ index 2f74ec96ece706de23156ebabfe493211bc05391..2c3d2f60d3f2f55a1a90791d37521c61
|
|||
@Override
|
||||
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
|
||||
return loadClass0(name, resolve, true, true);
|
||||
@@ -119,7 +144,7 @@ final class PluginClassLoader extends URLClassLoader {
|
||||
@@ -119,26 +142,11 @@ final class PluginClassLoader extends URLClassLoader {
|
||||
|
||||
if (checkGlobal) {
|
||||
// This ignores the libraries of other plugins, unless they are transitive dependencies.
|
||||
|
@ -2072,24 +2070,27 @@ index 2f74ec96ece706de23156ebabfe493211bc05391..2c3d2f60d3f2f55a1a90791d37521c61
|
|||
|
||||
if (result != null) {
|
||||
// If the class was loaded from a library instead of a PluginClassLoader, we can assume that its associated plugin is a transitive dependency and can therefore skip this check.
|
||||
@@ -128,14 +153,14 @@ final class PluginClassLoader extends URLClassLoader {
|
||||
|
||||
if (provider != description
|
||||
&& !seenIllegalAccess.contains(provider.getName())
|
||||
- if (result.getClassLoader() instanceof PluginClassLoader) {
|
||||
- PluginDescriptionFile provider = ((PluginClassLoader) result.getClassLoader()).description;
|
||||
-
|
||||
- if (provider != description
|
||||
- && !seenIllegalAccess.contains(provider.getName())
|
||||
- && !((SimplePluginManager) loader.server.getPluginManager()).isTransitiveDepend(description, provider)) {
|
||||
+ && !this.dependencyContext.isTransitiveDependency(description, provider)) { // Paper
|
||||
|
||||
seenIllegalAccess.add(provider.getName());
|
||||
if (plugin != null) {
|
||||
plugin.getLogger().log(Level.WARNING, "Loaded class {0} from {1} which is not a depend or softdepend of this plugin.", new Object[]{name, provider.getFullName()});
|
||||
} else {
|
||||
// In case the bad access occurs on construction
|
||||
-
|
||||
- seenIllegalAccess.add(provider.getName());
|
||||
- if (plugin != null) {
|
||||
- plugin.getLogger().log(Level.WARNING, "Loaded class {0} from {1} which is not a depend or softdepend of this plugin.", new Object[]{name, provider.getFullName()});
|
||||
- } else {
|
||||
- // In case the bad access occurs on construction
|
||||
- loader.server.getLogger().log(Level.WARNING, "[{0}] Loaded class {1} from {2} which is not a depend or softdepend of this plugin.", new Object[]{description.getName(), name, provider.getFullName()});
|
||||
+ org.bukkit.Bukkit.getLogger().log(Level.WARNING, "[{0}] Loaded class {1} from {2} which is not a depend or softdepend of this plugin.", new Object[]{description.getName(), name, provider.getFullName()}); // Paper
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -167,7 +192,7 @@ final class PluginClassLoader extends URLClassLoader {
|
||||
- }
|
||||
- }
|
||||
- }
|
||||
+ // Paper - Totally delete the illegal access logic, we are never going to enforce it anyways here.
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -167,7 +175,7 @@ final class PluginClassLoader extends URLClassLoader {
|
||||
throw new ClassNotFoundException(name, ex);
|
||||
}
|
||||
|
||||
|
@ -2098,7 +2099,7 @@ index 2f74ec96ece706de23156ebabfe493211bc05391..2c3d2f60d3f2f55a1a90791d37521c61
|
|||
|
||||
int dot = name.lastIndexOf('.');
|
||||
if (dot != -1) {
|
||||
@@ -197,8 +222,8 @@ final class PluginClassLoader extends URLClassLoader {
|
||||
@@ -197,8 +205,8 @@ final class PluginClassLoader extends URLClassLoader {
|
||||
result = super.findClass(name);
|
||||
}
|
||||
|
||||
|
@ -2108,7 +2109,7 @@ index 2f74ec96ece706de23156ebabfe493211bc05391..2c3d2f60d3f2f55a1a90791d37521c61
|
|||
}
|
||||
|
||||
return result;
|
||||
@@ -207,6 +232,12 @@ final class PluginClassLoader extends URLClassLoader {
|
||||
@@ -207,6 +215,12 @@ final class PluginClassLoader extends URLClassLoader {
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
try {
|
||||
|
@ -2121,7 +2122,7 @@ index 2f74ec96ece706de23156ebabfe493211bc05391..2c3d2f60d3f2f55a1a90791d37521c61
|
|||
super.close();
|
||||
} finally {
|
||||
jar.close();
|
||||
@@ -218,7 +249,7 @@ final class PluginClassLoader extends URLClassLoader {
|
||||
@@ -218,7 +232,7 @@ final class PluginClassLoader extends URLClassLoader {
|
||||
return classes.values();
|
||||
}
|
||||
|
||||
|
@ -2130,7 +2131,7 @@ index 2f74ec96ece706de23156ebabfe493211bc05391..2c3d2f60d3f2f55a1a90791d37521c61
|
|||
Preconditions.checkArgument(javaPlugin != null, "Initializing plugin cannot be null");
|
||||
Preconditions.checkArgument(javaPlugin.getClass().getClassLoader() == this, "Cannot initialize plugin outside of this class loader");
|
||||
if (this.plugin != null || this.pluginInit != null) {
|
||||
@@ -228,6 +259,32 @@ final class PluginClassLoader extends URLClassLoader {
|
||||
@@ -228,6 +242,32 @@ final class PluginClassLoader extends URLClassLoader {
|
||||
pluginState = new IllegalStateException("Initial initialization");
|
||||
this.pluginInit = javaPlugin;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue