From eddf01fc323b5e5d7f4e9fa3f8e921c93f1de588 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 29 Sep 2018 23:28:44 -0400 Subject: [PATCH] Reduce duplication between annotation processor and proxy. --- proxy/build.gradle | 2 + .../proxy/plugin/loader/JavaPluginLoader.java | 3 +- .../java/SerializedPluginDescription.java | 151 ------------------ 3 files changed, 3 insertions(+), 153 deletions(-) delete mode 100644 proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/SerializedPluginDescription.java diff --git a/proxy/build.gradle b/proxy/build.gradle index 61cfc8e91..47f174565 100644 --- a/proxy/build.gradle +++ b/proxy/build.gradle @@ -23,7 +23,9 @@ jar { } dependencies { + // Note: we depend on the API twice, first the main sourceset, and then the annotation processor. compile project(':velocity-api') + compile project(':velocity-api').sourceSets.ap.output compile project(':velocity-native') compile "io.netty:netty-codec:${nettyVersion}" diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/JavaPluginLoader.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/JavaPluginLoader.java index c67a18bd2..1931f36ad 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/JavaPluginLoader.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/JavaPluginLoader.java @@ -5,12 +5,12 @@ import com.google.inject.Injector; import com.velocitypowered.api.plugin.InvalidPluginException; import com.velocitypowered.api.plugin.PluginContainer; import com.velocitypowered.api.plugin.PluginDescription; +import com.velocitypowered.api.plugin.ap.SerializedPluginDescription; import com.velocitypowered.api.plugin.meta.PluginDependency; import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.plugin.PluginClassLoader; import com.velocitypowered.proxy.plugin.loader.java.JavaVelocityPluginDescription; -import com.velocitypowered.proxy.plugin.loader.java.SerializedPluginDescription; import com.velocitypowered.proxy.plugin.loader.java.VelocityPluginModule; import java.io.BufferedInputStream; @@ -24,7 +24,6 @@ import java.util.Optional; import java.util.Set; import java.util.jar.JarEntry; import java.util.jar.JarInputStream; -import java.util.regex.Pattern; public class JavaPluginLoader implements PluginLoader { private final ProxyServer server; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/SerializedPluginDescription.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/SerializedPluginDescription.java deleted file mode 100644 index b12b1694e..000000000 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/SerializedPluginDescription.java +++ /dev/null @@ -1,151 +0,0 @@ -package com.velocitypowered.proxy.plugin.loader.java; - -import com.google.common.base.Preconditions; -import com.google.common.base.Strings; -import com.velocitypowered.api.plugin.Plugin; -import org.checkerframework.checker.nullness.qual.Nullable; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -public class SerializedPluginDescription { - // @Nullable is used here to make GSON skip these in the serialized file - private final String id; - private final @Nullable String name; - private final @Nullable String version; - private final @Nullable String description; - private final @Nullable String url; - private final @Nullable List authors; - private final @Nullable List dependencies; - private final String main; - - public SerializedPluginDescription(String id, String name, String version, String description, String url, - List authors, List dependencies, String main) { - this.id = Preconditions.checkNotNull(id, "id"); - this.name = Strings.emptyToNull(name); - this.version = Strings.emptyToNull(version); - this.description = Strings.emptyToNull(description); - this.url = Strings.emptyToNull(url); - this.authors = authors == null || authors.isEmpty() ? null : authors; - this.dependencies = dependencies == null || dependencies.isEmpty() ? null : dependencies; - this.main = Preconditions.checkNotNull(main, "main"); - } - - public static SerializedPluginDescription from(Plugin plugin, String qualifiedName) { - List dependencies = new ArrayList<>(); - for (com.velocitypowered.api.plugin.Dependency dependency : plugin.dependencies()) { - dependencies.add(new Dependency(dependency.id(), dependency.optional())); - } - return new SerializedPluginDescription(plugin.id(), plugin.name(), plugin.version(), plugin.description(), plugin.url(), - Arrays.stream(plugin.authors()).filter(author -> !author.isEmpty()).collect(Collectors.toList()), dependencies, qualifiedName); - } - - public String getId() { - return id; - } - - public @Nullable String getName() { - return name; - } - - public @Nullable String getVersion() { - return version; - } - - public @Nullable String getDescription() { - return description; - } - - public @Nullable String getUrl() { - return url; - } - - public @Nullable List getAuthors() { - return authors; - } - - public @Nullable List getDependencies() { - return dependencies; - } - - public String getMain() { - return main; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - SerializedPluginDescription that = (SerializedPluginDescription) o; - return Objects.equals(id, that.id) && - Objects.equals(name, that.name) && - Objects.equals(version, that.version) && - Objects.equals(description, that.description) && - Objects.equals(url, that.url) && - Objects.equals(authors, that.authors) && - Objects.equals(dependencies, that.dependencies) && - Objects.equals(main, that.main); - } - - @Override - public int hashCode() { - return Objects.hash(id, name, version, description, url, authors, dependencies); - } - - @Override - public String toString() { - return "SerializedPluginDescription{" + - "id='" + id + '\'' + - ", name='" + name + '\'' + - ", version='" + version + '\'' + - ", description='" + description + '\'' + - ", url='" + url + '\'' + - ", authors=" + authors + - ", dependencies=" + dependencies + - ", main='" + main + '\'' + - '}'; - } - - public static class Dependency { - private final String id; - private final boolean optional; - - public Dependency(String id, boolean optional) { - this.id = id; - this.optional = optional; - } - - public String getId() { - return id; - } - - public boolean isOptional() { - return optional; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Dependency that = (Dependency) o; - return optional == that.optional && - Objects.equals(id, that.id); - } - - @Override - public int hashCode() { - return Objects.hash(id, optional); - } - - @Override - public String toString() { - return "Dependency{" + - "id='" + id + '\'' + - ", optional=" + optional + - '}'; - } - } -}