Skip to content

Commit be2eb70

Browse files
authored
Support updating classpaths for Maven/Gradle projects (#1283)
Signed-off-by: Sheng Chen <[email protected]>
1 parent 4fce346 commit be2eb70

21 files changed

+1080
-498
lines changed

ThirdPartyNotices.txt

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@ are grateful to these developers for their contribution to open source.
1616
8. highlight.js (https://github.com/highlightjs/highlight.js)
1717
9. jquery (https://github.com/jquery/jquery)
1818
10. lodash (lodash/lodash)
19-
11. minimatch (https://github.com/isaacs/minimatch)
20-
12. react (https://github.com/facebook/react)
21-
13. react-bootstrap (https://github.com/react-bootstrap/react-bootstrap)
22-
14. react-dom (https://github.com/facebook/react)
23-
15. react-redux (https://github.com/reduxjs/react-redux)
24-
16. semver (https://github.com/npm/node-semver)
25-
17. vscode-extension-telemetry-wrapper (https://github.com/Eskibear/vscode-extension-telemetry-wrapper)
26-
18. xmldom (https://github.com/xmldom/xmldom)
27-
19. HdrHistogramJS (https://github.com/HdrHistogram/HdrHistogramJS)
19+
11. react (https://github.com/facebook/react)
20+
12. react-bootstrap (https://github.com/react-bootstrap/react-bootstrap)
21+
13. react-dom (https://github.com/facebook/react)
22+
14. react-redux (https://github.com/reduxjs/react-redux)
23+
15. semver (https://github.com/npm/node-semver)
24+
16. vscode-extension-telemetry-wrapper (https://github.com/Eskibear/vscode-extension-telemetry-wrapper)
25+
17. xmldom (https://github.com/xmldom/xmldom)
26+
18. HdrHistogramJS (https://github.com/HdrHistogram/HdrHistogramJS)
2827

2928
@iconify/react NOTICES BEGIN HERE
3029
=============================
@@ -321,27 +320,6 @@ terms above.
321320
=========================================
322321
END OF lodash NOTICES AND INFORMATION
323322

324-
minimatch NOTICES BEGIN HERE
325-
=============================
326-
The ISC License
327-
328-
Copyright (c) Isaac Z. Schlueter and Contributors
329-
330-
Permission to use, copy, modify, and/or distribute this software for any
331-
purpose with or without fee is hereby granted, provided that the above
332-
copyright notice and this permission notice appear in all copies.
333-
334-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
335-
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
336-
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
337-
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
338-
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
339-
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
340-
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
341-
342-
=========================================
343-
END OF minimatch NOTICES AND INFORMATION
344-
345323
react NOTICES BEGIN HERE
346324
=============================
347325
MIT License

package-lock.json

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

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@
321321
"@types/expand-tilde": "^2.0.0",
322322
"@types/fs-extra": "^9.0.13",
323323
"@types/lodash": "^4.14.186",
324-
"@types/minimatch": "^3.0.5",
325324
"@types/node": "18.x",
326325
"@types/path-exists": "^3.0.0",
327326
"@types/react": "^17.0.50",
@@ -373,7 +372,6 @@
373372
"jdk-utils": "^0.4.4",
374373
"jquery": "^3.6.1",
375374
"lodash": "^4.17.21",
376-
"minimatch": "^3.1.2",
377375
"react": "^16.14.0",
378376
"react-bootstrap": "^1.6.6",
379377
"react-dom": "^16.14.0",

src/classpath/assets/features/classpathConfiguration/ClasspathConfigurationView.tsx

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@ import { Dispatch } from "@reduxjs/toolkit";
77
import Output from "./components/Output";
88
import ProjectSelector from "./components/ProjectSelector";
99
import Sources from "./components/Sources";
10-
import ReferencedLibraries from "./components/ReferencedLibraries";
11-
import Header from "./components/Header";
10+
import Libraries from "./components/Libraries";
1211
import Exception from "./components/Exception";
13-
import { ClasspathViewException, ProjectInfo, VmInstall } from "../../../types";
12+
import { ClasspathViewException, ProjectInfo, ClasspathEntry, VmInstall } from "../../../types";
1413
import { catchException, listProjects, listVmInstalls, loadClasspath } from "./classpathConfigurationViewSlice";
1514
import JdkRuntime from "./components/JdkRuntime";
1615
import { onWillListProjects, onWillListVmInstalls } from "../../utils";
17-
import { VSCodeProgressRing } from "@vscode/webview-ui-toolkit/react";
16+
import { VSCodePanelTab, VSCodePanelView, VSCodePanels, VSCodeProgressRing } from "@vscode/webview-ui-toolkit/react";
17+
import { ProjectType } from "../../../../utils/webview";
18+
import UnmanagedFolderSources from "./components/UnmanagedFolderSources";
19+
import Footer from "./components/Footer";
1820

1921
const ClasspathConfigurationView = (): JSX.Element => {
2022
const projects: ProjectInfo[] = useSelector((state: any) => state.classpathConfig.projects);
23+
const projectType: ProjectType = useSelector((state: any) => state.classpathConfig.projectType[state.classpathConfig.activeProjectIndex]);
2124
const exception: ClasspathViewException | undefined = useSelector((state: any) => state.classpathConfig.exception);
2225
let content: JSX.Element;
2326

@@ -28,11 +31,26 @@ const ClasspathConfigurationView = (): JSX.Element => {
2831
} else {
2932
content = (
3033
<div>
31-
<ProjectSelector />
32-
<Sources />
33-
<Output />
34-
<JdkRuntime />
35-
<ReferencedLibraries />
34+
<div className="mb-12">
35+
<ProjectSelector />
36+
<VSCodePanels className="setting-panels">
37+
<VSCodePanelTab id="source">Sources</VSCodePanelTab>
38+
<VSCodePanelTab id="jdk">JDK Runtime</VSCodePanelTab>
39+
<VSCodePanelTab id="libraries">Libraries</VSCodePanelTab>
40+
<VSCodePanelView className="setting-panels-view">
41+
{[ProjectType.Gradle, ProjectType.Maven].includes(projectType) && (<Sources />)}
42+
{projectType !== ProjectType.Gradle && projectType !== ProjectType.Maven && (<UnmanagedFolderSources />)}
43+
{projectType === ProjectType.UnmanagedFolder && (<Output />)}
44+
</VSCodePanelView>
45+
<VSCodePanelView className="setting-panels-view">
46+
<JdkRuntime />
47+
</VSCodePanelView>
48+
<VSCodePanelView className="setting-panels-view">
49+
<Libraries />
50+
</VSCodePanelView>
51+
</VSCodePanels>
52+
</div>
53+
<Footer />
3654
</div>
3755
);
3856
}
@@ -56,12 +74,13 @@ const ClasspathConfigurationView = (): JSX.Element => {
5674
window.addEventListener("message", onInitialize);
5775
onWillListProjects();
5876
onWillListVmInstalls();
59-
return () => window.removeEventListener("message", onInitialize);
77+
return () => {
78+
window.removeEventListener("message", onInitialize);
79+
}
6080
}, []);
6181

6282
return (
6383
<div className="root">
64-
<Header />
6584
{content}
6685
</div>
6786
);
@@ -76,9 +95,9 @@ interface OnInitializeEvent {
7695
projectType: string;
7796
}[];
7897
vmInstalls?: VmInstall[];
79-
sources?: string[];
98+
sources?: ClasspathEntry[];
8099
output?: string;
81-
referencedLibraries?: string[];
100+
libraries?: string[];
82101
exception?: ClasspathViewException;
83102
};
84103
}
Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4-
import { createSlice } from "@reduxjs/toolkit";
4+
import { createSlice, current } from "@reduxjs/toolkit";
55
import _ from "lodash";
6+
import { ClasspathEntry, ProjectState } from "../../../types";
7+
import { ProjectType } from "../../../../utils/webview";
68

79
export const classpathConfigurationViewSlice = createSlice({
810
name: "classpathConfig",
911
initialState: {
1012
activeProjectIndex: 0,
1113
projects: [],
12-
activeVmInstallPath: "",
14+
activeVmInstallPath: [] as string[],
1315
vmInstalls: [],
14-
projectType: undefined,
15-
sources: [] as string[],
16-
output: "",
17-
referencedLibraries: [] as string[],
16+
projectType: [] as ProjectType[],
17+
sources: [] as ClasspathEntry[][],
18+
output: [] as string[],
19+
libraries: [] as ClasspathEntry[][],
20+
projectState: [] as ProjectState[],
21+
loadingState: false,
1822
exception: undefined,
1923
},
2024
reducers: {
2125
listProjects: (state, action) => {
2226
state.projects = action.payload;
2327
state.activeProjectIndex = 0;
28+
const projectNum = state.projects.length;
29+
state.activeVmInstallPath = Array(projectNum).fill("");
30+
state.projectType = Array(projectNum).fill("");
31+
state.sources = Array(projectNum).fill([]);
32+
state.output = Array(projectNum).fill("");
33+
state.libraries = Array(projectNum).fill([]);
34+
state.projectState = Array(projectNum).fill(ProjectState.Unloaded);
2435
},
2536
listVmInstalls: (state, action) => {
2637
state.vmInstalls = action.payload;
@@ -29,43 +40,54 @@ export const classpathConfigurationViewSlice = createSlice({
2940
state.activeProjectIndex = action.payload;
3041
},
3142
loadClasspath: (state, action) => {
32-
state.projectType = action.payload.projectType;
33-
state.output = action.payload.output;
34-
state.activeVmInstallPath = action.payload.activeVmInstallPath;
43+
state.projectState[state.activeProjectIndex] = ProjectState.Loaded;
44+
state.projectType[state.activeProjectIndex] = action.payload.projectType;
45+
state.output[state.activeProjectIndex] = action.payload.output;
46+
state.activeVmInstallPath[state.activeProjectIndex] = action.payload.activeVmInstallPath;
3547
// Only update the array when they have different elements.
36-
if (isDifferentStringArray(state.sources, action.payload.sources)) {
37-
state.sources = action.payload.sources;
48+
const currentSources = _.sortBy(current(state.sources), ["path", "output"]);
49+
const newSources = _.sortBy(action.payload.sources, ["path", "output"]);
50+
if (!_.isEqual(currentSources, newSources)) {
51+
state.sources[state.activeProjectIndex] = action.payload.sources;
3852
}
39-
if (isDifferentStringArray(state.referencedLibraries, action.payload.referencedLibraries)) {
40-
state.referencedLibraries = action.payload.referencedLibraries;
53+
54+
const currentLibs = _.sortBy(current(state.libraries), ["path"]);
55+
const newLibs = _.sortBy(action.payload.libraries, ["path"]);
56+
if (!_.isEqual(currentLibs, newLibs)) {
57+
state.libraries[state.activeProjectIndex] = action.payload.libraries;
4158
}
4259
},
4360
updateSource: (state, action) => {
44-
state.sources = action.payload;
61+
state.sources[state.activeProjectIndex] = action.payload;
4562
},
4663
setOutputPath: (state, action) => {
47-
state.output = action.payload;
64+
state.output[state.activeProjectIndex] = action.payload;
4865
},
4966
setJdks: (state, action) => {
50-
state.activeVmInstallPath = action.payload.activeVmInstallPath;
67+
state.activeVmInstallPath[state.activeProjectIndex] = action.payload.activeVmInstallPath;
5168
if (action.payload.vmInstalls &&
5269
isDifferentStringArray(state.vmInstalls, action.payload.vmInstalls)) {
5370
state.vmInstalls = action.payload.vmInstalls;
5471
}
5572
},
5673
removeReferencedLibrary: (state, action) => {
5774
const removedIndex: number = action.payload as number;
58-
if (removedIndex > -1 && removedIndex < state.referencedLibraries.length) {
59-
state.referencedLibraries.splice(removedIndex, 1);
75+
if (removedIndex > -1 && removedIndex < state.libraries[state.activeProjectIndex].length) {
76+
state.libraries[state.activeProjectIndex].splice(removedIndex, 1);
6077
}
6178
},
62-
addReferencedLibraries: (state, action) => {
63-
state.referencedLibraries.push(...action.payload);
64-
state.referencedLibraries = _.uniq(state.referencedLibraries);
79+
addLibraries: (state, action) => {
80+
let newLibs = state.libraries[state.activeProjectIndex];
81+
newLibs.unshift(...action.payload);
82+
newLibs = _.uniq(newLibs);
83+
state.libraries[state.activeProjectIndex] = _.uniq(newLibs);
6584
},
6685
catchException: (state, action) => {
6786
state.exception = action.payload;
68-
}
87+
},
88+
updateLoadingState: (state, action) => {
89+
state.loadingState = action.payload;
90+
},
6991
},
7092
});
7193

@@ -82,8 +104,9 @@ export const {
82104
setOutputPath,
83105
setJdks,
84106
removeReferencedLibrary,
85-
addReferencedLibraries,
107+
addLibraries,
86108
catchException,
109+
updateLoadingState,
87110
} = classpathConfigurationViewSlice.actions;
88111

89112
export default classpathConfigurationViewSlice.reducer;

0 commit comments

Comments
 (0)