Required bundles that imported their own exports were not correctly exposing
their exported packages to requiring bundles. (FELIX-2479)


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@966242 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java b/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
index 0ef75f2..f3cf45f 100644
--- a/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
@@ -599,7 +599,7 @@
         }
 
         // First, add all exported packages to our package space.
-        calculateExportedPackages(module, modulePkgMap);
+        calculateExportedPackages(module, modulePkgMap, candidateMap);
         Packages modulePkgs = modulePkgMap.get(module);
 
         // Second, add all imported packages to our candidate space.
@@ -607,7 +607,7 @@
         {
             Requirement req = reqs.get(i);
             Capability cap = caps.get(i);
-            calculateExportedPackages(cap.getModule(), modulePkgMap);
+            calculateExportedPackages(cap.getModule(), modulePkgMap, candidateMap);
             mergeCandidatePackages(module, req, cap, modulePkgMap, candidateMap);
             addCapabilityDependency(cap, req, capDepSet);
         }
@@ -674,7 +674,7 @@
         else if (candCap.getNamespace().equals(Capability.MODULE_NAMESPACE))
         {
 // TODO: FELIX3 - THIS NEXT LINE IS A HACK. IMPROVE HOW/WHEN WE CALCULATE EXPORTS.
-            calculateExportedPackages(candCap.getModule(), modulePkgMap);
+            calculateExportedPackages(candCap.getModule(), modulePkgMap, candidateMap);
 
             // Get the candidate's package space to determine which packages
             // will be visible to the current module.
@@ -1110,7 +1110,8 @@
     }
 
     private static void calculateExportedPackages(
-        Module module, Map<Module, Packages> modulePkgMap)
+        Module module, Map<Module, Packages> modulePkgMap,
+        Map<Requirement, Set<Capability>> candidateMap)
     {
         Packages packages = modulePkgMap.get(module);
         if (packages != null)
@@ -1123,6 +1124,7 @@
 
         if (caps.size() > 0)
         {
+            // Grab all exported packages that are not also imported.
             for (int i = 0; i < caps.size(); i++)
             {
 // TODO: FELIX3 - Assume if a module imports the same package it
@@ -1135,6 +1137,24 @@
                         new Blame(caps.get(i), null));
                 }
             }
+            // Grab all imported packages for which the module imports from itself.
+            for (Requirement req : module.getRequirements())
+            {
+                if (req.getNamespace().equals(Capability.PACKAGE_NAMESPACE))
+                {
+                    Set<Capability> cands = candidateMap.get(req);
+                    if ((cands != null) && (cands.size() > 0))
+                    {
+                        Capability cand = cands.iterator().next();
+                        if (cand.getModule().equals(module))
+                        {
+                            packages.m_exportedPkgs.put(
+                                (String) cand.getAttribute(Capability.PACKAGE_ATTR).getValue(),
+                                new Blame(cand, null));
+                        }
+                    }
+                }
+            }
         }
 
         modulePkgMap.put(module, packages);
@@ -1434,22 +1454,16 @@
         {
         }
 
-        public Packages(Packages packages)
-        {
-            m_exportedPkgs.putAll(packages.m_exportedPkgs);
-            m_importedPkgs.putAll(packages.m_importedPkgs);
-            m_requiredPkgs.putAll(packages.m_requiredPkgs);
-            m_usedPkgs.putAll(packages.m_usedPkgs);
-        }
-
         public List<String> getExportedAndReexportedPackages()
         {
             List<String> pkgs = new ArrayList();
+            // Grab all exported packages.
             for (Entry<String, Blame> entry : m_exportedPkgs.entrySet())
             {
                 pkgs.add((String)
                     entry.getValue().m_cap.getAttribute(Capability.PACKAGE_ATTR).getValue());
             }
+            // Grab all required and reexported required packages.
             for (Entry<String, List<Blame>> entry : m_requiredPkgs.entrySet())
             {
                 for (Blame blame : entry.getValue())