ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hi...@apache.org
Subject [3/6] ant-ivy git commit: Make the latest-osgi take also into account the implementation when resolving requirements
Date Mon, 22 Dec 2014 17:37:19 GMT
Make the latest-osgi take also into account the implementation when resolving requirements

Project: http://git-wip-us.apache.org/repos/asf/ant-ivy/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant-ivy/commit/ee94e6d8
Tree: http://git-wip-us.apache.org/repos/asf/ant-ivy/tree/ee94e6d8
Diff: http://git-wip-us.apache.org/repos/asf/ant-ivy/diff/ee94e6d8

Branch: refs/heads/master
Commit: ee94e6d82370b6b6086cae2693dc2fe31388fb64
Parents: 10118c9
Author: Nicolas Lalevée <nicolas.lalevee@hibnet.org>
Authored: Sun Dec 21 17:58:49 2014 +0100
Committer: Nicolas Lalevée <nicolas.lalevee@hibnet.org>
Committed: Sun Dec 21 18:08:14 2014 +0100

----------------------------------------------------------------------
 .../ivy/osgi/core/OsgiLatestStrategy.java       | 53 +++++++++++++++++++-
 1 file changed, 52 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/ee94e6d8/src/java/org/apache/ivy/osgi/core/OsgiLatestStrategy.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/osgi/core/OsgiLatestStrategy.java b/src/java/org/apache/ivy/osgi/core/OsgiLatestStrategy.java
index e160fce..4cdf906 100644
--- a/src/java/org/apache/ivy/osgi/core/OsgiLatestStrategy.java
+++ b/src/java/org/apache/ivy/osgi/core/OsgiLatestStrategy.java
@@ -21,10 +21,14 @@ import java.text.ParseException;
 import java.util.Comparator;
 
 import org.apache.ivy.core.IvyContext;
+import org.apache.ivy.core.module.descriptor.DependencyDescriptor;
+import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
 import org.apache.ivy.core.module.id.ModuleRevisionId;
+import org.apache.ivy.core.resolve.ResolvedModuleRevision;
 import org.apache.ivy.osgi.util.Version;
 import org.apache.ivy.plugins.latest.ArtifactInfo;
 import org.apache.ivy.plugins.latest.ComparatorLatestStrategy;
+import org.apache.ivy.plugins.resolver.util.MDResolvedResource;
 import org.apache.ivy.plugins.version.VersionMatcher;
 
 public class OsgiLatestStrategy extends ComparatorLatestStrategy {
@@ -80,7 +84,54 @@ public class OsgiLatestStrategy extends ComparatorLatestStrategy {
                 return c >= 0 ? -1 : 1;
             }
 
-            return mridComparator.compare(mrid1, mrid2);
+            int res = mridComparator.compare(mrid1, mrid2);
+
+            if (res == 0) {
+                // if same requirements, maybe we can make a difference on the implementation
?
+                ModuleRevisionId implMrid1 = getImplMrid(o1);
+                ModuleRevisionId implMrid2 = getImplMrid(o2);
+                if (implMrid1 != null && implMrid2 != null) {
+                    if (implMrid1.getModuleId().equals(implMrid2.getModuleId())) {
+                        // same implementation, compare the versions
+                        res = mridComparator.compare(implMrid1, implMrid2);
+                    } else {
+                        // not same bundle
+                        // to keep a total order, compare module names even if it means nothing
+                        res = implMrid1.getModuleId().compareTo(implMrid2.getModuleId());
+                    }
+                }
+
+            }
+
+            return res;
+        }
+
+        /*
+         * In the resolve process, a resolved requirement is represented in a special way.
Here we
+         * deconstruct the resolved resource to know which implementation is actually resolved.
See
+         * AbstractOSGiResolver.buildResolvedCapabilityMd()
+         */
+        private ModuleRevisionId getImplMrid(ArtifactInfo o) {
+            if (!(o instanceof MDResolvedResource)) {
+                return null;
+            }
+            MDResolvedResource mdrr = (MDResolvedResource) o;
+            ResolvedModuleRevision rmr = mdrr.getResolvedModuleRevision();
+            if (rmr == null) {
+                return null;
+            }
+            ModuleDescriptor md = rmr.getDescriptor();
+            if (md == null) {
+                return null;
+            }
+            if (!md.getModuleRevisionId().getOrganisation().equals(BundleInfo.PACKAGE_TYPE))
{
+                return null;
+            }
+            DependencyDescriptor[] dds = md.getDependencies();
+            if (dds == null || dds.length != 1) {
+                return null;
+            }
+            return dds[0].getDependencyRevisionId();
         }
     }
 


Mime
View raw message