Skip to content

Commit 0172c75

Browse files
authored
update per new setting java.jdt.ls.java.home (#893)
1 parent 7f5ca54 commit 0172c75

File tree

3 files changed

+70
-417
lines changed

3 files changed

+70
-417
lines changed

src/java-runtime/index.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4-
import { findRuntimes, IJavaRuntime } from "jdk-utils";
4+
import { findRuntimes, getRuntime, IJavaRuntime } from "jdk-utils";
55
import * as _ from "lodash";
66
import * as path from "path";
77
import * as vscode from "vscode";
88
import { getExtensionContext, getNonce } from "../utils";
99
import { getProjectNameFromUri, getProjectType } from "../utils/jdt";
1010
import { ProjectType } from "../utils/webview";
1111
import { JavaRuntimeEntry, ProjectRuntimeEntry } from "./types";
12-
import { JAVAC_FILENAME, verifyJavaHome } from "./utils/findJavaRuntime";
1312
import { sourceLevelDisplayName } from "./utils/misc";
1413
import { resolveRequirements } from "./utils/upstreamApi";
1514

@@ -118,14 +117,14 @@ async function initializeJavaRuntimeView(context: vscode.ExtensionContext, webvi
118117
canSelectFiles: false,
119118
canSelectMany: false,
120119
canSelectFolders: true,
121-
title: "Specify Java Home"
120+
title: "Specify Java runtime to launch Language Server"
122121
});
123122
if (javaHomeUri) {
124123
const javaHome = javaHomeUri[0].fsPath;
125-
if (await verifyJavaHome(javaHome, JAVAC_FILENAME)) {
126-
await vscode.workspace.getConfiguration("java").update("home", javaHome, vscode.ConfigurationTarget.Global);
124+
if (await getRuntime(javaHome)) {
125+
await vscode.workspace.getConfiguration("java").update("jdt.ls.java.home", javaHome, vscode.ConfigurationTarget.Global);
127126
} else {
128-
await vscode.window.showWarningMessage(`${javaHome} is not a valid JDK home directory.`);
127+
await vscode.window.showWarningMessage(`${javaHome} is not a valid Java runtime home directory.`);
129128
}
130129
}
131130
break;
@@ -160,7 +159,7 @@ function getHtmlForWebview(scriptPath: string) {
160159
const scriptUri = (scriptPathOnDisk).with({ scheme: "vscode-resource" });
161160
// Use a nonce to whitelist which scripts can be run
162161
const nonce = getNonce();
163-
162+
164163
return `<!DOCTYPE html>
165164
<html lang="en">
166165
<head>
@@ -196,7 +195,7 @@ export async function validateJavaRuntime() {
196195
// * option b) use the same way to check java_home as vscode-java
197196
try {
198197
const runtime = await resolveRequirements();
199-
if (runtime.tooling_jre_version >=11 && runtime.tooling_jre) {
198+
if (runtime.tooling_jre_version >= 11 && runtime.tooling_jre) {
200199
return true;
201200
}
202201
} catch (error) {
@@ -212,7 +211,7 @@ export async function findJavaRuntimeEntries(): Promise<{
212211
javaHomeError?: string;
213212
}> {
214213
if (!javaHomes) {
215-
const runtimes: IJavaRuntime[] = await findRuntimes({checkJavac: true, withVersion: true});
214+
const runtimes: IJavaRuntime[] = await findRuntimes({ checkJavac: true, withVersion: true });
216215
javaHomes = runtimes.filter(r => r.hasJavac);
217216
}
218217
const javaRuntimes: JavaRuntimeEntry[] = javaHomes.map(elem => ({

0 commit comments

Comments
 (0)