|
1 | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
2 | 2 | // Licensed under the MIT license. |
3 | 3 |
|
4 | | -import * as expandHomeDir from "expand-home-dir"; |
5 | | -import * as findJavaHome from "find-java-home"; |
6 | 4 | import * as opn from "opn"; |
7 | | -import * as path from "path"; |
8 | | -import * as pathExists from "path-exists"; |
9 | 5 | import * as vscode from "vscode"; |
10 | 6 | import { logger, Type } from "./logger"; |
11 | 7 |
|
@@ -114,24 +110,15 @@ export function formatErrorProperties(ex: any): IProperties { |
114 | 110 | return properties; |
115 | 111 | } |
116 | 112 |
|
117 | | -export function getJavaHome(): Promise<string> { |
118 | | - const EXE_SUFFIX = process.platform.startsWith("win") ? ".exe" : ""; |
119 | | - return new Promise((resolve, reject) => { |
120 | | - let javaHome: string = readJavaConfig() || process.env.JDK_HOME || process.env.JAVA_HOME; |
121 | | - if (javaHome) { |
122 | | - javaHome = expandHomeDir(javaHome); |
123 | | - if (pathExists.sync(javaHome) && pathExists.sync(path.resolve(javaHome, "bin", `javac${EXE_SUFFIX}`))) { |
124 | | - return resolve(javaHome); |
125 | | - } |
| 113 | +export async function getJavaHome(): Promise<string> { |
| 114 | + const extension = vscode.extensions.getExtension("redhat.java"); |
| 115 | + try { |
| 116 | + const extensionApi = await extension.activate(); |
| 117 | + if (extensionApi && extensionApi.javaRequirement) { |
| 118 | + return extensionApi.javaRequirement.java_home; |
126 | 119 | } |
| 120 | + } catch (ex) { |
| 121 | + } |
127 | 122 |
|
128 | | - findJavaHome((err, home) => { |
129 | | - resolve(err ? "" : expandHomeDir(home)); |
130 | | - }); |
131 | | - }); |
132 | | -} |
133 | | - |
134 | | -function readJavaConfig(): string { |
135 | | - const config = vscode.workspace.getConfiguration(); |
136 | | - return config.get<string>("java.home", null); |
| 123 | + return ""; |
137 | 124 | } |
0 commit comments