karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject [1/2] karaf git commit: [KARAF-4701] Forcing deterministic heuristic of capbillities comparison for Subsystem Resolver
Date Mon, 27 Mar 2017 06:30:29 GMT
Repository: karaf
Updated Branches:
  refs/heads/master 67e2e46b4 -> e176808e6


[KARAF-4701] Forcing deterministic heuristic of capbillities comparison for Subsystem Resolver


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/0b3a4dbc
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/0b3a4dbc
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/0b3a4dbc

Branch: refs/heads/master
Commit: 0b3a4dbc938cf5431fc2cbe1d10d385037220ebf
Parents: 67e2e46
Author: Vladimir Konkov <vkonkov@citc.ru>
Authored: Fri Mar 24 12:50:23 2017 +0300
Committer: Jean-Baptiste Onofré <jbonofre@apache.org>
Committed: Mon Mar 27 08:04:45 2017 +0200

----------------------------------------------------------------------
 .../internal/region/CandidateComparator.java    | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/0b3a4dbc/features/core/src/main/java/org/apache/karaf/features/internal/region/CandidateComparator.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/region/CandidateComparator.java
b/features/core/src/main/java/org/apache/karaf/features/internal/region/CandidateComparator.java
index a3f6c51..8f53058 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/region/CandidateComparator.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/region/CandidateComparator.java
@@ -28,6 +28,7 @@ import org.osgi.framework.namespace.IdentityNamespace;
 import org.osgi.framework.namespace.PackageNamespace;
 import org.osgi.framework.wiring.BundleCapability;
 import org.osgi.resource.Capability;
+import org.osgi.resource.Requirement;
 import org.osgi.resource.Resource;
 
 public class CandidateComparator implements Comparator<Capability> {
@@ -79,9 +80,24 @@ public class CandidateComparator implements Comparator<Capability>
{
         }
         if (c == 0) {
             // We just want to have a deterministic heuristic
-            String n1 = ResolverUtil.getSymbolicName(cap1.getResource());
-            String n2 = ResolverUtil.getSymbolicName(cap2.getResource());
+            final Resource resource1 = cap1.getResource();
+            final Resource resource2 = cap2.getResource();
+            String n1 = ResolverUtil.getSymbolicName(resource1);
+            String n2 = ResolverUtil.getSymbolicName(resource2);
             c = n1.compareTo(n2);
+            // Resources looks like identical, but it required by different features/subsystems/regions
+            // so use this difference for deterministic heuristic
+            if (c == 0) {
+                final List<Requirement> reqs1 = resource1.getRequirements(IdentityNamespace.IDENTITY_NAMESPACE);
+                final List<Requirement> reqs2 = resource2.getRequirements(IdentityNamespace.IDENTITY_NAMESPACE);
+                if (!reqs1.isEmpty() && !reqs2.isEmpty()) {
+                    Requirement identityReq1 = reqs1.get(0);
+                    Requirement identityReq2 = reqs2.get(0);
+                    Object identity1 = identityReq1.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE);
+                    Object identity2 = identityReq2.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE);
+                    c = String.valueOf(identity1).compareTo(String.valueOf(identity2));
+                }
+            }
         }
         return c;
     }


Mime
View raw message