From d982ed436d5edab7069ce935e9c9c075bfb92b03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Mon, 5 Feb 2024 14:09:02 +0100 Subject: [PATCH] set-version should update a micro version range properly Currently when one uses a version range that even uses the micro version this is not properly updated when using tycho-versions:set-version and results in an invalid version update. This adds a testcase and code to detect such a range to upate it accordingly. (cherry picked from commit b47ffc083de05b15f7c19c08c5bdfc2a7c13e9cf) --- .../consumer.micro/META-INF/MANIFEST.MF | 8 ++++++++ .../version_ranges/consumer.micro/pom.xml | 14 +++++++++++++ .../set-version/version_ranges/pom.xml | 1 + .../TychoVersionsPluginTest.java | 8 ++++++++ .../DefaultVersionRangeUpdateStrategy.java | 20 ++++++++++++++++++- 5 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tycho-its/projects/tycho-version-plugin/set-version/version_ranges/consumer.micro/META-INF/MANIFEST.MF create mode 100644 tycho-its/projects/tycho-version-plugin/set-version/version_ranges/consumer.micro/pom.xml diff --git a/tycho-its/projects/tycho-version-plugin/set-version/version_ranges/consumer.micro/META-INF/MANIFEST.MF b/tycho-its/projects/tycho-version-plugin/set-version/version_ranges/consumer.micro/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..b607d50bb6 --- /dev/null +++ b/tycho-its/projects/tycho-version-plugin/set-version/version_ranges/consumer.micro/META-INF/MANIFEST.MF @@ -0,0 +1,8 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Test Bundle +Bundle-SymbolicName: consumer.micro +Bundle-Version: 1.0.0.qualifier +Import-Package: my.pkg;version="[1.0.0,1.0.1)" +Require-Bundle: provider.bundle;bundle-version="[1.0.0,1.0.1)" + diff --git a/tycho-its/projects/tycho-version-plugin/set-version/version_ranges/consumer.micro/pom.xml b/tycho-its/projects/tycho-version-plugin/set-version/version_ranges/consumer.micro/pom.xml new file mode 100644 index 0000000000..a537103dd8 --- /dev/null +++ b/tycho-its/projects/tycho-version-plugin/set-version/version_ranges/consumer.micro/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + + + org.tycho.its + parent + 1.0.0-SNAPSHOT + + consumer.micro + eclipse-plugin + diff --git a/tycho-its/projects/tycho-version-plugin/set-version/version_ranges/pom.xml b/tycho-its/projects/tycho-version-plugin/set-version/version_ranges/pom.xml index 51bc05f3bb..893b0e6ed1 100644 --- a/tycho-its/projects/tycho-version-plugin/set-version/version_ranges/pom.xml +++ b/tycho-its/projects/tycho-version-plugin/set-version/version_ranges/pom.xml @@ -10,6 +10,7 @@ pom provider.bundle + consumer.micro consumer.narrow consumer.wide consumer.open diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/versionsplugin/TychoVersionsPluginTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/versionsplugin/TychoVersionsPluginTest.java index 1c6453a866..4d992bb387 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/versionsplugin/TychoVersionsPluginTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/versionsplugin/TychoVersionsPluginTest.java @@ -150,6 +150,7 @@ public void updateVersionRanges() throws Exception { String expectedNewMavenVersion = "1.1.0-SNAPSHOT"; String expectedNewOSGiVersion = "1.1.0.qualifier"; String expectedPackageVersion = "1.1.0"; + String expectedMicroVersionRange = "[" + expectedPackageVersion + ",1.1.1)"; String expectedNarrowVersionRange = "[" + expectedPackageVersion + ",1.2.0)"; String expectedWideVersionRange = "[" + expectedPackageVersion + ",2)"; // example call: @@ -187,6 +188,13 @@ public void updateVersionRanges() throws Exception { assertVersionRange(consumerNarrow, expectedNarrowVersionRange, Constants.IMPORT_PACKAGE); assertVersionRange(consumerNarrow, expectedNarrowVersionRange, Constants.REQUIRE_BUNDLE); } + {// check micro version range is updated + Manifest consumerNarrow = getManifest(verifier, "consumer.micro"); + assertEquals("version in manifest was not updated for micro consumer bundle!", expectedNewOSGiVersion, + consumerNarrow.getMainAttributes().getValue(Constants.BUNDLE_VERSION)); + assertVersionRange(consumerNarrow, expectedMicroVersionRange, Constants.IMPORT_PACKAGE); + assertVersionRange(consumerNarrow, expectedMicroVersionRange, Constants.REQUIRE_BUNDLE); + } } private Manifest getManifest(Verifier verifier, String bundle) throws IOException, FileNotFoundException { diff --git a/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/engine/DefaultVersionRangeUpdateStrategy.java b/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/engine/DefaultVersionRangeUpdateStrategy.java index 82af6bfd22..b20e57ce0e 100644 --- a/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/engine/DefaultVersionRangeUpdateStrategy.java +++ b/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/engine/DefaultVersionRangeUpdateStrategy.java @@ -49,7 +49,12 @@ private VersionRange computeNewVersionRange(VersionRange versionRange, Version o Version newReferencedVersion, Version newArtifactVersion) { VersionRange newVersionRange; if (updateMatchingBounds) { - if (isProviderRange(versionRange)) { + if (isMicroRange(versionRange)) { + return new VersionRange( + VersionRange.LEFT_CLOSED, newReferencedVersion, new Version(newReferencedVersion.getMajor(), + newReferencedVersion.getMinor(), newReferencedVersion.getMicro() + 1), + VersionRange.RIGHT_OPEN); + } else if (isProviderRange(versionRange)) { return new VersionRange(VersionRange.LEFT_CLOSED, newReferencedVersion, new Version(newReferencedVersion.getMajor(), newReferencedVersion.getMinor() + 1, 0), VersionRange.RIGHT_OPEN); @@ -62,6 +67,19 @@ private VersionRange computeNewVersionRange(VersionRange versionRange, Version o newArtifactVersion); } + private boolean isMicroRange(VersionRange versionRange) { + if (versionRange.getLeftType() == VersionRange.LEFT_CLOSED + && versionRange.getRightType() == VersionRange.RIGHT_OPEN) { + Version right = versionRange.getRight(); + if (right != null) { + Version left = versionRange.getLeft(); + return left.getMajor() == right.getMajor() && left.getMinor() == right.getMinor() + && right.getMicro() > left.getMicro(); + } + } + return false; + } + private boolean isProviderRange(VersionRange versionRange) { if (versionRange.getLeftType() == VersionRange.LEFT_CLOSED && versionRange.getRightType() == VersionRange.RIGHT_OPEN) {