13
0
geforkt von Mirrors/Velocity

Merge pull request #44 from Minecrell/meta-cleanup

Various improvements to plugin metadata
Dieser Commit ist enthalten in:
Andrew Steinborn 2018-08-21 17:34:41 -04:00 committet von GitHub
Commit 9c4e43e1b0
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
11 geänderte Dateien mit 226 neuen und 113 gelöschten Zeilen

3
.gitignore vendored
Datei anzeigen

@ -130,4 +130,5 @@ gradle-app.setting
logs/
/velocity.toml
server-icon.png
/bin/
/bin/
run/

Datei anzeigen

@ -1,8 +1,9 @@
package com.velocitypowered.api.plugin.ap;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
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;
@ -11,22 +12,26 @@ 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 List<String> authors;
private final @Nullable String name;
private final @Nullable String version;
private final @Nullable String description;
private final @Nullable String url;
private final @Nullable List<String> authors;
private final @Nullable List<Dependency> dependencies;
private final String main;
private final String version;
private final List<Dependency> dependencies;
public SerializedPluginDescription(String id, List<String> author, String main, String version) {
this(id, author, main, version, ImmutableList.of());
}
public SerializedPluginDescription(String id, List<String> authors, String main, String version, List<Dependency> dependencies) {
public SerializedPluginDescription(String id, String name, String version, String description, String url,
List<String> authors, List<Dependency> dependencies, String main) {
this.id = Preconditions.checkNotNull(id, "id");
this.authors = Preconditions.checkNotNull(authors, "authors");
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");
this.version = Preconditions.checkNotNull(version, "version");
this.dependencies = ImmutableList.copyOf(dependencies);
}
public static SerializedPluginDescription from(Plugin plugin, String qualifiedName) {
@ -34,54 +39,73 @@ public class SerializedPluginDescription {
for (com.velocitypowered.api.plugin.Dependency dependency : plugin.dependencies()) {
dependencies.add(new Dependency(dependency.id(), dependency.optional()));
}
return new SerializedPluginDescription(plugin.id(), Arrays.stream(plugin.authors()).filter(author -> !author.isEmpty()).collect(Collectors.toList()), qualifiedName, plugin.version(), dependencies);
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 List<String> getAuthors() {
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<String> getAuthors() {
return authors;
}
public @Nullable List<Dependency> getDependencies() {
return dependencies;
}
public String getMain() {
return main;
}
public String getVersion() {
return version;
}
public List<Dependency> getDependencies() {
return dependencies;
}
@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(authors, that.authors) &&
Objects.equals(main, that.main) &&
Objects.equals(name, that.name) &&
Objects.equals(version, that.version) &&
Objects.equals(dependencies, that.dependencies);
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, authors, main, version, dependencies);
return Objects.hash(id, name, version, description, url, authors, dependencies);
}
@Override
public String toString() {
return "SerializedPluginDescription{" +
"id='" + id + '\'' +
", authors='" + authors + '\'' +
", main='" + main + '\'' +
", name='" + name + '\'' +
", version='" + version + '\'' +
", description='" + description + '\'' +
", url='" + url + '\'' +
", authors=" + authors +
", dependencies=" + dependencies +
", main='" + main + '\'' +
'}';
}

Datei anzeigen

@ -21,6 +21,14 @@ public @interface Plugin {
*/
String id();
/**
* The human readable name of the plugin as to be used in descriptions and
* similar things.
*
* @return The plugin name, or an empty string if unknown
*/
String name() default "";
/**
* The version of the plugin.
*
@ -28,6 +36,20 @@ public @interface Plugin {
*/
String version() default "";
/**
* The description of the plugin, explaining what it can be used for.
*
* @return The plugin description, or an empty string if unknown
*/
String description() default "";
/**
* The URL or website of the plugin.
*
* @return The plugin url, or an empty string if unknown
*/
String url() default "";
/**
* The author of the plugin.
*

Datei anzeigen

@ -1,5 +1,6 @@
package com.velocitypowered.api.plugin;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.velocitypowered.api.plugin.meta.PluginDependency;
@ -7,7 +8,6 @@ import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Pattern;
/**
@ -29,21 +29,55 @@ public interface PluginDescription {
*/
String getId();
/**
* Gets the name of the {@link Plugin} within this container.
*
* @return an {@link Optional} with the plugin name, may be empty
* @see Plugin#name()
*/
default Optional<String> getName() {
return Optional.empty();
}
/**
* Gets the version of the {@link Plugin} within this container.
*
* @return the plugin version
* @return an {@link Optional} with the plugin version, may be empty
* @see Plugin#version()
*/
String getVersion();
default Optional<String> getVersion() {
return Optional.empty();
}
/**
* Gets the description of the {@link Plugin} within this container.
*
* @return an {@link Optional} with the plugin description, may be empty
* @see Plugin#description()
*/
default Optional<String> getDescription() {
return Optional.empty();
}
/**
* Gets the url or website of the {@link Plugin} within this container.
*
* @return an {@link Optional} with the plugin url, may be empty
* @see Plugin#url()
*/
default Optional<String> getUrl() {
return Optional.empty();
}
/**
* Gets the authors of the {@link Plugin} within this container.
*
* @return the plugin authors
* @return the plugin authors, may be empty
* @see Plugin#authors()
*/
List<String> getAuthors();
default List<String> getAuthors() {
return ImmutableList.of();
}
/**
* Gets a {@link Collection} of all dependencies of the {@link Plugin} within

Datei anzeigen

@ -3,6 +3,7 @@ package com.velocitypowered.api.plugin.meta;
import javax.annotation.Nullable;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
@ -36,11 +37,10 @@ public final class PluginDependency {
/**
* Returns the version this {@link PluginDependency} should match.
*
* @return the plugin version, or {@code null} if unspecified
* @return an {@link Optional} with the plugin version, may be empty
*/
@Nullable
public String getVersion() {
return version;
public Optional<String> getVersion() {
return Optional.ofNullable(version);
}
/**

Datei anzeigen

@ -77,14 +77,7 @@ public class JavaPluginLoader implements PluginLoader {
Injector injector = Guice.createInjector(new VelocityPluginModule(server, javaDescription, baseDirectory));
Object instance = injector.getInstance(javaDescription.getMainClass());
return new VelocityPluginContainer(
description.getId(),
description.getVersion(),
description.getAuthors(),
description.getDependencies(),
source.get(),
instance
);
return new VelocityPluginContainer(description, instance);
}
private Optional<SerializedPluginDescription> getSerializedPluginInfo(Path source) throws Exception {
@ -105,13 +98,18 @@ public class JavaPluginLoader implements PluginLoader {
private VelocityPluginDescription createDescription(SerializedPluginDescription description, Path source, Class mainClass) {
Set<PluginDependency> dependencies = new HashSet<>();
for (SerializedPluginDescription.Dependency dependency : description.getDependencies()) {
dependencies.add(toDependencyMeta(dependency));
if (description.getDependencies() != null) {
for (SerializedPluginDescription.Dependency dependency : description.getDependencies()) {
dependencies.add(toDependencyMeta(dependency));
}
}
return new JavaVelocityPluginDescription(
description.getId(),
description.getName(),
description.getVersion(),
description.getDescription(),
description.getUrl(),
description.getAuthors(),
dependencies,
source,

Datei anzeigen

@ -2,24 +2,21 @@ package com.velocitypowered.proxy.plugin.loader;
import com.velocitypowered.api.plugin.PluginContainer;
import com.velocitypowered.api.plugin.PluginDescription;
import com.velocitypowered.api.plugin.meta.PluginDependency;
import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
public class VelocityPluginContainer extends VelocityPluginDescription implements PluginContainer {
public class VelocityPluginContainer implements PluginContainer {
private final PluginDescription description;
private final Object instance;
public VelocityPluginContainer(String id, String version, List<String> authors, Collection<PluginDependency> dependencies, Path source, Object instance) {
super(id, version, authors, dependencies, source);
public VelocityPluginContainer(PluginDescription description, Object instance) {
this.description = description;
this.instance = instance;
}
@Override
public PluginDescription getDescription() {
return this;
return this.description;
}
@Override

Datei anzeigen

@ -1,8 +1,11 @@
package com.velocitypowered.proxy.plugin.loader;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import com.velocitypowered.api.plugin.PluginDescription;
import com.velocitypowered.api.plugin.meta.PluginDependency;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.nio.file.Path;
import java.util.Collection;
@ -14,15 +17,22 @@ import static com.google.common.base.Preconditions.checkNotNull;
public class VelocityPluginDescription implements PluginDescription {
private final String id;
private final String version;
private final @Nullable String name;
private final @Nullable String version;
private final @Nullable String description;
private final @Nullable String url;
private final List<String> authors;
private final Map<String, PluginDependency> dependencies;
private final Path source;
public VelocityPluginDescription(String id, String version, List<String> authors, Collection<PluginDependency> dependencies, Path source) {
public VelocityPluginDescription(String id, @Nullable String name, @Nullable String version, @Nullable String description, @Nullable String url,
@Nullable List<String> authors, Collection<PluginDependency> dependencies, Path source) {
this.id = checkNotNull(id, "id");
this.version = checkNotNull(version, "version");
this.authors = checkNotNull(authors, "authors");
this.name = Strings.emptyToNull(name);
this.version = Strings.emptyToNull(version);
this.description = Strings.emptyToNull(description);
this.url = Strings.emptyToNull(url);
this.authors = authors == null ? ImmutableList.of() : ImmutableList.copyOf(authors);
this.dependencies = Maps.uniqueIndex(dependencies, PluginDependency::getId);
this.source = source;
}
@ -33,8 +43,23 @@ public class VelocityPluginDescription implements PluginDescription {
}
@Override
public String getVersion() {
return version;
public Optional<String> getName() {
return Optional.ofNullable(name);
}
@Override
public Optional<String> getVersion() {
return Optional.ofNullable(version);
}
@Override
public Optional<String> getDescription() {
return Optional.ofNullable(description);
}
@Override
public Optional<String> getUrl() {
return Optional.ofNullable(url);
}
@Override
@ -61,8 +86,11 @@ public class VelocityPluginDescription implements PluginDescription {
public String toString() {
return "VelocityPluginDescription{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", version='" + version + '\'' +
", authors='" + authors + '\'' +
", description='" + description + '\'' +
", url='" + url + '\'' +
", authors=" + authors +
", dependencies=" + dependencies +
", source=" + source +
'}';

Datei anzeigen

@ -2,6 +2,7 @@ package com.velocitypowered.proxy.plugin.loader.java;
import com.velocitypowered.api.plugin.meta.PluginDependency;
import com.velocitypowered.proxy.plugin.loader.VelocityPluginDescription;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.nio.file.Path;
import java.util.Collection;
@ -10,14 +11,15 @@ import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
public class JavaVelocityPluginDescription extends VelocityPluginDescription {
private final Class mainClass;
private final Class<?> mainClass;
public JavaVelocityPluginDescription(String id, String version, List<String> authors, Collection<PluginDependency> dependencies, Path source, Class mainClass) {
super(id, version, authors, dependencies, source);
public JavaVelocityPluginDescription(String id, @Nullable String name, @Nullable String version, @Nullable String description, @Nullable String url,
@Nullable List<String> authors, Collection<PluginDependency> dependencies, Path source, Class<?> mainClass) {
super(id, name, version, description, url, authors, dependencies, source);
this.mainClass = checkNotNull(mainClass);
}
public Class getMainClass() {
public Class<?> getMainClass() {
return mainClass;
}
}

Datei anzeigen

@ -1,8 +1,9 @@
package com.velocitypowered.proxy.plugin.loader.java;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
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;
@ -11,22 +12,26 @@ 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 List<String> authors;
private final @Nullable String name;
private final @Nullable String version;
private final @Nullable String description;
private final @Nullable String url;
private final @Nullable List<String> authors;
private final @Nullable List<Dependency> dependencies;
private final String main;
private final String version;
private final List<Dependency> dependencies;
public SerializedPluginDescription(String id, List<String> authors, String main, String version) {
this(id, authors, main, version, ImmutableList.of());
}
public SerializedPluginDescription(String id, List<String> authors, String main, String version, List<Dependency> dependencies) {
public SerializedPluginDescription(String id, String name, String version, String description, String url,
List<String> authors, List<Dependency> dependencies, String main) {
this.id = Preconditions.checkNotNull(id, "id");
this.authors = Preconditions.checkNotNull(authors, "author");
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");
this.version = Preconditions.checkNotNull(version, "version");
this.dependencies = ImmutableList.copyOf(dependencies);
}
public static SerializedPluginDescription from(Plugin plugin, String qualifiedName) {
@ -34,54 +39,73 @@ public class SerializedPluginDescription {
for (com.velocitypowered.api.plugin.Dependency dependency : plugin.dependencies()) {
dependencies.add(new Dependency(dependency.id(), dependency.optional()));
}
return new SerializedPluginDescription(plugin.id(), Arrays.stream(plugin.authors()).filter(author -> !author.isEmpty()).collect(Collectors.toList()), qualifiedName, plugin.version(), dependencies);
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 List<String> getAuthors() {
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<String> getAuthors() {
return authors;
}
public @Nullable List<Dependency> getDependencies() {
return dependencies;
}
public String getMain() {
return main;
}
public String getVersion() {
return version;
}
public List<Dependency> getDependencies() {
return dependencies;
}
@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(authors, that.authors) &&
Objects.equals(main, that.main) &&
Objects.equals(name, that.name) &&
Objects.equals(version, that.version) &&
Objects.equals(dependencies, that.dependencies);
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, authors, main, version, dependencies);
return Objects.hash(id, name, version, description, url, authors, dependencies);
}
@Override
public String toString() {
return "SerializedPluginDescription{" +
"id='" + id + '\'' +
", authors='" + authors + '\'' +
", main='" + main + '\'' +
", name='" + name + '\'' +
", version='" + version + '\'' +
", description='" + description + '\'' +
", url='" + url + '\'' +
", authors=" + authors +
", dependencies=" + dependencies +
", main='" + main + '\'' +
'}';
}

Datei anzeigen

@ -8,8 +8,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
public class FakePluginManager implements PluginManager {
@ -68,22 +66,7 @@ public class FakePluginManager implements PluginManager {
@Override
public @NonNull PluginDescription getDescription() {
return new PluginDescription() {
@Override
public String getId() {
return id;
}
@Override
public String getVersion() {
return "";
}
@Override
public List<String> getAuthors() {
return Collections.emptyList();
}
};
return () -> id;
}
@Override