From 867bf599a37d4edca06d1ce64c5479d1bb7e55fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Mon, 6 May 2024 14:36:35 +0200 Subject: [PATCH] Consider the version string when adding bnd requirements Currently Tycho ignores the version string for buildpath entries defined in pde.bnd what leads to faulty dependency requirements. This now correctly evaluates the version string and maps it to a P2 requirement. --- ...leRequirementsInstallableUnitProvider.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/resolver/AdditionalBundleRequirementsInstallableUnitProvider.java b/tycho-core/src/main/java/org/eclipse/tycho/core/resolver/AdditionalBundleRequirementsInstallableUnitProvider.java index 72303cf79d..13fd4fd175 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/core/resolver/AdditionalBundleRequirementsInstallableUnitProvider.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/core/resolver/AdditionalBundleRequirementsInstallableUnitProvider.java @@ -13,7 +13,6 @@ package org.eclipse.tycho.core.resolver; import java.io.IOException; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -37,6 +36,8 @@ import org.eclipse.tycho.p2maven.tmp.BundlesAction; import org.eclipse.tycho.resolver.InstallableUnitProvider; +import aQute.bnd.header.Attrs; +import aQute.bnd.header.OSGiHeader; import aQute.bnd.osgi.Constants; import aQute.bnd.osgi.Processor; @@ -86,10 +87,20 @@ public static List getBndClasspathRequirements(Processor processor //See https://bnd.bndtools.org/instructions/buildpath.html String buildPath = processor.mergeProperties(Constants.BUILDPATH); if (buildPath != null && !buildPath.isBlank()) { - return Arrays.stream(buildPath.split(",")) - .map(bundleName -> MetadataFactory.createRequirement(BundlesAction.CAPABILITY_NS_OSGI_BUNDLE, - bundleName.trim(), VersionRange.emptyRange, null, true, true)) - .toList(); + return OSGiHeader.parseHeader(buildPath).entrySet().stream().map(entry -> { + String bundleName = entry.getKey(); + Attrs attrs = entry.getValue(); + String version = attrs.get(Constants.VERSION_ATTRIBUTE, Constants.VERSION_ATTR_LATEST); + VersionRange range; + if (Constants.VERSION_ATTR_LATEST.equals(version)) { + range = VersionRange.emptyRange; + } else { + range = VersionRange.create(version); + } + return MetadataFactory.createRequirement(BundlesAction.CAPABILITY_NS_OSGI_BUNDLE, bundleName.trim(), + range, null, true, true); + }).toList(); + } return Collections.emptyList(); }