Skip to content

Commit

Permalink
Support updating (sub)incremental versions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
laeubi committed Aug 24, 2024
1 parent 359c1b0 commit c8a9954
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -259,14 +271,21 @@ String getMavenRulesUri() {
return mavenRulesUri;
}

Optional<Segment> getSegment() {
if (isAllowMajorUpdates() && isAllowMinorUpdates() && isAllowIncrementalUpdates()) {
return Optional.empty();
Stream<Segment> getSegments() {
Builder<Segment> 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();
}

}

0 comments on commit c8a9954

Please sign in to comment.