Framework should filter removal-pending revisions for fragments,
not the resolver. (FELIX-3141)


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1177749 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/StatefulResolver.java b/framework/src/main/java/org/apache/felix/framework/StatefulResolver.java
index cea167e..c099f15 100644
--- a/framework/src/main/java/org/apache/felix/framework/StatefulResolver.java
+++ b/framework/src/main/java/org/apache/felix/framework/StatefulResolver.java
@@ -1021,7 +1021,19 @@
 
         synchronized Set<BundleRevision> getFragments()
         {
-            return new HashSet(m_fragments);
+            Set<BundleRevision> fragments = new HashSet(m_fragments);
+            // Filter out any fragments that are not the current revision.
+            for (Iterator<BundleRevision> it = fragments.iterator(); it.hasNext(); )
+            {
+                BundleRevision fragment = it.next();
+                BundleRevision currentFragmentRevision =
+                    fragment.getBundle().adapt(BundleRevision.class);
+                if (fragment != currentFragmentRevision)
+                {
+                    it.remove();
+                }
+            }
+            return fragments;
         }
 
         synchronized boolean isSelectedSingleton(BundleRevision br)
@@ -1278,12 +1290,16 @@
 
                 // Find the matching candidates.
                 Set<BundleCapability> matches = capSet.match(sf, obeyMandatory);
+                // Filter matching candidates.
                 for (BundleCapability cap : matches)
                 {
+                    // Filter according to security.
                     if (filteredBySecurity(req, cap))
                     {
                         continue;
                     }
+                    // Filter already resolved hosts, since we don't support
+                    // dynamic attachment of fragments.
                     if (req.getNamespace().equals(BundleRevision.HOST_NAMESPACE)
                         && (cap.getRevision().getWiring() != null))
                     {
@@ -1331,7 +1347,8 @@
             return result;
         }
 
-        private boolean filteredBySecurity(BundleRequirement req, BundleCapability cap) {
+        private boolean filteredBySecurity(BundleRequirement req, BundleCapability cap)
+        {
             if (System.getSecurityManager() != null)
             {
                 BundleRevisionImpl reqRevision = (BundleRevisionImpl) req.getRevision();
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/Candidates.java b/framework/src/main/java/org/apache/felix/framework/resolver/Candidates.java
index 0d0b032..a411bcb 100644
--- a/framework/src/main/java/org/apache/felix/framework/resolver/Candidates.java
+++ b/framework/src/main/java/org/apache/felix/framework/resolver/Candidates.java
@@ -646,14 +646,10 @@
                 {
                     for (BundleRequirement hostReq : versionEntry.getValue())
                     {
-                        // Select the highest version of the fragment that
-                        // is not removal pending. If the fragment revision
-                        // is removal pending, then its current revision will
-                        // be null or won't match the existing revision.
-                        BundleRevision currentFragmentRevision =
-                            hostReq.getRevision().getBundle()
-                                .adapt(BundleRevision.class);
-                        if (isFirst && (currentFragmentRevision == hostReq.getRevision()))
+                        // Selecting the first fragment in each entry, which
+                        // is equivalent to selecting the highest version of
+                        // each fragment with a given symbolic name.
+                        if (isFirst)
                         {
                             selectedFragments.add(hostReq.getRevision());
                             isFirst = false;