felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r1305485 - in /felix/trunk/framework/src/main/java/org/apache/felix/framework: resolver/ResolverImpl.java util/Util.java
Date Mon, 26 Mar 2012 18:34:46 GMT
Author: rickhall
Date: Mon Mar 26 18:34:46 2012
New Revision: 1305485

URL: http://svn.apache.org/viewvc?rev=1305485&view=rev
Log:
Modify resolver implementation to not use BundleRequirement.matches()
since this is not present in the OBR resolver API. (FELIX-3394)

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/util/Util.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java?rev=1305485&r1=1305484&r2=1305485&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
(original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
Mon Mar 26 18:34:46 2012
@@ -190,7 +190,7 @@ public class ResolverImpl implements Res
                         try
                         {
                             checkPackageSpaceConsistency(
-                                false, allCandidates.getWrappedHost(target),
+                                rc, false, allCandidates.getWrappedHost(target),
                                 allCandidates, revisionPkgMap, new HashMap());
                         }
                         catch (ResolveException ex)
@@ -343,7 +343,7 @@ public class ResolverImpl implements Res
                         try
                         {
                             checkPackageSpaceConsistency(
-                                false, allCandidates.getWrappedHost(revision),
+                                rc, false, allCandidates.getWrappedHost(revision),
                                 allCandidates, revisionPkgMap, new HashMap());
                         }
                         catch (ResolveException ex)
@@ -911,6 +911,7 @@ public class ResolverImpl implements Res
     }
 
     private void checkPackageSpaceConsistency(
+        ResolveContext rc,
         boolean isDynamicImporting,
         BundleRevision revision,
         Candidates allCandidates,
@@ -964,9 +965,9 @@ public class ResolverImpl implements Res
                             + blame.m_cap.getRevision().getSymbolicName()
                             + " [" + blame.m_cap.getRevision()
                             + "] via two dependency chains.\n\nChain 1:\n"
-                            + toStringBlame(sourceBlame)
+                            + toStringBlame(rc, allCandidates, sourceBlame)
                             + "\n\nChain 2:\n"
-                            + toStringBlame(blame),
+                            + toStringBlame(rc, allCandidates, blame),
                             revision,
                             blame.m_reqs.get(0));
                         m_logger.log(
@@ -1010,7 +1011,7 @@ public class ResolverImpl implements Res
                             + usedBlame.m_cap.getRevision().getSymbolicName()
                             + " [" + usedBlame.m_cap.getRevision()
                             + "] via the following dependency chain:\n\n"
-                            + toStringBlame(usedBlame),
+                            + toStringBlame(rc, allCandidates, usedBlame),
                             null,
                             null);
 
@@ -1095,9 +1096,9 @@ public class ResolverImpl implements Res
                                 + usedBlame.m_cap.getRevision().getSymbolicName()
                                 + " [" + usedBlame.m_cap.getRevision()
                                 + "] via two dependency chains.\n\nChain 1:\n"
-                                + toStringBlame(importBlame)
+                                + toStringBlame(rc, allCandidates, importBlame)
                                 + "\n\nChain 2:\n"
-                                + toStringBlame(usedBlame),
+                                + toStringBlame(rc, allCandidates, usedBlame),
                                 null,
                                 null);
 
@@ -1186,7 +1187,7 @@ public class ResolverImpl implements Res
                     try
                     {
                         checkPackageSpaceConsistency(
-                            false, importBlame.m_cap.getRevision(),
+                            rc, false, importBlame.m_cap.getRevision(),
                             allCandidates, revisionPkgMap, resultCache);
                     }
                     catch (ResolveException ex)
@@ -1623,7 +1624,8 @@ public class ResolverImpl implements Res
         }
     }
 
