You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gg...@apache.org on 2017/04/11 10:10:50 UTC

karaf git commit: [KARAF-5089] Correctly filter out all bundle contexts when using GuardingEventHook

Repository: karaf
Updated Branches:
  refs/heads/master 8c8f50c84 -> b3572bff5


[KARAF-5089] Correctly filter out all bundle contexts when using GuardingEventHook


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/b3572bff
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/b3572bff
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/b3572bff

Branch: refs/heads/master
Commit: b3572bff5f4e1c52f909420a56eee814ce0978dd
Parents: 8c8f50c
Author: Grzegorz Grzybek <gr...@gmail.com>
Authored: Tue Apr 11 11:57:17 2017 +0200
Committer: Grzegorz Grzybek <gr...@gmail.com>
Committed: Tue Apr 11 12:10:24 2017 +0200

----------------------------------------------------------------------
 .../karaf/service/guard/impl/GuardingEventHook.java   |  7 ++++---
 .../service/guard/impl/GuardingEventHookTest.java     | 14 +++++++++++---
 2 files changed, 15 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/b3572bff/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardingEventHook.java
----------------------------------------------------------------------
diff --git a/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardingEventHook.java b/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardingEventHook.java
index a37e863..96b1a86 100644
--- a/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardingEventHook.java
+++ b/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardingEventHook.java
@@ -47,14 +47,15 @@ public class GuardingEventHook implements EventListenerHook {
             return;
         }
 
+        boolean proxificationDone = false;
+        BundleContext system = bundleContext.getBundle(0).getBundleContext();
         for (Iterator<BundleContext> i = listeners.keySet().iterator(); i.hasNext(); ) {
             BundleContext bc = i.next();
-            if (bundleContext.equals(bc) || bc.getBundle().getBundleId() == 0L) {
+            if (bc == bundleContext || bc == system) {
                 // don't hide anything from this bundle or the system bundle
                 continue;
             }
-
-            if (guardProxyCatalog.handleProxificationForHook(sr)) {
+            if (proxificationDone || (proxificationDone = guardProxyCatalog.handleProxificationForHook(sr))) {
                 i.remove();
             }
         }

http://git-wip-us.apache.org/repos/asf/karaf/blob/b3572bff/service/guard/src/test/java/org/apache/karaf/service/guard/impl/GuardingEventHookTest.java
----------------------------------------------------------------------
diff --git a/service/guard/src/test/java/org/apache/karaf/service/guard/impl/GuardingEventHookTest.java b/service/guard/src/test/java/org/apache/karaf/service/guard/impl/GuardingEventHookTest.java
index 31d683d..9b96cd0 100644
--- a/service/guard/src/test/java/org/apache/karaf/service/guard/impl/GuardingEventHookTest.java
+++ b/service/guard/src/test/java/org/apache/karaf/service/guard/impl/GuardingEventHookTest.java
@@ -51,7 +51,7 @@ public class GuardingEventHookTest {
 
         Dictionary<String, Object> config = new Hashtable<String, Object>();
         config.put("service.guard", "(service.id=*)");
-        BundleContext hookBC = mockConfigAdminBundleContext(config);
+        BundleContext hookBC = mockConfigAdminBundleContext(frameworkBC, config);
         GuardProxyCatalog gpc = new GuardProxyCatalog(hookBC);
 
         Filter serviceFilter = FrameworkUtil.createFilter("(foo=bar)");
@@ -127,9 +127,11 @@ public class GuardingEventHookTest {
     @SuppressWarnings("unchecked")
     @Test
     public void testEventHookProxyEvents() throws Exception {
+        BundleContext frameworkBC = mockBundleContext(0L);
+
         Dictionary<String, Object> config = new Hashtable<String, Object>();
         config.put("service.guard", "(service.id=*)");
-        BundleContext hookBC = mockConfigAdminBundleContext(config);
+        BundleContext hookBC = mockConfigAdminBundleContext(frameworkBC, config);
         GuardProxyCatalog gpc = new GuardProxyCatalog(hookBC);
 
         Filter serviceFilter = FrameworkUtil.createFilter("(service.id=*)"); // any service will match
@@ -189,7 +191,7 @@ public class GuardingEventHookTest {
     }
 
     @SuppressWarnings({ "rawtypes", "unchecked" })
-    private BundleContext mockConfigAdminBundleContext(Dictionary<String, Object> ... configs) throws IOException,
+    private BundleContext mockConfigAdminBundleContext(BundleContext frameworkContext, Dictionary<String, Object> ... configs) throws IOException,
             InvalidSyntaxException {
         Configuration [] configurations = new Configuration[configs.length];
 
@@ -208,12 +210,18 @@ public class GuardingEventHookTest {
         final ServiceReference caSR = EasyMock.createMock(ServiceReference.class);
         EasyMock.replay(caSR);
 
+        Bundle sb = EasyMock.createMock(Bundle.class);
+        EasyMock.expect(sb.getBundleId()).andReturn(0L).anyTimes();
+        EasyMock.expect(sb.getBundleContext()).andReturn(frameworkContext).anyTimes();
+        EasyMock.replay(sb);
+
         Bundle b = EasyMock.createMock(Bundle.class);
         EasyMock.expect(b.getBundleId()).andReturn(877342449L).anyTimes();
         EasyMock.replay(b);
 
         BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
         EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes();
+        EasyMock.expect(bc.getBundle(0L)).andReturn(sb).anyTimes();
         EasyMock.expect(bc.createFilter(EasyMock.isA(String.class))).andAnswer(new IAnswer<Filter>() {
             @Override
             public Filter answer() throws Throwable {