Skip to content

Commit d8f42b0

Browse files
committed
+ re-aligned min maven version to 3.9.0
1 parent bec2276 commit d8f42b0

23 files changed

Lines changed: 145 additions & 164 deletions

pom.xml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
<groupId>io.github.q3769</groupId>
3232
<artifactId>semver-maven-plugin</artifactId>
33-
<version>20240116.0.202507152048</version>
33+
<version>20240116.0.202507152211</version>
3434
<packaging>maven-plugin</packaging>
3535

3636
<name>semver-maven-plugin</name>
@@ -148,6 +148,13 @@
148148
<version>1.18.38</version>
149149
<scope>provided</scope>
150150
</dependency>
151+
<dependency>
152+
<groupId>org.jspecify</groupId>
153+
<artifactId>jspecify</artifactId>
154+
<version>1.0.0</version>
155+
<scope>provided</scope>
156+
<optional>true</optional>
157+
</dependency>
151158
</dependencies>
152159

153160
<build>
@@ -250,7 +257,7 @@
250257
<plugin>
251258
<groupId>io.github.q3769</groupId>
252259
<artifactId>semver-maven-plugin</artifactId>
253-
<version>20240116.0.202507152048</version>
260+
<version>20240116.0.202507152211</version>
254261
</plugin>
255262
<plugin>
256263
<groupId>org.apache.maven.plugins</groupId>

src/main/java/q3769/maven/plugins/semver/LabelUpdater.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.commons.lang3.StringUtils;
2929
import org.apache.maven.plugin.MojoFailureException;
3030
import org.apache.maven.plugins.annotations.Parameter;
31+
import org.jspecify.annotations.Nullable;
3132

3233
/**
3334
* Abstract class for updating semantic version labels.
@@ -44,7 +45,7 @@ public abstract class LabelUpdater extends Updater {
4445
* instead of incremented.
4546
*/
4647
@Parameter(property = "set")
47-
protected String set;
48+
protected @Nullable String set;
4849

