You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2013/12/12 00:02:27 UTC

svn commit: r1550304 - in /felix/trunk/framework/src: main/java/org/apache/felix/framework/BundleImpl.java main/java/org/apache/felix/framework/Felix.java test/java/org/apache/felix/framework/CollisionHookTest.java

Author: cziegeler
Date: Wed Dec 11 23:02:27 2013
New Revision: 1550304

URL: http://svn.apache.org/r1550304
Log:
FELIX-4085 : [Core R5] Implement updates to the Bundle Hook Specification. Apply patch from David Bosschaert

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
    felix/trunk/framework/src/test/java/org/apache/felix/framework/CollisionHookTest.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleImpl.java?rev=1550304&r1=1550303&r2=1550304&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleImpl.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleImpl.java Wed Dec 11 23:02:27 2013
@@ -73,6 +73,7 @@ class BundleImpl implements Bundle, Bund
     private final Map m_cachedHeaders = new HashMap();
     private Map m_uninstalledHeaders = null;
     private long m_cachedHeadersTimestamp;
+    private final Bundle m_installingBundle;
 
     // Indicates whether the bundle is stale, meaning that it has
     // been refreshed and completely removed from the framework.
@@ -94,9 +95,10 @@ class BundleImpl implements Bundle, Bund
         m_stale = false;
         m_activator = null;
         m_context = null;
+        m_installingBundle = null;
     }
 
-    BundleImpl(Felix felix, BundleArchive archive) throws Exception
+    BundleImpl(Felix felix, Bundle installingBundle, BundleArchive archive) throws Exception
     {
         __m_felix = felix;
         m_archive = archive;
@@ -105,6 +107,7 @@ class BundleImpl implements Bundle, Bund
         m_stale = false;
         m_activator = null;
         m_context = null;
+        m_installingBundle = installingBundle;
 
         BundleRevision revision = createRevision(false);
         addRevision(revision);
@@ -1273,9 +1276,21 @@ class BundleImpl implements Bundle, Bund
                         CollisionHook ch = getFramework().getService(getFramework(), hook);
                         if (ch != null)
                         {
-                            Felix.m_secureAction.invokeBundleCollisionHook(ch,
-                                isUpdate ? CollisionHook.UPDATING : CollisionHook.INSTALLING,
-                                this, shrinkableCollisionCandidates);
+                            int operationType;
+                            Bundle target;
+                            if (isUpdate)
+                            {
+                                operationType = CollisionHook.UPDATING;
+                                target = this;
+                            }
+                            else
+                            {
+                                operationType = CollisionHook.INSTALLING;
+                                target = m_installingBundle == null ? this : m_installingBundle;
+                            }
+
+                            Felix.m_secureAction.invokeBundleCollisionHook(ch, operationType, target,
+                                    shrinkableCollisionCandidates);
                         }
                     }
                 }

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java?rev=1550304&r1=1550303&r2=1550304&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java Wed Dec 11 23:02:27 2013
@@ -2790,7 +2790,7 @@ public class Felix extends BundleImpl im
             }
             try
             {
-                bundle = new BundleImpl(this, ba);
+                bundle = new BundleImpl(this, null, ba);
 
                 // Extensions are handled as a special case.
                 if (bundle.isExtension())
@@ -2902,7 +2902,7 @@ public class Felix extends BundleImpl im
                     }
                     try
                     {
-                        bundle = new BundleImpl(this, ba);
+                        bundle = new BundleImpl(this, origin, ba);
                     }
                     finally
                     {

Modified: felix/trunk/framework/src/test/java/org/apache/felix/framework/CollisionHookTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/test/java/org/apache/felix/framework/CollisionHookTest.java?rev=1550304&r1=1550303&r2=1550304&view=diff
==============================================================================
--- felix/trunk/framework/src/test/java/org/apache/felix/framework/CollisionHookTest.java (original)
+++ felix/trunk/framework/src/test/java/org/apache/felix/framework/CollisionHookTest.java Wed Dec 11 23:02:27 2013
@@ -39,10 +39,11 @@ public class CollisionHookTest extends T
     public void testCollisionHookInstall() throws Exception {
         BundleImpl identicalBundle = mockBundleImpl(1L, "foo", "1.2.1.a");
         BundleImpl differentBundle = mockBundleImpl(2L, "bar", "1.2.1.a");
+        BundleImpl originatingBundle = mockBundleImpl(4L, "xyz", "1.0.0");
 
         CollisionHook testCollisionHook = new CollisionHook() {
             public void filterCollisions(int operationType, Bundle target, Collection<Bundle> collisionCandidates) {
-                if ((target.getBundleId() == 3L) && (operationType == CollisionHook.INSTALLING)) {
+                if ((target.getBundleId() == 4L) && (operationType == CollisionHook.INSTALLING)) {
                     collisionCandidates.clear();
                 }
             }
@@ -72,7 +73,7 @@ public class CollisionHookTest extends T
         Mockito.when(archive.getCurrentRevision()).thenReturn(archiveRevision);
         Mockito.when(archive.getId()).thenReturn(3L);
 
-        BundleImpl bi = new BundleImpl(felixMock, archive);
+        BundleImpl bi = new BundleImpl(felixMock, originatingBundle, archive);
         assertEquals(3L, bi.getBundleId());
 
         // Do the revise operation.
@@ -125,7 +126,7 @@ public class CollisionHookTest extends T
         Mockito.when(archive.getCurrentRevision()).thenReturn(archiveRevision);
         Mockito.when(archive.getId()).thenReturn(3L);
 
-        BundleImpl bi = new BundleImpl(felixMock, archive);
+        BundleImpl bi = new BundleImpl(felixMock, null, archive);
         assertEquals("zar", bi.getSymbolicName());
 
         // Do the revise operation, change the bsn to foo
@@ -175,7 +176,7 @@ public class CollisionHookTest extends T
         Mockito.when(archive.getId()).thenReturn(3L);
 
         try {
-            new BundleImpl(felixMock, archive);
+            new BundleImpl(felixMock, null, archive);
             fail("Should have thrown a BundleException because the collision hook is not enabled");
         } catch (BundleException be) {
             // good
@@ -210,7 +211,7 @@ public class CollisionHookTest extends T
         Mockito.when(archive.getCurrentRevision()).thenReturn(archiveRevision);
         Mockito.when(archive.getId()).thenReturn(3L);
 
-        BundleImpl bi = new BundleImpl(felixMock, archive);
+        BundleImpl bi = new BundleImpl(felixMock, null, archive);
         assertEquals(3L, bi.getBundleId());
     }
 
@@ -238,7 +239,7 @@ public class CollisionHookTest extends T
         Mockito.when(archive.getId()).thenReturn(3L);
 
         try {
-            new BundleImpl(felixMock, archive);
+            new BundleImpl(felixMock, null, archive);
             fail("Should have thrown a BundleException because the installed bundle is not unique");
         } catch (BundleException be) {
             // good