geforkt von Mirrors/Paper
Backport some PluginClassLoader changes for soak testing.
By: md_5 <git@md-5.net>
Dieser Commit ist enthalten in:
Ursprung
e71f34ed53
Commit
1e918108e3
@ -13,8 +13,8 @@
|
|||||||
<description>A plugin API for Minecraft servers.</description>
|
<description>A plugin API for Minecraft servers.</description>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>1.6</maven.compiler.source>
|
<maven.compiler.source>1.7</maven.compiler.source>
|
||||||
<maven.compiler.target>1.6</maven.compiler.target>
|
<maven.compiler.target>1.7</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
@ -1,12 +1,20 @@
|
|||||||
package org.bukkit.plugin.java;
|
package org.bukkit.plugin.java;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
|
import java.security.CodeSigner;
|
||||||
|
import java.security.CodeSource;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.jar.JarEntry;
|
||||||
|
import java.util.jar.JarFile;
|
||||||
|
import java.util.jar.Manifest;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.plugin.InvalidPluginException;
|
import org.bukkit.plugin.InvalidPluginException;
|
||||||
@ -21,11 +29,14 @@ final class PluginClassLoader extends URLClassLoader {
|
|||||||
private final PluginDescriptionFile description;
|
private final PluginDescriptionFile description;
|
||||||
private final File dataFolder;
|
private final File dataFolder;
|
||||||
private final File file;
|
private final File file;
|
||||||
|
private final JarFile jar;
|
||||||
|
private final Manifest manifest;
|
||||||
|
private final URL url;
|
||||||
final JavaPlugin plugin;
|
final JavaPlugin plugin;
|
||||||
private JavaPlugin pluginInit;
|
private JavaPlugin pluginInit;
|
||||||
private IllegalStateException pluginState;
|
private IllegalStateException pluginState;
|
||||||
|
|
||||||
PluginClassLoader(final JavaPluginLoader loader, final ClassLoader parent, final PluginDescriptionFile description, final File dataFolder, final File file) throws InvalidPluginException, MalformedURLException {
|
PluginClassLoader(final JavaPluginLoader loader, final ClassLoader parent, final PluginDescriptionFile description, final File dataFolder, final File file) throws IOException, InvalidPluginException, MalformedURLException {
|
||||||
super(new URL[] {file.toURI().toURL()}, parent);
|
super(new URL[] {file.toURI().toURL()}, parent);
|
||||||
Validate.notNull(loader, "Loader cannot be null");
|
Validate.notNull(loader, "Loader cannot be null");
|
||||||
|
|
||||||
@ -33,6 +44,9 @@ final class PluginClassLoader extends URLClassLoader {
|
|||||||
this.description = description;
|
this.description = description;
|
||||||
this.dataFolder = dataFolder;
|
this.dataFolder = dataFolder;
|
||||||
this.file = file;
|
this.file = file;
|
||||||
|
this.jar = new JarFile(file, true);
|
||||||
|
this.manifest = jar.getManifest();
|
||||||
|
this.url = file.toURI().toURL();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Class<?> jarClass;
|
Class<?> jarClass;
|
||||||
@ -74,7 +88,35 @@ final class PluginClassLoader extends URLClassLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
result = super.findClass(name);
|
String path = name.replace('.', '/').concat(".class");
|
||||||
|
JarEntry entry = jar.getJarEntry(path);
|
||||||
|
|
||||||
|
if (entry != null) {
|
||||||
|
byte[] classBytes;
|
||||||
|
|
||||||
|
try (InputStream is = jar.getInputStream(entry)) {
|
||||||
|
classBytes = ByteStreams.toByteArray(is);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new ClassNotFoundException(name, ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
int dot = name.lastIndexOf('.');
|
||||||
|
if (dot != -1) {
|
||||||
|
String pkgName = name.substring(0, dot);
|
||||||
|
if (getPackage(pkgName) == null) {
|
||||||
|
definePackage(pkgName, manifest, url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CodeSigner[] signers = entry.getCodeSigners();
|
||||||
|
CodeSource source = new CodeSource(url, signers);
|
||||||
|
|
||||||
|
result = defineClass(name, classBytes, 0, classBytes.length, source);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result == null) {
|
||||||
|
result = super.findClass(name);
|
||||||
|
}
|
||||||
|
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
loader.setClass(name, result);
|
loader.setClass(name, result);
|
||||||
@ -87,6 +129,15 @@ final class PluginClassLoader extends URLClassLoader {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
try {
|
||||||
|
super.close();
|
||||||
|
} finally {
|
||||||
|
jar.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Set<String> getClasses() {
|
Set<String> getClasses() {
|
||||||
return classes.keySet();
|
return classes.keySet();
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren