Search in sources :

Example 6 with CapReqBuilder

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

the class BndrunResolveContextTest method testResolveSystemCapabilitiesExtra.

public static void testResolveSystemCapabilitiesExtra() {
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/repo3.index.xml")));
    BndEditModel runModel = new BndEditModel();
    runModel.setRunFw("org.apache.felix.framework");
    runModel.setEE(EE.JavaSE_1_6);
    runModel.genericSet("-runsystemcapabilities", "osgi.extender;osgi.extender=foobar;version:Version=1.0");
    BndrunResolveContext context = new BndrunResolveContext(runModel, registry, log);
    Requirement req = new CapReqBuilder("osgi.extender").addDirective("filter", "(&(osgi.extender=foobar)(version>=1.0))").buildSyntheticRequirement();
    List<Capability> providers = context.findProviders(req);
    assertEquals(1, providers.size());
    assertEquals(IO.getFile("testdata/repo3/org.apache.felix.framework-4.0.2.jar").toURI(), findContentURI(providers.get(0).getResource()));
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) MockRegistry(test.lib.MockRegistry) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 7 with CapReqBuilder

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

the class BndrunResolveContextTest method testResolveSystemBundleAlias.

public static void testResolveSystemBundleAlias() {
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/repo3.index.xml")));
    BndEditModel runModel = new BndEditModel();
    runModel.setRunFw("org.apache.felix.framework");
    runModel.setEE(EE.JavaSE_1_6);
    BndrunResolveContext context = new BndrunResolveContext(runModel, registry, log);
    Requirement req = new CapReqBuilder("osgi.wiring.host").addDirective("filter", "(osgi.wiring.host=system.bundle)").buildSyntheticRequirement();
    List<Capability> providers = context.findProviders(req);
    assertEquals(1, providers.size());
    assertEquals(IO.getFile("testdata/repo3/org.apache.felix.framework-4.0.2.jar").toURI(), findContentURI(providers.get(0).getResource()));
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) MockRegistry(test.lib.MockRegistry) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 8 with CapReqBuilder

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

the class BndrunResolveContextTest method testFrameworkCapabilitiesPreferredOverRepository.

public static void testFrameworkCapabilitiesPreferredOverRepository() {
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/osgi.cmpn-4.3.0.index.xml")));
    registry.addPlugin(createRepo(IO.getFile("testdata/org.apache.felix.framework-4.0.2.index.xml")));
    BndEditModel runModel = new BndEditModel();
    runModel.setRunFw("org.apache.felix.framework");
    Requirement requirement = new CapReqBuilder("osgi.wiring.package").addDirective("filter", "(&(osgi.wiring.package=org.osgi.util.tracker)(version>=1.5)(!(version>=1.6)))").buildSyntheticRequirement();
    BndrunResolveContext context = new BndrunResolveContext(runModel, registry, log);
    List<Capability> providers = context.findProviders(requirement);
    assertEquals(2, providers.size());
    assertEquals(IO.getFile("testdata/org.apache.felix.framework-4.0.2.jar").toURI(), findContentURI(providers.get(0).getResource()));
    assertEquals(IO.getFile("testdata/osgi.cmpn-4.3.0.jar").toURI(), findContentURI(providers.get(1).getResource()));
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) MockRegistry(test.lib.MockRegistry) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 9 with CapReqBuilder

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

the class BndrunResolveContextTest method testResolverHookCannotFilterFrameworkCapabilities.

public static void testResolverHookCannotFilterFrameworkCapabilities() {
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/osgi.cmpn-4.3.0.index.xml")));
    registry.addPlugin(createRepo(IO.getFile("testdata/org.apache.felix.framework-4.0.2.index.xml")));
    // Add a hook that tries to remove all capabilities from resource with
    // id "org.apache.felix.framework"
    registry.addPlugin(new ResolverHook() {

        public void filterMatches(Requirement requirement, List<Capability> candidates) {
            for (Iterator<Capability> iter = candidates.iterator(); iter.hasNext(); ) {
                Object id = iter.next().getResource().getCapabilities("osgi.identity").get(0).getAttributes().get("osgi.identity");
                if ("org.apache.felix.framework".equals(id)) {
                    fail("this line should not be reached");
                }
            }
        }
    });
    BndEditModel runModel = new BndEditModel();
    runModel.setRunFw("org.apache.felix.framework");
    Requirement requirement = new CapReqBuilder("osgi.wiring.package").addDirective("filter", "(&(osgi.wiring.package=org.osgi.util.tracker)(version>=1.5)(!(version>=1.6)))").buildSyntheticRequirement();
    BndrunResolveContext context = new BndrunResolveContext(runModel, registry, log);
    List<Capability> providers = context.findProviders(requirement);
    // The filter was ineffective
    assertEquals(2, providers.size());
    assertEquals(IO.getFile("testdata/org.apache.felix.framework-4.0.2.jar").toURI(), findContentURI(providers.get(0).getResource()));
    assertEquals(IO.getFile("testdata/osgi.cmpn-4.3.0.jar").toURI(), findContentURI(providers.get(1).getResource()));
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) ResolverHook(aQute.bnd.service.resolve.hook.ResolverHook) MockRegistry(test.lib.MockRegistry) Iterator(java.util.Iterator) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 10 with CapReqBuilder

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

the class BndrunResolveContextTest method testEffective3.

public static void testEffective3() {
    BndEditModel model = new BndEditModel();
    model.genericSet(BndrunResolveContext.RUN_EFFECTIVE_INSTRUCTION, "active;skip:=\"filtered.ns,another.filtered.ns\", arbitrary");
    BndrunResolveContext context = new BndrunResolveContext(model, new MockRegistry(), log);
    Requirement resolveReq = new CapReqBuilder("dummy.ns").addDirective(Namespace.REQUIREMENT_EFFECTIVE_DIRECTIVE, Namespace.EFFECTIVE_RESOLVE).buildSyntheticRequirement();
    Requirement activeReq = new CapReqBuilder("dummy.ns").addDirective(Namespace.REQUIREMENT_EFFECTIVE_DIRECTIVE, Namespace.EFFECTIVE_ACTIVE).buildSyntheticRequirement();
    Requirement filteredActiveReq = new CapReqBuilder("filtered.ns").addDirective(Namespace.REQUIREMENT_EFFECTIVE_DIRECTIVE, Namespace.EFFECTIVE_ACTIVE).buildSyntheticRequirement();
    Requirement anotherFilteredActiveReq = new CapReqBuilder("another.filtered.ns").addDirective(Namespace.REQUIREMENT_EFFECTIVE_DIRECTIVE, Namespace.EFFECTIVE_ACTIVE).buildSyntheticRequirement();
    Requirement arbitrary1Req = new CapReqBuilder("dummy.ns").addDirective(Namespace.REQUIREMENT_EFFECTIVE_DIRECTIVE, "arbitrary").buildSyntheticRequirement();
    Requirement noEffectiveDirectiveReq = new CapReqBuilder("dummy.ns").buildSyntheticRequirement();
    assertTrue(context.isEffective(resolveReq));
    assertTrue(context.isEffective(activeReq));
    assertTrue(context.isEffective(arbitrary1Req));
    assertFalse(context.isEffective(filteredActiveReq));
    assertFalse(context.isEffective(anotherFilteredActiveReq));
    assertTrue(context.isEffective(noEffectiveDirectiveReq));
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) MockRegistry(test.lib.MockRegistry) BndEditModel(aQute.bnd.build.model.BndEditModel)

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