// If there are any pending removals or installations, we cannot
// reload
boolean pending = false;
for (Iterator i = currentlyLoadedExtensions.entrySet().iterator(); !pending && i.hasNext();) {
Map.Entry ent = (Map.Entry) i.next();
final ExtensionBundle bundle = (ExtensionBundle) ent.getValue();
pending = bundle.getType() == ExtensionBundle.TYPE_PENDING_INSTALLATION || bundle.getType() == ExtensionBundle.TYPE_PENDING_REMOVAL
|| bundle.getType() == ExtensionBundle.TYPE_PENDING_UPDATE
|| bundle.getType() == ExtensionBundle.TYPE_PENDING_STATE_CHANGE;
}
if (pending) {
throw new Exception("There are pending installations / removals / updates. You must restart the server.");
}
// Reload
if (request.getParameter("id") == null) {
ExtensionStore.getInstance().reload();
} else {
String application = request.getParameter("id");
ExtensionStore.getInstance().reload(application);
}
/*
* Build up an error message from any exceptions that may have
* occured during reloading
*/
if (errors != null && errors.size() > 0) {
StringBuffer buf = new StringBuffer();
for (ExtensionBundle bundle : ExtensionStore.getInstance().getExtensionBundles()) {
if (bundle.getError() != null) {
if (buf.length() > 0) {
buf.append(". ");
}
buf.append(bundle.getError().getMessage());
}
}
throw new Exception(buf.toString());
}
// Look for new plugins
Map newLoadedPlugins = getLoadedPlugins();
// Look for new plugins
boolean newPluginsFound = false;
for (Iterator i = newLoadedPlugins.entrySet().iterator(); i.hasNext();) {
Map.Entry ent = (Map.Entry) i.next();
if (!currentlyLoadedPlugins.containsKey(ent.getKey())) {
ExtensionDescriptor des = (ExtensionDescriptor) newLoadedPlugins.get(ent.getKey());
des.getApplicationBundle().setType(ExtensionBundle.TYPE_PENDING_INSTALLATION);
newPluginsFound = true;
}
}
if (newPluginsFound) {
GlobalWarningManager.getInstance().addMultipleGlobalWarning(new GlobalWarning(GlobalWarning.MANAGEMENT_USERS, new BundleActionMessage("extensions",
"extensionStore.message.pluginInstalledRestartRequired"), DismissType.DISMISS_FOR_USER));
}
// Look for new extensions
Map newLoadedExtensions = getLoadedExtensions();
// Look for extension updates
File updatedExtensionsDir = ExtensionStore.getInstance().getUpdatedExtensionsDirectory();
boolean updatesFound = false;
for (Iterator i = newLoadedExtensions.entrySet().iterator(); i.hasNext();) {
Map.Entry ent = (Map.Entry) i.next();
if (new File(updatedExtensionsDir, (String) ent.getKey()).exists()) {
final ExtensionBundle bundle = (ExtensionBundle) ent.getValue();
for (Iterator j = bundle.iterator(); j.hasNext();) {
ExtensionDescriptor des = (ExtensionDescriptor) j.next();
des.getApplicationBundle().setType(ExtensionBundle.TYPE_PENDING_UPDATE);
}
updatesFound = true;
}
}
if (updatesFound) {
GlobalWarningManager.getInstance().addMultipleGlobalWarning(new GlobalWarning(GlobalWarning.MANAGEMENT_USERS, new BundleActionMessage("extensions",
"extensionStore.message.extensionUpdatedRestartRequired"), DismissType.DISMISS_FOR_USER));
}
// Check for new extensions
for (Iterator i = newLoadedExtensions.entrySet().iterator(); i.hasNext();) {
Map.Entry ent = (Map.Entry) i.next();
if (!currentlyLoadedExtensions.containsKey(ent.getKey())) {
final ExtensionBundle bundle = (ExtensionBundle) ent.getValue();
// If installing, there may be a license agreement to handle
File licenseFile = bundle.getLicenseFile();
if (licenseFile != null && licenseFile.exists()) {
final boolean fNewPluginsFound = newPluginsFound;
CoreUtil.requestLicenseAgreement(request.getSession(), new LicenseAgreement(bundle.getName(),
licenseFile,
new LicenseAgreementCallback() {
public void licenseAccepted(HttpServletRequest request) {
// Dont care
}