add logging

This commit is contained in:
dfsek 2021-11-17 15:29:28 -07:00
parent e1feb9bc5e
commit 42ece3f27a

View File

@ -24,12 +24,19 @@ import com.dfsek.terra.addons.manifest.impl.config.loaders.VersionRangeLoader;
import com.dfsek.terra.addons.manifest.impl.exception.AddonException; import com.dfsek.terra.addons.manifest.impl.exception.AddonException;
import com.dfsek.terra.addons.manifest.impl.exception.ManifestException; import com.dfsek.terra.addons.manifest.impl.exception.ManifestException;
import com.dfsek.terra.addons.manifest.impl.exception.ManifestNotPresentException; import com.dfsek.terra.addons.manifest.impl.exception.ManifestNotPresentException;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.addon.bootstrap.BootstrapBaseAddon; import com.dfsek.terra.api.addon.bootstrap.BootstrapBaseAddon;
import com.dfsek.terra.api.inject.annotations.Inject;
public class ManifestAddonLoader implements BootstrapBaseAddon<ManifestAddon> { public class ManifestAddonLoader implements BootstrapBaseAddon<ManifestAddon> {
@Inject
private Platform platform;
@Override @Override
public Iterable<ManifestAddon> loadAddons(Path addonsFolder, ClassLoader parent) { public Iterable<ManifestAddon> loadAddons(Path addonsFolder, ClassLoader parent) {
platform.logger().info("Loading addons...");
ConfigLoader manifestLoader = new ConfigLoader(); ConfigLoader manifestLoader = new ConfigLoader();
manifestLoader.registerLoader(Version.class, new VersionLoader()) manifestLoader.registerLoader(Version.class, new VersionLoader())
.registerLoader(VersionRange.class, new VersionRangeLoader()) .registerLoader(VersionRange.class, new VersionRangeLoader())
@ -40,17 +47,22 @@ public class ManifestAddonLoader implements BootstrapBaseAddon<ManifestAddon> {
.filter(path -> path.toFile().isFile() && path.toString().endsWith(".jar")) .filter(path -> path.toFile().isFile() && path.toString().endsWith(".jar"))
.flatMap(path -> { .flatMap(path -> {
try { try {
platform.getDebugLogger().info("Loading addon from JAR " + path);
JarFile jar = new JarFile(path.toFile()); JarFile jar = new JarFile(path.toFile());
JarEntry manifestEntry = jar.getJarEntry("terra.addon.yml"); JarEntry manifestEntry = jar.getJarEntry("terra.addon.yml");
if(manifestEntry == null) { if(manifestEntry == null) {
throw new ManifestNotPresentException("Addon " + path + " does not contain addon manifest."); throw new ManifestNotPresentException("Addon " + path + " does not contain addon manifest.");
} }
try { try {
AddonManifest manifest = manifestLoader.load(new AddonManifest(), AddonManifest manifest = manifestLoader.load(new AddonManifest(),
new YamlConfiguration(jar.getInputStream(manifestEntry), new YamlConfiguration(jar.getInputStream(manifestEntry),
"terra.addon.yml")); "terra.addon.yml"));
platform.logger().info("Loading addon " + manifest.getID());
ManifestAddonClassLoader loader = new ManifestAddonClassLoader(new URL[]{ path.toUri().toURL() }, ManifestAddonClassLoader loader = new ManifestAddonClassLoader(new URL[]{ path.toUri().toURL() },
getClass().getClassLoader()); getClass().getClassLoader());