From 4915ff4606fd49a91c7826c2c1eaf1c247b0d39e Mon Sep 17 00:00:00 2001 From: Vova K Date: Mon, 9 Dec 2024 14:58:21 +0200 Subject: [PATCH] refactor: Support for sdkman for Linux (#856) --- xmcl-runtime/java/JavaService.ts | 3 ++- xmcl-runtime/java/javaPaths.ts | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/xmcl-runtime/java/JavaService.ts b/xmcl-runtime/java/JavaService.ts index 771e8fd62..117ce5fc8 100644 --- a/xmcl-runtime/java/JavaService.ts +++ b/xmcl-runtime/java/JavaService.ts @@ -15,7 +15,7 @@ import { readdirIfPresent } from '../util/fs' import { requireString } from '../util/object' import { SafeFile, createSafeFile } from '../util/persistance' import { ensureClass, getJavaArch } from './detectJVMArch' -import { getJavaPathsLinux, getJavaPathsOSX, getMojangJavaPaths, getOpenJdkPaths, getOrcaleJavaPaths, getZuluJdkPath } from './javaPaths' +import { getJavaPathsLinux, getJavaPathsLinuxSDK, getJavaPathsOSX, getMojangJavaPaths, getOpenJdkPaths, getOrcaleJavaPaths, getZuluJdkPath } from './javaPaths' @ExposeServiceKey(JavaServiceKey) export class JavaService extends StatefulService implements IJavaService { @@ -301,6 +301,7 @@ export class JavaService extends StatefulService implements IJavaServ ) } else if (this.app.platform.os === 'linux') { commonLocations.push(...await getJavaPathsLinux()) + commonLocations.push(...await getJavaPathsLinuxSDK()) } else if (this.app.platform.os === 'osx') { commonLocations.push(...await getJavaPathsOSX()) } diff --git a/xmcl-runtime/java/javaPaths.ts b/xmcl-runtime/java/javaPaths.ts index e14aedee6..f7734ed4a 100644 --- a/xmcl-runtime/java/javaPaths.ts +++ b/xmcl-runtime/java/javaPaths.ts @@ -1,5 +1,6 @@ import { lstat, readdir } from 'fs-extra' import { join } from 'path' +import { homedir } from 'os' export async function getMojangJavaPaths() { const runtimeDir = 'C:\\Program Files (x86)\\Minecraft Launcher\\runtime' @@ -30,6 +31,11 @@ export async function getJavaPathsLinux() { return files.map(f => join('/usr/lib/jvm', f, 'bin', 'java')) } +export async function getJavaPathsLinuxSDK() { + const files = await readdir(`${homedir}/.sdkman/candidates/java`).catch(() => []) + return files.map(f => join(`${homedir}/.sdkman/candidates/java`, f, 'bin', 'java')) +} + export async function getJavaPathsOSX() { const files = await readdir('/Library/Java/JavaVirtualMachines').catch(() => []) return files.map(f => join('/Library/Java/JavaVirtualMachines', f, 'Contents', 'Home', 'bin', 'java'))