Search in sources :

Example 41 with CapReqBuilder

use of aQute.bnd.osgi.resource.CapReqBuilder in project bnd by bndtools.

the class FindProvidersTest method testReadGZippedStream.

public static void testReadGZippedStream() throws Exception {
    FixedIndexedRepo repo = new FixedIndexedRepo();
    Map<String, String> props = new HashMap<String, String>();
    props.put("locations", IO.getFile("testdata/big_index.xml.gz").toURI().toString());
    repo.setProperties(props);
    Requirement req = new CapReqBuilder("osgi.identity").addDirective("filter", "(&(osgi.identity=osgi.cmpn)(version>=4.2.0)(!(version>=4.2.1)))").buildSyntheticRequirement();
    Map<Requirement, Collection<Capability>> result = repo.findProviders(Collections.singleton(req));
    assertNotNull(result);
    assertTrue(result.containsKey(req));
    Collection<Capability> caps = result.get(req);
    assertEquals(1, caps.size());
    Capability identityCap = caps.iterator().next();
    List<Capability> contentCaps = identityCap.getResource().getCapabilities("osgi.content");
    assertNotNull(contentCaps);
    assertEquals(1, contentCaps.size());
    Capability contentCap = contentCaps.iterator().next();
    assertEquals(IO.getFile("testdata/osgi.cmpn/osgi.cmpn-4.2.0.jar").getAbsoluteFile().toURI(), contentCap.getAttributes().get("url"));
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) HashMap(java.util.HashMap) Collection(java.util.Collection)

Example 42 with CapReqBuilder

use of aQute.bnd.osgi.resource.CapReqBuilder in project bnd by bndtools.

the class PersistentResourceTest method testSimple.

public void testSimple() throws Exception {
    ResourceBuilder rb = new ResourceBuilder();
    rb.addCapability(new CapReqBuilder("test").addAttribute("double", 3.0).addAttribute("long", 3L).addAttribute("string", "3.0").addAttribute("version", new Version("3.0")).buildSyntheticCapability());
    Resource r = rb.build();
    PersistentResource pr = new PersistentResource(r);
    String s = new JSONCodec().enc().put(pr).toString();
    PersistentResource pr2 = new JSONCodec().dec().from(s).get(PersistentResource.class);
    List<Capability> capabilities = pr.getResource().getCapabilities(null);
    List<Requirement> requirements = pr.getResource().getRequirements(null);
    assertEquals(1, capabilities.size());
    assertEquals(0, requirements.size());
    Capability capability = capabilities.get(0);
    assertEquals("test", capability.getNamespace());
    assertEquals(3.0, capability.getAttributes().get("double"));
    assertEquals(3L, capability.getAttributes().get("long"));
    assertEquals("3.0", capability.getAttributes().get("string"));
    assertEquals(new Version("3.0"), capability.getAttributes().get("version"));
    assertEquals(0, capability.getDirectives().size());
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) PersistentResource(aQute.bnd.osgi.resource.PersistentResource) Requirement(org.osgi.resource.Requirement) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Capability(org.osgi.resource.Capability) Version(org.osgi.framework.Version) Resource(org.osgi.resource.Resource) PersistentResource(aQute.bnd.osgi.resource.PersistentResource) JSONCodec(aQute.lib.json.JSONCodec)

Example 43 with CapReqBuilder

use of aQute.bnd.osgi.resource.CapReqBuilder in project bnd by bndtools.

the class TestWrapper method augmentTest.

