// add the reasons to the map, use the requirement as the key, the
// resources required the requirement as the values
Set<Resource> resources = new HashSet<Resource>();
for (Reason reason : reasons) {
resources.add(reason.getResource());
Requirement key = reason.getRequirement();
String value = reason.getResource().getSymbolicName() + "_" + reason.getResource().getVersion().toString();
Set<String> values = req_resources.get(key);
if (values == null) {
values = new HashSet<String>();
}
values.add(value);
req_resources.put(key, values);
}
// remove the requirements that can be satisifed by the resources. It is
// listed because the resources are not satisfied by other requirements.
// For an instance, the unsatisfied reasons are [package a, required by
// bundle aa], [package b, required by bundle bb] and [package c,
// required by bundle cc],
// If the bundle aa exports the package a and c. In our error message,
// we only want to display package a is needed by bundle aa.
// Go through each requirement and find out whether the requirement can
// be satisfied by the reasons.
Set<Capability> caps = new HashSet<Capability>();
for (Resource res : resources) {
if ((res != null) && (res.getCapabilities() != null)) {
List<Capability> capList = Arrays.asList(res.getCapabilities());
if (capList != null) {
caps.addAll(capList);
}
}
}
Iterator<Map.Entry<Requirement, Set<String>>> iterator = req_resources.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<Requirement, Set<String>> entry = iterator.next();
Requirement req = entry.getKey();
for (Capability cap : caps) {
if (req.isSatisfied(cap)) { // remove the key from the map
iterator.remove();
break;
}
}
}