Skip to content

Commit caaaeb9

Browse files
authored
Fix version hint functionality and date format locale issues (#94)
- Fix version hint processing to correctly add SNAPSHOT qualifier - Modify findHighestVersionFromHints to preserve original version strings - Apply mayAddSnapshotQualifier to version hints as intended - Fix date formatting to use English locale consistently - Update test assertions to provide better error messages Version hints now work as designed: tags matching the hint pattern are treated as if the previous commit was tagged with that version, and SNAPSHOT qualifier is added when ahead of that commit.
1 parent b40e67f commit caaaeb9

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

it/extension3-its/src/it/it-dynamic-versioning-version-hint-custom/verify.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ assert matcher.find() : "Version information not found in log file"
1414
// Extract the version from the matched group
1515
def actualVersion = matcher[0][1]
1616

17-
// Should use the highest version hint tag with custom pattern (3.2.0)
17+
// Should use the highest version hint tag with custom pattern (3.2.0) and add SNAPSHOT since we're ahead
1818
// The 5.0.0-SNAPSHOT tag should be ignored because it doesn't match "hint-${version}" pattern
19-
def expectedVersion = '3.2.0'
19+
def expectedVersion = '3.2.0-SNAPSHOT'
2020

2121
assert actualVersion == expectedVersion : "Expected version '${expectedVersion}', but found '${actualVersion}'"

it/extension3-its/src/it/it-dynamic-versioning-version-hint-snapshot/verify.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ assert matcher.find() : "Version information not found in log file"
1414
// Extract the version from the matched group
1515
def actualVersion = matcher[0][1]
1616

17-
// Should use the highest version hint tag (4.2.0)
18-
def expectedVersion = '4.2.0'
17+
// Should use the highest version hint tag (4.2.0) and add SNAPSHOT since we're ahead
18+
def expectedVersion = '4.2.0-SNAPSHOT'
1919

2020
assert actualVersion == expectedVersion : "Expected version '${expectedVersion}', but found '${actualVersion}'"

sources/jgit-source/src/main/java/eu/maveniverse/maven/nisse/source/jgit/JGitPropertySource.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.Comparator;
1717
import java.util.HashMap;
1818
import java.util.List;
19+
import java.util.Locale;
1920
import java.util.Map;
2021
import java.util.Optional;
2122
import java.util.regex.Pattern;
@@ -202,7 +203,7 @@ private DateTimeFormatter resolveDateTimeFormatter(NisseConfiguration configurat
202203

203204
switch (dateFormat.toLowerCase()) {
204205
case "git":
205-
return DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss yyyy Z");
206+
return DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss yyyy Z", Locale.ENGLISH);
206207
case "iso8601":
207208
return DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
208209
case "iso8601-offset":
@@ -218,19 +219,19 @@ private DateTimeFormatter resolveDateTimeFormatter(NisseConfiguration configurat
218219
"Invalid custom date format pattern '{}', falling back to default 'git' format",
219220
customPattern,
220221
e);
221-
return DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss yyyy Z");
222+
return DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss yyyy Z", Locale.ENGLISH);
222223
}
223224
} else {
224225
logger.warn(
225226
"Custom date format specified but no pattern provided via '{}', falling back to default 'git' format",
226227
JGIT_CONF_SYSTEM_PROPERTY_DATE_FORMAT_PATTERN);
227-
return DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss yyyy Z");
228+
return DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss yyyy Z", Locale.ENGLISH);
228229
}
229230
default:
230231
logger.warn(
231232
"Unknown date format '{}', falling back to default 'git' format. Supported formats: git, iso8601, iso8601-offset, custom",
232233
dateFormat);
233-
return DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss yyyy Z");
234+
return DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss yyyy Z", Locale.ENGLISH);
234235
}
235236
}
236237

@@ -248,6 +249,9 @@ public String resolveDynamicVersion(NisseConfiguration configuration, Repository
248249
Optional<String> versionHint = findVersionHint(configuration, repository);
249250
if (versionHint.isPresent()) {
250251
vi = new VersionInformation(versionHint.get());
252+
// Version hints are treated as if the previous commit was tagged,
253+
// so we should add SNAPSHOT qualifier since we're ahead of that "previous commit"
254+
vi = mayAddSnapshotQualifier(configuration, vi);
251255
logger.debug("Using version hint from tag: {}", versionHint.get());
252256
} else {
253257
vi = getVersionFromGit(configuration, repository);
@@ -413,9 +417,6 @@ protected List<String> findVersionHintTags(Git git, String hintPattern) throws G
413417
* @return Optional highest version string
414418
*/
415419
protected Optional<String> findHighestVersionFromHints(List<String> hintVersions) {
416-
return hintVersions.stream()
417-
.map(this::version)
418-
.max(Comparator.comparing(version -> version))
419-
.map(Version::toString);
420+
return hintVersions.stream().max(Comparator.comparing(this::version));
420421
}
421422
}

sources/jgit-source/src/test/java/eu/maveniverse/maven/nisse/source/jgit/JGitPropertySourceTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ void testDefaultDateFormat() throws IOException {
3131
System.out.println("Default date format: " + dateValue);
3232
// Default format should match: EEE MMM dd HH:mm:ss yyyy Z
3333
// Example: Mon May 27 18:20:45 2024 +0200
34-
assertTrue(dateValue.matches("\\w{3} \\w{3} \\d{2} \\d{2}:\\d{2}:\\d{2} \\d{4} [+-]\\d{4}"));
34+
assertTrue(
35+
dateValue.matches("\\w{3} \\w{3} \\d{2} \\d{2}:\\d{2}:\\d{2} \\d{4} [+-]\\d{4}"),
36+
"Expected date format 'EEE MMM dd HH:mm:ss yyyy Z' but got: " + dateValue);
3537
}
3638
}
3739

@@ -108,7 +110,9 @@ void testInvalidDateFormatFallsBackToDefault() throws IOException {
108110
String dateValue = properties.get("date");
109111
System.out.println("Fallback date format: " + dateValue);
110112
// Should fall back to default git format
111-
assertTrue(dateValue.matches("\\w{3} \\w{3} \\d{2} \\d{2}:\\d{2}:\\d{2} \\d{4} [+-]\\d{4}"));
113+
assertTrue(
114+
dateValue.matches("\\w{3} \\w{3} \\d{2} \\d{2}:\\d{2}:\\d{2} \\d{4} [+-]\\d{4}"),
115+
"Expected fallback date format 'EEE MMM dd HH:mm:ss yyyy Z' but got: " + dateValue);
112116
}
113117
}
114118

0 commit comments

Comments
 (0)