-    private static String toStringBlame(Blame blame)
+    private static String toStringBlame(
+        ResolveContext rc, Candidates allCandidates, Blame blame)
     {
         StringBuffer sb = new StringBuffer();
         if ((blame.m_reqs != null) && !blame.m_reqs.isEmpty())
@@ -1656,27 +1658,20 @@ public class ResolverImpl implements Res
                 }
                 if ((i + 1) < blame.m_reqs.size())
                 {
-                    BundleCapability cap = Util.getSatisfyingCapability(
-                        blame.m_reqs.get(i + 1).getRevision(),
-                        (BundleRequirementImpl) blame.m_reqs.get(i));
+                    BundleCapability cap = getSatisfyingCapability(
+                        rc,
+                        allCandidates,
+                        blame.m_reqs.get(i));
                     if (cap.getNamespace().equals(BundleRevision.PACKAGE_NAMESPACE))
                     {
                         sb.append(BundleRevision.PACKAGE_NAMESPACE);
                         sb.append("=");
                         sb.append(cap.getAttributes().get(BundleRevision.PACKAGE_NAMESPACE).toString());
-                        BundleCapability usedCap;
-                        if ((i + 2) < blame.m_reqs.size())
-                        {
-                            usedCap = Util.getSatisfyingCapability(
-                                blame.m_reqs.get(i + 2).getRevision(),
-                                (BundleRequirementImpl) blame.m_reqs.get(i + 1));
-                        }
-                        else
-                        {
-                            usedCap = Util.getSatisfyingCapability(
-                                blame.m_cap.getRevision(),
-                                (BundleRequirementImpl) blame.m_reqs.get(i + 1));
-                        }
+                        BundleCapability usedCap =
+                            getSatisfyingCapability(
+                                rc,
+                                allCandidates,
+                                blame.m_reqs.get(i + 1));
                         sb.append("; uses:=");
                         sb.append(usedCap.getAttributes().get(BundleRevision.PACKAGE_NAMESPACE));
                     }
@@ -1688,9 +1683,10 @@ public class ResolverImpl implements Res
                 }
                 else
                 {
-                    BundleCapability export = Util.getSatisfyingCapability(
-                        blame.m_cap.getRevision(),
-                        (BundleRequirementImpl) blame.m_reqs.get(i));
+                    BundleCapability export = getSatisfyingCapability(
+                        rc,
+                        allCandidates,
+                        blame.m_reqs.get(i));
                     sb.append(export.getNamespace());
                     sb.append("=");
                     sb.append(export.getAttributes().get(export.getNamespace()).toString());
@@ -1721,6 +1717,42 @@ public class ResolverImpl implements Res
         return sb.toString();
     }
 
+    private static BundleCapability getSatisfyingCapability(
+        ResolveContext rc, Candidates allCandidates, BundleRequirement req)
+    {
+        BundleCapability cap = null;
+
+        // If the requiring revision is not resolved, then check in the
+        // candidate map for its matching candidate.
+        List<BundleCapability> cands = allCandidates.getCandidates(req);
+        if (cands != null)
+        {
+            cap = cands.get(0);
+        }
+        // Otherwise, if the requiring revision is resolved then check
+        // in its wires for the capability satisfying the requirement.
+        else if (rc.getWirings().containsKey(req.getRevision()))
+        {
+            List<BundleWire> wires = rc.getWirings().get(req.getRevision()).getRequiredWires(null);
+            req = getDeclaredRequirement(req);
+            for (BundleWire w : wires)
+            {
+                if (w.getRequirement().equals(req))
+                {
+// TODO: RESOLVER - This is not 100% correct, since requirements for
+//       dynamic imports with wildcards will reside on many wires and
+//       this code only finds the first one, not necessarily the correct
+//       one. This is only used for the diagnostic message, but it still
+//       could confuse the user.
+                    cap = w.getCapability();
+                    break;
+                }
+            }
+        }
+
+        return cap;
+    }
+
     private static class Packages
     {
         private final BundleRevision m_revision;

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/util/Util.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/util/Util.java?rev=1305485&r1=1305484&r2=1305485&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/util/Util.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/util/Util.java Mon Mar
26 18:34:46 2012
@@ -285,26 +285,6 @@ public class Util
         return allow;
     }
 
-    public static BundleCapability getSatisfyingCapability(
-        BundleRevision br, BundleRequirementImpl req)
-    {
-        List<BundleCapability> caps = (br.getWiring() != null)
-            ? br.getWiring().getCapabilities(null)
-            : br.getDeclaredCapabilities(null);
-        if (caps != null)
-        {
-            for (BundleCapability cap : caps)
-            {
-                if (cap.getNamespace().equals(req.getNamespace())
-                    && CapabilitySet.matches((BundleCapabilityImpl) cap, req.getFilter()))
-                {
-                    return cap;
-                }
-            }
-        }
-        return null;
-    }
-
     /**
      * Returns all the capabilities from a module that has a specified namespace.
      *



Mime
View raw message