mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 20:07:41 +01:00
Close plugin jar file on classloader close and after retrieving name for updating (#8902)
This commit is contained in:
parent
5a125e0fc3
commit
2ad6c390e0
@ -12,8 +12,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
this.description = description;
|
||||
this.dataFolder = dataFolder;
|
||||
this.file = file;
|
||||
- this.jar = new JarFile(file);
|
||||
+ this.jar = new JarFile(file, true, java.util.zip.ZipFile.OPEN_READ, JarFile.runtimeVersion()); // Paper - enable multi-release jars for Java 9+
|
||||
- this.jar = jarFile == null ? new JarFile(file) : jarFile; // Paper - use JarFile provided by SpigotPluginProvider
|
||||
+ this.jar = jarFile == null ? new JarFile(file, true, java.util.zip.ZipFile.OPEN_READ, JarFile.runtimeVersion()) : jarFile; // Paper - use JarFile provided by SpigotPluginProvider // Paper - enable multi-release jars for Java 9+
|
||||
this.manifest = jar.getManifest();
|
||||
this.url = file.toURI().toURL();
|
||||
this.libraryLoader = libraryLoader;
|
||||
|
@ -1993,7 +1993,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
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); // Paper
|
||||
+ loader = new PluginClassLoader(getClass().getClassLoader(), description, dataFolder, file, (libraryLoader != null) ? libraryLoader.createLoader(description) : null, null); // Paper
|
||||
} catch (InvalidPluginException ex) {
|
||||
throw ex;
|
||||
} catch (Throwable ex) {
|
||||
@ -2040,7 +2040,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
|
||||
- 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) 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, @Nullable JarFile jarFile) throws IOException, InvalidPluginException, MalformedURLException { // Paper // Paper - use JarFile provided by SpigotPluginProvider
|
||||
super(new URL[] {file.toURI().toURL()}, parent);
|
||||
- Preconditions.checkArgument(loader != null, "Loader cannot be null");
|
||||
+ this.loader = null; // Paper - pass null into loader field
|
||||
@ -2049,7 +2049,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
this.description = description;
|
||||
this.dataFolder = dataFolder;
|
||||
this.file = file;
|
||||
@@ -0,0 +0,0 @@ final class PluginClassLoader extends URLClassLoader {
|
||||
- this.jar = new JarFile(file);
|
||||
+ this.jar = jarFile == null ? new JarFile(file) : jarFile; // Paper - use JarFile provided by SpigotPluginProvider
|
||||
this.manifest = jar.getManifest();
|
||||
this.url = file.toURI().toURL();
|
||||
this.libraryLoader = libraryLoader;
|
||||
|
||||
|
@ -11,7 +11,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
@@ -0,0 +0,0 @@ public final class PluginClassLoader extends URLClassLoader implements io.paperm
|
||||
|
||||
@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) 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, @Nullable JarFile jarFile) throws IOException, InvalidPluginException, MalformedURLException { // Paper // Paper - use JarFile provided by SpigotPluginProvider
|
||||
- super(new URL[] {file.toURI().toURL()}, parent);
|
||||
+ super(file.getName(), new URL[] {file.toURI().toURL()}, parent);
|
||||
this.loader = null; // Paper - pass null into loader field
|
||||
|
@ -1004,10 +1004,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+
|
||||
+ @Override
|
||||
+ public void close() throws IOException {
|
||||
+ try {
|
||||
+ try (this.jar; this.libraryLoader) {
|
||||
+ super.close();
|
||||
+ } finally {
|
||||
+ this.libraryLoader.close();
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
@ -5089,13 +5087,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ }
|
||||
+
|
||||
+ private String getPluginName(Path path) throws Exception {
|
||||
+ JarFile file = new JarFile(path.toFile());
|
||||
+ PluginFileType<?, ?> type = PluginFileType.guessType(file);
|
||||
+ if (type == null) {
|
||||
+ throw new IllegalArgumentException(path + " is not a valid plugin file, cannot load a plugin from it!");
|
||||
+ }
|
||||
+ try (JarFile file = new JarFile(path.toFile())) {
|
||||
+ PluginFileType<?, ?> type = PluginFileType.guessType(file);
|
||||
+ if (type == null) {
|
||||
+ throw new IllegalArgumentException(path + " is not a valid plugin file, cannot load a plugin from it!");
|
||||
+ }
|
||||
+
|
||||
+ return type.getConfig(file).getName();
|
||||
+ return type.getConfig(file).getName();
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ private class UpdateFileVisitor implements FileVisitor<Path> {
|
||||
@ -5944,7 +5943,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+
|
||||
+ final PluginClassLoader loader;
|
||||
+ try {
|
||||
+ loader = new PluginClassLoader(this.getClass().getClassLoader(), this.description, dataFolder, this.path.toFile(), LIBRARY_LOADER.createLoader(this.description)); // Paper
|
||||
+ loader = new PluginClassLoader(this.getClass().getClassLoader(), this.description, dataFolder, this.path.toFile(), LIBRARY_LOADER.createLoader(this.description), this.jarFile); // Paper
|
||||
+ } catch (InvalidPluginException ex) {
|
||||
+ throw ex;
|
||||
+ } catch (Throwable ex) {
|
||||
|
Loading…
Reference in New Issue
Block a user