Need to alias system bundle name for bundle/host capabilities. (FELIX-3205)


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1199155 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java b/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
index 1b3e2e6..5981be4 100644
--- a/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
+++ b/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
@@ -241,10 +241,34 @@
 
         List<BundleCapability> aliasCaps = new ArrayList<BundleCapability>(caps);
 
+        String[] aliases = {
+            FelixConstants.SYSTEM_BUNDLE_SYMBOLICNAME,
+            Constants.SYSTEM_BUNDLE_SYMBOLICNAME };
+
         for (int capIdx = 0; capIdx < aliasCaps.size(); capIdx++)
         {
-            // Get the attributes and search for bundle symbolic name.
-            for (Entry<String, Object> entry : aliasCaps.get(capIdx).getAttributes().entrySet())
+            BundleCapability cap = aliasCaps.get(capIdx);
+
+            // Need to alias bundle and host capabilities.
+            if (cap.getNamespace().equals(BundleRevision.BUNDLE_NAMESPACE)
+                || cap.getNamespace().equals(BundleRevision.HOST_NAMESPACE))
+            {
+                // Make a copy of the attribute array.
+                Map<String, Object> aliasAttrs =
+                    new HashMap<String, Object>(cap.getAttributes());
+                // Add the aliased value.
+                aliasAttrs.put(cap.getNamespace(), aliases);
+                // Create the aliased capability to replace the old capability.
+                cap = new BundleCapabilityImpl(
+                    cap.getRevision(),
+                    cap.getNamespace(),
+                    cap.getDirectives(),
+                    aliasAttrs);
+                aliasCaps.set(capIdx, cap);
+            }
+
+            // Further, search attributes for bundle symbolic name and alias it too.
+            for (Entry<String, Object> entry : cap.getAttributes().entrySet())
             {
                 // If there is a bundle symbolic name attribute, add the
                 // standard alias as a value.
@@ -252,18 +276,14 @@
                 {
                     // Make a copy of the attribute array.
                     Map<String, Object> aliasAttrs =
-                        new HashMap<String, Object>(aliasCaps.get(capIdx).getAttributes());
+                        new HashMap<String, Object>(cap.getAttributes());
                     // Add the aliased value.
-                    aliasAttrs.put(
-                        Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE,
-                        new String[] {
-                            (String) entry.getValue(),
-                            Constants.SYSTEM_BUNDLE_SYMBOLICNAME});
+                    aliasAttrs.put(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE, aliases);
                     // Create the aliased capability to replace the old capability.
                     aliasCaps.set(capIdx, new BundleCapabilityImpl(
-                        caps.get(capIdx).getRevision(),
-                        caps.get(capIdx).getNamespace(),
-                        caps.get(capIdx).getDirectives(),
+                        cap.getRevision(),
+                        cap.getNamespace(),
+                        cap.getDirectives(),
                         aliasAttrs));
                     // Continue with the next capability.
                     break;