}
@Override
public ResolvedResource findResource(ResolvedResource[] rress, ResourceMDParser rmdparser,
ModuleRevisionId mrid, Date date) {
ResolvedResource found = super.findResource(rress, rmdparser, mrid, date);
String osgiType = mrid.getOrganisation();
// for non bundle requirement : log the selected bundle
if (!BundleInfo.BUNDLE_TYPE.equals(osgiType)) {
// several candidates with different symbolic name : make an warning about the ambiguity
if (rress.length != 1) {
// several candidates with different symbolic name ?
Map<String, List<MDResolvedResource>> matching = new HashMap<String, List<MDResolvedResource>>();
for (int i = 0; i < rress.length; i++) {
String name = ((MDResolvedResource) rress[i]).getResolvedModuleRevision()
.getDescriptor().getExtraAttribute(CAPABILITY_EXTRA_ATTR);
List<MDResolvedResource> list = matching.get(name);
if (list == null) {
list = new ArrayList<MDResolvedResource>();
matching.put(name, list);
}
list.add((MDResolvedResource) rress[i]);
}
if (matching.keySet().size() != 1) {
if (requirementStrategy == RequirementStrategy.first) {
Message.warn("Ambiguity for the '" + osgiType + "' requirement "
+ mrid.getName() + ";version=" + mrid.getRevision());
for (Entry<String, List<MDResolvedResource>> entry : matching.entrySet()) {
Message.warn("\t" + entry.getKey());
for (MDResolvedResource c : entry.getValue()) {
Message.warn("\t\t" + c.getRevision()
+ (found == c ? " (selected)" : ""));
}
}
} else if (requirementStrategy == RequirementStrategy.noambiguity) {
Message.error("Ambiguity for the '" + osgiType + "' requirement "
+ mrid.getName() + ";version=" + mrid.getRevision());
for (Entry<String, List<MDResolvedResource>> entry : matching.entrySet()) {
Message.error("\t" + entry.getKey());
for (MDResolvedResource c : entry.getValue()) {
Message.error("\t\t" + c.getRevision()
+ (found == c ? " (best match)" : ""));
}
}
return null;
}
}
}
Message.info("'" + osgiType + "' requirement " + mrid.getName() + ";version="
+ mrid.getRevision() + " satisfied by "
+ ((MDResolvedResource) found).getResolvedModuleRevision().getId().getName()
+ ";" + found.getRevision());
}
return found;
}