felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r898826 - /felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java
Date Wed, 13 Jan 2010 16:31:13 GMT
Author: rickhall
Date: Wed Jan 13 16:31:13 2010
New Revision: 898826

URL: http://svn.apache.org/viewvc?rev=898826&view=rev
Log:
Merged resolved package space calculation with unresolved package space calculation.

Modified:
    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/proto3/Proto3Resolver.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java?rev=898826&r1=898825&r2=898826&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
Wed Jan 13 16:31:13 2010
@@ -275,11 +275,12 @@
 
                 // If we are here, the candidate was consistent. Try to
                 // merge the candidate into the target module's packages.
-                mergeResolvedCandidatePackages(
+                mergeCandidatePackages(
                     module,
                     incomingReqs,
                     wire.getCapability(),
-                    modulePkgMap);
+                    modulePkgMap,
+                    candidateMap);
 
                 // If we are here, we merged the candidate successfully,
                 // so we can continue with the next requirement
@@ -426,7 +427,7 @@
             // will be visible to the current module.
             Packages candPkgs = modulePkgMap.get(candCap.getModule());
 
-// TODO: PROTO2 RESOLVER - For now assume only exports, but eventually we also
+// TODO: PROTO3 RESOLVER - For now assume only exports, but eventually we also
 //       have to support re-exported packages.
             for (Entry<String, Blame> entry : candPkgs.m_exportedPkgs.entrySet())
             {
@@ -491,18 +492,23 @@
             // any existing uses constraints
             //
 
-            List<Blame> currentUsedBlames = currentPkgs.m_usedPkgs.get(pkgName);
-            checkExistingUsesConstraints(
-                current, pkgName, currentUsedBlames, candBlame, modulePkgMap, candidateMap);
-
-            //
-            // Last, check to see if any uses constraints implied by the
-            // candidate conflict with any of the existing hard constraints.
-            //
+            Packages currentPkgsCopy = currentPkgs;
 
-            // For now, create a copy of the module's package space and
-            // add the current candidate to the imported packages.
-            Packages currentPkgsCopy = new Packages(currentPkgs);
+            if (!current.isResolved())
+            {
+                List<Blame> currentUsedBlames = currentPkgs.m_usedPkgs.get(pkgName);
+                checkExistingUsesConstraints(
+                    current, pkgName, currentUsedBlames, candBlame, modulePkgMap, candidateMap);
+
+                //
+                // Last, check to see if any uses constraints implied by the
+                // candidate conflict with any of the existing hard constraints.
+                //
+
+                // For now, create a copy of the module's package space and
+                // add the current candidate to the imported packages.
+                currentPkgsCopy = new Packages(currentPkgs);
+            }
 
             if (requires)
             {
@@ -518,7 +524,7 @@
             {
                 currentPkgsCopy.m_importedPkgs.put(pkgName, candBlame);
             }
-
+// if not resolved
             // Verify and merge the candidate's transitive uses constraints.
             verifyAndMergeUses(
                 current,
@@ -530,10 +536,13 @@
 
             // If we are here, then there were no conflict, so we should update
             // the module's package space.
-            currentPkgs.m_exportedPkgs.putAll(currentPkgsCopy.m_exportedPkgs);
-            currentPkgs.m_importedPkgs.putAll(currentPkgsCopy.m_importedPkgs);
-            currentPkgs.m_requiredPkgs.putAll(currentPkgsCopy.m_requiredPkgs);
-            currentPkgs.m_usedPkgs.putAll(currentPkgsCopy.m_usedPkgs);
+            if (!current.isResolved())
+            {
+                currentPkgs.m_exportedPkgs.putAll(currentPkgsCopy.m_exportedPkgs);
+                currentPkgs.m_importedPkgs.putAll(currentPkgsCopy.m_importedPkgs);
+                currentPkgs.m_requiredPkgs.putAll(currentPkgsCopy.m_requiredPkgs);
+                currentPkgs.m_usedPkgs.putAll(currentPkgsCopy.m_usedPkgs);
+            }
 dumpModulePkgs(current, currentPkgs);
         }
     }
@@ -658,244 +667,53 @@
                     usedCaps.add(candSourceBlame);
                     return;
                 }
