Skip to content

Commit 5933b8e

Browse files
authored
use jdk-utils to detect installed jdks (#840)
Signed-off-by: Yan Zhang <[email protected]>
1 parent ef4013f commit 5933b8e

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@
379379
"expand-tilde": "^2.0.2",
380380
"fs-extra": "^9.0.1",
381381
"highlight.js": "10.5.0",
382+
"jdk-utils": "^0.2.1",
382383
"jquery": "^3.5.1",
383384
"lodash": "^4.17.21",
384385
"minimatch": "^3.0.4",

src/java-runtime/index.ts

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

4+
import { findRuntimes, IJavaRuntime } from "jdk-utils";
45
import * as _ from "lodash";
56
import * as path from "path";
67
import * as vscode from "vscode";
78
import { getExtensionContext, getNonce } from "../utils";
8-
import { findJavaHomes, JAVAC_FILENAME, JavaRuntime, verifyJavaHome } from "./utils/findJavaRuntime";
9-
import { resolveRequirements } from "./utils/upstreamApi";
9+
import { getProjectNameFromUri, getProjectType } from "../utils/jdt";
10+
import { ProjectType } from "../utils/webview";
1011
import { JavaRuntimeEntry, ProjectRuntimeEntry } from "./types";
12+
import { JAVAC_FILENAME, verifyJavaHome } from "./utils/findJavaRuntime";
1113
import { sourceLevelDisplayName } from "./utils/misc";
12-
import { ProjectType } from "../utils/webview";
13-
import { getProjectNameFromUri, getProjectType } from "../utils/jdt";
14+
import { resolveRequirements } from "./utils/upstreamApi";
1415

1516
let javaRuntimeView: vscode.WebviewPanel | undefined;
16-
let javaHomes: JavaRuntime[];
17+
let javaHomes: IJavaRuntime[];
1718

1819
export async function javaRuntimeCmdHandler(context: vscode.ExtensionContext, _operationId: string) {
1920
if (javaRuntimeView) {
@@ -211,13 +212,14 @@ export async function findJavaRuntimeEntries(): Promise<{
211212
javaHomeError?: string;
212213
}> {
213214
if (!javaHomes) {
214-
javaHomes = await findJavaHomes();
215+
const runtimes: IJavaRuntime[] = await findRuntimes({checkJavac: true, withVersion: true});
216+
javaHomes = runtimes.filter(r => r.hasJavac);
215217
}
216218
const javaRuntimes: JavaRuntimeEntry[] = javaHomes.map(elem => ({
217-
name: elem.home,
218-
fspath: elem.home,
219-
majorVersion: elem.version,
220-
type: elem.sources.join(","),
219+
name: elem.homedir,
220+
fspath: elem.homedir,
221+
majorVersion: elem.version?.major || 0,
222+
type: "from jdk-utils"
221223
})).sort((a, b) => b.majorVersion - a.majorVersion);
222224

223225
let javaDotHome;

0 commit comments

Comments
 (0)