Skip to content

Commit

Permalink
refactor: Support for sdkman for Linux (#856)
Browse files Browse the repository at this point in the history
  • Loading branch information
v1mkss authored Dec 9, 2024
1 parent 9c68c33 commit 4915ff4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion xmcl-runtime/java/JavaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<JavaState> implements IJavaService {
Expand Down Expand Up @@ -301,6 +301,7 @@ export class JavaService extends StatefulService<JavaState> 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())
}
Expand Down
6 changes: 6 additions & 0 deletions xmcl-runtime/java/javaPaths.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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'))
Expand Down

0 comments on commit 4915ff4

Please sign in to comment.