Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
Rename Java plugin loader to JVM plugin loader
This is to prevent confusion with Java Edition - Velocity is built on the JVM and this handles plugins loaded into the same JVM Velocity is running in.
Dieser Commit ist enthalten in:
Ursprung
eef2b2040c
Commit
4a8be52c93
@ -37,7 +37,7 @@ import com.velocitypowered.api.plugin.meta.PluginDependency;
|
|||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
import com.velocitypowered.proxy.VelocityServer;
|
import com.velocitypowered.proxy.VelocityServer;
|
||||||
import com.velocitypowered.proxy.plugin.loader.VelocityPluginContainer;
|
import com.velocitypowered.proxy.plugin.loader.VelocityPluginContainer;
|
||||||
import com.velocitypowered.proxy.plugin.loader.java.JavaPluginLoader;
|
import com.velocitypowered.proxy.plugin.loader.jvm.JvmPluginLoader;
|
||||||
import com.velocitypowered.proxy.plugin.util.PluginDependencyUtils;
|
import com.velocitypowered.proxy.plugin.util.PluginDependencyUtils;
|
||||||
import com.velocitypowered.proxy.plugin.util.ProxyPluginContainer;
|
import com.velocitypowered.proxy.plugin.util.ProxyPluginContainer;
|
||||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
@ -92,7 +92,7 @@ public class VelocityPluginManager implements PluginManager {
|
|||||||
checkArgument(directory.toFile().isDirectory(), "provided path isn't a directory");
|
checkArgument(directory.toFile().isDirectory(), "provided path isn't a directory");
|
||||||
|
|
||||||
List<PluginDescription> found = new ArrayList<>();
|
List<PluginDescription> found = new ArrayList<>();
|
||||||
JavaPluginLoader loader = new JavaPluginLoader(server, directory);
|
JvmPluginLoader loader = new JvmPluginLoader(server, directory);
|
||||||
|
|
||||||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(directory,
|
try (DirectoryStream<Path> stream = Files.newDirectoryStream(directory,
|
||||||
p -> p.toFile().isFile() && p.toString().endsWith(".jar"))) {
|
p -> p.toFile().isFile() && p.toString().endsWith(".jar"))) {
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.velocitypowered.proxy.plugin.loader.java;
|
package com.velocitypowered.proxy.plugin.loader.jvm;
|
||||||
|
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
@ -52,12 +52,12 @@ import java.util.Set;
|
|||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarInputStream;
|
import java.util.jar.JarInputStream;
|
||||||
|
|
||||||
public class JavaPluginLoader implements PluginLoader {
|
public class JvmPluginLoader implements PluginLoader {
|
||||||
|
|
||||||
private final Path baseDirectory;
|
private final Path baseDirectory;
|
||||||
private final Map<URI, PluginClassLoader> classLoaders = new HashMap<>();
|
private final Map<URI, PluginClassLoader> classLoaders = new HashMap<>();
|
||||||
|
|
||||||
public JavaPluginLoader(ProxyServer server, Path baseDirectory) {
|
public JvmPluginLoader(ProxyServer server, Path baseDirectory) {
|
||||||
this.baseDirectory = baseDirectory;
|
this.baseDirectory = baseDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,8 +77,8 @@ public class JavaPluginLoader implements PluginLoader {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PluginDescription materializePlugin(PluginDescription source) throws Exception {
|
public PluginDescription materializePlugin(PluginDescription source) throws Exception {
|
||||||
if (!(source instanceof JavaVelocityPluginDescriptionCandidate)) {
|
if (!(source instanceof JvmVelocityPluginDescriptionCandidate)) {
|
||||||
throw new IllegalArgumentException("Description provided isn't of the Java plugin loader");
|
throw new IllegalArgumentException("Description provided isn't of the JVM plugin loader");
|
||||||
}
|
}
|
||||||
|
|
||||||
Path jarFilePath = source.file();
|
Path jarFilePath = source.file();
|
||||||
@ -91,13 +91,13 @@ 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},
|
||||||
JavaPluginLoader.class.getClassLoader(), source));
|
JvmPluginLoader.class.getClassLoader(), source));
|
||||||
classLoader.addToClassloaders();
|
classLoader.addToClassloaders();
|
||||||
return classLoader;
|
return classLoader;
|
||||||
});
|
});
|
||||||
|
|
||||||
JavaVelocityPluginDescriptionCandidate candidate =
|
JvmVelocityPluginDescriptionCandidate candidate =
|
||||||
(JavaVelocityPluginDescriptionCandidate) source;
|
(JvmVelocityPluginDescriptionCandidate) source;
|
||||||
Class mainClass = loader.loadClass(candidate.getMainClass());
|
Class mainClass = loader.loadClass(candidate.getMainClass());
|
||||||
return createDescription(candidate, mainClass);
|
return createDescription(candidate, mainClass);
|
||||||
}
|
}
|
||||||
@ -105,11 +105,11 @@ public class JavaPluginLoader implements PluginLoader {
|
|||||||
@Override
|
@Override
|
||||||
public Module createModule(PluginContainer container) throws Exception {
|
public Module createModule(PluginContainer container) throws Exception {
|
||||||
PluginDescription description = container.description();
|
PluginDescription description = container.description();
|
||||||
if (!(description instanceof JavaVelocityPluginDescription)) {
|
if (!(description instanceof JvmVelocityPluginDescription)) {
|
||||||
throw new IllegalArgumentException("Description provided isn't of the Java plugin loader");
|
throw new IllegalArgumentException("Description provided isn't of the JVM plugin loader");
|
||||||
}
|
}
|
||||||
|
|
||||||
JavaVelocityPluginDescription javaDescription = (JavaVelocityPluginDescription) description;
|
JvmVelocityPluginDescription javaDescription = (JvmVelocityPluginDescription) description;
|
||||||
Path source = javaDescription.file();
|
Path source = javaDescription.file();
|
||||||
|
|
||||||
if (source == null) {
|
if (source == null) {
|
||||||
@ -125,13 +125,13 @@ public class JavaPluginLoader implements PluginLoader {
|
|||||||
throw new IllegalArgumentException("Container provided isn't of the Java plugin loader");
|
throw new IllegalArgumentException("Container provided isn't of the Java plugin loader");
|
||||||
}
|
}
|
||||||
PluginDescription description = container.description();
|
PluginDescription description = container.description();
|
||||||
if (!(description instanceof JavaVelocityPluginDescription)) {
|
if (!(description instanceof JvmVelocityPluginDescription)) {
|
||||||
throw new IllegalArgumentException("Description provided isn't of the Java plugin loader");
|
throw new IllegalArgumentException("Description provided isn't of the Java plugin loader");
|
||||||
}
|
}
|
||||||
|
|
||||||
Injector injector = Guice.createInjector(modules);
|
Injector injector = Guice.createInjector(modules);
|
||||||
Object instance = injector
|
Object instance = injector
|
||||||
.getInstance(((JavaVelocityPluginDescription) description).getMainClass());
|
.getInstance(((JvmVelocityPluginDescription) description).getMainClass());
|
||||||
|
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
@ -190,7 +190,7 @@ public class JavaPluginLoader implements PluginLoader {
|
|||||||
dependencies.add(toDependencyMeta(dependency));
|
dependencies.add(toDependencyMeta(dependency));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new JavaVelocityPluginDescriptionCandidate(
|
return new JvmVelocityPluginDescriptionCandidate(
|
||||||
description.getId(),
|
description.getId(),
|
||||||
description.getName(),
|
description.getName(),
|
||||||
description.getVersion(),
|
description.getVersion(),
|
||||||
@ -204,9 +204,9 @@ public class JavaPluginLoader implements PluginLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private VelocityPluginDescription createDescription(
|
private VelocityPluginDescription createDescription(
|
||||||
JavaVelocityPluginDescriptionCandidate description,
|
JvmVelocityPluginDescriptionCandidate description,
|
||||||
Class mainClass) {
|
Class mainClass) {
|
||||||
return new JavaVelocityPluginDescription(
|
return new JvmVelocityPluginDescription(
|
||||||
description.id(),
|
description.id(),
|
||||||
description.name(),
|
description.name(),
|
||||||
description.version(),
|
description.version(),
|
@ -15,7 +15,7 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.velocitypowered.proxy.plugin.loader.java;
|
package com.velocitypowered.proxy.plugin.loader.jvm;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
@ -26,11 +26,11 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
class JavaVelocityPluginDescription extends VelocityPluginDescription {
|
class JvmVelocityPluginDescription extends VelocityPluginDescription {
|
||||||
|
|
||||||
private final Class<?> mainClass;
|
private final Class<?> mainClass;
|
||||||
|
|
||||||
JavaVelocityPluginDescription(String id, @Nullable String name, String version,
|
JvmVelocityPluginDescription(String id, @Nullable String name, String version,
|
||||||
@Nullable String description, @Nullable String url,
|
@Nullable String description, @Nullable String url,
|
||||||
@Nullable List<String> authors, Collection<PluginDependency> dependencies,
|
@Nullable List<String> authors, Collection<PluginDependency> dependencies,
|
||||||
@Nullable Path source, Class<?> mainClass) {
|
@Nullable Path source, Class<?> mainClass) {
|
@ -15,7 +15,7 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.velocitypowered.proxy.plugin.loader.java;
|
package com.velocitypowered.proxy.plugin.loader.jvm;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
@ -26,11 +26,11 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
class JavaVelocityPluginDescriptionCandidate extends VelocityPluginDescription {
|
class JvmVelocityPluginDescriptionCandidate extends VelocityPluginDescription {
|
||||||
|
|
||||||
private final String mainClass;
|
private final String mainClass;
|
||||||
|
|
||||||
JavaVelocityPluginDescriptionCandidate(String id, @Nullable String name, String version,
|
JvmVelocityPluginDescriptionCandidate(String id, @Nullable String name, String version,
|
||||||
@Nullable String description, @Nullable String url,
|
@Nullable String description, @Nullable String url,
|
||||||
@Nullable List<String> authors, Collection<PluginDependency> dependencies, Path source,
|
@Nullable List<String> authors, Collection<PluginDependency> dependencies, Path source,
|
||||||
String mainClass) {
|
String mainClass) {
|
@ -15,7 +15,7 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.velocitypowered.proxy.plugin.loader.java;
|
package com.velocitypowered.proxy.plugin.loader.jvm;
|
||||||
|
|
||||||
import com.google.inject.Binder;
|
import com.google.inject.Binder;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
@ -29,11 +29,11 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
class VelocityPluginModule implements Module {
|
class VelocityPluginModule implements Module {
|
||||||
|
|
||||||
private final JavaVelocityPluginDescription description;
|
private final JvmVelocityPluginDescription description;
|
||||||
private final PluginContainer pluginContainer;
|
private final PluginContainer pluginContainer;
|
||||||
private final Path basePluginPath;
|
private final Path basePluginPath;
|
||||||
|
|
||||||
VelocityPluginModule(JavaVelocityPluginDescription description,
|
VelocityPluginModule(JvmVelocityPluginDescription description,
|
||||||
PluginContainer pluginContainer, Path basePluginPath) {
|
PluginContainer pluginContainer, Path basePluginPath) {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.pluginContainer = pluginContainer;
|
this.pluginContainer = pluginContainer;
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren