Skip to content

Commit

Permalink
Read SDKMAN! Java candidates from a file maintained on disk
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Dec 27, 2024
1 parent 57175ce commit b8bf36d
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 12 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/sdkman-candidates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
name: Update SDKMAN! candidates

on:
workflow_dispatch: {}
schedule:
- cron: 0 10 * * MON

jobs:
update-candidates:
if: github.event_name != 'schedule' || github.repository_owner == 'openrewrite'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-java@v4
with:
cache: 'gradle'
distribution: 'temurin'
java-version: '17'

- name: Update candidates
run: curl https://api.sdkman.io/2/candidates/java/linux/versions/all | tr , '\n' > src/main/resources/sdkman-java.csv

# Commit and push
- name: configure-git-user
run: |
git config user.email "team@moderne.io"
git config user.name "team-moderne[bot]"
- name: Create timestamp
run: echo "NOW=$(date +'%Y-%m-%dT%H%M')" >> $GITHUB_ENV
- name: Commit and push
run: |
git add src/main/resources/sdkman-java.csv
git diff --quiet HEAD || (git commit -m "[Auto] SDKMAN! Java candidates as of ${{ env.NOW }}" && git push origin main)
31 changes: 19 additions & 12 deletions src/main/java/org/openrewrite/java/migrate/UpdateSdkMan.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
import org.openrewrite.text.PlainText;
import org.openrewrite.text.PlainTextParser;

