Added Plugin.uninstall() method to cleanup, but remove for now

This commit is contained in:
Naoki Takezoe
2017-03-23 20:20:34 +09:00
parent 832b33f949
commit d39d6691e6
2 changed files with 17 additions and 6 deletions

View File

@@ -248,11 +248,17 @@ abstract class Plugin {
}
/**
* This method is invoked in shutdown of plugin system.
* This method is invoked when the plugin system is shutting down.
* If the plugin has any resources, release them in this method.
*/
def shutdown(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Unit = {}
// /**
// * This method is invoked when this plugin is uninstalled.
// * Cleanup database or any other resources in this method if necessary.
// */
// def uninstall(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Unit = {}
/**
* Helper method to get a resource from classpath.
*/

View File

@@ -181,8 +181,13 @@ object PluginRegistry {
*/
def uninstall(pluginId: String, context: ServletContext, settings: SystemSettings, conn: java.sql.Connection): Unit = synchronized {
instance.getPlugins().find(_.pluginId == pluginId).foreach { plugin =>
// try {
// plugin.pluginClass.uninstall(instance, context, settings)
// } catch {
// case e: Exception =>
// logger.error(s"Error during uninstalling plugin: ${plugin.pluginJar.getName}", e)
// }
shutdown(context, settings)
// TODO kick uninstall action here?
plugin.pluginJar.delete()
instance = new PluginRegistry()
initialize(context, settings, conn)
@@ -260,15 +265,15 @@ object PluginRegistry {
}
def shutdown(context: ServletContext, settings: SystemSettings): Unit = synchronized {
instance.getPlugins().foreach { pluginInfo =>
instance.getPlugins().foreach { plugin =>
try {
pluginInfo.pluginClass.shutdown(instance, context, settings)
plugin.pluginClass.shutdown(instance, context, settings)
} catch {
case e: Exception => {
logger.error(s"Error during plugin shutdown: ${pluginInfo.pluginJar.getName}", e)
logger.error(s"Error during plugin shutdown: ${plugin.pluginJar.getName}", e)
}
} finally {
pluginInfo.classLoader.close()
plugin.classLoader.close()
}
}
}