Skip to content

Commit

Permalink
fix - Task Server jdk search compatibility check (#1547)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiaaming authored Aug 1, 2024
1 parent e1325e9 commit 7f2f6d6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## 3.16.1
## What's Changed
* enhancement - Support debug test delegation by @jdneo in https://github.com/microsoft/vscode-gradle/pull/1536
* fix - Gradle build server cannot be started when path has spaces @Jiaaming in https://github.com/microsoft/vscode-gradle/pull/1542
* fix - Gradle build server cannot be started when path has spaces by @Jiaaming in https://github.com/microsoft/vscode-gradle/pull/1542
* fix - Fail to start if import.gradle.java.home jdk version lower than 17 by @Jiaaming in https://github.com/microsoft/vscode-gradle/pull/1547

## 3.16.0
## What's Changed
Expand Down
8 changes: 6 additions & 2 deletions extension/src/server/serverUtil.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {
checkEnvJavaExecutable,
findValidJavaHome,
getConfigJavaImportGradleJavaHome,
getConfigJavaImportGradleJavaHomeIfHigherThan,
getRedHatJavaEmbeddedJRE,
REQUIRED_JDK_VERSION,
} from "../util/config";
import { GRADLE_SERVER_BASE_JVM_OPTS } from "../constant";

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

export async function getGradleServerEnv(): Promise<ProcessEnv | undefined> {
const javaHome = getConfigJavaImportGradleJavaHome() || getRedHatJavaEmbeddedJRE() || (await findValidJavaHome());
const javaHome =
(await getConfigJavaImportGradleJavaHomeIfHigherThan(REQUIRED_JDK_VERSION)) ||
getRedHatJavaEmbeddedJRE() ||
(await findValidJavaHome());
const env = { ...process.env };
if (javaHome) {
Object.assign(env, {
Expand Down
15 changes: 14 additions & 1 deletion extension/src/util/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as fse from "fs-extra";
import * as path from "path";
import { findDefaultRuntimeFromSettings, getMajorVersion, listJdks } from "./jdkUtils";
type AutoDetect = "on" | "off";
const REQUIRED_JDK_VERSION = 17;
export const REQUIRED_JDK_VERSION = 17;

export function getConfigIsAutoDetectionEnabled(rootProject: RootProject): boolean {
return (
Expand All @@ -29,6 +29,19 @@ 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);
}
Expand Down

0 comments on commit 7f2f6d6

Please sign in to comment.