Search in sources :

Example 36 with ResourceBuilder

use of aQute.bnd.osgi.resource.ResourceBuilder 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 37 with ResourceBuilder

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

the class ResourceTest method testOSGiWiringHostFragment.

public void testOSGiWiringHostFragment() throws Exception {
    ResourceBuilder rb = new ResourceBuilder();
    rb.addManifest(Domain.domain(IO.getFile("../demo-fragment/generated/demo-fragment.jar")));
    Resource resource = rb.build();
    assertEquals(0, resource.getCapabilities(BundleNamespace.BUNDLE_NAMESPACE).size());
    assertEquals(0, resource.getCapabilities(HostNamespace.HOST_NAMESPACE).size());
    List<Requirement> requirements = resource.getRequirements(HostNamespace.HOST_NAMESPACE);
    assertEquals(1, requirements.size());
    Map<String, String> directives = requirements.get(0).getDirectives();
    assertTrue(directives.containsKey(HostNamespace.REQUIREMENT_FILTER_DIRECTIVE));
    String filter = directives.get(HostNamespace.REQUIREMENT_FILTER_DIRECTIVE);
    assertEquals("(&(osgi.wiring.host=demo)(&(bundle-version>=1.0.0)(!(bundle-version>=1.0.1))))", filter);
}
Also used : Requirement(org.osgi.resource.Requirement) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Resource(org.osgi.resource.Resource)

Example 38 with ResourceBuilder

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

the class ResourceTest method testImportPackage.

public void testImportPackage() throws Exception {
    ResourceBuilder rb = new ResourceBuilder();
    Requirement importPackage = rb.addImportPackage("com.foo", Attrs.create("version", "1.2.3").with("mandatory:", "a,b").with("a", "1").with("b", "2"));
    String filter = importPackage.getDirectives().get("filter");
    assertEquals("(&(osgi.wiring.package=com.foo)(version>=1.2.3)(a=1)(b=2))", filter);
}
Also used : Requirement(org.osgi.resource.Requirement) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder)

Example 39 with ResourceBuilder

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

the class ResourceTest method testOSGiWiringHostBundle.

public void testOSGiWiringHostBundle() throws Exception {
    ResourceBuilder rb = new ResourceBuilder();
    rb.addManifest(Domain.domain(IO.getFile("../demo/generated/demo.jar")));
    Resource resource = rb.build();
    List<Capability> capabilities = resource.getCapabilities(HostNamespace.HOST_NAMESPACE);
    assertEquals(1, capabilities.size());
    Map<String, Object> attributes = capabilities.get(0).getAttributes();
    assertTrue(attributes.containsKey(HostNamespace.HOST_NAMESPACE));
    assertTrue(attributes.containsKey(HostNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE));
    assertEquals("demo", attributes.get(HostNamespace.HOST_NAMESPACE));
    assertNotNull(attributes.get(HostNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE));
    assertEquals(0, resource.getRequirements(HostNamespace.HOST_NAMESPACE).size());
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Capability(org.osgi.resource.Capability) Resource(org.osgi.resource.Resource)

Example 40 with ResourceBuilder

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

the class ResourceTest method testResourceToVersionedClause.

public void testResourceToVersionedClause() throws Exception {
    ResourceBuilder rb = new ResourceBuilder();
    rb.addManifest(Domain.domain(IO.getFile("../demo-fragment/generated/demo-fragment.jar")));
    Resource resource = rb.build();
    VersionedClause versionClause = ResourceUtils.toVersionClause(resource, "[===,==+)");
    StringBuilder sb = new StringBuilder();
    versionClause.formatTo(sb);
    assertEquals("demo-fragment;version='[1.0.0,1.0.1)'", sb.toString());
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) Resource(org.osgi.resource.Resource)

Aggregations

ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)41 Resource (org.osgi.resource.Resource)22 File (java.io.File)13 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)8 Capability (org.osgi.resource.Capability)8 Requirement (org.osgi.resource.Requirement)8 Parameters (aQute.bnd.header.Parameters)6 ResourcesRepository (aQute.bnd.osgi.repository.ResourcesRepository)6 Version (org.osgi.framework.Version)6 Domain (aQute.bnd.osgi.Domain)5 Resolution (biz.aQute.resolve.ResolverValidator.Resolution)5 HashSet (java.util.HashSet)5 IOException (java.io.IOException)4 URI (java.net.URI)4 ArrayList (java.util.ArrayList)4 Processor (aQute.bnd.osgi.Processor)3 HashMap (java.util.HashMap)3 List (java.util.List)3 VersionedClause (aQute.bnd.build.model.clauses.VersionedClause)2 Referral (aQute.bnd.deployer.repository.api.Referral)2