Skip to content

Commit 9a05b66

Browse files
committed
+ better error messages
1 parent 5bddaa6 commit 9a05b66

15 files changed

Lines changed: 65 additions & 45 deletions

pom.xml

Lines changed: 2 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.202408091532</version>
33+
<version>20240116.0.202408091618</version>
3434
<packaging>maven-plugin</packaging>
3535

3636
<name>semver-maven-plugin</name>
@@ -229,7 +229,7 @@
229229
<plugin>
230230
<groupId>io.github.q3769</groupId>
231231
<artifactId>semver-maven-plugin</artifactId>
232-
<version>20240116.0.202408091532</version>
232+
<version>20240116.0.202408091618</version>
233233
</plugin>
234234
<plugin>
235235
<groupId>org.apache.maven.plugins</groupId>

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ protected String originalPomVersion() {
113113
return project.getOriginalModel().getVersion();
114114
}
115115

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+
116124
protected void logWarn(String message, Object... args) {
117125
getLog().warn(String.format(message, args));
118126
}

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@
4040
*/
4141
public abstract class Updater extends SemverMojo {
4242
private static final String SNAPSHOT = "SNAPSHOT";
43+
4344
/**
4445
* Flag to append SNAPSHOT as the prerelease label in the target version. Expected to be passed in
4546
* as a -D parameter from CLI.
4647
*/
4748
@Parameter(property = "snapshot", defaultValue = "false")
4849
protected boolean addingSnapshotLabel;
50+
4951
/** */
5052
@Component
5153
protected BuildPluginManager pluginManager;
@@ -67,14 +69,17 @@ protected void doExecute() throws MojoExecutionException, MojoFailureException {
6769
* @throws MojoFailureException if original version in POM is malformed
6870
*/
6971
private Version getUpdatedVersion() throws MojoFailureException {
70-
Version updatedVersion = update(requireValidSemVer(project.getVersion()));
72+
Version original = requireValidSemVer(project.getVersion());
73+
Version updatedVersion = update(original);
7174
if (!addingSnapshotLabel) {
7275
return updatedVersion;
7376
}
7477
if (hasPreReleaseVersionOrBuildMetadata(updatedVersion)) {
75-
throw new MojoFailureException(String.format(
76-
"snapshot labeling requested for updated semver %s but not honored, because snapshot flag only supports normal version number increments with no labels",
77-
updatedVersion));
78+
logError(
79+
"SNAPSHOT labeling requested for POM version %s but not honored, because SNAPSHOT may collide with other labels in the updated version %s",
80+
original, updatedVersion);
81+
throw new MojoFailureException(
82+
String.format("SNAPSHOT may collide with other labels in %s", updatedVersion));
7883
}
7984
logInfo("labeling version %s as a SNAPSHOT...", updatedVersion);
8085
return addSnapshotLabel(updatedVersion);

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 CalendarVersionFormatter.calendarIncrement(original, SemverNormalVersion.MAJOR);
5353
} catch (Exception e) {
54-
throw new MojoFailureException(
55-
String.format(
56-
"Failed to increment the %s version of semver %s",
57-
SemverNormalVersion.MAJOR, original),
58-
e);
54+
logError(
55+
e,
56+
"Failed to calendar-increment the %s version of semver %s",
57+
SemverNormalVersion.MAJOR,
58+
original);
59+
throw new MojoFailureException(e);
5960
}
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 CalendarVersionFormatter.calendarIncrement(original, SemverNormalVersion.MINOR);
4646
} catch (Exception e) {
47-
throw new MojoFailureException(
48-
String.format(
49-
"Failed to increment the %s version of semver %s",
50-
SemverNormalVersion.MINOR, original),
51-
e);
47+
logError(
48+
e,
49+
"Failed to calendar-increment the %s version of semver %s",
50+
SemverNormalVersion.MINOR,
51+
original);
52+
throw new MojoFailureException(e);
5253
}
5354
}
5455
}

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 CalendarVersionFormatter.calendarIncrement(original, SemverNormalVersion.PATCH);
4646
} catch (Exception e) {
47-
throw new MojoFailureException(
48-
String.format(
49-
"Failed to increment the %s version of semver %s",
50-
SemverNormalVersion.PATCH, original),
51-
e);
47+
logError(
48+
e,
49+
"Failed to calendar-increment the %s version of semver %s",
50+
SemverNormalVersion.PATCH,
51+
original);
52+
throw new MojoFailureException(e);
5253
}
5354
}
5455
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ protected Version update(@NonNull Version original) throws MojoFailureException
4343
try {
4444
return original.nextMajorVersion();
4545
} catch (Exception e) {
46-
throw new MojoFailureException(
47-
"Failed to increment the major version of semver " + original, e);
46+
logError(e, "Failed to increment the major version of semver %s", original);
47+
throw new MojoFailureException(e);
4848
}
4949
}
5050
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ protected Version update(@NonNull Version original) throws MojoFailureException
4343
try {
4444
return original.nextMinorVersion();
4545
} catch (Exception e) {
46-
throw new MojoFailureException(
47-
"Failed to increment the minor version of semver " + original, e);
46+
logError(e, "Failed to increment the minor version of semver %s", original);
47+
throw new MojoFailureException(e);
4848
}
4949
}
5050
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ protected Version update(@NonNull Version original) throws MojoFailureException
4343
try {
4444
return original.nextPatchVersion();
4545
} catch (Exception e) {
46-
throw new MojoFailureException(
47-
"Failed to increment the patch version of semver " + original, e);
46+
logError(e, "Failed to increment the patch version of semver %s", original);
47+
throw new MojoFailureException(e);
4848
}
4949
}
5050
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,9 @@ protected Version update(final Version original) throws MojoFailureException {
6767
try {
6868
incrementedVersion = increment(other, pomIncrementedNormalVersion);
6969
} catch (Exception e) {
70-
throw new MojoFailureException(
71-
String.format(
72-
"Failed to merge the provided version %s with the POM version %s", other, original),
73-
e);
70+
logError(
71+
e, "Failed to merge the provided version %s with the POM version %s", other, original);
72+
throw new MojoFailureException(e);
7473
}
7574
logDebug(
7675
"Incrementing provided version %s on POM semver incremented normal version %s, provisional merge version: %s",

0 commit comments

Comments
 (0)