*/
Map<String, Module> pending = new HashMap(this.pendingMananger.getModules());
Iterator<Map.Entry<String, Module>> it = pending.entrySet().iterator();
while (it.hasNext() == true) {
Map.Entry<String, Module> entry = it.next();
Module module = entry.getValue();
DeploymentQueryResult res = this.deployManager.canDeploy(module);
if (res.getResult() == false) {
StringBuffer message = new StringBuffer("[MODULES] Unable to install " +
module.getName() + ":\n");
for (String reason : res.getReasons()) {
message.append(reason + "\n");
}
logger.warning(message.toString());
it.remove();
}
}
/*
* Check to see that the module can be safely installed by making sure
* that first its dependencies are met.
*/
Map<Module, List<ModuleInfo>> failures =
new LinkedHashMap<Module, List<ModuleInfo>>();
Map<String, Module> passed = this.checkDependencies(pending, failures);
/* Format a message to describe any failures */
if (failures.isEmpty() == false) {
StringBuffer failureMessage = new StringBuffer("[MODULES] Module dependency failures: \n");
for (Map.Entry<Module, List<ModuleInfo>> e : failures.entrySet()) {
failureMessage.append("Module " + e.getKey().getName() +
" depends on ");
for (ModuleInfo depend : e.getValue()) {
failureMessage.append(depend.getName() + " ");
failureMessage.append(" v. " + depend.getMajor() + ".");
failureMessage.append(depend.getMinor() + ".");
failureMessage.append(depend.getMini() + " ");
}
failureMessage.append("\n");
}
logger.warning(failureMessage.toString());
}
/*
* Next check whether the module is overwriting an existing installed
* module. Make sure that the new version of the module does not
* violate the dependencies of other modules.
*/
Iterator<Map.Entry<String, Module>> it1 = passed.entrySet().iterator();
while (it1.hasNext() == true) {
Map.Entry<String, Module> entry = it1.next();
ModuleInfo info = entry.getValue().getInfo();
OverwriteQueryResult res = ModuleOverwriteUtils.canOverwrite(info);
if (res.getResult() == false) {
StringBuffer message = new StringBuffer("[MODULES] Unable to replace module " +
info.getName() + ":\n");
for (String reason : res.getReasons()) {
message.append(reason + "\n");
}
logger.warning(message.toString());
it1.remove();
}
}
/*
* Go ahead and install the module and deploy. Make sure to do
* this in a valid deploy order
*/
List<String> ordered = DeployManager.getDeploymentOrder(passed);
if (logger.isLoggable(Level.FINE)) {
logger.fine("[MODULES] Calculated deployment order: " + ordered.toString());
}
for (String moduleName : ordered) {
Module module = passed.get(moduleName);
/*
* Check to see if the module is already installed. If we have
* reached here it means that we can safely uninstall the module.
* But we first have to undeploy it.
*/
if (installed.containsKey(moduleName) == true) {
try {
this.deployManager.undeploy(module);
} catch (DeployerException excp) {
logger.log(Level.WARNING, "[MODULES] INSTALL ALL Unable to undeploy " + moduleName, excp);
}
}
/*
* Install the module into the installed/ directory. Fetch the
* newly installed module (which differs from the pending Module)
*/
File file = module.getFile();
module = this.installedMananger.add(moduleName,file);
if (module == null) {
logger.warning("[MODULES] INSTALL ALL Failed on " + moduleName);
continue;
}