diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2012-11-26 10:58:10 +0100 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2012-11-26 10:58:10 +0100 |
| commit | 86a025e1f46c1809500df2a71a9fe743a968e760 (patch) | |
| tree | 6d8d8bbe129abd1865c8926718060df5a149ab6c | |
| parent | a850e1b5d2e55773812a375613f9df713a23f6bd (diff) | |
Fixes #84
| -rw-r--r-- | src/main/java/com/c2kernel/process/module/ModuleManager.java | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/src/main/java/com/c2kernel/process/module/ModuleManager.java b/src/main/java/com/c2kernel/process/module/ModuleManager.java index e78c25d..049558e 100644 --- a/src/main/java/com/c2kernel/process/module/ModuleManager.java +++ b/src/main/java/com/c2kernel/process/module/ModuleManager.java @@ -52,7 +52,7 @@ public class ModuleManager { if (errors.length() > 0)
throw new ModuleException("Module XML found at "+newModuleURL+" was not valid: "+errors);
Module newModule = (Module)Gateway.getMarshaller().unmarshall(moduleXML);
- Resource.addModuleBaseURL(newModule.ns, newModule.resURL);
+ if (newModule.resURL != null && newModule.resURL.length()>0) Resource.addModuleBaseURL(newModule.ns, newModule.resURL);
modules.add(newModule);
modulesXML.put(newModule.ns, moduleXML);
if (loadedModules.contains(newModule.getName())) throw new ModuleException("Module name clash: "+newModule.getName());
@@ -74,7 +74,6 @@ public class ModuleManager { }
Logger.debug(5, "Checking dependencies");
- //TODO: order the importing so each modules dependencies are imported ahead of it
boolean depFailed = false;
for (Module thisMod : modules) {
ArrayList<String> deps = thisMod.getDependencies();
@@ -116,10 +115,32 @@ public class ModuleManager { public void registerModules() throws ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException, ObjectAlreadyExistsException, NoSuchAlgorithmException {
ItemProxy serverEntity = (ItemProxy)Gateway.getProxyManager().getProxy(new DomainPath("/servers/"+Gateway.getProperty("ItemServer.name")));
Logger.debug(3, "Registering modules");
- for (Module thisMod : modules) {
+ ArrayList<String> importedModules = new ArrayList<String>();
+ for (int i=0; i<modules.size();i++) {
+ boolean depClean = false;
+ int skipped = 0;
+ Module thisMod = modules.get(i);
+ while (!depClean) {
+ ArrayList<String> deps = thisMod.getDependencies();
+ depClean = true;
+ for (String dep : deps) {
+ if (!importedModules.contains(dep)) {
+ Logger.debug(3, "Modules "+thisMod.getName()+" depends on "+dep+" which hasn't been imported yet. Deferring.");
+ modules.remove(i);
+ modules.add(thisMod);
+ thisMod = modules.get(i);
+ skipped++;
+ depClean = false;
+ }
+ }
+ if (skipped > modules.size()-i)
+ throw new CannotManageException("Too many modules deferred. There might be circular dependencies", "");
+ }
+
Logger.msg("Registering module "+thisMod.getName());
thisMod.importAll(serverEntity, modulesXML.get(thisMod.ns));
Logger.msg("Module "+thisMod.getName()+" registered");
+ importedModules.add(thisMod.getName());
}
}
|
