From c9bdda42ff0eaae2ce62c0c4883f6ab0576fa50b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sat, 24 Aug 2024 07:55:28 +0200 Subject: [PATCH] Support updating (sub)incremental versions Currently due to how the underlying library works, if there is only a micro version update it is not considered. Also subincremental versions are only taken into account if major is allowed (what currently include all increments) what is inconsistent. This now changes the single optional to a stream in order of update hierarchy and let the MavenLocationUpdater choose the first matching update offered and adding an option for subincremental updates as well. (cherry picked from commit 3f002a6fdff1ea65536d6f69e52bb0a9c4b3b0d1) --- .../versionbump/MavenLocationUpdater.java | 6 ++- .../tycho/versionbump/UpdateTargetMojo.java | 41 ++++++++++++++----- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/tycho-extras/tycho-version-bump-plugin/src/main/java/org/eclipse/tycho/versionbump/MavenLocationUpdater.java b/tycho-extras/tycho-version-bump-plugin/src/main/java/org/eclipse/tycho/versionbump/MavenLocationUpdater.java index 52e840f7c7..3fd175237f 100644 --- a/tycho-extras/tycho-version-bump-plugin/src/main/java/org/eclipse/tycho/versionbump/MavenLocationUpdater.java +++ b/tycho-extras/tycho-version-bump-plugin/src/main/java/org/eclipse/tycho/versionbump/MavenLocationUpdater.java @@ -13,6 +13,8 @@ package org.eclipse.tycho.versionbump; import java.util.Map; +import java.util.Objects; +import java.util.Optional; import javax.inject.Inject; import javax.inject.Named; @@ -58,7 +60,9 @@ boolean update(Element mavenLocation, UpdateTargetMojo context) throws VersionRa Dependency mavenDependency = getDependency(dependency); Artifact dependencyArtifact = helper.createDependencyArtifact(mavenDependency); ArtifactVersions versions = helper.lookupArtifactVersions(dependencyArtifact, false); - ArtifactVersion updateVersion = versions.getNewestUpdateWithinSegment(context.getSegment(), false); + ArtifactVersion updateVersion = context.getSegments() + .map(seg -> versions.getNewestUpdateWithinSegment(Optional.of(seg), false)) + .filter(Objects::nonNull).findFirst().orElse(null); if (updateVersion != null) { String oldVersion = mavenDependency.getVersion(); String newVersion = updateVersion.toString(); diff --git a/tycho-extras/tycho-version-bump-plugin/src/main/java/org/eclipse/tycho/versionbump/UpdateTargetMojo.java b/tycho-extras/tycho-version-bump-plugin/src/main/java/org/eclipse/tycho/versionbump/UpdateTargetMojo.java index 1536b591e8..c296b2a938 100644 --- a/tycho-extras/tycho-version-bump-plugin/src/main/java/org/eclipse/tycho/versionbump/UpdateTargetMojo.java +++ b/tycho-extras/tycho-version-bump-plugin/src/main/java/org/eclipse/tycho/versionbump/UpdateTargetMojo.java @@ -21,8 +21,9 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.List; -import java.util.Optional; import java.util.Set; +import java.util.stream.Stream; +import java.util.stream.Stream.Builder; import javax.inject.Inject; @@ -90,6 +91,13 @@ public class UpdateTargetMojo extends AbstractUpdateMojo { @Parameter(property = "allowIncrementalUpdates", defaultValue = "true") private boolean allowIncrementalUpdates; + /** + * Whether to allow the subIncremental version number to be changed. + * + */ + @Parameter(property = "allowSubIncrementalUpdates", defaultValue = "true") + private boolean allowSubIncrementalUpdates; + /** * A comma separated list of update site discovery strategies, the following is currently * supported: @@ -205,18 +213,22 @@ protected File getFileToBeUpdated() throws MojoFailureException { } } - boolean isAllowIncrementalUpdates() { - return allowIncrementalUpdates; + boolean isAllowSubIncrementalUpdates() { + return allowSubIncrementalUpdates; } - boolean isAllowMajorUpdates() { - return allowMajorUpdates; + boolean isAllowIncrementalUpdates() { + return allowIncrementalUpdates; } boolean isAllowMinorUpdates() { return allowMinorUpdates; } + boolean isAllowMajorUpdates() { + return allowMajorUpdates; + } + MavenSession getMavenSession() { return mavenSession; } @@ -259,14 +271,21 @@ String getMavenRulesUri() { return mavenRulesUri; } - Optional getSegment() { - if (isAllowMajorUpdates() && isAllowMinorUpdates() && isAllowIncrementalUpdates()) { - return Optional.empty(); + Stream getSegments() { + Builder builder = Stream.builder(); + if (isAllowMajorUpdates()) { + builder.accept(Segment.MAJOR); + } + if (isAllowMinorUpdates()) { + builder.accept(Segment.MINOR); + } + if (isAllowIncrementalUpdates()) { + builder.accept(Segment.INCREMENTAL); } - if (isAllowMinorUpdates() && isAllowIncrementalUpdates()) { - return Optional.of(Segment.MINOR); + if (isAllowSubIncrementalUpdates()) { + builder.accept(Segment.SUBINCREMENTAL); } - return Optional.of(Segment.INCREMENTAL); + return builder.build(); } }