3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00

Some classloader/dependency versioning fix ups

Dieser Commit ist enthalten in:
Andrew Steinborn 2021-05-16 00:33:03 -04:00
Ursprung a155f91dfd
Commit a6d4ad6950
4 geänderte Dateien mit 14 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -343,7 +343,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
} }
} }
logger.info("Loaded {} plugins", pluginManager.plugins().size()); logger.info("Loaded {} plugin(s)", pluginManager.plugins().size() - 1);
} }
public Bootstrap createBootstrap(@Nullable EventLoopGroup group, SocketAddress target) { public Bootstrap createBootstrap(@Nullable EventLoopGroup group, SocketAddress target) {

Datei anzeigen

@ -36,8 +36,8 @@ public class PluginClassLoader extends URLClassLoader {
private final PluginDescription description; private final PluginDescription description;
public PluginClassLoader(URL[] urls, PluginDescription description) { public PluginClassLoader(URL[] urls, ClassLoader parent, PluginDescription description) {
super(urls); super(urls, parent);
this.description = description; this.description = description;
} }
@ -60,14 +60,18 @@ public class PluginClassLoader extends URLClassLoader {
} }
@Override @Override
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { protected Class<?> findClass(String name) throws ClassNotFoundException {
return loadClass0(name, resolve, true); return findClass0(name, true);
} }
private Class<?> loadClass0(String name, boolean resolve, boolean checkOther) private Class<?> findClass0(String name, boolean checkOther)
throws ClassNotFoundException { throws ClassNotFoundException {
if (name.startsWith("com.velocitypowered")) {
throw new ClassNotFoundException();
}
try { try {
return super.loadClass(name, resolve); return super.findClass(name);
} catch (ClassNotFoundException ignored) { } catch (ClassNotFoundException ignored) {
// Ignored: we'll try others // Ignored: we'll try others
} }
@ -76,7 +80,7 @@ public class PluginClassLoader extends URLClassLoader {
for (PluginClassLoader loader : loaders) { for (PluginClassLoader loader : loaders) {
if (loader != this) { if (loader != this) {
try { try {
return loader.loadClass0(name, resolve, false); return loader.findClass0(name, false);
} catch (ClassNotFoundException ignored) { } catch (ClassNotFoundException ignored) {
// We're trying others, safe to ignore // We're trying others, safe to ignore
} }

Datei anzeigen

@ -136,7 +136,7 @@ public class VelocityPluginManager implements PluginManager {
Semver dependencyCandidateVersion = new Semver( Semver dependencyCandidateVersion = new Semver(
dependencyContainer.description().version(), SemverType.NPM); dependencyContainer.description().version(), SemverType.NPM);
if (!dependencyCandidateVersion.satisfies(requiredRange)) { if (!dependencyCandidateVersion.satisfies(requiredRange)) {
if (dependency.optional()) { if (!dependency.optional()) {
logger.error( logger.error(
"Can't load plugin {} due to incompatible dependency {} {} (you have {})", "Can't load plugin {} due to incompatible dependency {} {} (you have {})",
candidate.id(), dependency.id(), requiredRange, candidate.id(), dependency.id(), requiredRange,

Datei anzeigen

@ -92,7 +92,7 @@ public class JavaPluginLoader implements PluginLoader {
PluginClassLoader loader = this.classLoaders.computeIfAbsent(pluginJarUri, (uri) -> { PluginClassLoader loader = this.classLoaders.computeIfAbsent(pluginJarUri, (uri) -> {
PluginClassLoader classLoader = AccessController.doPrivileged( PluginClassLoader classLoader = AccessController.doPrivileged(
(PrivilegedAction<PluginClassLoader>) () -> new PluginClassLoader(new URL[]{pluginJarUrl}, (PrivilegedAction<PluginClassLoader>) () -> new PluginClassLoader(new URL[]{pluginJarUrl},
source)); JavaPluginLoader.class.getClassLoader(), source));
classLoader.addToClassloaders(); classLoader.addToClassloaders();
return classLoader; return classLoader;
}); });