AllModuleReferences exportData) {
// create node data for all existing modules and check if there are ambiguities
Multimap<ModuleName, ModuleNodeData> processedModules = ArrayListMultimap.create();
for(MetadataInfo mi : moduleData.values()) {
Metadata m = mi.getMetadata();
ModuleNodeData mnd = ModuleNodeData.existing(m.getName(), m.getVersion(), mi.isRole(), toHREF_URL(mi));
moduleNodeData.put(mi, mnd);
processedModules.put(m.getName(), mnd);
}
for(ModuleName key : processedModules.keySet()) {
Collection<ModuleNodeData> modules = processedModules.get(key);
if(modules.size() > 1) {
int counter = 0;
for(ModuleNodeData mnd : modules)
mnd.setAmbiguous(++counter);
}
}
// moduleData is keyed by "fullName" to lower case
// Create pseudo module for non modular content
nonModularNode = ModuleNodeData.root(root);
pptpNode = new ModuleNodeData(ModuleName.create("root", "puppet", false), null, ModuleType.PPTP, ""); // will not be rendered
// create module nodes for missing (unsatisfied dependencies)
// unless dependency is to represented module name, but version is not matched (in which case
// the unmatched but existing node is used.
// if a dependency appears more than once, use the first (skip the rest with same name)
for(MetadataInfo mi : moduleData.values()) {
final ModuleNodeData a = moduleNodeData.get(mi);
Set<ModuleName> processed = Sets.newHashSet();
for(Dependency d : mi.getUnresolvedDependencies()) {
final ModuleName name = d.getName();
if(!processed.add(name))
continue;
Collection<MetadataInfo> existingVersions = moduleData.get(name);
ModuleNodeData b = null;
if(existingVersions == null || existingVersions.size() < 1) {
b = moduleNodeData.get(name);
if(b == null) {
// need a node for the missing module
b = ModuleNodeData.unresolved(name);
// need to generate one that can not be found if name is null
moduleNodeData.put(name == null
? ModuleName.create("no", "name", false)
: name, b);
}
}
else {
// pick (one of) the existing versions (it is actually illegal to have more
// than one, so just pick the first one).
MetadataInfo first = Iterables.get(existingVersions, 0);
b = moduleNodeData.get(first);
}
createUnresolvedEdge(a, b, d);
}
// Add edges for all resolved dependencies
for(MetadataInfo.Resolution r : mi.getResolvedDependencies()) {
createResolvedEdge(a, moduleNodeData.get(r.metadata), r.dependency);
}
}
Map<File, ModuleNodeData> fileIndex = Maps.newHashMap();
for(Map.Entry<Object, ModuleNodeData> m : moduleNodeData.entrySet()) {
if(!(m.getKey() instanceof ModuleName)) {
MetadataInfo mi = (MetadataInfo) m.getKey();
fileIndex.put(mi.getFile(), m.getValue());
}
}
Map<File, Multimap<File, Export>> ambiguities = exportData.getAmbiguityMap();
for(Map.Entry<File, Multimap<File, AllModuleReferences.Export>> x : exportData.getImportMap().entrySet()) {
// get the imported
File fromFile = x.getKey();
Multimap<File, Export> m = x.getValue();
// get any ambiguities
Multimap<File, Export> ambiguitiesForFile = ambiguities.get(fromFile);
for(File toFile : m.keySet()) {
createImportEdge(
file2Module(fromFile, fileIndex), file2Module(toFile, fileIndex), m.get(toFile),
ambiguitiesForFile != null
? ambiguitiesForFile.get(toFile)
: null);
}
}