use of aQute.bnd.service.resolve.hook.ResolverHook 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.service.resolve.hook.ResolverHook in project bnd by bndtools.
the class BndrunResolveContext method postProcessProviders.
protected void postProcessProviders(Requirement requirement, Set<Capability> wired, List<Capability> candidates) {
if (candidates.size() == 0)
return;
// Call resolver hooks
for (ResolverHook resolverHook : registry.getPlugins(ResolverHook.class)) {
resolverHook.filterMatches(requirement, candidates);
}
// Process the resolve preferences
boolean prefsUsed = false;
if (resolvePrefs != null && !resolvePrefs.isEmpty()) {
List<Capability> insertions = new LinkedList<Capability>();
for (Iterator<Capability> iterator = candidates.iterator(); iterator.hasNext(); ) {
Capability cap = iterator.next();
if (resolvePrefs.containsKey(getResourceIdentity(cap.getResource()))) {
iterator.remove();
insertions.add(cap);
}
}
if (!insertions.isEmpty()) {
candidates.addAll(0, insertions);
prefsUsed = true;
}
}
if (!prefsUsed) {
for (ResolutionCallback callback : getCallbacks()) {
callback.processCandidates(requirement, wired, candidates);
}
}
}
use of aQute.bnd.service.resolve.hook.ResolverHook in project bnd by bndtools.
the class BndrunResolveContextTest method testResolverHookFiltersResult.
public static void testResolverHookFiltersResult() {
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 removes all capabilities from resource with id
// "osgi.cmpn"
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 ("osgi.cmpn".equals(id))
iter.remove();
}
}
});
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(1, providers.size());
assertEquals(IO.getFile("testdata/org.apache.felix.framework-4.0.2.jar").toURI(), findContentURI(providers.get(0).getResource()));
// The capability from osgi.cmpn is NOT here
}
Aggregations