* Update any system-installed module to be the latest version from
* the Wonderland.jar file.
* @throws IOException if there is an error reading or writing modules
*/
protected void updateModules() throws IOException {
ModuleManager mm = ModuleManager.getModuleManager();
// create the directory to extract modules to, if it doesn't already
// exist
File moduleDir = RunUtil.createTempDir("module", ".jar");
// read the list of modules and their checksums from the jar file
Map<String, String> checksums =
FileListUtil.readChecksums("META-INF/modules");
// get the list of all installed module with the "system-installed"
// key set. This is set on all modules installed by the system
Map<String, Module> installed =
mm.getInstalledModulesByKey(ModuleAttributes.SYSTEM_MODULE);
// get the checksum of any module that has a checksum. As a
// side-effect, any module with a checksum is removed from the
// list of installed modules, so that list can be used to decide
// which modules to uninstall
Map<String, String[]> installedChecksums = getChecksums(installed);
// add all modules remaining in the installed list to the
// uninstall list. These are modules that were installed by an
// old version of Wonderland and do not have a filename or
// checksum attribute set.
Collection<String> uninstall = new ArrayList<String>(installed.keySet());
// now go through the checksums of old and new modules to determine
// which modules need to be installed and which are unchanged
List<TaggedModule> install = new ArrayList<TaggedModule>();
for (Map.Entry<String, String> checksum : checksums.entrySet()) {
// compare an existing checksum to an old checksum. If the
// old checksum doesn't exist or is different than the new
// checksum, install the new file. This will overwrite the old
// checksum in the process.
String[] installedChecksum = installedChecksums.remove(checksum.getKey());
if (installedChecksum == null ||
!installedChecksum[0].equals(checksum.getValue()))
{
install.add(createTaggedModule(checksum.getKey(),
checksum.getValue(),
moduleDir));
}
}
// any modules not removed from the installedChecksums list are
// old modules that were installed by a previous version of Wonderland
// (not by the user) and aren't in the new module list. We need to
// remove these modules
for (String[] moduleDesc : installedChecksums.values()) {
uninstall.add(moduleDesc[1]);
}
// uninstall any modules on the uninstall list
logger.warning("Uninstall: " + uninstall);
mm.addToUninstall(uninstall);
// install any modules on the install list
String installList = "";
for (TaggedModule tm : install) {
installList += " " + tm.getFile().getName();
}
logger.warning("Install: " + installList);
mm.addTaggedToInstall(install);
}