-
Notifications
You must be signed in to change notification settings - Fork 163
Expand file tree
/
Copy pathProjectJDKPanel.tsx
More file actions
101 lines (91 loc) · 4.61 KB
/
Copy pathProjectJDKPanel.tsx
File metadata and controls
101 lines (91 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import "@vscode-elements/elements/dist/vscode-button/index.js";
import "@vscode-elements/elements/dist/vscode-table/index.js";
import "@vscode-elements/elements/dist/vscode-table-body/index.js";
import "@vscode-elements/elements/dist/vscode-table-row/index.js";
import "@vscode-elements/elements/dist/vscode-table-cell/index.js";
import "@vscode-elements/elements/dist/vscode-table-header/index.js";
import "@vscode-elements/elements/dist/vscode-table-header-cell/index.js";
import { useState } from "react";
import { encodeCommandUriWithTelemetry, ProjectType } from "../../utils/webview";
import { JavaRuntimeEntry, ProjectRuntimeEntry } from "../types";
import { DefaultJDKSelector } from "./components/DefaultJDKSelector";
import { ProjectTypeHint } from "./components/ProjectTypeHint";
import { onWillListRuntimes, openBuildScript } from "./vscode.api";
interface Props {
jdkEntries: JavaRuntimeEntry[];
projectRuntimes: ProjectRuntimeEntry[];
}
export function ProjectJDKPanel({ jdkEntries, projectRuntimes }: Props) {
const [showHintFor, setShowHintFor] = useState<"Maven" | "Gradle" | "Others" | undefined>();
const projectTypeHint = (projectType: ProjectType) => {
switch (projectType) {
case "Maven":
return <vscode-button onClick={() => setShowHintFor("Maven")} icon-only title="For projects managed by build tools, Java version is specified in build scripts(e.g. pom.xml)."><span className="codicon codicon-info"></span></vscode-button>;
case "Gradle":
return <vscode-button onClick={() => setShowHintFor("Gradle")} icon-only title="For projects managed by build tools, Java version is specified in build scripts(e.g. build.gradle)."><span className="codicon codicon-info"></span></vscode-button>;
default:
return <vscode-button onClick={() => setShowHintFor("Others")} icon-only title="For folders containing .java files, but not managed by build tools like Maven/Gradle, a default JDK is used."><span className="codicon codicon-info"></span></vscode-button>;
}
};
const onClickEdit = (p: ProjectRuntimeEntry) => {
let scriptFile;
if (p.projectType === ProjectType.Maven) {
scriptFile = "pom.xml";
} else if (p.projectType === ProjectType.Gradle) {
scriptFile = "build.gradle";
}
if (scriptFile) {
openBuildScript(p.rootPath, scriptFile);
}
};
const projectEntries = projectRuntimes
.filter(p => p.projectType !== ProjectType.Default)
.map((p, index) => (
<vscode-table-row key={index}>
<vscode-table-cell>{p.name}</vscode-table-cell>
<vscode-table-cell><div className="inline-flex">{p.projectType}{projectTypeHint(p.projectType)}</div></vscode-table-cell>
<vscode-table-cell>
{
hasBuildTool(p) ?
<div className="inline-flex">
<span>{p.sourceLevel}</span>
<vscode-button icon-only onClick={() => onClickEdit(p)} title="Edit"><span className="codicon codicon-edit"></span></vscode-button>
</div>
:
<DefaultJDKSelector projectRuntime={p} jdkEntries={jdkEntries} />
}
</vscode-table-cell>
</vscode-table-row>
));
const downloadJDKCommand = encodeCommandUriWithTelemetry("java.runtime", "download", "java.installJdk");
return (
<div className="container">
<h1>Configure Runtime for Projects</h1>
{projectEntries.length > 0 && <p>Manage Java runtime for your projects. If you don't have a valid Java runtime, you can <a href={downloadJDKCommand}>download</a> one.</p>}
{
projectEntries.length > 0 ?
<vscode-table>
<vscode-table-header slot="header">
<vscode-table-header-cell>Project Name</vscode-table-header-cell>
<vscode-table-header-cell>Type</vscode-table-header-cell>
<vscode-table-header-cell>Java Version</vscode-table-header-cell>
</vscode-table-header>
<vscode-table-body slot="body">
{projectEntries}
</vscode-table-body>
</vscode-table>
:
<div>
<p>No project detected yet. Please refresh later if Java extension is importing your projects.</p>
<vscode-button onClick={onWillListRuntimes}>Refresh<span slot="start" className="codicon codicon-refresh"></span></vscode-button>
</div>
}
<ProjectTypeHint projectType={showHintFor} />
</div>
);
}
function hasBuildTool(p: ProjectRuntimeEntry) {
return (p.projectType === ProjectType.Maven || p.projectType === ProjectType.Gradle);
}