mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-06 15:56:14 +00:00
addon dependency sorting
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package com.dfsek.terra.addons.manifest.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import ca.solostudios.strata.version.Version;
|
||||
import ca.solostudios.strata.version.VersionRange;
|
||||
|
||||
import com.dfsek.terra.addons.manifest.api.AddonInitializer;
|
||||
import com.dfsek.terra.addons.manifest.impl.config.AddonManifest;
|
||||
@@ -43,4 +47,18 @@ public class ManifestAddon implements BaseAddon {
|
||||
initializer.initialize();
|
||||
});
|
||||
}
|
||||
|
||||
public AddonManifest getManifest() {
|
||||
return manifest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, VersionRange> getDependencies() {
|
||||
return manifest.getDependencies();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return manifest.getVersion();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.addons.manifest.impl;
|
||||
|
||||
import ca.solostudios.strata.Versions;
|
||||
import ca.solostudios.strata.version.Version;
|
||||
import ca.solostudios.strata.version.VersionRange;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
@@ -33,6 +34,8 @@ public class ManifestAddonLoader implements BootstrapBaseAddon<ManifestAddon> {
|
||||
@Inject
|
||||
private Platform platform;
|
||||
|
||||
private static final Version VERSION = Versions.getVersion(1, 0, 0);
|
||||
|
||||
@Override
|
||||
public Iterable<ManifestAddon> loadAddons(Path addonsFolder, ClassLoader parent) {
|
||||
platform.logger().info("Loading addons...");
|
||||
@@ -44,51 +47,51 @@ public class ManifestAddonLoader implements BootstrapBaseAddon<ManifestAddon> {
|
||||
|
||||
try {
|
||||
return Files.walk(addonsFolder, 1)
|
||||
.filter(path -> path.toFile().isFile() && path.toString().endsWith(".jar"))
|
||||
.map(path -> {
|
||||
try {
|
||||
platform.getDebugLogger().info("Loading addon from JAR " + path);
|
||||
JarFile jar = new JarFile(path.toFile());
|
||||
|
||||
JarEntry manifestEntry = jar.getJarEntry("terra.addon.yml");
|
||||
if(manifestEntry == null) {
|
||||
throw new ManifestNotPresentException("Addon " + path + " does not contain addon manifest.");
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
AddonManifest manifest = manifestLoader.load(new AddonManifest(),
|
||||
new YamlConfiguration(jar.getInputStream(manifestEntry),
|
||||
"terra.addon.yml"));
|
||||
|
||||
platform.logger().info("Loading addon " + manifest.getID());
|
||||
|
||||
ManifestAddonClassLoader loader = new ManifestAddonClassLoader(new URL[]{ path.toUri().toURL() },
|
||||
getClass().getClassLoader());
|
||||
|
||||
return new ManifestAddon(manifest, manifest.getEntryPoints().stream().map(entryPoint -> {
|
||||
try {
|
||||
Object in = loader.loadClass(entryPoint).getConstructor().newInstance();
|
||||
if(!(in instanceof AddonInitializer)) {
|
||||
throw new AddonException(in.getClass() + " does not extend " + AddonInitializer.class);
|
||||
}
|
||||
return (AddonInitializer) in;
|
||||
} catch(InvocationTargetException e) {
|
||||
throw new AddonException("Exception occurred while instantiating addon: ", e);
|
||||
} catch(NoSuchMethodException | IllegalAccessException | InstantiationException e) {
|
||||
throw new AddonException("No valid default constructor found in entry point " + entryPoint);
|
||||
} catch(ClassNotFoundException e) {
|
||||
throw new AddonException("Entry point " + entryPoint + " not found in JAR.");
|
||||
}
|
||||
}).collect(Collectors.toList()));
|
||||
|
||||
} catch(LoadException e) {
|
||||
throw new ManifestException("Failed to load addon manifest", e);
|
||||
}
|
||||
} catch(IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
.filter(path -> path.toFile().isFile() && path.toString().endsWith(".jar"))
|
||||
.map(path -> {
|
||||
try {
|
||||
platform.getDebugLogger().info("Loading addon from JAR " + path);
|
||||
JarFile jar = new JarFile(path.toFile());
|
||||
|
||||
JarEntry manifestEntry = jar.getJarEntry("terra.addon.yml");
|
||||
if(manifestEntry == null) {
|
||||
throw new ManifestNotPresentException("Addon " + path + " does not contain addon manifest.");
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
AddonManifest manifest = manifestLoader.load(new AddonManifest(),
|
||||
new YamlConfiguration(jar.getInputStream(manifestEntry),
|
||||
"terra.addon.yml"));
|
||||
|
||||
platform.logger().info("Loading addon " + manifest.getID());
|
||||
|
||||
ManifestAddonClassLoader loader = new ManifestAddonClassLoader(new URL[]{ path.toUri().toURL() },
|
||||
getClass().getClassLoader());
|
||||
|
||||
return new ManifestAddon(manifest, manifest.getEntryPoints().stream().map(entryPoint -> {
|
||||
try {
|
||||
Object in = loader.loadClass(entryPoint).getConstructor().newInstance();
|
||||
if(!(in instanceof AddonInitializer)) {
|
||||
throw new AddonException(in.getClass() + " does not extend " + AddonInitializer.class);
|
||||
}
|
||||
return (AddonInitializer) in;
|
||||
} catch(InvocationTargetException e) {
|
||||
throw new AddonException("Exception occurred while instantiating addon: ", e);
|
||||
} catch(NoSuchMethodException | IllegalAccessException | InstantiationException e) {
|
||||
throw new AddonException("No valid default constructor found in entry point " + entryPoint);
|
||||
} catch(ClassNotFoundException e) {
|
||||
throw new AddonException("Entry point " + entryPoint + " not found in JAR.");
|
||||
}
|
||||
}).collect(Collectors.toList()));
|
||||
|
||||
} catch(LoadException e) {
|
||||
throw new ManifestException("Failed to load addon manifest", e);
|
||||
}
|
||||
} catch(IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
} catch(IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
@@ -98,4 +101,9 @@ public class ManifestAddonLoader implements BootstrapBaseAddon<ManifestAddon> {
|
||||
public String getID() {
|
||||
return "MANIFEST";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return VERSION;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class AddonManifest implements ConfigTemplate, StringIdentifiable {
|
||||
|
||||
@Value("depends")
|
||||
@Default
|
||||
private Map<String, VersionRange> dependencies;
|
||||
private Map<String, VersionRange> dependencies = Collections.emptyMap();
|
||||
|
||||
@Value("website")
|
||||
private WebsiteConfig website;
|
||||
|
||||
Reference in New Issue
Block a user