use of aQute.bnd.build.model.BndEditModel 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.build.model.BndEditModel 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.build.model.BndEditModel 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));
}
use of aQute.bnd.build.model.BndEditModel in project bnd by bndtools.
the class BndrunResolveContextTest method testResolveSystemPackagesExtra.
public static void testResolveSystemPackagesExtra() {
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.setSystemPackages(Collections.singletonList(new ExportedPackage("sun.reflect", new Attrs())));
BndrunResolveContext context = new BndrunResolveContext(runModel, registry, log);
Requirement req = new CapReqBuilder("osgi.wiring.package").addDirective("filter", "(osgi.wiring.package=sun.reflect)").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.build.model.BndEditModel in project bnd by bndtools.
the class BndrunResolveContextTest method testChooseHighestFrameworkVersion.
public static void testChooseHighestFrameworkVersion() {
MockRegistry registry;
BndEditModel runModel;
BndrunResolveContext context;
Collection<Resource> resources;
Resource fwkResource;
registry = new MockRegistry();
registry.addPlugin(createRepo(IO.getFile("testdata/org.apache.felix.framework-4.0.0.index.xml")));
registry.addPlugin(createRepo(IO.getFile("testdata/repo3.index.xml")));
runModel = new BndEditModel();
runModel.setRunFw("org.apache.felix.framework;version='[4,4.1)'");
context = new BndrunResolveContext(runModel, registry, log);
context.init();
assertEquals(IO.getFile("testdata/repo3/org.apache.felix.framework-4.0.2.jar").toURI(), findContentURI(context.getFramework()));
// Try it the other way round
registry = new MockRegistry();
registry.addPlugin(createRepo(IO.getFile("testdata/repo3.index.xml")));
registry.addPlugin(createRepo(IO.getFile("testdata/org.apache.felix.framework-4.0.0.index.xml")));
runModel = new BndEditModel();
runModel.setRunFw("org.apache.felix.framework;version='[4,4.1)'");
context = new BndrunResolveContext(runModel, registry, log);
context.init();
assertEquals(IO.getFile("testdata/repo3/org.apache.felix.framework-4.0.2.jar").toURI(), findContentURI(context.getFramework()));
}
Aggregations