mirror of
https://github.com/correl/mage.git
synced 2024-12-26 11:09:27 +00:00
ensure closing of plugin classloader
This commit is contained in:
parent
1ec5a3fb4d
commit
ccb0d3da52
1 changed files with 8 additions and 3 deletions
|
@ -29,6 +29,7 @@
|
|||
package mage.server;
|
||||
|
||||
import mage.server.util.PluginClassLoader;
|
||||
import mage.util.StreamUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -54,10 +55,12 @@ public final class ExtensionPackageLoader {
|
|||
String entryPoint = entryPointReader.nextLine().trim();
|
||||
entryPointReader.close();
|
||||
|
||||
PluginClassLoader classLoader = new PluginClassLoader();
|
||||
for(File f : packagesDirectory.listFiles()) classLoader.addURL(f.toURI().toURL());
|
||||
|
||||
PluginClassLoader classLoader = null;
|
||||
try {
|
||||
classLoader = new PluginClassLoader();
|
||||
for(File f : packagesDirectory.listFiles()) {
|
||||
classLoader.addURL(f.toURI().toURL());
|
||||
}
|
||||
return (ExtensionPackage) Class.forName(entryPoint, false, classLoader).newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
@ -65,6 +68,8 @@ public final class ExtensionPackageLoader {
|
|||
throw new RuntimeException("Entry point class not found!", e);
|
||||
} catch (ClassCastException e) {
|
||||
throw new RuntimeException("Entry point not an instance of ExtensionPackage.", e);
|
||||
} finally {
|
||||
StreamUtils.closeQuietly(classLoader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue