You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by gn...@apache.org on 2015/07/13 17:17:03 UTC

svn commit: r1690704 - in /felix/trunk/resolver/src/main/java/org/apache/felix/resolver: Candidates.java ResolverImpl.java

Author: gnodet
Date: Mon Jul 13 15:17:02 2015
New Revision: 1690704

URL: http://svn.apache.org/r1690704
Log:
[FELIX-4942] Extract the consistency check into its own method

Modified:
    felix/trunk/resolver/src/main/java/org/apache/felix/resolver/Candidates.java
    felix/trunk/resolver/src/main/java/org/apache/felix/resolver/ResolverImpl.java

Modified: felix/trunk/resolver/src/main/java/org/apache/felix/resolver/Candidates.java
URL: http://svn.apache.org/viewvc/felix/trunk/resolver/src/main/java/org/apache/felix/resolver/Candidates.java?rev=1690704&r1=1690703&r2=1690704&view=diff
==============================================================================
--- felix/trunk/resolver/src/main/java/org/apache/felix/resolver/Candidates.java (original)
+++ felix/trunk/resolver/src/main/java/org/apache/felix/resolver/Candidates.java Mon Jul 13 15:17:02 2015
@@ -113,6 +113,11 @@ class Candidates
         m_delta = new OpenHashMapSet<Requirement, Capability>(3);
     }
 
+    public int getNbResources()
+    {
+        return m_populateResultCache.size();
+    }
+
     /**
      * Returns the delta which is the differences in the candidates from the
      * original Candidates permutation.

Modified: felix/trunk/resolver/src/main/java/org/apache/felix/resolver/ResolverImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/resolver/src/main/java/org/apache/felix/resolver/ResolverImpl.java?rev=1690704&r1=1690703&r2=1690704&view=diff
==============================================================================
--- felix/trunk/resolver/src/main/java/org/apache/felix/resolver/ResolverImpl.java (original)
+++ felix/trunk/resolver/src/main/java/org/apache/felix/resolver/ResolverImpl.java Mon Jul 13 15:17:02 2015
@@ -123,8 +123,6 @@ public class ResolverImpl implements Res
         ResolveSession session = new ResolveSession(rc);
         Map<Resource, List<Wire>> wireMap =
             new HashMap<Resource, List<Wire>>();
-        Map<Resource, Packages> resourcePkgMap =
-            new HashMap<Resource, Packages>();
 
         // Make copies of arguments in case we want to modify them.
         Collection<Resource> mandatoryResources = new ArrayList<Resource>(rc.getMandatoryResources());
@@ -239,7 +237,6 @@ public class ResolverImpl implements Res
                         continue;
                     }
 
-                    resourcePkgMap.clear();
                     session.getPackageSourcesCache().clear();
                     // Null out each time a new permutation is attempted.
                     // We only use this to store a valid permutation which is a
@@ -248,22 +245,16 @@ public class ResolverImpl implements Res
 
 //allCandidates.dump();
 
-                    Map<Resource, ResolutionError> currentFaultyResources = null;
                     rethrow = allCandidates.checkSubstitutes(importPermutations);
                     if (rethrow != null)
                     {
                         continue;
                     }
 
-                    // Reuse a resultCache map for checking package consistency
-                    // for all resources.
-                    Map<Resource, Object> resultCache =
-                        new HashMap<Resource, Object>(allResources.size());
-                    // Check the package space consistency for all 'root' resources.
+                    // Compute the list of hosts
+                    Map<Resource, Resource> hosts = new LinkedHashMap<Resource, Resource>();
                     for (Resource resource : allResources)
                     {
-                        Resource target = resource;
-
                         // If we are resolving a fragment, then get its
                         // host candidate and verify it instead.
                         Requirement hostReq = hostReqs.get(resource);
@@ -277,42 +268,15 @@ public class ResolverImpl implements Res
                             {
                                 continue;
                             }
-                            target = hostCap.getResource();
+                            resource = hostCap.getResource();
                         }
+                        hosts.put(resource, allCandidates.getWrappedHost(resource));
+                    }
 
-                        calculatePackageSpaces(
-                            session, allCandidates.getWrappedHost(target), allCandidates,
-                            resourcePkgMap, new HashMap<Capability, Set<Resource>>(256),
-                            new HashSet<Resource>(64));
-//System.out.println("+++ PACKAGE SPACES START +++");
-//dumpResourcePkgMap(resourcePkgMap);
-//System.out.println("+++ PACKAGE SPACES END +++");
+                    Map<Resource, ResolutionError> currentFaultyResources = new HashMap<Resource, ResolutionError>();
+                    rethrow = checkConsistency(session, allCandidates, currentFaultyResources, hosts);
 
-                        rethrow = checkPackageSpaceConsistency(
-                                session, allCandidates.getWrappedHost(target),
-                                allCandidates, resourcePkgMap, resultCache);
-                        if (rethrow != null)
-                        {
-                            if (currentFaultyResources == null)
-                            {
-                                currentFaultyResources = new HashMap<Resource, ResolutionError>();
-                            }
-                            Resource faultyResource = resource;
-                            // check that the faulty requirement is not from a fragment
-                            for (Requirement faultyReq : rethrow.getUnresolvedRequirements())
-                            {
-                                if (faultyReq instanceof WrappedRequirement)
-                                {
-                                    faultyResource =
-                                        ((WrappedRequirement) faultyReq)
-                                        .getDeclaredRequirement().getResource();
-                                    break;
-                                }
-                            }
-                            currentFaultyResources.put(faultyResource, rethrow);
-                        }
-                    }
-                    if (currentFaultyResources != null)
+                    if (!currentFaultyResources.isEmpty())
                     {
                         if (faultyResources == null)
                         {
@@ -415,6 +379,54 @@ public class ResolverImpl implements Res
         return wireMap;
     }
 
+    private ResolutionError checkConsistency(
+        ResolveSession session,
+        Candidates allCandidates,
+        Map<Resource, ResolutionError> currentFaultyResources,
+        Map<Resource, Resource> hosts)
+    {
+        Map<Resource, Packages> resourcePkgMap =
+                new HashMap<Resource, Packages>(allCandidates.getNbResources());
+        // Reuse a resultCache map for checking package consistency
+        // for all resources.
+        Map<Resource, Object> resultCache =
+                new HashMap<Resource, Object>();
+        // Check the package space consistency for all 'root' resources.
+        ResolutionError error = null;
+        for (Entry<Resource, Resource> entry : hosts.entrySet())
+        {
+            calculatePackageSpaces(
+                    session, entry.getValue(), allCandidates,
+                    resourcePkgMap, new HashMap<Capability, Set<Resource>>(256),
+                    new HashSet<Resource>(64));
+//System.out.println("+++ PACKAGE SPACES START +++");
+//dumpResourcePkgMap(resourcePkgMap);
+//System.out.println("+++ PACKAGE SPACES END +++");
+
+            ResolutionError rethrow = checkPackageSpaceConsistency(
+                    session, entry.getValue(),
+                    allCandidates, resourcePkgMap, resultCache);
+            if (rethrow != null)
+            {
+                Resource faultyResource = entry.getKey();
+                // check that the faulty requirement is not from a fragment
+                for (Requirement faultyReq : rethrow.getUnresolvedRequirements())
+                {
+                    if (faultyReq instanceof WrappedRequirement)
+                    {
+                        faultyResource =
+                                ((WrappedRequirement) faultyReq)
+                                        .getDeclaredRequirement().getResource();
+                        break;
+                    }
+                }
+                currentFaultyResources.put(faultyResource, rethrow);
+                error = rethrow;
+            }
+        }
+        return error;
+    }
+
     /**
      * Resolves a dynamic requirement for the specified host resource using the
      * specified {@link ResolveContext}. The dynamic requirement may contain