private void augmentTest(InfoRepository repo) throws Exception, IOException {
    assertNotNull(repo.get("biz.aQute.jpm.daemon", new Version("1.1.0"), null));
    InfoRepositoryWrapper iw = new InfoRepositoryWrapper(tmp, Collections.singleton(repo));
    Properties augments = new UTF8Properties();
    augments.load(new StringReader("biz.aQute.jpm.daemon: cap=test;test=1\n"));
    iw.addAugment(augments);
    //
    // Get the test and identity capability
    //
    Requirement testreq = new CapReqBuilder("test").filter("(test=1)").buildSyntheticRequirement();
    Requirement identity = new CapReqBuilder("osgi.identity").filter("(osgi.identity=biz.aQute.jpm.daemon)").buildSyntheticRequirement();
    Map<Requirement, Collection<Capability>> result = iw.findProviders(Arrays.asList(testreq, identity));
    assertNotNull(result);
    assertEquals(2, result.size());
    //
    // Test if they come from the same resource
    //
    Capability testcap = result.get(testreq).iterator().next();
    Capability identitycap = result.get(identity).iterator().next();
    assertNotNull(testcap);
    assertNotNull(identitycap);
    assertEquals(testcap.getResource(), identitycap.getResource());
    iw.close();
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) Version(aQute.bnd.version.Version) StringReader(java.io.StringReader) Collection(java.util.Collection) UTF8Properties(aQute.lib.utf8properties.UTF8Properties) Properties(java.util.Properties) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Example 44 with CapReqBuilder

use of aQute.bnd.osgi.resource.CapReqBuilder in project bndtools by bndtools.

the class RunRequirementsPart method convertLegacyRequireList.

private List<Requirement> convertLegacyRequireList(String input) throws IllegalArgumentException {
    List<Requirement> result = new ArrayList<Requirement>();
    if (Constants.EMPTY_HEADER.equalsIgnoreCase(input.trim()))
        return result;
    QuotedTokenizer qt = new QuotedTokenizer(input, ",");
    String token = qt.nextToken();
    while (token != null) {
        String item = token.trim();
        int index = item.indexOf(":");
        if (index < 0)
            throw new IllegalArgumentException("Invalid format for requirement");
        String name = item.substring(0, index);
        String filter = item.substring(index + 1);
        Requirement req = new CapReqBuilder(name).addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter).buildSyntheticRequirement();
        result.add(req);
        token = qt.nextToken();
    }
    return result;
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) QuotedTokenizer(aQute.libg.qtokens.QuotedTokenizer) ArrayList(java.util.ArrayList)

Example 45 with CapReqBuilder

use of aQute.bnd.osgi.resource.CapReqBuilder in project bnd by bndtools.

the class GenericResolveContextResolveTest method testResolveRequirementResolveDirective.

/**
	 * Check expressly set directive
	 */
public void testResolveRequirementResolveDirective() {
    Repository repository = createRepo(IO.getFile("testdata/repo6/index.xml"));
    GenericResolveContext grc = new GenericResolveContext(logger);
    grc.addRepository(repository);
    Requirement logservice = new CapReqBuilder("osgi.service").addDirective("filter", "(objectClass=org.osgi.service.log.LogService)").addDirective("effective", "resolve").buildSyntheticRequirement();
    List<Capability> providers = grc.findProviders(logservice);
    assertEquals(2, providers.size());
    assertNames(providers, "test.a", "test.b");
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) Repository(org.osgi.service.repository.Repository) Capability(org.osgi.resource.Capability)

Aggregations

CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)69 Requirement (org.osgi.resource.Requirement)53 Capability (org.osgi.resource.Capability)35 BndEditModel (aQute.bnd.build.model.BndEditModel)32 MockRegistry (test.lib.MockRegistry)28 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)23 Resource (org.osgi.resource.Resource)18 ArrayList (java.util.ArrayList)11 Collection (java.util.Collection)10 Repository (org.osgi.service.repository.Repository)9 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)8 HashMap (java.util.HashMap)8 File (java.io.File)7 List (java.util.List)7 AndFilter (aQute.libg.filters.AndFilter)6 LiteralFilter (aQute.libg.filters.LiteralFilter)6 SimpleFilter (aQute.libg.filters.SimpleFilter)6 Parameters (aQute.bnd.header.Parameters)5 InfoRepository (aQute.bnd.service.repository.InfoRepository)5 Version (aQute.bnd.version.Version)5