Skip to content

Commit

Permalink
Support updating classpaths for Maven/Gradle projects (#1283)
Browse files Browse the repository at this point in the history
Signed-off-by: Sheng Chen <sheche@microsoft.com>
  • Loading branch information
jdneo authored Mar 25, 2024
1 parent 4fce346 commit be2eb70
Show file tree
Hide file tree
Showing 21 changed files with 1,080 additions and 498 deletions.
38 changes: 8 additions & 30 deletions ThirdPartyNotices.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ are grateful to these developers for their contribution to open source.
8. highlight.js (https://github.com/highlightjs/highlight.js)
9. jquery (https://github.com/jquery/jquery)
10. lodash (lodash/lodash)
11. minimatch (https://github.com/isaacs/minimatch)
12. react (https://github.com/facebook/react)
13. react-bootstrap (https://github.com/react-bootstrap/react-bootstrap)
14. react-dom (https://github.com/facebook/react)
15. react-redux (https://github.com/reduxjs/react-redux)
16. semver (https://github.com/npm/node-semver)
17. vscode-extension-telemetry-wrapper (https://github.com/Eskibear/vscode-extension-telemetry-wrapper)
18. xmldom (https://github.com/xmldom/xmldom)
19. HdrHistogramJS (https://github.com/HdrHistogram/HdrHistogramJS)
11. react (https://github.com/facebook/react)
12. react-bootstrap (https://github.com/react-bootstrap/react-bootstrap)
13. react-dom (https://github.com/facebook/react)
14. react-redux (https://github.com/reduxjs/react-redux)
15. semver (https://github.com/npm/node-semver)
16. vscode-extension-telemetry-wrapper (https://github.com/Eskibear/vscode-extension-telemetry-wrapper)
17. xmldom (https://github.com/xmldom/xmldom)
18. HdrHistogramJS (https://github.com/HdrHistogram/HdrHistogramJS)

@iconify/react NOTICES BEGIN HERE
=============================
Expand Down Expand Up @@ -321,27 +320,6 @@ terms above.
=========================================
END OF lodash NOTICES AND INFORMATION

minimatch NOTICES BEGIN HERE
=============================
The ISC License

Copyright (c) Isaac Z. Schlueter and Contributors

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

=========================================
END OF minimatch NOTICES AND INFORMATION

react NOTICES BEGIN HERE
=============================
MIT License
Expand Down
30 changes: 12 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@
"@types/expand-tilde": "^2.0.0",
"@types/fs-extra": "^9.0.13",
"@types/lodash": "^4.14.186",
"@types/minimatch": "^3.0.5",
"@types/node": "18.x",
"@types/path-exists": "^3.0.0",
"@types/react": "^17.0.50",
Expand Down Expand Up @@ -373,7 +372,6 @@
"jdk-utils": "^0.4.4",
"jquery": "^3.6.1",
"lodash": "^4.17.21",
"minimatch": "^3.1.2",
"react": "^16.14.0",
"react-bootstrap": "^1.6.6",
"react-dom": "^16.14.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ import { Dispatch } from "@reduxjs/toolkit";
import Output from "./components/Output";
import ProjectSelector from "./components/ProjectSelector";
import Sources from "./components/Sources";
import ReferencedLibraries from "./components/ReferencedLibraries";
import Header from "./components/Header";
import Libraries from "./components/Libraries";
import Exception from "./components/Exception";
import { ClasspathViewException, ProjectInfo, VmInstall } from "../../../types";
import { ClasspathViewException, ProjectInfo, ClasspathEntry, VmInstall } from "../../../types";
import { catchException, listProjects, listVmInstalls, loadClasspath } from "./classpathConfigurationViewSlice";
import JdkRuntime from "./components/JdkRuntime";
import { onWillListProjects, onWillListVmInstalls } from "../../utils";
import { VSCodeProgressRing } from "@vscode/webview-ui-toolkit/react";
import { VSCodePanelTab, VSCodePanelView, VSCodePanels, VSCodeProgressRing } from "@vscode/webview-ui-toolkit/react";
import { ProjectType } from "../../../../utils/webview";
import UnmanagedFolderSources from "./components/UnmanagedFolderSources";
import Footer from "./components/Footer";

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

Expand All @@ -28,11 +31,26 @@ const ClasspathConfigurationView = (): JSX.Element => {
} else {
content = (
<div>
<ProjectSelector />
<Sources />
<Output />
<JdkRuntime />
<ReferencedLibraries />
<div className="mb-12">
<ProjectSelector />
<VSCodePanels className="setting-panels">
<VSCodePanelTab id="source">Sources</VSCodePanelTab>
<VSCodePanelTab id="jdk">JDK Runtime</VSCodePanelTab>
<VSCodePanelTab id="libraries">Libraries</VSCodePanelTab>
<VSCodePanelView className="setting-panels-view">
{[ProjectType.Gradle, ProjectType.Maven].includes(projectType) && (<Sources />)}
{projectType !== ProjectType.Gradle && projectType !== ProjectType.Maven && (<UnmanagedFolderSources />)}
{projectType === ProjectType.UnmanagedFolder && (<Output />)}
</VSCodePanelView>
<VSCodePanelView className="setting-panels-view">
<JdkRuntime />
</VSCodePanelView>
<VSCodePanelView className="setting-panels-view">
<Libraries />
</VSCodePanelView>
</VSCodePanels>
</div>
<Footer />
</div>
);
}
Expand All @@ -56,12 +74,13 @@ const ClasspathConfigurationView = (): JSX.Element => {
window.addEventListener("message", onInitialize);
onWillListProjects();
onWillListVmInstalls();
return () => window.removeEventListener("message", onInitialize);
return () => {
window.removeEventListener("message", onInitialize);
}
}, []);

return (
<div className="root">
<Header />
{content}
</div>
);
Expand All @@ -76,9 +95,9 @@ interface OnInitializeEvent {
projectType: string;
}[];
vmInstalls?: VmInstall[];
sources?: string[];
sources?: ClasspathEntry[];
output?: string;
referencedLibraries?: string[];
libraries?: string[];
exception?: ClasspathViewException;
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import { createSlice } from "@reduxjs/toolkit";
import { createSlice, current } from "@reduxjs/toolkit";
import _ from "lodash";
import { ClasspathEntry, ProjectState } from "../../../types";
import { ProjectType } from "../../../../utils/webview";

export const classpathConfigurationViewSlice = createSlice({
name: "classpathConfig",
initialState: {
activeProjectIndex: 0,
projects: [],
activeVmInstallPath: "",
activeVmInstallPath: [] as string[],
vmInstalls: [],
projectType: undefined,
sources: [] as string[],
output: "",
referencedLibraries: [] as string[],
projectType: [] as ProjectType[],
sources: [] as ClasspathEntry[][],
output: [] as string[],
libraries: [] as ClasspathEntry[][],
projectState: [] as ProjectState[],
loadingState: false,
exception: undefined,
},
reducers: {
listProjects: (state, action) => {
state.projects = action.payload;
state.activeProjectIndex = 0;
const projectNum = state.projects.length;
state.activeVmInstallPath = Array(projectNum).fill("");
state.projectType = Array(projectNum).fill("");
state.sources = Array(projectNum).fill([]);
state.output = Array(projectNum).fill("");
state.libraries = Array(projectNum).fill([]);
state.projectState = Array(projectNum).fill(ProjectState.Unloaded);
},
listVmInstalls: (state, action) => {
state.vmInstalls = action.payload;
Expand All @@ -29,43 +40,54 @@ export const classpathConfigurationViewSlice = createSlice({
state.activeProjectIndex = action.payload;
},
loadClasspath: (state, action) => {
state.projectType = action.payload.projectType;
state.output = action.payload.output;
state.activeVmInstallPath = action.payload.activeVmInstallPath;
state.projectState[state.activeProjectIndex] = ProjectState.Loaded;
state.projectType[state.activeProjectIndex] = action.payload.projectType;
state.output[state.activeProjectIndex] = action.payload.output;
state.activeVmInstallPath[state.activeProjectIndex] = action.payload.activeVmInstallPath;
// Only update the array when they have different elements.
if (isDifferentStringArray(state.sources, action.payload.sources)) {
state.sources = action.payload.sources;
const currentSources = _.sortBy(current(state.sources), ["path", "output"]);
const newSources = _.sortBy(action.payload.sources, ["path", "output"]);
if (!_.isEqual(currentSources, newSources)) {
state.sources[state.activeProjectIndex] = action.payload.sources;
}
if (isDifferentStringArray(state.referencedLibraries, action.payload.referencedLibraries)) {
state.referencedLibraries = action.payload.referencedLibraries;

const currentLibs = _.sortBy(current(state.libraries), ["path"]);
const newLibs = _.sortBy(action.payload.libraries, ["path"]);
if (!_.isEqual(currentLibs, newLibs)) {
state.libraries[state.activeProjectIndex] = action.payload.libraries;
}
},
updateSource: (state, action) => {
state.sources = action.payload;
state.sources[state.activeProjectIndex] = action.payload;
},
setOutputPath: (state, action) => {
state.output = action.payload;
state.output[state.activeProjectIndex] = action.payload;
},
setJdks: (state, action) => {
state.activeVmInstallPath = action.payload.activeVmInstallPath;
state.activeVmInstallPath[state.activeProjectIndex] = action.payload.activeVmInstallPath;
if (action.payload.vmInstalls &&
isDifferentStringArray(state.vmInstalls, action.payload.vmInstalls)) {
state.vmInstalls = action.payload.vmInstalls;
}
},
removeReferencedLibrary: (state, action) => {
const removedIndex: number = action.payload as number;
if (removedIndex > -1 && removedIndex < state.referencedLibraries.length) {
state.referencedLibraries.splice(removedIndex, 1);
if (removedIndex > -1 && removedIndex < state.libraries[state.activeProjectIndex].length) {
state.libraries[state.activeProjectIndex].splice(removedIndex, 1);
}
},
addReferencedLibraries: (state, action) => {
state.referencedLibraries.push(...action.payload);
state.referencedLibraries = _.uniq(state.referencedLibraries);
addLibraries: (state, action) => {
let newLibs = state.libraries[state.activeProjectIndex];
newLibs.unshift(...action.payload);
newLibs = _.uniq(newLibs);
state.libraries[state.activeProjectIndex] = _.uniq(newLibs);
},
catchException: (state, action) => {
state.exception = action.payload;
}
},
updateLoadingState: (state, action) => {
state.loadingState = action.payload;
},
},
});

Expand All @@ -82,8 +104,9 @@ export const {
setOutputPath,
setJdks,
removeReferencedLibrary,
addReferencedLibraries,
addLibraries,
catchException,
updateLoadingState,
} = classpathConfigurationViewSlice.actions;

export default classpathConfigurationViewSlice.reducer;
Loading

0 comments on commit be2eb70

Please sign in to comment.