use of org.apache.felix.bundlerepository.Requirement in project aries by apache.
the class FelixRequirementAdapterTest method testResolutionDirectiveMandatory.
@Test
public void testResolutionDirectiveMandatory() {
Requirement req = EasyMock.createNiceMock(Requirement.class);
EasyMock.expect(req.getFilter()).andReturn("");
EasyMock.expect(req.isOptional()).andReturn(false);
EasyMock.replay(req);
FelixRequirementAdapter adapter = new FelixRequirementAdapter(req, EasyMock.createNiceMock(Resource.class));
assertEquals("Wrong value for directive " + Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE, Namespace.RESOLUTION_MANDATORY, adapter.getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE));
}
use of org.apache.felix.bundlerepository.Requirement in project aries by apache.
the class OBRAriesResolver method satisfiesAll.
protected boolean satisfiesAll(Resource res, Reason[] reasons) {
log.debug(LOG_ENTRY, "satisfiesAll", new Object[] { res, Arrays.toString(reasons) });
//Let's convert the reason to requirement
List<Requirement> reqs = new ArrayList<Requirement>();
for (Reason reason : reasons) {
reqs.add(reason.getRequirement());
}
boolean result = true;
outer: for (Requirement r : reqs) {
boolean found = false;
inner: for (Capability c : res.getCapabilities()) {
if (r.isSatisfied(c)) {
found = true;
break inner;
}
}
if (!!!found && !!!r.isOptional()) {
result = false;
break outer;
}
}
log.debug(LOG_EXIT, "satisfiesAll", result);
return result;
}
use of org.apache.felix.bundlerepository.Requirement in project aries by apache.
the class RepositoryGeneratorImpl method writeResource.
/**
* Write out the resource element
*
* @param r
* resource
* @param writer
* buffer writer
* @throws IOException
*/
private static void writeResource(Resource r, String uri, Document doc, Element root) throws IOException {
logger.debug(LOG_ENTRY, "writeResource", new Object[] { r, uri, doc, root });
Element resource = doc.createElement("resource");
resource.setAttribute(Resource.VERSION, r.getVersion().toString());
resource.setAttribute("uri", r.getURI());
resource.setAttribute(Resource.SYMBOLIC_NAME, r.getSymbolicName());
resource.setAttribute(Resource.ID, r.getSymbolicName() + "/" + r.getVersion());
resource.setAttribute(Resource.PRESENTATION_NAME, r.getPresentationName());
root.appendChild(resource);
for (Capability c : r.getCapabilities()) writeCapability(c, doc, resource);
for (Requirement req : r.getRequirements()) {
writeRequirement(req, doc, resource);
}
logger.debug(LOG_EXIT, "writeResource");
}
use of org.apache.felix.bundlerepository.Requirement in project karaf by apache.
the class FindCommand method printResource.
private void printResource(PrintStream out, Resource resource) {
String name = resource.getPresentationName();
if (name == null) {
name = resource.getSymbolicName();
}
printUnderline(out, name.length());
out.println(name);
printUnderline(out, name.length());
Map map = resource.getProperties();
for (Object o : map.entrySet()) {
Map.Entry entry = (Map.Entry) o;
if (entry.getValue().getClass().isArray()) {
out.println(entry.getKey() + ":");
for (int j = 0; j < Array.getLength(entry.getValue()); j++) {
out.println(" " + Array.get(entry.getValue(), j));
}
} else {
out.println(entry.getKey() + ": " + entry.getValue());
}
}
Requirement[] reqs = resource.getRequirements();
if ((reqs != null) && (reqs.length > 0)) {
boolean hdr = false;
for (Requirement req : reqs) {
if (!req.isOptional()) {
if (!hdr) {
hdr = true;
out.println("Requirements:");
}
out.println(" " + req.getName() + ":" + req.getFilter());
}
}
hdr = false;
for (Requirement req : reqs) {
if (req.isOptional()) {
if (!hdr) {
hdr = true;
out.println("Optional Requirements:");
}
out.println(" " + req.getName() + ":" + req.getFilter());
}
}
}
Capability[] caps = resource.getCapabilities();
if ((caps != null) && (caps.length > 0)) {
out.println("Capabilities:");
for (Capability cap : caps) {
out.println(" " + cap.getName() + ":" + cap.getPropertiesAsMap());
}
}
}
use of org.apache.felix.bundlerepository.Requirement in project aries by apache.
the class OBRAriesResolver method refineUnsatisfiedRequirements.
/**
* Refine the unsatisfied requirements ready for later human comsumption
*
* @param resolver The resolver to be used to refine the requirements
* @param reasons The reasons
* @return A map of the unsatifiedRequirement to the set of bundles that have that requirement unsatisfied (values associated with the keys can be null)
*/
private Map<String, Set<String>> refineUnsatisfiedRequirements(Resolver resolver, Reason[] reasons) {
log.debug(LOG_ENTRY, "refineUnsatisfiedRequirements", new Object[] { resolver, Arrays.toString(reasons) });
Map<Requirement, Set<String>> req_resources = new HashMap<Requirement, Set<String>>();
// 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;
}
}
}
//Now the map only contains the necessary missing requirements
Map<String, Set<String>> result = new HashMap<String, Set<String>>();
for (Map.Entry<Requirement, Set<String>> req_res : req_resources.entrySet()) {
result.put(req_res.getKey().getFilter(), req_res.getValue());
}
log.debug(LOG_EXIT, "refineUnsatisfiedRequirements", new Object[] { result });
return result;
}
Aggregations