Skip to content

Commit

Permalink
Read Sdkman candidates through getResourceAsStream
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Jan 2, 2025
1 parent 3f52b88 commit 11ddbd7
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 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,16 +25,18 @@
import org.openrewrite.text.PlainText;
import org.openrewrite.text.PlainTextParser;

import java.io.BufferedReader;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;

@Value
@EqualsAndHashCode(callSuper = false)
Expand Down Expand Up @@ -102,15 +104,14 @@ public Tree visit(@Nullable Tree tree, ExecutionContext ctx) {
}

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);
}
try (InputStream resourceAsStream = UpdateSdkMan.class.getResourceAsStream("/sdkman-java.csv");
InputStreamReader inputStreamReader = new InputStreamReader(resourceAsStream, StandardCharsets.UTF_8);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
return bufferedReader.lines().collect(toList());
} catch (IOException e) {
throw new RuntimeException(e);
}
throw new IllegalStateException("Could not find /sdkman-java.csv file");

}
};
return Preconditions.check(new FindSourceFiles(".sdkmanrc"), visitor);
Expand Down

0 comments on commit 11ddbd7

Please sign in to comment.