Skip to content

Commit

Permalink
Duplicate mise's logic for finding Java installations
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiX committed Oct 15, 2024
1 parent 6cab2be commit 989ae7d
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,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 @@ -165,6 +165,26 @@ private Collection<File> computeCandidateVMs(StandardVMType standardType) {
.collect(Collectors.toCollection(HashSet::new));
}

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 989ae7d

Please sign in to comment.