List<PluginKey> pluginKeys = new ArrayList<PluginKey>();
for (Integer pluginId : pluginIds) {
serverPluginsBean.setServerPluginEnabledFlag(subject, pluginId, false);
ServerPlugin plugin = null;
try {
plugin = entityManager.getReference(ServerPlugin.class, pluginId);
} catch (Exception e) {
log.debug("Cannot undeploy plugin [" + pluginId + "]. Cause: " + ThrowableUtil.getAllMessages(e));
}
if (plugin != null) {
PluginKey pluginKey = new PluginKey(plugin);
boolean success = undeployServerPluginInMasterContainer(pluginKey);
if (success) {
pluginKeys.add(pluginKey);
}
// if this plugin ever gets re-installed, let's support the use-case where the new plugin
// will have different config metadata. Here we null out the old config so the new
// config can be set to the new config definition's default values.
if (plugin.getPluginConfiguration() != null) {
entityManager.remove(plugin.getPluginConfiguration());
plugin.setPluginConfiguration(null);
}
if (plugin.getScheduledJobsConfiguration() != null) {
entityManager.remove(plugin.getScheduledJobsConfiguration());
plugin.setScheduledJobsConfiguration(null);
}
plugin.setStatus(PluginStatusType.DELETED);
// purge the file from the filesystem, we do not want this deployed again
try {
File pluginDir = LookupUtil.getServerPluginService().getServerPluginsDirectory();
File currentFile = new File(pluginDir, plugin.getPath());
currentFile.delete();
} catch (Exception e) {
log.error("Failed to delete the undeployed plugin file [" + plugin.getPath() + "]. Cause: "
+ ThrowableUtil.getAllMessages(e));
}
log.info("Server plugin [" + pluginKey + "] has been undeployed");
}
}