use of io.xol.chunkstories.plugin.NotAPluginException in project chunkstories by Hugobros3.
the class ModsManagerImplementation method loadModAssets.
private ClassLoader loadModAssets(ModImplementation mod, ClassLoader parentClassLoader) {
List<File> jarFiles = new LinkedList<File>();
// For each asset in the said mod
for (Asset asset : mod.assets()) {
// Skips mod.txt
if (asset.getName().equals("./mod.txt"))
continue;
// Special case for .jar files : we extract them in the cache/ folder and make them avaible through secure ClassLoaders
if (asset.getName().endsWith(".jar")) {
File jarFile = loadJarFile(asset);
if (jarFile != null)
jarFiles.add(jarFile);
continue;
}
// Look for it's entry
ModsAssetHierarchy entry = avaibleAssets.get(asset.getName());
if (entry == null) {
entry = new ModsAssetHierarchy(asset);
avaibleAssets.put(asset.getName(), entry);
} else {
System.out.println("Adding asset " + asset + ", overriding previous stuff (top=" + entry.topInstance() + ")");
entry.addAssetInstance(asset);
}
}
// No jar files ? Just return the parent class loader.
if (jarFiles.size() == 0)
return parentClassLoader;
// Build a specialized class loader based on the parent one and the jars found within the mod
ForeignCodeClassLoader classLoader;
try {
classLoader = new ForeignCodeClassLoader(mod, parentClassLoader, jarFiles);
} catch (IOException e1) {
e1.printStackTrace();
System.out.println("Error whilst creating a ForeignCodeClassLoader for " + mod);
return parentClassLoader;
}
for (String className : classLoader.classes()) {
avaibleForeignClasses.put(className, classLoader);
}
// Load any plugins those jar files might be
for (File jarFile : jarFiles) {
try {
PluginInformationImplementation pluginInformation = new PluginInformationImplementation(jarFile, classLoader);
logger.info("Found plugin " + pluginInformation + " in " + mod);
pluginsWithinEnabledMods.add(pluginInformation);
} catch (NotAPluginException nap) {
// Discard silently
} catch (PluginLoadException | IOException e) {
System.out.println("Something went wrong loading the plugin " + jarFile + " from " + mod);
e.printStackTrace();
}
}
return classLoader;
}
Aggregations