Skip to content

Commit

Permalink
Duplicate mise's logic for finding Java installations (#538)
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiX authored Oct 28, 2024
1 parent 9e1b75a commit c73de59
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private Collection<File> computeCandidateVMs(StandardVMType standardType) {
rootDirectories.add(new File("/usr/lib/jvm")); //$NON-NLS-1$
}
rootDirectories.add(new File(System.getProperty("user.home"), ".sdkman/candidates/java")); //$NON-NLS-1$ //$NON-NLS-2$
rootDirectories.add(new File(System.getProperty("user.home"), ".local/share/mise/installs/java")); //$NON-NLS-1$ //$NON-NLS-2$
rootDirectories.add(new File(miseDataDir(), "installs/java")); //$NON-NLS-1$

Set<File> directories = rootDirectories.stream().filter(File::isDirectory)
.map(dir -> dir.listFiles(File::isDirectory))
Expand Down Expand Up @@ -180,6 +180,26 @@ private void computeWindowsCandidates(Collection<File> rootDirectories) {
.collect(Collectors.toList()));
}

private static File miseDataDir() {
String miseDataDir = System.getenv("MISE_DATA_DIR"); //$NON-NLS-1$
return miseDataDir != null ? new File(miseDataDir) : new File(xdgDataHome(), "mise"); //$NON-NLS-1$
}

private static File xdgDataHome() {
String xdgDataHome = System.getenv("XDG_DATA_HOME"); //$NON-NLS-1$
if (Platform.OS_WIN32.equals(Platform.getOS())) {
if (xdgDataHome == null) {
xdgDataHome = System.getenv("LOCALAPPDATA"); //$NON-NLS-1$
}
if (xdgDataHome == null) {
return new File(System.getProperty("user.home"), "AppData/Local"); //$NON-NLS-1$ //$NON-NLS-2$
}
} else if (xdgDataHome == null) {
return new File(System.getProperty("user.home"), ".local/share"); //$NON-NLS-1$ //$NON-NLS-2$
}
return new File(xdgDataHome);
}

private static Set<File> knownVMs() {
return Stream.of(JavaRuntime.getVMInstallTypes())
.map(IVMInstallType::getVMInstalls)
Expand Down

0 comments on commit c73de59

Please sign in to comment.