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()));
}
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()));
}
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()));
}
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()));
}
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));
}
Aggregations