Skip to content

Commit 5b955f6

Browse files
authored
Remove java runtime from overview (#175)
* Remove java runtime from overview Signed-off-by: Rome Li <[email protected]> * Resolve comments Signed-off-by: Rome Li <[email protected]>
1 parent cc8781f commit 5b955f6

File tree

5 files changed

+26
-62
lines changed

5 files changed

+26
-62
lines changed

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async function initializeExtension(operationId: string, context: vscode.Extensio
2929
await showReleaseNotesOnStart(context);
3030

3131
if (!await validateJavaRuntime()) {
32-
vscode.commands.executeCommand("java.overview");
32+
vscode.commands.executeCommand("java.runtime");
3333
}
3434
}
3535

src/java-runtime/assets/java.runtime.entries.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,23 @@ import * as React from "react";
55
import { JavaRuntimeEntry } from "../types";
66

77
export const JavaRuntimeEntryPanel = (props: JavaRuntimeEntry[]) => {
8-
const current = props.findIndex(entry => entry.isValid || false);
8+
const currentIndex = props.findIndex(entry => !!entry.path);
9+
let errorIndex = -1;
10+
if (currentIndex !== -1 && !props[currentIndex].isValid) {
11+
errorIndex = currentIndex;
12+
}
13+
914
const entries = props.map((entry, index) =>
10-
<tr>
15+
<tr key={index}>
1116
<th scope="row">{index + 1}</th>
1217
<td>
13-
{!entry.path && <em>*Empty*</em>}
18+
{!entry.path && <em>{"<Empty>"}</em>}
1419
{entry.path}
15-
{index === current && <span className="badge badge-pill badge-primary">Current</span>}
16-
{entry.path && !entry.isValid && <span className="badge badge-pill badge-secondary" title={entry.hint}>Invalid</span>}
20+
&nbsp;
21+
{index === currentIndex && errorIndex === -1 && <span className="badge badge-pill badge-primary">Current</span>}
22+
{entry.path && !entry.isValid && errorIndex === -1 && <span className="badge badge-pill badge-secondary" title={entry.hint}>Invalid</span>}
23+
{entry.path && errorIndex === index && <span className="badge badge-pill badge-danger" title={entry.hint}>Error</span>}
24+
{!!entry.path && !!entry.hint && <div><em className={errorIndex === index ? "text-danger" : "text-warning"}>{entry.hint}</em></div>}
1725
</td>
1826
<td>
1927
{entry.name}

src/java-runtime/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ async function checkJdkInstallation(javaHome: string | undefined) {
167167

168168
export async function validateJavaRuntime() {
169169
const entries = await findJavaRuntimeEntries();
170+
// Java LS uses the first non-empty path to locate the JDK
171+
const currentPathIndex = entries.findIndex(entry => !_.isEmpty(entry.path));
172+
if (currentPathIndex !== -1) {
173+
return entries[currentPathIndex].isValid;
174+
}
175+
170176
return _.some(entries, entry => entry.isValid);
171177
}
172178

@@ -175,14 +181,18 @@ export async function findJavaRuntimeEntries(): Promise<JavaRuntimeEntry[]> {
175181
return Promise.all(_.map(entries, async entry => {
176182
if (!await checkJdkInstallation(entry.path)) {
177183
entry.isValid = false;
178-
entry.hint = "This path does not point to a JDK.";
184+
entry.hint = "This path is not pointing to a JDK.";
185+
const pathObject = path.parse(entry.path||"");
186+
if (pathObject.name && pathObject.name.toLowerCase() === "bin") {
187+
entry.hint += " Try remove the \"bin\" from the path.";
188+
}
179189
return entry;
180190
}
181191

182192
const version = await getJavaVersion(entry.path);
183193
if (version < MIN_JDK_VERSION) {
184194
entry.isValid = false;
185-
entry.hint = `JDK 8+ is required while the path points to ${version}`;
195+
entry.hint = `JDK 8+ is required while the path is pointing to version ${version}`;
186196
return entry;
187197
}
188198

src/overview/assets/index.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,16 @@
44
import $ = require("jquery");
55
import "../../assets/vscode.scss";
66
import "bootstrap/js/src/tab";
7-
import bytes = require("bytes");
87

98
window.addEventListener("message", event => {
109
if (event.data.command === "syncExtensionVisibility") {
1110
syncExtensionVisibility(event.data.installedExtensions);
1211
syncSectionVisibility();
1312
} else if (event.data.command === "setOverviewVisibility") {
1413
$("#showWhenUsingJava").prop("checked", event.data.visibility);
15-
} else if (event.data.command === "showJavaRuntimePanel") {
16-
$("#javaRuntimePanel").removeClass("d-none");
17-
} else if (event.data.command === "applyJdkInfo") {
18-
applyJdkInfo(event.data.jdkInfo);
1914
}
2015
});
2116

22-
function applyJdkInfo(jdkInfo: any) {
23-
let binary = jdkInfo.binaries[0];
24-
let downloadLink = binary.installer_link || binary.binary_link;
25-
$("#jdkOs").text(binary.os);
26-
$("#jdkArch").text(binary.architecture);
27-
$("#jdkReleaseName").text(jdkInfo.release_name);
28-
$("#jdkDownloadSize").text(bytes(binary.binary_size, {unitSeparator: " "}));
29-
30-
let encodedLink = `command:java.helper.openUrl?${encodeURIComponent(JSON.stringify(downloadLink))}`;
31-
$("#jdkDownloadLink").attr("href", encodedLink);
32-
33-
$("#jdkSpinner").addClass("d-none");
34-
$("#jdkDownloadLink").removeClass("d-none");
35-
}
36-
3717
function syncExtensionVisibility(extensions: any) {
3818
$("div[ext]").each((index, elem) => {
3919
const anchor = $(elem);
@@ -66,14 +46,6 @@ $("#showWhenUsingJava").change(function () {
6646
});
6747
});
6848

69-
function requestJdkInfo(jdkVersion: string, jvmImpl: string) {
70-
vscode.postMessage({
71-
command: "requestJdkInfo",
72-
jdkVersion: jdkVersion,
73-
jvmImpl: jvmImpl
74-
});
75-
}
76-
7749
function installExtension(extName: string, displayName: string) {
7850
vscode.postMessage({
7951
command: "installExtension",
@@ -85,9 +57,3 @@ function installExtension(extName: string, displayName: string) {
8557
$("div[ext]").click(function () {
8658
installExtension($(this).attr("ext"), $(this).attr("displayName"));
8759
});
88-
89-
$("input[type=radio]").change(() => {
90-
$("#jdkSpinner").removeClass("d-none");
91-
$("#jdkDownloadLink").addClass("d-none");
92-
requestJdkInfo($("input[name=jdkVersion]:checked").val() + "", $("input[name=jvmImpl]:checked").val() + "");
93-
});

src/overview/index.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import * as path from "path";
77

88
import { instrumentOperation, sendInfo } from "vscode-extension-telemetry-wrapper";
99
import { getExtensionContext } from "../utils";
10-
import { validateJavaRuntime, suggestOpenJdk } from "../java-runtime";
1110
import { loadTextFromFile } from "../utils";
1211

1312
let overviewView: vscode.WebviewPanel | undefined;
@@ -80,29 +79,10 @@ async function initializeOverviewView(context: vscode.ExtensionContext, webviewP
8079
context.subscriptions.push(webviewPanel.webview.onDidReceiveMessage(async (e) => {
8180
if (e.command === "setOverviewVisibility") {
8281
toggleOverviewVisibilityOperation(context, e.visibility);
83-
} else if (e.command === "requestJdkInfo") {
84-
let jdkInfo = await suggestOpenJdk(e.jdkVersion, e.jvmImpl);
85-
applyJdkInfo(jdkInfo);
8682
} else if (e.command === "installExtension") {
8783
await vscode.commands.executeCommand("java.helper.installExtension", e.extName, e.displayName);
8884
}
8985
}));
90-
91-
if (!await validateJavaRuntime()) {
92-
webviewPanel.webview.postMessage({
93-
command: "showJavaRuntimePanel",
94-
});
95-
96-
let jdkInfo = await suggestOpenJdk();
97-
applyJdkInfo(jdkInfo);
98-
}
99-
100-
function applyJdkInfo(jdkInfo: any) {
101-
webviewPanel.webview.postMessage({
102-
command: "applyJdkInfo",
103-
jdkInfo: jdkInfo
104-
});
105-
}
10686
}
10787

10888
export async function showOverviewPageOnActivation(context: vscode.ExtensionContext) {

0 commit comments

Comments
 (0)