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

[tycho-4.0.x] Support updating (sub)incremental versions #4179

Merged
merged 1 commit into from
Aug 24, 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
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();
}

}
Loading