Search in sources :

Example 31 with CapReqBuilder

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

the class AbstractResolveContext method createIdentityRequirement.

public static Requirement createIdentityRequirement(String identity, String versionRange) {
    // Construct a filter & requirement to find matches
    Filter filter = new SimpleFilter(IdentityNamespace.IDENTITY_NAMESPACE, identity);
    if (versionRange != null)
        filter = new AndFilter().addChild(filter).addChild(new LiteralFilter(Filters.fromVersionRange(versionRange)));
    Requirement frameworkReq = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE).addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter.toString()).buildSyntheticRequirement();
    return frameworkReq;
}
Also used : LiteralFilter(aQute.libg.filters.LiteralFilter) CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) AndFilter(aQute.libg.filters.AndFilter) Requirement(org.osgi.resource.Requirement) SimpleFilter(aQute.libg.filters.SimpleFilter) AndFilter(aQute.libg.filters.AndFilter) Filter(aQute.libg.filters.Filter) LiteralFilter(aQute.libg.filters.LiteralFilter) SimpleFilter(aQute.libg.filters.SimpleFilter)

Example 32 with CapReqBuilder

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

the class AbstractResolveContext method createPackageCapability.

public static Capability createPackageCapability(String packageName, String versionString) throws Exception {
    CapReqBuilder builder = new CapReqBuilder(PackageNamespace.PACKAGE_NAMESPACE);
    builder.addAttribute(PackageNamespace.PACKAGE_NAMESPACE, packageName);
    Version version = versionString != null ? new Version(versionString) : Version.emptyVersion;
    builder.addAttribute(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE, version);
    return builder.buildSyntheticCapability();
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Version(org.osgi.framework.Version)

Example 33 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 34 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 35 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)

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