Search in sources :

Example 1 with FindHook

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);
}
Also used : EventHook(org.osgi.framework.hooks.bundle.EventHook) FindHook(org.osgi.framework.hooks.bundle.FindHook) Iterator(java.util.Iterator) BundleEvent(org.osgi.framework.BundleEvent) Collection(java.util.Collection) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Aggregations

Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 Before (org.junit.Before)1 BundleContext (org.osgi.framework.BundleContext)1 BundleEvent (org.osgi.framework.BundleEvent)1 EventHook (org.osgi.framework.hooks.bundle.EventHook)1 FindHook (org.osgi.framework.hooks.bundle.FindHook)1