4950
/**
5051
* Increments the label of the given semantic version.
@@ -75,10 +76,10 @@ public abstract class LabelUpdater extends Updater {
7576
@Override
7677
protected Version update(Version original) throws MojoFailureException {
7778
if (StringUtils.isBlank(set)) {
78-
logInfo("Incrementing label of version: %s", original);
79+
getLog().info(String.format("Incrementing label of version: %s", original));
7980
return incrementLabel(original);
8081
} else {
81-
logInfo("Setting label of version '%s' into '%s'...", original, set);
82+
getLog().info(String.format("Setting label of version '%s' into '%s'...", original, set));
8283
return setLabel(original, set);
8384
}
8485
}

src/main/java/q3769/maven/plugins/semver/NormalVersion.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
package q3769.maven.plugins.semver;
2626

2727
import com.github.zafarkhaja.semver.Version;
28-
import javax.annotation.Nonnull;
29-
import lombok.NonNull;
3028

3129
/**
3230
* Enum representing the normal version categories (MAJOR, MINOR, PATCH) of a semantic version.
@@ -140,7 +138,7 @@ public Version incrementTo(long target, Version semver) {
140138
* @param semver the original semantic version to be incremented
141139
* @return the exception to be thrown
142140
*/
143-
private static @NonNull IllegalArgumentException newIllegalIncrementError(
141+
private static IllegalArgumentException newIllegalIncrementError(
144142
NormalVersion normalVersion, long target, Version semver) {
145143
String errorMessage = String.format(
146144
"%s version of %s is already higher than its increment target %d",
@@ -155,7 +153,7 @@ public Version incrementTo(long target, Version semver) {
155153
* @return the last incremented normal version category
156154
* @throws IllegalArgumentException if all version numbers are zero
157155
*/
158-
public static @Nonnull NormalVersion getLastIncrementedNormalVersion(@Nonnull Version version) {
156+
public static NormalVersion getLastIncrementedNormalVersion(Version version) {
159157
final long major = version.majorVersion();
160158
final long minor = version.minorVersion();
161159
final long patch = version.patchVersion();

src/main/java/q3769/maven/plugins/semver/SemverMojo.java

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@
2323
*/
2424
package q3769.maven.plugins.semver;
2525

26+
import static java.util.Objects.requireNonNull;
27+
2628
import com.github.zafarkhaja.semver.Version;
27-
import lombok.NonNull;
2829
import org.apache.maven.execution.MavenSession;
2930
import org.apache.maven.plugin.AbstractMojo;
3031
import org.apache.maven.plugin.MojoExecution;
3132
import org.apache.maven.plugin.MojoExecutionException;
3233
import org.apache.maven.plugin.MojoFailureException;
3334
import org.apache.maven.plugins.annotations.Parameter;
3435
import org.apache.maven.project.MavenProject;
36+
import org.jspecify.annotations.Nullable;
3537

3638
/**
3739
* Updates the POM file with a new SemVer version
@@ -43,27 +45,27 @@ public abstract class SemverMojo extends AbstractMojo {
4345

4446
/** */
4547
@Parameter(defaultValue = "${mojoExecution}", readonly = true)
46-
protected MojoExecution mojo;
48+
protected @Nullable MojoExecution mojo;
4749

4850
/** */
4951
@Parameter(property = "processModule", defaultValue = FALSE)
50-
protected String processModule;
52+
protected @Nullable String processModule;
5153

5254
/** Current Maven POM */
5355
@Parameter(property = "project", defaultValue = "${project}", readonly = true, required = true)
54-
protected MavenProject project;
56+
protected @Nullable MavenProject project;
5557

5658
/** Default session */
5759
@Parameter(property = "session", defaultValue = "${session}", readonly = true, required = true)
58-
protected MavenSession session;
60+
protected @Nullable MavenSession session;
5961

6062
/**
6163
* @param version text that is supposed to be valid per SemVer spec
6264
* @return A valid SemVer
6365
*/
64-
public static @NonNull Version requireValidSemVer(String version) {
66+
public static Version requireValidSemVer(@Nullable String version) {
6567
try {
66-
return Version.parse(version);
68+
return Version.parse(requireNonNull(version));
6769
} catch (Exception ex) {
6870
throw new IllegalArgumentException("Error parsing '" + version + "' as a SemVer", ex);
6971
}
@@ -83,53 +85,38 @@ public abstract class SemverMojo extends AbstractMojo {
8385
*/
8486
@Override
8587
public void execute() throws MojoExecutionException, MojoFailureException {
88+
requireNonNull(project);
8689
String projectName = project.getName();
8790
String pomVersion = originalPomVersion();
88-
logInfo(
89-
"Goal '%s' processing project '%s' with POM version '%s'...",
90-
this.mojo.getGoal(), projectName, pomVersion);
91+
getLog()
92+
.info(String.format(
93+
"Goal '%s' processing project '%s' with POM version '%s'...",
94+
requireNonNull(this.mojo).getGoal(), projectName, pomVersion));
9195
if (project.hasParent()) {
92-
logInfo(
93-
"current project %s is a module of %s",
94-
projectName, project.getParent().getName());
96+
getLog()
97+
.info(String.format(
98+
"current project %s is a module of %s",
99+
projectName, project.getParent().getName()));
95100
if (FALSE.equalsIgnoreCase(processModule)) {
96-
logWarn(
97-
"Version of module '%s' will not be processed. By default, only parent project is processed; if otherwise desired, use the `-DprocessModule` CLI flag",
98-
projectName);
101+
getLog()
102+
.warn(String.format(
103+
"Version of module '%s' will not be processed. By default, only parent project is processed; if otherwise desired, use the `-DprocessModule` CLI flag",
104+
projectName));
99105
return;
100106
}
101107
if (pomVersion == null) {
102-
logWarn(
103-
"Version of module '%s' is inherited to be the same as parent '%s', thus will not be processed independently",
104-
projectName, project.getParent().getName());
108+
getLog()
109+
.warn(String.format(
110+
"Version of module '%s' is inherited to be the same as parent '%s', thus will not be processed independently",
111+
projectName, project.getParent().getName()));
105112
return;
106113
}
107114
}
108115
doExecute();
109116
}
110117

111118
/** @return original version in pom.xml */
112-
protected String originalPomVersion() {
113-
return project.getModel().getVersion();
114-
}
115-
116-
protected void logError(String message, Object... args) {
117-
getLog().error(String.format(message, args));
118-
}
119-
120-
protected void logError(Throwable t, String message, Object... args) {
121-
getLog().error(String.format(message, args), t);
122-
}
123-
124-
protected void logWarn(String message, Object... args) {
125-
getLog().warn(String.format(message, args));
126-
}
127-
128-
protected void logInfo(String message, Object... args) {
129-
getLog().info(String.format(message, args));
130-
}
131-
132-
protected void logDebug(String message, Object... args) {
133-
getLog().debug(String.format(message, args));
119+
protected @Nullable String originalPomVersion() {
120+
return requireNonNull(project).getModel().getVersion();
134121
}
135122
}

src/main/java/q3769/maven/plugins/semver/Updater.java

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@
2323
*/
2424
package q3769.maven.plugins.semver;
2525

26+
import static java.util.Objects.requireNonNull;
2627
import static org.twdata.maven.mojoexecutor.MojoExecutor.*;
2728

2829
import com.github.zafarkhaja.semver.Version;
2930
import javax.inject.Inject;
30-
import lombok.NonNull;
3131
import org.apache.maven.plugin.BuildPluginManager;
3232
import org.apache.maven.plugin.MojoExecutionException;
3333
import org.apache.maven.plugin.MojoFailureException;
3434
import org.apache.maven.plugins.annotations.Parameter;
35+
import org.jspecify.annotations.Nullable;
3536

3637
/**
3738
* Updates POM version, based on current value
@@ -50,13 +51,13 @@ public abstract class Updater extends SemverMojo {
5051

5152
/** */
5253
@Inject
53-
protected BuildPluginManager pluginManager;
54+
protected @Nullable BuildPluginManager pluginManager;
5455

55-
private static boolean hasPreReleaseVersionOrBuildMetadata(@NonNull Version version) {
56+
private static boolean hasPreReleaseVersionOrBuildMetadata(Version version) {
5657
return version.preReleaseVersion().isPresent() || version.buildMetadata().isPresent();
5758
}
5859

59-
private static Version addSnapshotLabel(@NonNull Version version) {
60+
private static Version addSnapshotLabel(Version version) {
6061
return version.toBuilder().setPreReleaseVersion(SNAPSHOT).build();
6162
}
6263

@@ -77,33 +78,36 @@ protected void doExecute() throws MojoExecutionException, MojoFailureException {
7778
* @throws MojoFailureException if original version in POM is malformed
7879
*/
7980
private Version getUpdatedVersion() throws MojoFailureException {
80-
Version original = requireValidSemVer(project.getVersion());
81+
Version original = requireValidSemVer(requireNonNull(project).getVersion());
8182
Version updatedVersion = update(original);
8283
if (!addingSnapshotLabel) {
8384
return updatedVersion;
8485
}
8586
if (hasPreReleaseVersionOrBuildMetadata(updatedVersion)) {
86-
logError(
87-
"SNAPSHOT labeling requested for POM version %s but not honored, because SNAPSHOT may collide with other labels in the updated version %s",
88-
original, updatedVersion);
87+
getLog()
88+
.error(String.format(
89+
"SNAPSHOT labeling requested for POM version %s but not honored, because SNAPSHOT may collide with other labels in the updated version %s",
90+
original, updatedVersion));
8991
throw new MojoFailureException(
9092
String.format("SNAPSHOT may collide with other labels in %s", updatedVersion));
9193
}
92-
logInfo("labeling version %s as a SNAPSHOT...", updatedVersion);
94+
getLog().info(String.format("labeling version %s as a SNAPSHOT...", updatedVersion));
9395
return addSnapshotLabel(updatedVersion);
9496
}
9597

9698
/**
9799
* @param newVersion New version to be set in the POM file
98100
* @throws MojoExecutionException if unexpected error occurred while updating the POM file
99101
*/
100-
private void updatePomFile(@NonNull String newVersion) throws MojoExecutionException {
102+
private void updatePomFile(String newVersion) throws MojoExecutionException {
103+
requireNonNull(project);
101104
String originalVersion = project.getVersion();
102-
String executedGoal = mojo.getGoal();
105+
String executedGoal = requireNonNull(mojo).getGoal();
103106
if (newVersion.equals(originalVersion)) {
104-
logInfo(
105-
"Original POM version: %s remains unchanged after executing goal: %s",
106-
originalVersion, executedGoal);
107+
getLog()
108+
.info(String.format(
109+
"Original POM version: %s remains unchanged after executing goal: %s",
110+
originalVersion, executedGoal));
107111
return;
108112
}
109113
executeMojo(
@@ -112,9 +116,10 @@ private void updatePomFile(@NonNull String newVersion) throws MojoExecutionExcep
112116
goal("set"),
113117
configuration(
114118
element(name("generateBackupPoms"), "false"), element(name("newVersion"), newVersion)),
115-
executionEnvironment(project, session, pluginManager));
116-
logInfo(
117-
"Updated original POM version: %s into: %s after executing goal: %s",
118-
originalVersion, newVersion, executedGoal);
119+
executionEnvironment(project, requireNonNull(session), requireNonNull(pluginManager)));
120+
getLog()
121+
.info(String.format(
122+
"Updated original POM version: %s into: %s after executing goal: %s",
123+
originalVersion, newVersion, executedGoal));
119124
}
120125
}

src/main/java/q3769/maven/plugins/semver/mojos/CalendarMajor.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ protected Version update(Version original) throws MojoFailureException {
5151
try {
5252
return CalendarNormalVersionIncrementer.calendarIncrement(original, NormalVersion.MAJOR);
5353
} catch (Exception e) {
54-
logError(
55-
e,
56-
"Failed to calendar-increment the %s version of semver %s",
57-
NormalVersion.MAJOR,
58-
original);
54+
getLog()
55+
.error(
56+
String.format(
57+
"Failed to calendar-increment the %s version of semver %s",
58+
NormalVersion.MAJOR, original),
59+
e);
5960
throw new MojoFailureException(e);
6061
}
6162
}

src/main/java/q3769/maven/plugins/semver/mojos/CalendarMinor.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ protected Version update(Version original) throws MojoFailureException {
4444
try {
4545
return CalendarNormalVersionIncrementer.calendarIncrement(original, NormalVersion.MINOR);
4646
} catch (Exception e) {
47-
logError(
48-
e,
49-
"Failed to calendar-increment the %s version of semver %s",
50-
NormalVersion.MINOR,
51-
original);
47+
getLog()
48+
.error(
49+
String.format(
50+
"Failed to calendar-increment the %s version of semver %s",
51+
NormalVersion.MINOR, original),
52+
e);
5253
throw new MojoFailureException(e);
5354
}
5455
}

src/main/java/q3769/maven/plugins/semver/mojos/CalendarNormalVersionIncrementer.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
import java.time.Instant;
2929
import java.time.ZoneOffset;
3030
import java.time.format.DateTimeFormatter;
31-
import javax.annotation.Nonnull;
32-
import lombok.NonNull;
3331
import q3769.maven.plugins.semver.NormalVersion;
3432

3533
enum CalendarNormalVersionIncrementer {
@@ -52,8 +50,7 @@ enum CalendarNormalVersionIncrementer {
5250
* @param selectedNormalVersion to increment
5351
* @return new instance incremented to current date in UTC zone
5452
*/
55-
public static Version calendarIncrement(
56-
Version original, @Nonnull NormalVersion selectedNormalVersion) {
53+
public static Version calendarIncrement(Version original, NormalVersion selectedNormalVersion) {
5754
long selectedNormalVersionNumber = selectedNormalVersion.getNumber(original);
5855
Instant now = Instant.now();
5956
for (CalendarNormalVersionIncrementer formatter : values()) {
@@ -62,12 +59,12 @@ public static Version calendarIncrement(
6259
return selectedNormalVersion.incrementTo(updatedNormalVersionNumber, original);
6360
}
6461
}
65-
throw new UnsupportedOperationException(String.format(
62+
throw new IllegalArgumentException(String.format(
6663
"%s version %s in POM semver %s is not supported for calendar style increment - it has to be older than current date in UTC zone",
6764
selectedNormalVersion, selectedNormalVersionNumber, original));
6865
}
6966

70-
long format(@NonNull Instant instant) {
67+
long format(Instant instant) {
7168
return Long.parseLong(dateTimeFormatter.format(instant.atZone(ZoneOffset.UTC)));
7269
}
7370
}

src/main/java/q3769/maven/plugins/semver/mojos/CalendarPatch.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ protected Version update(Version original) throws MojoFailureException {
4444
try {
4545
return CalendarNormalVersionIncrementer.calendarIncrement(original, NormalVersion.PATCH);
4646
} catch (Exception e) {
47-
logError(
48-
e,
49-
"Failed to calendar-increment the %s version of semver %s",
50-
NormalVersion.PATCH,
51-
original);
47+
getLog()
48+
.error(
49+
String.format(
50+
"Failed to calendar-increment the %s version of semver %s",
51+
NormalVersion.PATCH, original),
52+
e);
5253
throw new MojoFailureException(e);
5354
}
5455
}

0 commit comments

Comments
 (0)