use of aQute.bnd.osgi.resource.RequirementBuilder in project bnd by bndtools.
the class ProcessorTest method assertNative.
private void assertNative(String in, String filter, String... fixup) throws Exception {
List<String> split = in == null ? new ArrayList<String>() : Strings.split("\\s*;\\s*", in);
split.add(0, "native_capability");
try (Processor p = new Processor()) {
String s = p._native_capability(split.toArray(new String[0]));
assertNotNull(s);
System.out.println(s);
ResourceBuilder rb = new ResourceBuilder();
List<Capability> capabilities = rb.addProvideCapabilities(s);
RequirementBuilder qb = new RequirementBuilder("osgi.native");
qb.addDirective("filter", filter);
List<Capability> found = ResourceUtils.findProviders(qb.synthetic(), capabilities);
assertTrue(!found.isEmpty());
assertTrue(p.check(fixup));
}
}
use of aQute.bnd.osgi.resource.RequirementBuilder in project bnd by bndtools.
the class RepositoryTest method testXMLParserSmall.
public void testXMLParserSmall() throws Exception {
URL url = RepositoryTest.class.getResource("repoindex-file.xml");
try (XMLResourceParser xrp = new XMLResourceParser(url.toURI())) {
xrp.setTrace(true);
List<Resource> resources = xrp.parse();
assertTrue(xrp.check());
assertNotNull(resources);
assertEquals(21, resources.size());
Requirement requirement = new RequirementBuilder("osgi.extender").addDirective("filter", "(osgi.extender=osgi.component)").buildSyntheticRequirement();
Map<Requirement, Collection<Capability>> caps = getResourcesRepository(resources).findProviders(Collections.singleton(requirement));
assertEquals(1, caps.get(requirement).size());
Resource res = caps.get(requirement).iterator().next().getResource();
assertEquals("org.apache.felix.scr", ResourceUtils.getIdentityCapability(res).getAttributes().get("osgi.identity"));
String location = ResourceUtils.getContentCapability(res).getAttributes().get("url").toString();
assertFalse(location, location.contains("file:"));
}
}
use of aQute.bnd.osgi.resource.RequirementBuilder in project bnd by bndtools.
the class RepositoryTest method testXMLParserLarge.
public void testXMLParserLarge() throws Exception {
URL url = RepositoryTest.class.getResource("larger-repo.xml");
try (XMLResourceParser xrp = new XMLResourceParser(url.toURI())) {
xrp.setTrace(true);
List<Resource> resources = xrp.parse();
assertTrue(xrp.check());
assertNotNull(resources);
assertEquals(61, resources.size());
Requirement requirement = new RequirementBuilder("osgi.extender").addDirective("filter", "(osgi.extender=osgi.component)").buildSyntheticRequirement();
Map<Requirement, Collection<Capability>> caps = getResourcesRepository(resources).findProviders(Collections.singleton(requirement));
assertEquals(1, caps.get(requirement).size());
Resource res = caps.get(requirement).iterator().next().getResource();
assertEquals("org.apache.felix.scr", ResourceUtils.getIdentityCapability(res).getAttributes().get("osgi.identity"));
String location = ResourceUtils.getContentCapability(res).getAttributes().get("url").toString();
String base = url.toURI().toString();
assertFalse(location, location.startsWith(base));
}
}
use of aQute.bnd.osgi.resource.RequirementBuilder in project bnd by bndtools.
the class ResourceTest method assertConfigAdminServices.
public void assertConfigAdminServices(Resource build) throws Exception {
assertEquals(2, build.getCapabilities(ServiceNamespace.SERVICE_NAMESPACE).size());
List<Requirement> requireLog = build.getRequirements(ServiceNamespace.SERVICE_NAMESPACE);
assertEquals(1, requireLog.size());
RequirementBuilder rqb = new RequirementBuilder(ServiceNamespace.SERVICE_NAMESPACE);
rqb.addFilter("(objectClass=org.osgi.service.cm.ConfigurationAdmin)");
List<Capability> findProviders = ResourceUtils.findProviders(rqb.buildSyntheticRequirement(), build.getCapabilities(ServiceNamespace.SERVICE_NAMESPACE));
assertEquals(1, findProviders.size());
rqb = new RequirementBuilder(ServiceNamespace.SERVICE_NAMESPACE);
rqb.addFilter("(objectClass=org.apache.felix.cm.PersistenceManager)");
findProviders = ResourceUtils.findProviders(rqb.buildSyntheticRequirement(), build.getCapabilities(ServiceNamespace.SERVICE_NAMESPACE));
assertEquals(1, findProviders.size());
CapabilityBuilder rcb = new CapabilityBuilder(ServiceNamespace.SERVICE_NAMESPACE);
rcb.addAttribute("objectClass", "org.osgi.service.log.LogService");
findProviders = ResourceUtils.findProviders(requireLog.get(0), Collections.singleton(rcb.buildSyntheticCapability()));
assertEquals(1, findProviders.size());
}
use of aQute.bnd.osgi.resource.RequirementBuilder in project bnd by bndtools.
the class CapReqFilterTest method testReqNoFilterCapWithNoAttr.
public void testReqNoFilterCapWithNoAttr() {
Capability cap = new CapabilityBuilder("foobar").buildSyntheticCapability();
Requirement req = new RequirementBuilder("foobar").buildSyntheticRequirement();
assertTrue(ResourceUtils.matches(req, cap));
}
Aggregations