Collection<MetadataInfo> candidates = moduleData.get(requiredName);
List<Version> candidateVersions = Lists.newArrayList();
List<MetadataInfo> unversioned = Lists.newArrayList();
if(candidates != null)
for(MetadataInfo mi : candidates) {
Version cv = mi.getMetadata().getVersion();
if(cv == null) {
unversioned.add(mi);
continue; // the (possibly) broken version
// is reported elsewhere
}
candidateVersions.add(cv);
}
// if the dependency has no version requirement use ">=0"
final VersionRange versionRequirement = d.getVersionRequirement();
if(versionRequirement == null) {
// find best match for >= 0 if there are candidates with versions
// the best will always win over unversioned.
if(candidateVersions.size() > 0) {
Collections.sort(candidateVersions);
Version best = candidateVersions.get(candidateVersions.size() - 1);
// get the matched MetaDataInfo as the resolution of the dependency
// and remember it
for(MetadataInfo mi : candidates) {
if(mi.getMetadata().getVersion().equals(best))
info.addResolvedDependency(d, mi);
}
}
// or there must be unversioned candidates
else if(unversioned.size() == 0)
if(shouldDiagnosticBeReported)
addFileDiagnostic(
diagnostics, (candidates.size() > 0
? Diagnostic.WARNING
: Diagnostic.ERROR), info.getFile(), root,
"Unresolved Dependency to: " + d.getName() + " (unversioned).",
IValidationConstants.ISSUE__MODULEFILE_UNSATISFIED_DEPENDENCY);
else {
// pick the first as resolution
// worry about ambiguity elsewhere
info.addResolvedDependency(d, unversioned.get(0));
}
}
else {
// there was a version requirement, it must match something with a version.
Version best = d.getVersionRequirement().findBestMatch(candidateVersions);
if(best == null) {
info.addUnresolvedDependency(d);
if(shouldDiagnosticBeReported)
addFileDiagnostic(
diagnostics,