Skip to content

Commit

Permalink
enhancement - Notify user to install jdk when GradleServerEnv not fou…
Browse files Browse the repository at this point in the history
…nd (#1569)

Co-authored-by: Sheng Chen <[email protected]>
  • Loading branch information
Jiaaming and jdneo authored Aug 8, 2024
1 parent d94b31b commit 5ff06bb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 2 additions & 0 deletions extension/src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export const NO_JAVA_EXECUTABLE =

export const OPT_RESTART = "Restart";

export const INSTALL_JDK = "Install JDK";

export const GRADLE_SERVER_BASE_JVM_OPTS =
"--add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED";

Expand Down
15 changes: 10 additions & 5 deletions extension/src/server/GradleServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { commands } from "vscode";
import { sendInfo } from "vscode-extension-telemetry-wrapper";
import { getGradleServerCommand, getGradleServerEnv, quoteArg } from "./serverUtil";
import { Logger } from "../logger/index";
import { NO_JAVA_EXECUTABLE, OPT_RESTART } from "../constant";
import { redHatJavaInstalled } from "../util/config";
import { NO_JAVA_EXECUTABLE, OPT_RESTART, INSTALL_JDK } from "../constant";
import { extensionInstalled } from "../util/config";
import { BspProxy } from "../bs/BspProxy";
import { getRandomPipeName } from "../util/generateRandomPipeName";
const SERVER_LOGLEVEL_REGEX = /^\[([A-Z]+)\](.*)$/;
Expand Down Expand Up @@ -51,7 +51,7 @@ export class GradleServer {
}
public async start(): Promise<void> {
let startBuildServer = false;
if (redHatJavaInstalled()) {
if (extensionInstalled("redhat.java")) {
const isPrepared = this.bspProxy.prepareToStart();
if (isPrepared) {
startBuildServer = true;
Expand All @@ -65,12 +65,16 @@ export class GradleServer {
const cwd = this.context.asAbsolutePath("lib");
const cmd = path.join(cwd, getGradleServerCommand());
const env = await getGradleServerEnv();
const bundleDirectory = this.context.asAbsolutePath("server");
if (!env) {
sendInfo("", {
kind: "GradleServerEnvMissing",
});
await vscode.window.showErrorMessage(NO_JAVA_EXECUTABLE);
const choice = extensionInstalled("vscjava.vscode-java-pack") ? [INSTALL_JDK] : [];
vscode.window.showErrorMessage(NO_JAVA_EXECUTABLE, ...choice).then((selection) => {
if (selection === INSTALL_JDK) {
vscode.commands.executeCommand("java.installJdk");
}
});
return;
}
const args = [
Expand All @@ -80,6 +84,7 @@ export class GradleServer {
];
if (startBuildServer) {
const buildServerPipeName = this.bspProxy.getBuildServerPipeName();
const bundleDirectory = this.context.asAbsolutePath("server");
args.push(quoteArg(`--pipeName=${buildServerPipeName}`));
args.push(quoteArg(`--bundleDir=${bundleDirectory}`));
}
Expand Down
6 changes: 3 additions & 3 deletions extension/src/util/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ export async function findValidJavaHome(): Promise<string | undefined> {
return undefined;
}

export function redHatJavaInstalled(): boolean {
return !!vscode.extensions.getExtension("redhat.java");
export function extensionInstalled(extensionId: string): boolean {
return !!vscode.extensions.getExtension(extensionId);
}

export function getRedHatJavaEmbeddedJRE(): string | undefined {
if (!redHatJavaInstalled()) {
if (!extensionInstalled("redhat.java")) {
return undefined;
}

Expand Down

0 comments on commit 5ff06bb

Please sign in to comment.