From 03fd6edce644d42267b5796c552b2bf2f45da274 Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Wed, 16 Oct 2024 21:11:57 +0200 Subject: [PATCH] Support version-ranges and no-version for units in IU target locations Relates to https://github.com/eclipse-pde/eclipse.pde/pull/1245 --- RELEASE_NOTES.md | 5 +++++ .../p2resolver/InstallableUnitResolver.java | 18 +++++++++++++----- .../p2resolver/TargetPlatformFactoryTest.java | 14 +++++++++++++- .../targetresolver/versionRanges.target | 11 +++++++++++ .../targetplatform/TargetDefinitionFile.java | 3 +++ 5 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 tycho-core/src/test/resources/targetresolver/versionRanges.target diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index e9a37db075..7fcba3e104 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -2,6 +2,11 @@ This page describes the noteworthy improvements provided by each release of Eclipse Tycho. +## 4.0.10 + +backports: +- Support version-ranges and no-version for units in IU target locations + ## 4.0.9 backports: diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/InstallableUnitResolver.java b/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/InstallableUnitResolver.java index 6edba2fa89..68e424901c 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/InstallableUnitResolver.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/InstallableUnitResolver.java @@ -275,7 +275,7 @@ private static IInstallableUnit findUnits(Unit unitReference, IQueryable findUnit(Unit unitReference, IQueryable units) throws TargetDefinitionSyntaxException { - Version version = parseVersion(unitReference); + VersionRange version = parseVersion(unitReference); // the createIUQuery treats 0.0.0 version as "any version", and all other versions as exact versions IQuery matchingIUQuery = QueryUtil.createIUQuery(unitReference.getId(), version); @@ -285,12 +285,20 @@ private static IQueryResult findUnit(Unit unitReference, IQuer return queryResult; } - private static Version parseVersion(Unit unitReference) throws TargetDefinitionSyntaxException { + private static VersionRange parseVersion(Unit unitReference) throws TargetDefinitionSyntaxException { + String version = unitReference.getVersion(); try { - return Version.parseVersion(unitReference.getVersion()); + if ("0.0.0".equals(version)) { + return VersionRange.emptyRange; + } else if (version.contains(",")) { // a real version range + return VersionRange.create(version); + } else { // an explicit/exact version -> create strict version range + Version v = Version.parseVersion(version); + return new VersionRange(v, true, v, true); + } } catch (IllegalArgumentException e) { - throw new TargetDefinitionSyntaxException(NLS.bind("Cannot parse version \"{0}\" of unit \"{1}\"", - unitReference.getVersion(), unitReference.getId()), e); + throw new TargetDefinitionSyntaxException( + NLS.bind("Cannot parse version \"{0}\" of unit \"{1}\"", version, unitReference.getId()), e); } } diff --git a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/TargetPlatformFactoryTest.java b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/TargetPlatformFactoryTest.java index 1fa142563c..9228f24ba1 100644 --- a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/TargetPlatformFactoryTest.java +++ b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/TargetPlatformFactoryTest.java @@ -42,6 +42,7 @@ import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.equinox.p2.metadata.IInstallableUnit; import org.eclipse.equinox.p2.metadata.IVersionedId; +import org.eclipse.equinox.p2.metadata.VersionedId; import org.eclipse.tycho.ArtifactType; import org.eclipse.tycho.DefaultArtifactKey; import org.eclipse.tycho.IDependencyMetadata.DependencyMetadataType; @@ -298,7 +299,7 @@ public void testDuplicateReactorUnits() throws Exception { @Ignore("This test don't work because maven provides a 'not real' local repo to the test") public void testMavenArtifactsInTargetDefinitionResolveToMavenPath() throws Exception { File targetDefinition = resourceFile("targetresolver/mavenDep.target"); - tpConfig.getTargetDefinitions().add(TargetDefinitionFile.read(targetDefinition)); + tpConfig.addTargetDefinition(TargetDefinitionFile.read(targetDefinition)); P2TargetPlatform targetPlatform = subject.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, List.of()); File artifactLocation = targetPlatform.getArtifactLocation( new DefaultArtifactKey(ArtifactType.TYPE_ECLIPSE_PLUGIN, "org.apache.commons.logging", "1.2.0")); @@ -307,6 +308,17 @@ public void testMavenArtifactsInTargetDefinitionResolveToMavenPath() throws Exce assertTrue(p2ArtifactPath.startsWith(localM2Repo)); } + @Test + public void testUnitsWithVersionRangeAndNoVersionInTargetDefinition() throws Exception { + File targetDefinition = resourceFile("targetresolver/versionRanges.target"); + tpConfig.addTargetDefinition(TargetDefinitionFile.read(targetDefinition)); + P2TargetPlatform tp = subject.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, List.of()); + Set ius = tp.getInstallableUnits(); + assertThat(ius, hasItem(unitWithIdAndVersion(new VersionedId("jakarta.activation-api", "2.1.3")))); + assertThat(tp.getInstallableUnits(), + hasItem(unitWithIdAndVersion(new VersionedId("jakarta.inject.jakarta.inject-api", "1.0.5")))); + } + private static TargetDefinition plannerTargetDefinition(TestRepositories repository, IVersionedId unit) { TargetDefinition.Location location = new TargetDefinitionResolverIncludeModeTest.PlannerLocationStub(repository, unit); diff --git a/tycho-core/src/test/resources/targetresolver/versionRanges.target b/tycho-core/src/test/resources/targetresolver/versionRanges.target new file mode 100644 index 0000000000..2e50d0f9a6 --- /dev/null +++ b/tycho-core/src/test/resources/targetresolver/versionRanges.target @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/tycho-targetplatform/src/main/java/org/eclipse/tycho/targetplatform/TargetDefinitionFile.java b/tycho-targetplatform/src/main/java/org/eclipse/tycho/targetplatform/TargetDefinitionFile.java index 383456df63..5864add332 100644 --- a/tycho-targetplatform/src/main/java/org/eclipse/tycho/targetplatform/TargetDefinitionFile.java +++ b/tycho-targetplatform/src/main/java/org/eclipse/tycho/targetplatform/TargetDefinitionFile.java @@ -525,6 +525,9 @@ private static IULocation parseIULocation(Element dom) { for (Element unitDom : getChildren(dom, "unit")) { String id = unitDom.getAttribute("id"); String version = unitDom.getAttribute("version"); + if (version == null || version.isBlank()) { + version = "0.0.0"; + } units.add(new Unit(id, version)); } final List repositories = new ArrayList<>();