use of org.osgi.framework.hooks.bundle.FindHook in project aries by apache.
the class BlueprintContainerUseSystemContextTest method regiserHook.
@Before
public void regiserHook() {
final BundleContext systemContext = context().getBundle(Constants.SYSTEM_BUNDLE_LOCATION).getBundleContext();
eventHook = context().registerService(EventHook.class, new EventHook() {
@Override
public void event(BundleEvent event, Collection contexts) {
if ("org.apache.aries.blueprint.sample".equals(event.getBundle().getSymbolicName())) {
// hide sample from everything but the system bundle
// TODO on R6 we should be able to even try hiding from the system bundle
// R5 it was not clear if hooks could hide from the system bundle
// equinox R5 does allow hiding from system bundle
contexts.retainAll(Collections.singleton(systemContext));
}
}
}, null);
findHook = context().registerService(FindHook.class, new FindHook() {
@Override
public void find(BundleContext context, Collection bundles) {
if (context.equals(systemContext)) {
// equinox R5 does allow hiding from system bundle
return;
}
for (Iterator iBundles = bundles.iterator(); iBundles.hasNext(); ) {
if ("org.apache.aries.blueprint.sample".equals(((Bundle) iBundles.next()).getSymbolicName())) {
// hide sample from everything
iBundles.remove();
}
}
}
}, null);
}
Aggregations