Skip to content

Commit

Permalink
fix - Refine findValidJavaHome logic (#1554)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiaaming authored Aug 5, 2024
1 parent 5763213 commit 78fd1d8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<repository location="https://download.eclipse.org/jdtls/snapshots/repository/latest/"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="https://download.eclipse.org/lsp4j/updates/releases/0.22.0/"/>
<repository location="https://download.eclipse.org/lsp4j/updates/releases/0.23.1/"/>
<unit id="org.eclipse.lsp4j" version="0.0.0"/>
</location>
</locations>
Expand Down
13 changes: 2 additions & 11 deletions extension/src/server/serverUtil.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
checkEnvJavaExecutable,
findValidJavaHome,
getConfigJavaImportGradleJavaHomeIfHigherThan,
getRedHatJavaEmbeddedJRE,
REQUIRED_JDK_VERSION,
} from "../util/config";
import { checkEnvJavaExecutable, findValidJavaHome, getRedHatJavaEmbeddedJRE } from "../util/config";
import { GRADLE_SERVER_BASE_JVM_OPTS } from "../constant";

export function getGradleServerCommand(): string {
Expand All @@ -27,10 +21,7 @@ export function quoteArg(arg: string): string {
}

export async function getGradleServerEnv(): Promise<ProcessEnv | undefined> {
const javaHome =
(await getConfigJavaImportGradleJavaHomeIfHigherThan(REQUIRED_JDK_VERSION)) ||
getRedHatJavaEmbeddedJRE() ||
(await findValidJavaHome());
const javaHome = getRedHatJavaEmbeddedJRE() || (await findValidJavaHome());
const env = { ...process.env };
if (javaHome) {
Object.assign(env, {
Expand Down
15 changes: 1 addition & 14 deletions extension/src/util/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,12 @@ export function getConfigJavaImportGradleJavaHome(): string | null {
return vscode.workspace.getConfiguration("java").get<string | null>("import.gradle.java.home", null);
}

export async function getConfigJavaImportGradleJavaHomeIfHigherThan(
requiredJdkVersion: number
): Promise<string | null> {
const javaHome = vscode.workspace.getConfiguration("java").get<string | null>("import.gradle.java.home", null);
if (javaHome) {
const javaVersion = await getMajorVersion(javaHome);
if (javaVersion >= requiredJdkVersion) {
return javaHome;
}
}
return null;
}

export function getJavaExecutablePathFromJavaHome(javaHome: string): string {
return path.join(javaHome, "bin", JAVA_FILENAME);
}

export async function findValidJavaHome(): Promise<string | undefined> {
const javaHomeGetters = [getJdtlsConfigJavaHome, getConfigJavaHome];
const javaHomeGetters = [getConfigJavaImportGradleJavaHome, getJdtlsConfigJavaHome, getConfigJavaHome];
let javaHome: string | undefined = undefined;
let javaVersion = 0;

Expand Down

0 comments on commit 78fd1d8

Please sign in to comment.