/** Get imported module by its name and revision from moduleGraph */ private static ModuleNodeImpl getModuleByNameAndRevision( final Map<String, Map<Date, ModuleNodeImpl>> moduleGraph, final String fromName, final Date fromRevision, final String toName, final Date toRevision) { ModuleNodeImpl to = null; if (moduleGraph.get(toName) == null || !moduleGraph.get(toName).containsKey(toRevision)) { // If revision is not specified in import, but module exists // with different revisions, take first if (moduleGraph.get(toName) != null && !moduleGraph.get(toName).isEmpty() && toRevision.equals(DEFAULT_REVISION)) { to = moduleGraph.get(toName).values().iterator().next(); LOGGER.trace( String.format( "Import:%s:%s by module:%s:%s does not specify revision, using:%s:%s for module dependency sort", toName, formatRevDate(toRevision), fromName, formatRevDate(fromRevision), to.getName(), formatRevDate(to.getRevision()))); } else { LOGGER.warn( String.format( "Not existing module imported:%s:%s by:%s:%s", toName, formatRevDate(toRevision), fromName, formatRevDate(fromRevision))); LOGGER.warn("Available models: {}", moduleGraph); ex( String.format( "Not existing module imported:%s:%s by:%s:%s", toName, formatRevDate(toRevision), fromName, formatRevDate(fromRevision))); } } else { to = moduleGraph.get(toName).get(toRevision); } return to; }
/** Extract module:revision from module builders */ private static void processDependencies( final Map<String, Map<Date, ModuleNodeImpl>> moduleGraph, final Iterable<ModuleOrModuleBuilder> mmbs) { Map<URI, ModuleOrModuleBuilder> allNS = new HashMap<>(); // Create edges in graph for (ModuleOrModuleBuilder mmb : mmbs) { Map<String, Date> imported = Maps.newHashMap(); String fromName; Date fromRevision; Collection<ModuleImport> imports; URI ns; if (mmb.isModule()) { Module module = mmb.getModule(); fromName = module.getName(); fromRevision = module.getRevision(); imports = module.getImports(); ns = module.getNamespace(); } else { ModuleBuilder moduleBuilder = mmb.getModuleBuilder(); fromName = moduleBuilder.getName(); fromRevision = moduleBuilder.getRevision(); imports = moduleBuilder.getImports().values(); ns = moduleBuilder.getNamespace(); } // check for existence of module with same namespace if (allNS.containsKey(ns)) { ModuleOrModuleBuilder mod = allNS.get(ns); String name = null; Date revision = null; if (mod.isModule()) { name = mod.getModule().getName(); revision = mod.getModule().getRevision(); } else if (mod.isModuleBuilder()) { name = mod.getModuleBuilder().getName(); revision = mod.getModuleBuilder().getRevision(); } if (!(fromName.equals(name))) { LOGGER.warn( "Error while sorting module [{}, {}]: module with same namespace ({}) already loaded: [{}, {}]", fromName, fromRevision, ns, name, revision); } } else { allNS.put(ns, mmb); } // no need to check if other Type of object, check is performed in // process modules if (fromRevision == null) { fromRevision = DEFAULT_REVISION; } for (ModuleImport imprt : imports) { String toName = imprt.getModuleName(); Date toRevision = imprt.getRevision() == null ? DEFAULT_REVISION : imprt.getRevision(); ModuleNodeImpl from = moduleGraph.get(fromName).get(fromRevision); ModuleNodeImpl to = getModuleByNameAndRevision(moduleGraph, fromName, fromRevision, toName, toRevision); /* * Check imports: If module is imported twice with different * revisions then throw exception */ if (imported.get(toName) != null && !imported.get(toName).equals(toRevision) && !imported.get(toName).equals(DEFAULT_REVISION) && !toRevision.equals(DEFAULT_REVISION)) { ex( String.format( "Module:%s imported twice with different revisions:%s, %s", toName, formatRevDate(imported.get(toName)), formatRevDate(toRevision))); } imported.put(toName, toRevision); from.addEdge(to); } } }