use of org.apache.felix.bundlerepository.Requirement in project karaf by apache.
the class InfoCommand method printResource.
private void printResource(PrintStream out, Resource resource) {
// OBR R5 per Spec has no presentation name
String resourceId = getResourceId(resource);
printUnderline(out, resourceId.length());
out.println(resourceId);
printUnderline(out, resourceId.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)) {
out.println("Requires:");
for (Requirement req : reqs) {
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 FelixRequirementAdapterTest method testCardinalityDirectiveMultiple.
@Test
public void testCardinalityDirectiveMultiple() {
Requirement req = EasyMock.createNiceMock(Requirement.class);
EasyMock.expect(req.getFilter()).andReturn("");
EasyMock.expect(req.isMultiple()).andReturn(true);
EasyMock.replay(req);
FelixRequirementAdapter adapter = new FelixRequirementAdapter(req, EasyMock.createNiceMock(Resource.class));
assertEquals("Wrong value for directive " + Namespace.REQUIREMENT_CARDINALITY_DIRECTIVE, Namespace.CARDINALITY_MULTIPLE, adapter.getDirectives().get(Namespace.REQUIREMENT_CARDINALITY_DIRECTIVE));
}
use of org.apache.felix.bundlerepository.Requirement in project aries by apache.
the class FelixRequirementAdapterTest method testResolutionDirectiveOptional.
@Test
public void testResolutionDirectiveOptional() {
Requirement req = EasyMock.createNiceMock(Requirement.class);
EasyMock.expect(req.getFilter()).andReturn("");
EasyMock.expect(req.isOptional()).andReturn(true);
EasyMock.replay(req);
FelixRequirementAdapter adapter = new FelixRequirementAdapter(req, EasyMock.createNiceMock(Resource.class));
assertEquals("Wrong value for directive " + Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE, Namespace.RESOLUTION_OPTIONAL, adapter.getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE));
}
use of org.apache.felix.bundlerepository.Requirement in project aries by apache.
the class FelixRequirementAdapterTest method testCardinalityDirectiveSingle.
@Test
public void testCardinalityDirectiveSingle() {
Requirement req = EasyMock.createNiceMock(Requirement.class);
EasyMock.expect(req.getFilter()).andReturn("");
EasyMock.expect(req.isMultiple()).andReturn(false);
EasyMock.replay(req);
FelixRequirementAdapter adapter = new FelixRequirementAdapter(req, EasyMock.createNiceMock(Resource.class));
assertEquals("Wrong value for directive " + Namespace.REQUIREMENT_CARDINALITY_DIRECTIVE, Namespace.CARDINALITY_SINGLE, adapter.getDirectives().get(Namespace.REQUIREMENT_CARDINALITY_DIRECTIVE));
}
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