/** * Builds a map of all the modules, keyed against the groupId and artifactId. The values are a list of modules * that match this criteria. * * @return {@link #allModules} keyed by their {@linkplain ModuleName names}. */ private Multimap<ModuleName,ModuleDependency> byName() { Multimap<ModuleName,ModuleDependency> map = HashMultimap.create(); for (ModuleDependency dependency : allModules.keySet()) { map.put(dependency.getName(),dependency); } return map; } }
/** * Checks whether this ModuleDependency is satisfied by the dependency of the given ModuleDependency. * If the version string is a defined version, then it does a comparison. If the version string * is a version range if parses this and caters for this. * * @param other The dependency to check for. * @return true if contained false otherwise. */ public boolean contains(ModuleDependency other) { if (other == null || !getName().equals(other.getName())) return false; try { return isVersionRange() ? getVersionAsRange().containsVersion(other.parseVersion()) : parseVersion().compareTo(other.parseVersion()) == 0; } catch (InvalidVersionSpecificationException ivse) { return false; } }
private MavenModule chooseMoreRelevantModule(MavenModule mm1, MavenModule mm2) { if (mm1 == null) { return mm2; } if (mm2 == null) { return mm1; } int score = mm1.getDependencyRelevancy() - mm2.getDependencyRelevancy(); if (score==0) { // tie breaker. this is arbitrary, but reproduceable score = mm1.getParent().getFullName().compareTo(mm2.getParent().getFullName()); } assert score!=0; final MavenModule moreRelevant, lessRelevant; if (score>0) { moreRelevant = mm1; lessRelevant = mm2; } else { moreRelevant = mm2; lessRelevant = mm1; } if (LOGGER.isLoggable(Level.FINER)) { LOGGER.finer("Choosing " + moreRelevant.getParent().getName() + " over " + lessRelevant.getParent().getName() + " for module " + mm1.asDependency().getName() + ". Relevancies: " + mm1.getDependencyRelevancy() + ", " + mm2.getDependencyRelevancy()); } return moreRelevant; }
Collection<ModuleDependency> candidates = mapModules.get(d.getName()); ModuleDependency winner = d.findHighestFrom(candidates); src = data.allModules.get(winner);