|
15 | 15 | *******************************************************************************/ |
16 | 16 | package org.eclipse.pde.bnd.ui.model.resolution; |
17 | 17 |
|
| 18 | +import java.util.Collection; |
18 | 19 | import java.util.Comparator; |
19 | 20 |
|
20 | 21 | import org.eclipse.pde.bnd.ui.model.resource.R5LabelFormatter; |
@@ -85,16 +86,32 @@ private int compareCapToCap(Capability c1, Capability c2) { |
85 | 86 | String versionAttribName = R5LabelFormatter.getVersionAttributeName(ns1); |
86 | 87 | if (versionAttribName == null) |
87 | 88 | return 0; |
88 | | - Version v1 = (Version) c1.getAttributes() |
89 | | - .get(versionAttribName); |
90 | | - if (v1 == null) |
91 | | - v1 = Version.emptyVersion; |
92 | | - Version v2 = (Version) c2.getAttributes() |
93 | | - .get(versionAttribName); |
| 89 | + |
| 90 | + Version v1 = highestVersion(c1.getAttributes().get(versionAttribName)); |
| 91 | + Version v2 = highestVersion(c2.getAttributes().get(versionAttribName)); |
| 92 | + |
94 | 93 | if (v2 == null) |
95 | 94 | v2 = Version.emptyVersion; |
| 95 | + |
96 | 96 | return v1.compareTo(v2); |
97 | 97 | } |
| 98 | + |
| 99 | + private static Version highestVersion(Object attr) { |
| 100 | + if (attr instanceof Version v) { |
| 101 | + return v; |
| 102 | + } |
| 103 | + if (attr instanceof Collection<?> col) { |
| 104 | + // e.g. namespace 'osgi.ee' can contain List<Version> |
| 105 | + // see https://osgi.github.io/osgi/core/framework.namespaces.html#framework.namespaces-ee.namespace |
| 106 | + // so we compare the highest versions |
| 107 | + return col.stream() |
| 108 | + .filter(Version.class::isInstance) |
| 109 | + .map(Version.class::cast) |
| 110 | + .max(Version::compareTo) |
| 111 | + .orElse(Version.emptyVersion); |
| 112 | + } |
| 113 | + return Version.emptyVersion; // null or wrong type |
| 114 | + } |
98 | 115 |
|
99 | 116 | private int compareReqToReq(Requirement r1, Requirement r2) { |
100 | 117 | return ResourceUtils.REQUIREMENT_COMPARATOR.compare(r1, r2); |
|
0 commit comments