Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set-version should update a micro version range properly #3461

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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)"

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.tycho.its</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>consumer.micro</artifactId>
<packaging>eclipse-plugin</packaging>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<packaging>pom</packaging>
<modules>
<module>provider.bundle</module>
<module>consumer.micro</module>
<module>consumer.narrow</module>
<module>consumer.wide</module>
<module>consumer.open</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
Loading