import java.util.Arrays;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -35,15 +39,6 @@
@Value
@EqualsAndHashCode(callSuper = false)
public class UpdateSdkMan extends Recipe {
private static final String SDKMAN_CONFIG_FILE_PATTERN = ".sdkmanrc";

/**
* Retrieve from https://api.sdkman.io/2/candidates/java/linuxx64/versions/all
* TODO: Investifate the best way to get the latest versions from SDKMAN
*/
private static final List<String> SDKMAN_CANDIDATES_LIST = Arrays.asList(
"11.0.14.1-jbr,11.0.15-trava,11.0.25-albba,11.0.25-amzn,11.0.25-kona,11.0.25-librca,11.0.25-ms,11.0.25-sapmchn,11.0.25-sem,11.0.25-tem,11.0.25-zulu,11.0.25.fx-librca,11.0.25.fx-zulu,17.0.12-graal,17.0.12-jbr,17.0.12-oracle,17.0.13-albba,17.0.13-amzn,17.0.13-kona,17.0.13-librca,17.0.13-ms,17.0.13-sapmchn,17.0.13-sem,17.0.13-tem,17.0.13-zulu,17.0.13.crac-librca,17.0.13.crac-zulu,17.0.13.fx-librca,17.0.13.fx-zulu,17.0.9-graalce,21.0.2-graalce,21.0.2-open,21.0.5-amzn,21.0.5-graal,21.0.5-jbr,21.0.5-kona,21.0.5-librca,21.0.5-ms,21.0.5-oracle,21.0.5-sapmchn,21.0.5-sem,21.0.5-tem,21.0.5-zulu,21.0.5.crac-librca,21.0.5.crac-zulu,21.0.5.fx-librca,21.0.5.fx-zulu,22.0.2-oracle,22.1.0.1.r11-gln,22.1.0.1.r17-gln,22.3.5.r11-nik,22.3.5.r17-mandrel,22.3.5.r17-nik,23-open,23.0.1-amzn,23.0.1-graal,23.0.1-graalce,23.0.1-librca,23.0.1-oracle,23.0.1-sapmchn,23.0.1-tem,23.0.1-zulu,23.0.1.crac-zulu,23.0.1.fx-librca,23.0.1.fx-zulu,23.0.6.fx-nik,23.0.6.r17-mandrel,23.0.6.r17-nik,23.1.5.fx-nik,23.1.5.r21-mandrel,23.1.5.r21-nik,24.0.2.r22-mandrel,24.1.1.r23-mandrel,24.1.1.r23-nik,24.ea.22-graal,24.ea.23-graal,24.ea.24-graal,24.ea.26-open,24.ea.27-open,24.ea.28-open,24.ea.29-open,25.ea.1-graal,25.ea.1-open,25.ea.2-open,25.ea.3-open,6.0.119-zulu,7.0.352-zulu,8.0.282-trava,8.0.432-albba,8.0.432-amzn,8.0.432-kona,8.0.432-librca,8.0.432-sem,8.0.432-tem,8.0.432-zulu,8.0.432.fx-librca,8.0.432.fx-zulu"
.split(","));

@Option(displayName = "Java version", description = "The Java version to update to.", example = "17")
@Nullable
Expand Down Expand Up @@ -91,15 +86,27 @@ public Tree visit(@Nullable Tree tree, ExecutionContext ctx) {
if (matcher.find()) {
String ver = newVersion == null ? matcher.group(1) : newVersion;
String dist = newDistribution == null ? matcher.group(2) : newDistribution;
for (String candidate : SDKMAN_CANDIDATES_LIST) {
for (String candidate : readSdkmanJavaCandidates()) {
if (candidate.startsWith(ver) && candidate.endsWith(dist)) {
return plainText.withText(matcher.replaceFirst("java=" + candidate));
}
}
}
return sourceFile;
}

private List<String> readSdkmanJavaCandidates() {
URL resource = getClass().getResource("/sdkman-java.csv");
if (resource != null) {
try {
return Files.readAllLines(Paths.get(resource.toURI()));
} catch (IOException | URISyntaxException e) {
throw new RuntimeException(e);
}
}
throw new IllegalStateException("Could not find /sdkman-java.csv file");
}
};
return Preconditions.check(new FindSourceFiles(SDKMAN_CONFIG_FILE_PATTERN), visitor);
return Preconditions.check(new FindSourceFiles(".sdkmanrc"), visitor);
}
}
99 changes: 99 additions & 0 deletions src/main/resources/sdkman-java.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
11.0.14.1-jbr
11.0.15-trava
11.0.25-albba
11.0.25-amzn
11.0.25-kona
11.0.25-librca
11.0.25-ms
11.0.25-sapmchn
11.0.25-sem
11.0.25-tem
11.0.25-zulu
11.0.25.fx-librca
11.0.25.fx-zulu
17.0.12-graal
17.0.12-jbr
17.0.12-oracle
17.0.13-albba
17.0.13-amzn
17.0.13-kona
17.0.13-librca
17.0.13-ms
17.0.13-sapmchn
17.0.13-sem
17.0.13-tem
17.0.13-zulu
17.0.13.crac-librca
17.0.13.crac-zulu
17.0.13.fx-librca
17.0.13.fx-zulu
17.0.9-graalce
21.0.2-graalce
21.0.2-open
21.0.5-amzn
21.0.5-graal
21.0.5-jbr
21.0.5-kona
21.0.5-librca
21.0.5-ms
21.0.5-oracle
21.0.5-sapmchn
21.0.5-sem
21.0.5-tem
21.0.5-zulu
21.0.5.crac-librca
21.0.5.crac-zulu
21.0.5.fx-librca
21.0.5.fx-zulu
22.0.2-oracle
22.1.0.1.r11-gln
22.1.0.1.r17-gln
22.3.5.r11-nik
22.3.5.r17-mandrel
22.3.5.r17-nik
23-open
23.0.1-amzn
23.0.1-graal
23.0.1-graalce
23.0.1-librca
23.0.1-oracle
23.0.1-sapmchn
23.0.1-tem
23.0.1-zulu
23.0.1.crac-zulu
23.0.1.fx-librca
23.0.1.fx-zulu
23.0.6.fx-nik
23.0.6.r17-mandrel
23.0.6.r17-nik
23.1.5.fx-nik
23.1.5.r21-mandrel
23.1.5.r21-nik
24.0.2.r22-mandrel
24.1.1.r23-mandrel
24.1.1.r23-nik
24.ea.22-graal
24.ea.23-graal
24.ea.24-graal
24.ea.25-graal
24.ea.26-open
24.ea.27-open
24.ea.28-open
24.ea.29-open
25.ea.1-graal
25.ea.1-open
25.ea.2-graal
25.ea.2-open
25.ea.3-open
6.0.119-zulu
7.0.352-zulu
8.0.282-trava
8.0.432-albba
8.0.432-amzn
8.0.432-kona
8.0.432-librca
8.0.432-sem
8.0.432-tem
8.0.432-zulu
8.0.432.fx-librca
8.0.432.fx-zulu

0 comments on commit b8bf36d

Please sign in to comment.