-                else if ((currentExportedBlame != null)
-                    && !isCompatible(currentExportedBlame.m_cap, candSourceBlame.m_cap,
modulePkgMap))
+                else if (!current.isResolved())
                 {
-                    throw new ResolveException("Constraint violation for package '" + usedPkgName
-                        + "' when resolving module " + current
-                        + " between existing constraint "
-                        + currentExportedBlame
-                        + " and candidate constraint "
-                        + candSourceBlame);
-                }
-                else if ((currentImportedBlame != null)
-                    && !isCompatible(currentImportedBlame.m_cap, candSourceBlame.m_cap,
modulePkgMap))
-                {
-//System.out.println("+++ CIB " + currentImportedBlame + " SB " + sourceBlame);
-                    // Try to remove the previously selected candidate associated
-                    // with the requirement blamed for adding the constraint. This
-                    // Permutate the candidate map.
-                    if (currentImportedBlame.m_reqs.size() != 0)
+                    if ((currentExportedBlame != null)
+                        && !isCompatible(currentExportedBlame.m_cap, candSourceBlame.m_cap,
modulePkgMap))
                     {
+                        throw new ResolveException(
+                            "Constraint violation for package '" + usedPkgName
+                            + "' when resolving module " + current
+                            + " between existing constraint "
+                            + currentExportedBlame
+                            + " and candidate constraint "
+                            + candSourceBlame);
+                    }
+                    else if ((currentImportedBlame != null)
+                        && !isCompatible(currentImportedBlame.m_cap, candSourceBlame.m_cap,
modulePkgMap))
+                    {
+    //System.out.println("+++ CIB " + currentImportedBlame + " SB " + sourceBlame);
+                        // Try to remove the previously selected candidate associated
+                        // with the requirement blamed for adding the constraint. This
                         // Permutate the candidate map.
-                        for (int reqIdx = 0; reqIdx < currentImportedBlame.m_reqs.size();
reqIdx++)
+                        if (currentImportedBlame.m_reqs.size() != 0)
                         {
-                            Map<Requirement, Set<Capability>> copy = copyCandidateMap(candidateMap);
-                            Set<Capability> candidates =
-                                copy.get(currentImportedBlame.m_reqs.get(reqIdx));
-                            Iterator it = candidates.iterator();
-                            it.next();
-                            it.remove();
-// TODO: PROTO3 RESOLVER - We could check before doing the candidate map copy.
-                            if (candidates.size() > 0)
+                            // Permutate the candidate map.
+                            for (int reqIdx = 0; reqIdx < currentImportedBlame.m_reqs.size();
reqIdx++)
                             {
-                                m_candidatePermutations.add(copy);
+                                Map<Requirement, Set<Capability>> copy = copyCandidateMap(candidateMap);
+                                Set<Capability> candidates =
+                                    copy.get(currentImportedBlame.m_reqs.get(reqIdx));
+                                Iterator it = candidates.iterator();
+                                it.next();
+                                it.remove();
+    // TODO: PROTO3 RESOLVER - We could check before doing the candidate map copy.
+                                if (candidates.size() > 0)
+                                {
+                                    m_candidatePermutations.add(copy);
+                                }
                             }
                         }
-                    }
-
-                    throw new ResolveException("Constraint violation for package '" + usedPkgName
-                        + "' when resolving module " + current
-                        + " between existing constraint "
-                        + currentImportedBlame
-                        + " and candidate constraint "
-                        + candSourceBlame);
-                }
-
-                // This does not need to be recursive, even though "uses" constraints
-                // are transitive.
-//                verifyAndMergeUses(
-//                    current,
-//                    currentPkgs,
-//                    sourceBlame,
-//                    modulePkgMap,
-//                    candidateMap,
-//                    cycleMap);
-            }
-        }
-    }
-
-    private void mergeResolvedCandidatePackages(
-        Module current, List<Requirement> outgoingReqs,
-        Capability candCap, Map<Module, Packages> modulePkgMap)
-    {
-        if (m_isInvokeCount)
-        {
-            String methodName = new Exception().fillInStackTrace().getStackTrace()[0].getMethodName();
-            Long count = m_invokeCounts.get(methodName);
-            count = (count == null) ? new Long(1) : new Long(count.longValue() + 1);
-            m_invokeCounts.put(methodName, count);
-        }
-
-        if (candCap.getNamespace().equals(Capability.PACKAGE_NAMESPACE))
-        {
-            mergeResolvedCandidatePackage(
-                current, false, new Blame(outgoingReqs, candCap), modulePkgMap);
-        }
-        else if (candCap.getNamespace().equals(Capability.MODULE_NAMESPACE))
-        {
-            // Get the candidate's package space to determine which packages
-            // will be visible to the current module.
-            Packages candPkgs = modulePkgMap.get(candCap.getModule());
-
-// TODO: PROTO3 RESOLVER - For now assume only exports, but eventually we also
-//       have to support re-exported packages.
-            for (Entry<String, Blame> entry : candPkgs.m_exportedPkgs.entrySet())
-            {
-                mergeResolvedCandidatePackage(
-                    current,
-                    true,
-                    new Blame(outgoingReqs, entry.getValue().m_cap),
-                    modulePkgMap);
-            }
-        }
-    }
-
-    private void mergeResolvedCandidatePackage(
-        Module current, boolean requires,
-        Blame candBlame, Map<Module, Packages> modulePkgMap)
-    {
-        if (m_isInvokeCount)
-        {
-            String methodName = new Exception().fillInStackTrace().getStackTrace()[0].getMethodName();
-            Long count = m_invokeCounts.get(methodName);
-            count = (count == null) ? new Long(1) : new Long(count.longValue() + 1);
-            m_invokeCounts.put(methodName, count);
-        }
-
-// TODO: PROTO3 RESOLVER - Check for merging where module imports from itself,
-//       then it should be listed as an export.
-        if (candBlame.m_cap.getNamespace().equals(Capability.PACKAGE_NAMESPACE))
-        {
-System.out.println("+++ MERGING " + candBlame.m_cap + " INTO " + current);
-            String pkgName = (String)
-                candBlame.m_cap.getAttribute(Capability.PACKAGE_ATTR).getValue();
 
-            // Since this capability represents a package, it will become
-            // a hard constraint on the module's package space, so we need
-            // to make sure it doesn't conflict with any other hard constraints
-            // or any other uses constraints.
-
-            //
-            // First, check to see if the capability conflicts with
-            // any existing hard constraints.
-            //
-
-            Packages currentPkgs = modulePkgMap.get(current);
-            Blame currentExportedBlame = currentPkgs.m_exportedPkgs.get(pkgName);
-            Blame currentImportedBlame = currentPkgs.m_importedPkgs.get(pkgName);
-            List<Blame> currentRequiredBlames = currentPkgs.m_requiredPkgs.get(pkgName);
-
-            if (!requires &&
-                (((currentExportedBlame != null) && !currentExportedBlame.m_cap.equals(candBlame.m_cap))
-                || ((currentImportedBlame != null) && !currentImportedBlame.m_cap.equals(candBlame.m_cap))
-                || ((currentRequiredBlames != null) && !currentRequiredBlames.contains(candBlame))))
-            {
-                throw new ResolveException("Constraint violation between "
-                    + current + " and " + candBlame.m_cap.getModule()
-                    + " for " + pkgName);
-            }
-
-            if (requires)
-            {
-                if (currentRequiredBlames == null)
-                {
-                    currentRequiredBlames = new ArrayList<Blame>();
-                    currentPkgs.m_requiredPkgs.put(pkgName, currentRequiredBlames);
-                }
-// TODO: PROTO2 RESOLVER - This is potentially modifying the original, we need to modify
a copy.
-                currentRequiredBlames.add(candBlame);
-            }
-            else
-            {
-                currentPkgs.m_importedPkgs.put(pkgName, candBlame);
-            }
-
-            // Verify and merge the candidate's transitive uses constraints.
-            mergeResolvedUses(
-                current,
-                currentPkgs,
-                candBlame,
-                modulePkgMap,
-                new HashMap<String, List<Module>>());
-dumpModulePkgs(current, currentPkgs);
-        }
-    }
-
-// TODO: PROTO3 RESOLVER - We end up with duplicates in uses constraints,
-//       see scenario 2 for an example.
-    private void mergeResolvedUses(
-        Module current, Packages currentPkgs,
-        Blame candBlame, Map<Module, Packages> modulePkgMap,
-        Map<String, List<Module>> cycleMap)
-    {
-        if (m_isInvokeCount)
-        {
-            String methodName = new Exception().fillInStackTrace().getStackTrace()[0].getMethodName();
-            Long count = m_invokeCounts.get(methodName);
-            count = (count == null) ? new Long(1) : new Long(count.longValue() + 1);
-            m_invokeCounts.put(methodName, count);
-        }
-
-        // Check for cycles.
-        String pkgName = (String)
-            candBlame.m_cap.getAttribute(Capability.PACKAGE_ATTR).getValue();
-        List<Module> list = cycleMap.get(pkgName);
-        if ((list != null) && list.contains(current))
-        {
-            return;
-        }
-        list = (list == null) ? new ArrayList<Module>() : list;
-        list.add(current);
-        cycleMap.put(pkgName, list);
-
-//System.out.println("+++ VERIFYING USES " + current + " FOR " + candBlame);
-        for (Capability candSourceCap : getPackageSources(candBlame.m_cap, modulePkgMap,
new ArrayList<Capability>()))
-        {
-            for (String usedPkgName : candSourceCap.getUses())
-            {
-                Blame currentExportedBlame = currentPkgs.m_exportedPkgs.get(usedPkgName);
-                Blame currentImportedBlame = currentPkgs.m_importedPkgs.get(usedPkgName);
-// TODO: PROTO3 RESOLVER - What do we do with required packages?
-                List<Blame> currentRequiredBlames = currentPkgs.m_requiredPkgs.get(usedPkgName);
-
-                Packages candSourcePkgs = modulePkgMap.get(candSourceCap.getModule());
-System.out.println("+++ candSourceCap " + candSourceCap);
-System.out.println("+++ candSourceCap.getModule() " + candSourceCap.getModule() + " (" +
candSourceCap.getModule().isResolved() + ")");
-System.out.println("+++ candSourcePkgs " + candSourcePkgs);
-System.out.println("+++ candSourcePkgs.m_exportedPkgs " + candSourcePkgs.m_exportedPkgs);
-                Blame candSourceBlame = candSourcePkgs.m_exportedPkgs.get(usedPkgName);
-                candSourceBlame = (candSourceBlame != null)
-                    ? candSourceBlame
-                    : candSourcePkgs.m_importedPkgs.get(usedPkgName);
-//                sourceCap = (sourceCap != null)
-//                    ? sourceCap
-//                    : sourcePkgs.m_requiredPkgs.get(usedPkgName);
-
-                // If the candidate doesn't actually have a constraint for
-                // the used package, then just ignore it since this is likely
-                // an error in its metadata.
-                if (candSourceBlame == null)
-                {
-                    return;
-                }
-
-                // If there is no current mapping for this package, then
-                // we can just return.
-                if ((currentExportedBlame == null)
-                    && (currentImportedBlame == null)
-                    && (currentRequiredBlames == null))
-                {
-                    List<Blame> usedCaps = currentPkgs.m_usedPkgs.get(usedPkgName);
-                    if (usedCaps == null)
-                    {
-                        usedCaps = new ArrayList<Blame>();
-                        currentPkgs.m_usedPkgs.put(usedPkgName, usedCaps);
+                        throw new ResolveException(
+                            "Constraint violation for package '" + usedPkgName
+                            + "' when resolving module " + current
+                            + " between existing constraint "
+                            + currentImportedBlame
+                            + " and candidate constraint "
+                            + candSourceBlame);
                     }
-System.out.println("+++ MERGING CB " + candBlame + " SB " + candSourceBlame);
-//                    usedCaps.add(new Blame(candBlame.m_reqs, sourceBlame.m_cap));
-                    usedCaps.add(candSourceBlame);
-                    return;
                 }
             }
         }



Mime
View raw message