Skip to content

Commit fb20ec7

Browse files
authored
Accept -SNAPSHOT versions in Jvm.Support (#1673)
2 parents 48771ab + ec9a414 commit fb20ec7

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1111

1212
## [Unreleased]
1313

14+
### Added
15+
* `Jvm.Support` now accepts `-SNAPSHOT` versions, treated as the non`-SNAPSHOT`. ([#1583](https://github.com/diffplug/spotless/issues/1583))
16+
1417
## [2.38.0] - 2023-04-06
1518
### Added
1619
* Support configuration of mirrors for P2 repositories in `EquoBasedStepBuilder` ([#1629](https://github.com/diffplug/spotless/issues/1629)).

lib/src/main/java/com/diffplug/spotless/Jvm.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,11 @@ public int compare(V version0, V version1) {
280280

281281
private static <V> int[] convert(V versionObject) {
282282
try {
283-
return Arrays.asList(versionObject.toString().split("\\.")).stream().mapToInt(Integer::parseInt).toArray();
283+
String versionString = versionObject.toString();
284+
if (versionString.endsWith("-SNAPSHOT")) {
285+
versionString = versionString.substring(0, versionString.length() - "-SNAPSHOT".length());
286+
}
287+
return Arrays.asList(versionString.split("\\.")).stream().mapToInt(Integer::parseInt).toArray();
284288
} catch (Exception e) {
285289
throw new IllegalArgumentException(String.format("Not a semantic version: %s", versionObject), e);
286290
}

testlib/src/test/java/com/diffplug/spotless/JvmTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void supportListsMinimumJvmIfOnlyHigherJvmSupported() {
9393

9494
assertNull(testSupport.getRecommendedFormatterVersion(), "No formatter version is supported");
9595

96-
for (String fmtVersion : Arrays.asList("1.2", "1.2.3")) {
96+
for (String fmtVersion : Arrays.asList("1.2", "1.2.3", "1.2-SNAPSHOT", "1.2.3-SNAPSHOT")) {
9797
String proposal = assertThrows(Exception.class, () -> {
9898
testSupport.assertFormatterSupported(fmtVersion);
9999
}).getMessage();
@@ -111,7 +111,7 @@ void supportListsMinimumJvmIfOnlyHigherJvmSupported() {
111111
assertThat(proposal).contains(String.format("try %s alternatives", TEST_NAME));
112112
}
113113

114-
for (String fmtVersion : Arrays.asList("1.2.4", "2")) {
114+
for (String fmtVersion : Arrays.asList("1.2.4", "2", "1.2.5-SNAPSHOT")) {
115115
String proposal = assertThrows(Exception.class, () -> {
116116
testSupport.assertFormatterSupported(fmtVersion);
117117
}).getMessage();
@@ -132,7 +132,7 @@ void supportProposesFormatterUpgrade() {
132132
testSupport.add(Jvm.version() - 2, "1");
133133
testSupport.add(requiredJvm, "2");
134134
testSupport.add(Jvm.version() + 1, "3");
135-
for (String fmtVersion : Arrays.asList("0", "1", "1.9")) {
135+
for (String fmtVersion : Arrays.asList("0", "1", "1.9", "1.9-SNAPSHOT")) {
136136
testSupport.assertFormatterSupported(fmtVersion);
137137

138138
String proposal = assertThrows(Exception.class, () -> {
@@ -168,7 +168,7 @@ void supportProposesJvmUpgrade() {
168168
@Test
169169
void supportAllowsExperimentalVersions() {
170170
testSupport.add(Jvm.version(), "1.0");
171-
for (String fmtVersion : Arrays.asList("1", "2.0")) {
171+
for (String fmtVersion : Arrays.asList("1", "2.0", "1.1-SNAPSHOT", "2.0-SNAPSHOT")) {
172172
testSupport.assertFormatterSupported(fmtVersion);
173173

174174
Exception testException = new Exception("Some test exception");

0 commit comments

Comments
 (0)