Search in sources :

Example 6 with RequirementBuilder

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));
    }
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Processor(aQute.bnd.osgi.Processor) Capability(org.osgi.resource.Capability) RequirementBuilder(aQute.bnd.osgi.resource.RequirementBuilder)

Example 7 with RequirementBuilder

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:"));
    }
}
Also used : Requirement(org.osgi.resource.Requirement) Resource(org.osgi.resource.Resource) Collection(java.util.Collection) XMLResourceParser(aQute.bnd.osgi.repository.XMLResourceParser) URL(java.net.URL) RequirementBuilder(aQute.bnd.osgi.resource.RequirementBuilder)

Example 8 with RequirementBuilder

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));
    }
}
Also used : Requirement(org.osgi.resource.Requirement) Resource(org.osgi.resource.Resource) Collection(java.util.Collection) XMLResourceParser(aQute.bnd.osgi.repository.XMLResourceParser) URL(java.net.URL) RequirementBuilder(aQute.bnd.osgi.resource.RequirementBuilder)

Example 9 with RequirementBuilder

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());
}
Also used : Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) CapabilityBuilder(aQute.bnd.osgi.resource.CapabilityBuilder) RequirementBuilder(aQute.bnd.osgi.resource.RequirementBuilder)

Example 10 with RequirementBuilder

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));
}
Also used : Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) CapabilityBuilder(aQute.bnd.osgi.resource.CapabilityBuilder) RequirementBuilder(aQute.bnd.osgi.resource.RequirementBuilder)

Aggregations

RequirementBuilder (aQute.bnd.osgi.resource.RequirementBuilder)10 Requirement (org.osgi.resource.Requirement)9 Capability (org.osgi.resource.Capability)8 CapabilityBuilder (aQute.bnd.osgi.resource.CapabilityBuilder)5 Collection (java.util.Collection)3 Resource (org.osgi.resource.Resource)3 Processor (aQute.bnd.osgi.Processor)2 XMLResourceParser (aQute.bnd.osgi.repository.XMLResourceParser)2 URL (java.net.URL)2 Repository (org.osgi.service.repository.Repository)2 HttpClient (aQute.bnd.http.HttpClient)1 AggregateRepository (aQute.bnd.osgi.repository.AggregateRepository)1 AugmentRepository (aQute.bnd.osgi.repository.AugmentRepository)1 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)1 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)1 Version (aQute.bnd.version.Version)1 Slf4jReporter (aQute.libg.reporter.slf4j.Slf4jReporter)1 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Semaphore (java.util.concurrent.Semaphore)1