Improve logging

Signed-off-by: solonovamax <solonovamax@12oclockpoint.com>
This commit is contained in:
solonovamax
2021-08-30 22:04:17 -04:00
parent 7b9c88f8a6
commit b6c40302b6
17 changed files with 94 additions and 56 deletions

View File

@@ -49,7 +49,7 @@ public class AddonClassLoader extends URLClassLoader {
if(addon == null) continue;
if(!TerraAddon.class.isAssignableFrom(clazz))
throw new IllegalArgumentException("Addon class \"" + clazz + "\" must extend TerraAddon.");
throw new IllegalArgumentException(String.format("Addon class \"%s\" must extend TerraAddon.", clazz));
set.add((Class<? extends TerraAddon>) clazz);
} catch(ClassNotFoundException e) {

View File

@@ -13,15 +13,13 @@ public class AddonPool {
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();
String message = String.format("Duplicate addon " +
"ID: %s; original ID from file: %s, class: %sDuplicate ID from file: %s, class: %s",
addon.getId(),
pool.get(addon.getId()).getFile().getAbsolutePath(),
pool.get(addon.getId()).getAddonClass().getCanonicalName(),
addon.getFile().getAbsolutePath(),
addon.getAddonClass().getCanonicalName());
throw new AddonLoadException(message);
}
pool.put(addon.getId(), addon);

View File

@@ -14,6 +14,8 @@ import com.dfsek.terra.api.addon.annotations.Depends;
public class PreLoadAddon {
public static final String[] ZERO_LENGTH_STRING_ARRAY = { }; // Don't allocate more than once
private final List<PreLoadAddon> depends = new ArrayList<>();
private final Class<? extends TerraAddon> addonClass;
private final String id;
@@ -25,19 +27,19 @@ public class PreLoadAddon {
this.id = addonClass.getAnnotation(Addon.class).value();
this.file = file;
Depends depends = addonClass.getAnnotation(Depends.class);
this.dependencies = depends == null ? new String[]{ } : depends.value();
this.dependencies = depends == null ? ZERO_LENGTH_STRING_ARRAY : 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));
throw new CircularDependencyException(String.format("Detected circular dependency in addon \"%s\", dependencies: %s",
id, 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 + ".");
throw new DependencyMissingException(String.format("Dependency %s was not found. Please install %s to use %s.",
dependency, dependency, id));
depends.add(preLoadAddon);
preLoadAddon.rebuildDependencies(pool, origin, false);
}