diff --git a/tycho-its/projects/tycho-version-plugin/set-version/version_ranges/consumer.narrow/META-INF/MANIFEST.MF b/tycho-its/projects/tycho-version-plugin/set-version/version_ranges/consumer.narrow/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..e6f03b5ea7
--- /dev/null
+++ b/tycho-its/projects/tycho-version-plugin/set-version/version_ranges/consumer.narrow/META-INF/MANIFEST.MF
@@ -0,0 +1,8 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Test Bundle
+Bundle-SymbolicName: consumer.narrow
+Bundle-Version: 1.0.0.qualifier
+Import-Package: my.pkg;version="[1.0.0,1.1.0)"
+Require-Bundle: provider.bundle;bundle-version="[1.0.0,1.1.0)"
+
diff --git a/tycho-its/projects/tycho-version-plugin/set-version/version_ranges/consumer.narrow/pom.xml b/tycho-its/projects/tycho-version-plugin/set-version/version_ranges/consumer.narrow/pom.xml
new file mode 100644
index 0000000000..04a3011c43
--- /dev/null
+++ b/tycho-its/projects/tycho-version-plugin/set-version/version_ranges/consumer.narrow/pom.xml
@@ -0,0 +1,14 @@
+
+
* This test verifies that current and future versions of the @@ -132,12 +140,62 @@ public void updateProjectVersionWithNestedPom() throws Exception { pomModel.getVersion()); } } - Manifest manifest = new Manifest( - new FileInputStream(new File(verifier.getBasedir(), "bundle/" + JarFile.MANIFEST_NAME))); + Manifest manifest = getManifest(verifier, "bundle"); assertEquals("version in manifest was not updated!", expectedNewVersion, manifest.getMainAttributes().getValue(Constants.BUNDLE_VERSION)); } + @Test + public void updateVersionRanges() throws Exception { + String expectedNewMavenVersion = "1.1.0-SNAPSHOT"; + String expectedNewOSGiVersion = "1.1.0.qualifier"; + String expectedPackageVersion = "1.1.0"; + String expectedNarrowVersionRange = "[" + expectedPackageVersion + ",1.2.0)"; + String expectedWideVersionRange = "[" + expectedPackageVersion + ",2)"; + // example call: + // mvn org.eclipse.tycho:tycho-versions-plugin:5.0.0-SNAPSHOT:set-version + // -DnewVersion=1.1.0-SNAPSHOT + // -DupdateVersionRangeMatchingBounds + Verifier verifier = getVerifier("tycho-version-plugin/set-version/version_ranges", true); + verifier.addCliOption("-DnewVersion=" + expectedNewMavenVersion); + verifier.addCliOption("-DupdateVersionRangeMatchingBounds"); + verifier.executeGoal("org.eclipse.tycho:tycho-versions-plugin:" + VERSION + ":set-version"); + {// check the package itself is updated + Manifest provider = getManifest(verifier, "provider.bundle"); + assertEquals("version in manifest was not updated for provider bundle!", expectedNewOSGiVersion, + provider.getMainAttributes().getValue(Constants.BUNDLE_VERSION)); + assertVersion(provider, expectedPackageVersion, Constants.EXPORT_PACKAGE); + } + {// check open range is updated + Manifest consumerOpen = getManifest(verifier, "consumer.open"); + assertEquals("version in manifest was not updated for open consumer bundle!", expectedNewOSGiVersion, + consumerOpen.getMainAttributes().getValue(Constants.BUNDLE_VERSION)); + assertVersion(consumerOpen, expectedPackageVersion, Constants.IMPORT_PACKAGE); + assertVersion(consumerOpen, expectedPackageVersion, Constants.REQUIRE_BUNDLE); + } + {// check wide version range is updated + Manifest consumerWide = getManifest(verifier, "consumer.wide"); + assertEquals("version in manifest was not updated for wide consumer bundle!", expectedNewOSGiVersion, + consumerWide.getMainAttributes().getValue(Constants.BUNDLE_VERSION)); + assertVersionRange(consumerWide, expectedWideVersionRange, Constants.IMPORT_PACKAGE); + assertVersionRange(consumerWide, expectedWideVersionRange, Constants.REQUIRE_BUNDLE); + } + {// check narrow version range is updated + Manifest consumerNarrow = getManifest(verifier, "consumer.narrow"); + assertEquals("version in manifest was not updated for narrow consumer bundle!", expectedNewOSGiVersion, + consumerNarrow.getMainAttributes().getValue(Constants.BUNDLE_VERSION)); + assertVersionRange(consumerNarrow, expectedNarrowVersionRange, Constants.IMPORT_PACKAGE); + assertVersionRange(consumerNarrow, expectedNarrowVersionRange, Constants.REQUIRE_BUNDLE); + } + } + + private Manifest getManifest(Verifier verifier, String bundle) throws IOException, FileNotFoundException { + try (FileInputStream stream = new FileInputStream( + new File(verifier.getBasedir(), bundle + "/" + JarFile.MANIFEST_NAME))) { + return new Manifest(stream); + } + } + @Test public void updateProjectMetadataVersionBndTest() throws Exception { String expectedNewVersion = "2.0.0.qualifier"; @@ -263,4 +321,26 @@ public static File file(Verifier verifier, String... path) { return Path.of(verifier.getBasedir(), path).toFile(); } + private static void assertVersionRange(Manifest manifest, String versionRange, String header) { + String value = manifest.getMainAttributes().getValue(header); + assertNotNull("Header " + header + " not found", value); + Matcher matcher = VERSION_PATTERN.matcher(value); + assertTrue("no version found on " + value, matcher.find()); + VersionRange expected = VersionRange.valueOf(versionRange); + VersionRange actual = VersionRange.valueOf(matcher.group(1)); + assertTrue(header + " " + value + ": expected version range = " + expected + " but actual version range = " + + actual, expected.equals(actual)); + } + + private static void assertVersion(Manifest manifest, String version, String header) { + String value = manifest.getMainAttributes().getValue(header); + assertNotNull("Header " + header + " not found", value); + Matcher matcher = VERSION_PATTERN.matcher(value); + assertTrue("no version found on " + value, matcher.find()); + Version expected = Version.valueOf(version); + Version actual = Version.valueOf(matcher.group(1)); + assertTrue(header + " " + value + ": expected version = " + expected + " but actual version = " + actual, + expected.equals(actual)); + } + } 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 23b619f909..82af6bfd22 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) { - newVersionRange = handleMatchingBouds(versionRange, originalReferencedVersion, newReferencedVersion); + if (isProviderRange(versionRange)) { + return new VersionRange(VersionRange.LEFT_CLOSED, newReferencedVersion, + new Version(newReferencedVersion.getMajor(), newReferencedVersion.getMinor() + 1, 0), + VersionRange.RIGHT_OPEN); + } + newVersionRange = handleMatchingBounds(versionRange, originalReferencedVersion, newReferencedVersion); } else { newVersionRange = versionRange; } @@ -57,7 +62,19 @@ private VersionRange computeNewVersionRange(VersionRange versionRange, Version o newArtifactVersion); } - private VersionRange handleMatchingBouds(VersionRange versionRange, Version originalReferencedVersion, + private boolean isProviderRange(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() + 1 == right.getMinor(); + } + } + return false; + } + + private VersionRange handleMatchingBounds(VersionRange versionRange, Version originalReferencedVersion, Version newReferencedVersion) { Version newLeft; if (versionRange.getLeft().equals(originalReferencedVersion)) { diff --git a/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/engine/VersionsEngine.java b/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/engine/VersionsEngine.java index ce8258f40e..5da2490aeb 100644 --- a/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/engine/VersionsEngine.java +++ b/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/engine/VersionsEngine.java @@ -112,7 +112,7 @@ public void reset() { public void apply() throws IOException { VersionChangesDescriptor versionChangeContext = new VersionChangesDescriptor(originalVersionChanges, - new DefaultVersionRangeUpdateStrategy(updateVersionRangeMatchingBounds), projects); + new DefaultVersionRangeUpdateStrategy(isUpdateVersionRangeMatchingBounds()), projects); // collecting secondary changes boolean newChanges = true;