ExtensionStoreDescriptor store;
try {
// Get the application store descriptor
store = getDownloadableExtensionStoreDescriptor(true);
if (store == null) {
throw new ExtensionException(ExtensionException.INTERNAL_ERROR, "No downloadable applications.");
}
ExtensionBundle bundle = store.getApplicationBundle(id);
if (bundle == null) {
throw new ExtensionException(ExtensionException.INVALID_EXTENSION, id);
}
// Check host version
Context context = ContextHolder.getContext();
if (bundle.getRequiredHostVersion() != null && bundle.getRequiredHostVersion().compareTo(context.getVersion()) > 0) {
throw new ExtensionException(ExtensionException.INSUFFICIENT_ADITO_HOST_VERSION,
bundle.getId(),
bundle.getRequiredHostVersion().toString());
}
// Install all dependencies
if (bundle.getDependencies() != null) {
for (String dep : bundle.getDependencies()) {
if (isExtensionBundleLoaded(dep)) {
ExtensionBundle current = getExtensionBundle(dep);
ExtensionBundle available = store.getApplicationBundle(dep);
if(available != null) {
if (!current.isDevExtension() && isNewerVersionAvailable(available, current)) {
if (log.isInfoEnabled())
log.info("Found a dependency (" + dep + "), that needs upgrading. " + current.getVersion().toString() + " is the current version, " + available.getVersion().toString() + " is available. Installing now");
installExtensionFromStore(current.getId(), available.getVersion().toString(), request);
}
}
} else {
try {
if (log.isInfoEnabled())
log.info("Found a dependency (" + dep + "), that is not installed. Installing now");
installExtensionFromStore(dep, store.getApplicationBundle(dep).getVersion().toString(), request);
} catch (Exception e) {
throw new ExtensionException(ExtensionException.INTERNAL_ERROR, "Failed to install dependency " + dep);
}
}
}
}
// This action may be wrapped in a task progress monitor
Task task = (Task)request.getAttribute(TaskHttpServletRequest.ATTR_TASK);
if(task != null && request.getAttribute(TaskHttpServletRequest.ATTR_TASK_PROGRESS_HANDLED_EXTERNALLY) == null) {
TaskProgressBar bar = new TaskProgressBar("installExtension", 0, (int)contentLength, 0); // TODO should accept longs
task.clearProgressBars();
task.addProgressBar(bar);
in = new TaskInputStream(bar, in);
((TaskInputStream)in).getProgressBar().setNote(new BundleActionMessage("extensions", "taskProgress.downloadExtension.note", id));
if(!task.isConfigured())
task.configured();
}
return installExtension(id, in);
} catch (IOException jde) {
throw new ExtensionException(ExtensionException.INTERNAL_ERROR, "Failed to load descriptor.");
} catch (JDOMException jde) {
throw new ExtensionException(ExtensionException.FAILED_TO_PARSE_DESCRIPTOR);
}
}