From 1028ed09892621260eea31961af43c6eaeafe262 Mon Sep 17 00:00:00 2001 From: dfsek Date: Thu, 18 Nov 2021 21:50:41 -0700 Subject: [PATCH] delete old addon system --- .../com/dfsek/terra/api/addon/TerraAddon.java | 61 ------------------- .../terra/api/addon/annotations/Addon.java | 21 ------- .../terra/api/addon/annotations/Author.java | 21 ------- .../terra/api/addon/annotations/Depends.java | 21 ------- .../terra/api/addon/annotations/Version.java | 21 ------- .../dfsek/terra/api/config/ConfigPack.java | 2 - .../dfsek/terra/addon/AddonClassLoader.java | 44 ------------- .../java/com/dfsek/terra/addon/AddonPool.java | 43 ------------- .../com/dfsek/terra/addon/PreLoadAddon.java | 61 ------------------- .../com/dfsek/terra/bukkit/BukkitAddon.java | 24 -------- .../com/dfsek/terra/fabric/FabricAddon.java | 3 - 11 files changed, 322 deletions(-) delete mode 100644 common/api/core/src/main/java/com/dfsek/terra/api/addon/TerraAddon.java delete mode 100644 common/api/core/src/main/java/com/dfsek/terra/api/addon/annotations/Addon.java delete mode 100644 common/api/core/src/main/java/com/dfsek/terra/api/addon/annotations/Author.java delete mode 100644 common/api/core/src/main/java/com/dfsek/terra/api/addon/annotations/Depends.java delete mode 100644 common/api/core/src/main/java/com/dfsek/terra/api/addon/annotations/Version.java delete mode 100644 common/loader/addon/src/main/java/com/dfsek/terra/addon/AddonPool.java delete mode 100644 common/loader/addon/src/main/java/com/dfsek/terra/addon/PreLoadAddon.java delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/BukkitAddon.java diff --git a/common/api/core/src/main/java/com/dfsek/terra/api/addon/TerraAddon.java b/common/api/core/src/main/java/com/dfsek/terra/api/addon/TerraAddon.java deleted file mode 100644 index 92fe2a7a3..000000000 --- a/common/api/core/src/main/java/com/dfsek/terra/api/addon/TerraAddon.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.dfsek.terra.api.addon; - - -import ca.solostudios.strata.Versions; -import org.jetbrains.annotations.NotNull; - -import com.dfsek.terra.api.addon.annotations.Addon; -import com.dfsek.terra.api.addon.annotations.Author; -import com.dfsek.terra.api.addon.annotations.Version; - - -/** - * Represents an entry point for an com.dfsek.terra.addon. Implementations must be annotated with {@link Addon}. - */ - -//todo delete this -public abstract class TerraAddon implements BaseAddon { - /** - * Invoked immediately after an com.dfsek.terra.addon is loaded. - */ - public abstract void initialize(); - - /** - * Gets the version of this com.dfsek.terra.addon. - * - * @return Addon version. - */ - public final @NotNull ca.solostudios.strata.version.Version getVersion() { - Version version = getClass().getAnnotation(Version.class); - return Versions.getVersion(1, 2, 3); - } - - /** - * Gets the author of this com.dfsek.terra.addon. - * - * @return Addon author. - */ - public final @NotNull String getAuthor() { - Author author = getClass().getAnnotation(Author.class); - return author == null ? "Anon Y. Mous" : author.value(); - } - - /** - * Gets the name (ID) of this com.dfsek.terra.addon. - * - * @return Addon ID. - */ - public final @NotNull String getName() { - Addon addon = getClass().getAnnotation(Addon.class); - if(addon == null) - throw new IllegalStateException( - "Addon annotation not present"); // This should never happen; the presence of this annotation is checked by the com - // .dfsek.terra.addon loader. - return addon.value(); - } - - @Override - public String getID() { - return getName(); - } -} diff --git a/common/api/core/src/main/java/com/dfsek/terra/api/addon/annotations/Addon.java b/common/api/core/src/main/java/com/dfsek/terra/api/addon/annotations/Addon.java deleted file mode 100644 index a10b0bd50..000000000 --- a/common/api/core/src/main/java/com/dfsek/terra/api/addon/annotations/Addon.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.dfsek.terra.api.addon.annotations; - -import org.jetbrains.annotations.NotNull; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - - -/** - * Specifies that the annotated class is an entry point for a Terra com.dfsek.terra.addon. - */ -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -public @interface Addon { - /** - * @return The ID of the com.dfsek.terra.addon. - */ - @NotNull String value(); -} diff --git a/common/api/core/src/main/java/com/dfsek/terra/api/addon/annotations/Author.java b/common/api/core/src/main/java/com/dfsek/terra/api/addon/annotations/Author.java deleted file mode 100644 index 879e57553..000000000 --- a/common/api/core/src/main/java/com/dfsek/terra/api/addon/annotations/Author.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.dfsek.terra.api.addon.annotations; - -import org.jetbrains.annotations.NotNull; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - - -/** - * Optional annotation that specifies the author of an com.dfsek.terra.addon. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface Author { - /** - * @return Name of the com.dfsek.terra.addon author. - */ - @NotNull String value(); -} diff --git a/common/api/core/src/main/java/com/dfsek/terra/api/addon/annotations/Depends.java b/common/api/core/src/main/java/com/dfsek/terra/api/addon/annotations/Depends.java deleted file mode 100644 index 73c6bcb94..000000000 --- a/common/api/core/src/main/java/com/dfsek/terra/api/addon/annotations/Depends.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.dfsek.terra.api.addon.annotations; - -import org.jetbrains.annotations.NotNull; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - - -/** - * Optional annotation that specifies dependencies of an com.dfsek.terra.addon. - */ -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -public @interface Depends { - /** - * @return All addons this com.dfsek.terra.addon is dependent upon. - */ - @NotNull String[] value(); -} diff --git a/common/api/core/src/main/java/com/dfsek/terra/api/addon/annotations/Version.java b/common/api/core/src/main/java/com/dfsek/terra/api/addon/annotations/Version.java deleted file mode 100644 index b52c027ff..000000000 --- a/common/api/core/src/main/java/com/dfsek/terra/api/addon/annotations/Version.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.dfsek.terra.api.addon.annotations; - -import org.jetbrains.annotations.NotNull; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - - -/** - * Optional annotation that specifies the version of an com.dfsek.terra.addon. - */ -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -public @interface Version { - /** - * @return Version of the com.dfsek.terra.addon. - */ - @NotNull String value(); -} diff --git a/common/api/core/src/main/java/com/dfsek/terra/api/config/ConfigPack.java b/common/api/core/src/main/java/com/dfsek/terra/api/config/ConfigPack.java index e170c76c3..9f95c064a 100644 --- a/common/api/core/src/main/java/com/dfsek/terra/api/config/ConfigPack.java +++ b/common/api/core/src/main/java/com/dfsek/terra/api/config/ConfigPack.java @@ -3,12 +3,10 @@ package com.dfsek.terra.api.config; import java.lang.reflect.Type; import java.util.List; import java.util.Map; -import java.util.Set; import ca.solostudios.strata.version.VersionRange; import com.dfsek.terra.api.addon.BaseAddon; -import com.dfsek.terra.api.addon.TerraAddon; import com.dfsek.terra.api.registry.CheckedRegistry; import com.dfsek.terra.api.registry.meta.RegistryFactory; import com.dfsek.terra.api.registry.meta.RegistryHolder; diff --git a/common/loader/addon/src/main/java/com/dfsek/terra/addon/AddonClassLoader.java b/common/loader/addon/src/main/java/com/dfsek/terra/addon/AddonClassLoader.java index ff072ad12..e7ec26117 100644 --- a/common/loader/addon/src/main/java/com/dfsek/terra/addon/AddonClassLoader.java +++ b/common/loader/addon/src/main/java/com/dfsek/terra/addon/AddonClassLoader.java @@ -1,17 +1,7 @@ package com.dfsek.terra.addon; -import java.io.File; -import java.io.IOException; import java.net.URL; import java.net.URLClassLoader; -import java.util.Enumeration; -import java.util.HashSet; -import java.util.Set; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; - -import com.dfsek.terra.api.addon.TerraAddon; -import com.dfsek.terra.api.addon.annotations.Addon; public class AddonClassLoader extends URLClassLoader { @@ -22,38 +12,4 @@ public class AddonClassLoader extends URLClassLoader { public AddonClassLoader(URL[] urls, ClassLoader parent) { super(urls, parent); } - - @SuppressWarnings("unchecked") - public static Set> fetchAddonClasses(File file, ClassLoader parent) throws IOException { - JarFile jarFile = new JarFile(file); - Enumeration entries = jarFile.entries(); - - try(AddonClassLoader loader = new AddonClassLoader(new URL[]{ file.toURI().toURL() }, parent)) { - - Set> set = new HashSet<>(); - while(entries.hasMoreElements()) { - JarEntry entry = entries.nextElement(); - - if(entry.isDirectory() || !entry.getName().endsWith(".class")) continue; - String className = entry.getName().substring(0, entry.getName().length() - 6).replace('/', '.'); - - try { - Class clazz = loader.loadClass(className); - - Addon addon = clazz.getAnnotation(Addon.class); - - if(addon == null) continue; - - if(!TerraAddon.class.isAssignableFrom(clazz)) - throw new IllegalArgumentException("Addon class \"" + clazz + "\" must extend TerraAddon."); - - set.add((Class) clazz); - } catch(ClassNotFoundException e) { - throw new IllegalStateException(e); // this should literally never happen, if it does something is very wrong - } - } - - return set; - } - } } diff --git a/common/loader/addon/src/main/java/com/dfsek/terra/addon/AddonPool.java b/common/loader/addon/src/main/java/com/dfsek/terra/addon/AddonPool.java deleted file mode 100644 index 35faba3e0..000000000 --- a/common/loader/addon/src/main/java/com/dfsek/terra/addon/AddonPool.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.dfsek.terra.addon; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import com.dfsek.terra.addon.exception.AddonLoadException; - - -public class AddonPool { - private final Map pool = new HashMap<>(); - - public void add(PreLoadAddon addon) throws AddonLoadException { - if(pool.containsKey(addon.getId())) { - String message = "Duplicate com.dfsek.terra.addon ID: " + - addon.getId() + "; original ID from file: " + - pool.get(addon.getId()).getFile().getAbsolutePath() + - ", class: " + - pool.get(addon.getId()).getAddonClass().getCanonicalName() + - "Duplicate ID from file: " + - addon.getFile().getAbsolutePath() + - ", class: " + - addon.getAddonClass().getCanonicalName(); - throw new AddonLoadException(message); - } - pool.put(addon.getId(), addon); - } - - public PreLoadAddon get(String id) { - return pool.get(id); - } - - public void buildAll() throws AddonLoadException { - for(PreLoadAddon value : pool.values()) { - value.rebuildDependencies(this, value, true); - } - } - - public Set getAddons() { - return new HashSet<>(pool.values()); - } -} diff --git a/common/loader/addon/src/main/java/com/dfsek/terra/addon/PreLoadAddon.java b/common/loader/addon/src/main/java/com/dfsek/terra/addon/PreLoadAddon.java deleted file mode 100644 index 09648bda9..000000000 --- a/common/loader/addon/src/main/java/com/dfsek/terra/addon/PreLoadAddon.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.dfsek.terra.addon; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import com.dfsek.terra.addon.exception.AddonLoadException; -import com.dfsek.terra.addon.exception.CircularDependencyException; -import com.dfsek.terra.addon.exception.DependencyMissingException; -import com.dfsek.terra.api.addon.TerraAddon; -import com.dfsek.terra.api.addon.annotations.Addon; -import com.dfsek.terra.api.addon.annotations.Depends; - - -public class PreLoadAddon { - private final List depends = new ArrayList<>(); - private final Class addonClass; - private final String id; - private final String[] dependencies; - private final File file; - - public PreLoadAddon(Class addonClass, File file) { - this.addonClass = addonClass; - this.id = addonClass.getAnnotation(Addon.class).value(); - this.file = file; - Depends depends = addonClass.getAnnotation(Depends.class); - this.dependencies = depends == null ? new String[]{ } : depends.value(); - } - - public void rebuildDependencies(AddonPool pool, PreLoadAddon origin, boolean levelG1) throws AddonLoadException { - if(this.equals(origin) && !levelG1) - throw new CircularDependencyException( - "Detected circular dependency in addon \"" + id + "\", dependencies: " + Arrays.toString(dependencies)); - - for(String dependency : dependencies) { - PreLoadAddon preLoadAddon = pool.get(dependency); - if(preLoadAddon == null) - throw new DependencyMissingException( - "Dependency " + dependency + " was not found. Please install " + dependency + " to use " + id + "."); - depends.add(preLoadAddon); - preLoadAddon.rebuildDependencies(pool, origin, false); - } - } - - public List getDepends() { - return depends; - } - - public String getId() { - return id; - } - - public Class getAddonClass() { - return addonClass; - } - - public File getFile() { - return file; - } -} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/BukkitAddon.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/BukkitAddon.java deleted file mode 100644 index d032b11e3..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/BukkitAddon.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.dfsek.terra.bukkit; - -import com.dfsek.terra.api.Platform; -import com.dfsek.terra.api.addon.TerraAddon; -import com.dfsek.terra.api.addon.annotations.Addon; -import com.dfsek.terra.api.addon.annotations.Author; -import com.dfsek.terra.api.addon.annotations.Version; - - -@Addon("Terra-Bukkit") -@Version("1.0.0") -@Author("Terra") -final class BukkitAddon extends TerraAddon { - private final Platform platform; - - public BukkitAddon(Platform platform) { - this.platform = platform; - } - - @Override - public void initialize() { - - } -} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/FabricAddon.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/FabricAddon.java index d772b2f4b..44d1a7b93 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/FabricAddon.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/FabricAddon.java @@ -15,9 +15,6 @@ import net.minecraft.world.gen.feature.ConfiguredFeature; import java.util.HashMap; import java.util.Map; -import com.dfsek.terra.api.addon.TerraAddon; -import com.dfsek.terra.api.addon.annotations.Addon; -import com.dfsek.terra.api.addon.annotations.Author; import com.dfsek.terra.api.config.ConfigPack; import com.dfsek.terra.api.event.events.config.pack.ConfigPackPostLoadEvent; import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;