felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r944447 - in /felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver: Main.java proto3/Proto3Resolver.java
Date Fri, 14 May 2010 20:24:53 GMT
Author: rickhall
Date: Fri May 14 20:24:53 2010
New Revision: 944447

URL: http://svn.apache.org/viewvc?rev=944447&view=rev
Log:
Fix a bug in one scenario and align resolver with trunk.

Modified:
    felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/Main.java
    felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java

Modified: felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/Main.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/Main.java?rev=944447&r1=944446&r2=944447&view=diff
==============================================================================
--- felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/Main.java (original)
+++ felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/Main.java Fri
May 14 20:24:53 2010
@@ -2843,7 +2843,7 @@ public class Main
         // Bundle B
         moduleList.add(
             (m = new Module("B"))
-                .providing(new CapabilityImpl(m, Capability.PACKAGE_NAMESPACE).with("package=bar"))
+                .providing(new CapabilityImpl(m, Capability.PACKAGE_NAMESPACE).with("package=bar").using("foo"))
                 .requiring(new RequirementImpl(m, Capability.PACKAGE_NAMESPACE).with("package=foo")));
         // Bundle C
         moduleList.add(

Modified: felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java?rev=944447&r1=944446&r2=944447&view=diff
==============================================================================
--- felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java
(original)
+++ felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java
Fri May 14 20:24:53 2010
@@ -92,62 +92,68 @@ System.out.println("+++ PROTO3 RESOLVER"
 
         if (!module.isResolved())
         {
-// TODO: FELIX3 - Should we clear these in a finally block?
-            m_usesPermutations.clear();
-            m_importPermutations.clear();
-
-            Map<Requirement, Set<Capability>> candidateMap =
-                new HashMap<Requirement, Set<Capability>>();
+            try
+            {
+                Map<Requirement, Set<Capability>> candidateMap =
+                    new HashMap<Requirement, Set<Capability>>();
 
-            populateCandidates(state, module, candidateMap, new HashMap<Module, Object>());
-            m_usesPermutations.add(candidateMap);
+                populateCandidates(
+                    state, module, candidateMap, new HashMap<Module, Object>());
+                m_usesPermutations.add(candidateMap);
 
-            ResolveException rethrow = null;
+                ResolveException rethrow = null;
 
-            Map<Capability, Set<Requirement>> capDepSet = new HashMap();
+                Map<Capability, Set<Requirement>> capDepSet = new HashMap();
 
-            do
-            {
-                rethrow = null;
+                do
+                {
+                    rethrow = null;
 
-                modulePkgMap.clear();
-                capDepSet.clear();
-                m_packageSourcesCache.clear();
+                    modulePkgMap.clear();
+                    capDepSet.clear();
+                    m_packageSourcesCache.clear();
 
-                candidateMap = (m_usesPermutations.size() > 0)
-                    ? m_usesPermutations.remove(0)
-                    : m_importPermutations.remove(0);
+                    candidateMap = (m_usesPermutations.size() > 0)
+                        ? m_usesPermutations.remove(0)
+                        : m_importPermutations.remove(0);
 dumpCandidateMap(state, candidateMap);
 
-                calculatePackageSpaces(
-                    module, candidateMap, modulePkgMap,
-                    capDepSet, new HashMap(), new HashSet());
+                    calculatePackageSpaces(
+                        module, candidateMap, modulePkgMap,
+                        capDepSet, new HashMap(), new HashSet());
 System.out.println("+++ PACKAGE SPACES START +++");
 dumpModulePkgMap(modulePkgMap);
 System.out.println("+++ PACKAGE SPACES END +++");
 
-                try
-                {
-                    checkPackageSpaceConsistency(
-                        module, candidateMap, modulePkgMap, capDepSet, new HashMap());
+                    try
+                    {
+                        checkPackageSpaceConsistency(
+                            module, candidateMap, modulePkgMap, capDepSet, new HashMap());
+                    }
+                    catch (ResolveException ex)
+                    {
+                        rethrow = ex;
+                        System.out.println("RE: " + ex);
+                    }
                 }
-                catch (ResolveException ex)
+                while ((rethrow != null)
+                    && ((m_usesPermutations.size() > 0) || (m_importPermutations.size()
> 0)));
+
+                if (rethrow != null)
                 {
-                    rethrow = ex;
-                    System.out.println("RE: " + ex);
+                    throw rethrow;
                 }
-            }
-            while ((rethrow != null)
-                && ((m_usesPermutations.size() > 0) || (m_importPermutations.size()
> 0)));
 
-            if (rethrow != null)
-            {
-                throw rethrow;
+                wireMap =
+                    populateWireMap(module, modulePkgMap, wireMap,
+                    candidateMap);
+            }
+            finally
+            {
+                // Always clear the state.
+                m_usesPermutations.clear();
+                m_importPermutations.clear();
             }
-
-            wireMap =
-                populateWireMap(module, modulePkgMap, wireMap,
-                candidateMap);
         }
 
         if (m_isInvokeCount)
@@ -181,66 +187,72 @@ System.out.println("+++ PACKAGE SPACES E
             getDynamicImportCandidates(state, module, pkgName);
         if (candidateMap != null)
         {
-// TODO: FELIX3 - Should we clear these in a finally block?
-            m_usesPermutations.clear();
-            m_importPermutations.clear();
-
-            Map<Module, List<Wire>> wireMap = new HashMap();
-            Map<Module, Packages> modulePkgMap = new HashMap();
+            try
+            {
+                Map<Module, List<Wire>> wireMap = new HashMap();
+                Map<Module, Packages> modulePkgMap = new HashMap();
 
-            populateDynamicCandidates(state, module, candidateMap);
-            m_usesPermutations.add(candidateMap);
+                populateDynamicCandidates(state, module, candidateMap);
+                m_usesPermutations.add(candidateMap);
 
-            ResolveException rethrow = null;
+                ResolveException rethrow = null;
 
-            Map<Capability, Set<Requirement>> capDepSet = new HashMap();
+                Map<Capability, Set<Requirement>> capDepSet = new HashMap();
 
-            do
-            {
-                rethrow = null;
+                do
+                {
+                    rethrow = null;
 
-                modulePkgMap.clear();
-                capDepSet.clear();
+                    modulePkgMap.clear();
+                    capDepSet.clear();
 
-                candidateMap = (m_usesPermutations.size() > 0)
-                    ? m_usesPermutations.remove(0)
-                    : m_importPermutations.remove(0);
+                    candidateMap = (m_usesPermutations.size() > 0)
+                        ? m_usesPermutations.remove(0)
+                        : m_importPermutations.remove(0);
 
-                calculatePackageSpaces(
-                    module, candidateMap, modulePkgMap,
-                    capDepSet, new HashMap(), new HashSet());
+                    calculatePackageSpaces(
+                        module, candidateMap, modulePkgMap,
+                        capDepSet, new HashMap(), new HashSet());
 
-                try
-                {
-                    checkPackageSpaceConsistency(
-                        module, candidateMap, modulePkgMap, capDepSet, new HashMap());
+                    try
+                    {
+                        checkPackageSpaceConsistency(
+                            module, candidateMap, modulePkgMap,
+                            capDepSet, new HashMap());
+                    }
+                    catch (ResolveException ex)
+                    {
+                        rethrow = ex;
+                        System.out.println("RE: " + ex);
+                    }
                 }
-                catch (ResolveException ex)
+                while ((rethrow != null)
+                    && ((m_usesPermutations.size() > 0)
+                        || (m_importPermutations.size() > 0)));
+
+                if (rethrow != null)
                 {
-                    rethrow = ex;
-                    System.out.println("RE: " + ex);
+                    throw rethrow;
                 }
-            }
-            while ((rethrow != null)
-                && ((m_usesPermutations.size() > 0) || (m_importPermutations.size()
> 0)));
-
-            if (rethrow != null)
-            {
-                throw rethrow;
-            }
 
 //dumpModulePkgMap(modulePkgMap);
-            wireMap = populateDynamicWireMap(
-                module, pkgName, modulePkgMap, wireMap, candidateMap);
+                wireMap = populateDynamicWireMap(
+                    module, pkgName, modulePkgMap, wireMap, candidateMap);
 
-            return wireMap;
+                return wireMap;
+            }
+            finally
+            {
+                // Always clear the state.
+                m_usesPermutations.clear();
+                m_importPermutations.clear();
+            }
         }
 
         return null;
     }
 
-// TODO: FELIX3 - It would be nice to make this private.
-    public static Map<Requirement, Set<Capability>> getDynamicImportCandidates(
+    private static Map<Requirement, Set<Capability>> getDynamicImportCandidates(
         ResolverState state, Module module, String pkgName)
     {
         if (m_isInvokeCount)
@@ -472,7 +484,7 @@ System.out.println("+++ PACKAGE SPACES E
                     new ResolveException("Unable to resolve " + module
                         + ": missing requirement " + req, module, req);
                 resultCache.put(module, ex);
-                System.out.println(ex);
+                System.out.println("No viable candidates: " + ex);
                 throw ex;
             }
             // If we actually have candidates for the requirement, then
@@ -537,9 +549,6 @@ System.out.println("+++ PACKAGE SPACES E
             }
         }
 
-// TODO: FELIX3 - Since we reuse the same dynamic requirement, is it possible
-//       that some sort of cycle could cause us to try to match another set
-//       of candidates to the same requirement?
         if (candidates.size() == 0)
         {
             candidateMap.remove(dynReq);
@@ -713,6 +722,8 @@ System.out.println("+++ PACKAGE SPACES E
 
             // We have to merge all exported packages from the candidate,
             // since the current module requires it.
+// TODO: FELIX3 - If a module imports its exports, then imported exports should
+//       be reexported to requiring bundles.
             for (Entry<String, Blame> entry : candPkgs.m_exportedPkgs.entrySet())
             {
                 mergeCandidatePackage(
@@ -758,8 +769,6 @@ System.out.println("+++ PACKAGE SPACES E
             m_invokeCounts.put(methodName, count);
         }
 
-// TODO: FELIX3 - Check for merging where module imports from itself,
-//       then it should be listed as an export for requiring bundles.
         if (candCap.getNamespace().equals(Capability.PACKAGE_NAMESPACE))
         {
             String pkgName = (String)
@@ -825,8 +834,6 @@ System.out.println("+++ PACKAGE SPACES E
         reqs.add(req);
     }
 
-// TODO: FELIX3 - We end up with duplicates in uses constraints,
-//       see scenario 2 for an example.
     private void mergeUses(
         Module current, Packages currentPkgs,
         Capability mergeCap, List<Requirement> blameReqs, Map<Module, Packages>
modulePkgMap,
@@ -985,10 +992,11 @@ System.out.println("+++ PACKAGE SPACES E
                         ResolveException ex = new ResolveException(
                             "Constraint violation for package '"
                             + entry.getKey() + "' when resolving module "
-                            + module + " between an imported constraint "
-                            + sourceBlame + " and an additional imported constraint "
+                            + module + " between an import "
+                            + sourceBlame + " and a fragment import "
                             + blame, module, blame.m_reqs.get(0));
-                        System.out.println(ex);
+                        System.out.println("Conflicting fragment import:" + ex);
+                        throw ex;
                     }
                 }
             }
@@ -997,14 +1005,17 @@ System.out.println("+++ PACKAGE SPACES E
         for (Entry<String, Blame> entry : pkgs.m_exportedPkgs.entrySet())
         {
             String pkgName = entry.getKey();
+            Blame exportBlame = entry.getValue();
             if (!pkgs.m_usedPkgs.containsKey(pkgName))
             {
                 continue;
             }
-            for (Blame blame : pkgs.m_usedPkgs.get(pkgName))
+            for (Blame usedBlame : pkgs.m_usedPkgs.get(pkgName))
             {
-                if (!isCompatible(entry.getValue().m_cap, blame.m_cap, modulePkgMap))
+                if (!isCompatible(exportBlame.m_cap, usedBlame.m_cap, modulePkgMap))
                 {
+                    // Create a candidate permutation that eliminates any candidates
+                    // that conflict with existing selected candidates.
                     copyConflict = (copyConflict != null)
                         ? copyConflict
                         : copyCandidateMap(candidateMap);
@@ -1013,33 +1024,50 @@ System.out.println("+++ PACKAGE SPACES E
                         : new ResolveException(
                             "Constraint violation for package '"
                             + pkgName + "' when resolving module "
-                            + module + " between existing exported constraint "
-                            + entry.getValue() + " and uses constraint "
-                            + blame, null, null);
+                            + module + " between existing export "
+                            + exportBlame + " and uses constraint "
+                            + usedBlame, null, null);
+
                     mutated = (mutated != null)
                         ? mutated
                         : new HashSet();
-// TODO: FELIX3 - I think we need to walk up this chain too.
-// TODO: FELIX3 - What about uses and import permutations?
-                    Requirement req = blame.m_reqs.get(blame.m_reqs.size() - 1);
-                    if (!mutated.contains(req))
+
+                    for (int reqIdx = usedBlame.m_reqs.size() - 1; reqIdx >= 0; reqIdx--)
                     {
-                        mutated.add(req);
-                        Set<Capability> caps = copyConflict.get(req);
-                        Iterator it = caps.iterator();
-                        it.next();
-                        it.remove();
-                        if (caps.size() == 0)
+                        Requirement req = usedBlame.m_reqs.get(reqIdx);
+
+                        // If we've already permutated this requirement in another
+                        // uses constraint, don't permutate it again just continue
+                        // with the next uses constraint.
+                        if (mutated.contains(req))
+                        {
+                            break;
+                        }
+
+                        // See if we can permutate the candidates for blamed
+                        // requirement; there may be no candidates if the module
+                        // associated with the requirement is already resolved.
+                        Set<Capability> candidates = copyConflict.get(req);
+                        if ((candidates != null) && (candidates.size() > 1))
                         {
-                            removeInvalidateCandidate(req.getModule(), capDepSet, copyConflict);
+                            mutated.add(req);
+                            Iterator it = candidates.iterator();
+                            it.next();
+                            it.remove();
+                            // Continue with the next uses constraint.
+                            break;
                         }
                     }
                 }
             }
+
             if (rethrow != null)
             {
-                m_usesPermutations.add(copyConflict);
-                System.out.println(rethrow);
+                if (mutated.size() > 0)
+                {
+                    m_usesPermutations.add(copyConflict);
+                }
+                System.out.println("Conflict between an export and import: " + rethrow);
                 throw rethrow;
             }
         }
@@ -1073,7 +1101,7 @@ System.out.println("+++ PACKAGE SPACES E
                             : new ResolveException(
                                 "Constraint violation for package '"
                                 + pkgName + "' when resolving module "
-                                + module + " between existing imported constraint "
+                                + module + " between existing import "
                                 + importBlame + " and uses constraint "
                                 + usedBlame, null, null);
 
@@ -1137,7 +1165,7 @@ System.out.println("+++ PACKAGE SPACES E
                         m_usesPermutations.add(copyConflict);
                     }
 
-                    System.out.println(rethrow);
+                    System.out.println("Conflict between imports: " + rethrow);
                     throw rethrow;
                 }
             }



Mime
View raw message