Skip to content

Accept -SNAPSHOT versions in Jvm.Support #1673

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

Merged
merged 2 commits into from
Apr 12, 2023
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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (

## [Unreleased]

### Added
* `Jvm.Support` now accepts `-SNAPSHOT` versions, treated as the non`-SNAPSHOT`. ([#1583](https://github.com/diffplug/spotless/issues/1583))

## [2.38.0] - 2023-04-06
### Added
* Support configuration of mirrors for P2 repositories in `EquoBasedStepBuilder` ([#1629](https://github.com/diffplug/spotless/issues/1629)).
Expand Down
6 changes: 5 additions & 1 deletion lib/src/main/java/com/diffplug/spotless/Jvm.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,11 @@ public int compare(V version0, V version1) {

private static <V> int[] convert(V versionObject) {
try {
return Arrays.asList(versionObject.toString().split("\\.")).stream().mapToInt(Integer::parseInt).toArray();
String versionString = versionObject.toString();
if (versionString.endsWith("-SNAPSHOT")) {
versionString = versionString.substring(0, versionString.length() - "-SNAPSHOT".length());
}
return Arrays.asList(versionString.split("\\.")).stream().mapToInt(Integer::parseInt).toArray();
} catch (Exception e) {
throw new IllegalArgumentException(String.format("Not a semantic version: %s", versionObject), e);
}
Expand Down
8 changes: 4 additions & 4 deletions testlib/src/test/java/com/diffplug/spotless/JvmTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void supportListsMinimumJvmIfOnlyHigherJvmSupported() {

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

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

for (String fmtVersion : Arrays.asList("1.2.4", "2")) {
for (String fmtVersion : Arrays.asList("1.2.4", "2", "1.2.5-SNAPSHOT")) {
String proposal = assertThrows(Exception.class, () -> {
testSupport.assertFormatterSupported(fmtVersion);
}).getMessage();
Expand All @@ -132,7 +132,7 @@ void supportProposesFormatterUpgrade() {
testSupport.add(Jvm.version() - 2, "1");
testSupport.add(requiredJvm, "2");
testSupport.add(Jvm.version() + 1, "3");
for (String fmtVersion : Arrays.asList("0", "1", "1.9")) {
for (String fmtVersion : Arrays.asList("0", "1", "1.9", "1.9-SNAPSHOT")) {
testSupport.assertFormatterSupported(fmtVersion);

String proposal = assertThrows(Exception.class, () -> {
Expand Down Expand Up @@ -168,7 +168,7 @@ void supportProposesJvmUpgrade() {
@Test
void supportAllowsExperimentalVersions() {
testSupport.add(Jvm.version(), "1.0");
for (String fmtVersion : Arrays.asList("1", "2.0")) {
for (String fmtVersion : Arrays.asList("1", "2.0", "1.1-SNAPSHOT", "2.0-SNAPSHOT")) {
testSupport.assertFormatterSupported(fmtVersion);

Exception testException = new Exception("Some test exception");
Expand Down