Skip to content

Commit 118806a

Browse files
authored
feat: Update project from project node in explorer (#391)
1 parent 3e41544 commit 118806a

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
lines changed

package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
"command": "java.project.clean.workspace",
6868
"title": "%contributes.commands.java.project.clean.workspace%"
6969
},
70+
{
71+
"command": "java.project.update",
72+
"title": "%contributes.commands.java.project.update%"
73+
},
7074
{
7175
"command": "java.view.package.revealInProjectExplorer",
7276
"title": "%contributes.commands.java.view.package.revealInProjectExplorer%",
@@ -294,6 +298,10 @@
294298
"command": "java.project.clean.workspace",
295299
"when": "false"
296300
},
301+
{
302+
"command": "java.project.update",
303+
"when": "false"
304+
},
297305
{
298306
"command": "java.view.package.revealInProjectExplorer",
299307
"when": "false"
@@ -455,6 +463,11 @@
455463
"command": "java.view.package.exportJar",
456464
"when": "view == javaProjectExplorer && viewItem =~ /java:workspace(?=.*?\\b\\+uri\\b)/ && java:serverMode!= LightWeight",
457465
"group": "inline"
466+
},
467+
{
468+
"command": "java.project.update",
469+
"when": "view == javaProjectExplorer && viewItem =~ /java:project(?=.*?\\b\\+uri\\b)(?=.*?\\b\\+(maven|gradle)\\b)/",
470+
"group": "9_sync@10"
458471
}
459472
]
460473
},

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"contributes.commands.java.view.package.refresh": "Refresh",
77
"contributes.commands.java.project.build.workspace": "Build Workspace",
88
"contributes.commands.java.project.clean.workspace": "Clean Workspace",
9+
"contributes.commands.java.project.update": "Update Project",
910
"contributes.commands.java.view.package.revealInProjectExplorer": "Reveal in Java Projects",
1011
"contributes.commands.java.view.package.changeToFlatPackageView":"Flat View",
1112
"contributes.commands.java.view.package.changeToHierarchicalPackageView":"Hierarchical View",

package.nls.zh.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"contributes.commands.java.view.package.refresh": "刷新",
77
"contributes.commands.java.project.build.workspace": "构建工作空间",
88
"contributes.commands.java.project.clean.workspace": "清理工作空间",
9+
"contributes.commands.java.project.update": "更新项目",
910
"contributes.commands.java.view.package.revealInProjectExplorer": "在 Java 项目视图中显示",
1011
"contributes.commands.java.view.package.changeToFlatPackageView":"平行显示",
1112
"contributes.commands.java.view.package.changeToHierarchicalPackageView":"层级显示",

src/commands.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ export namespace Commands {
5454

5555
export const JAVA_PROJECT_CLEAN_WORKSPACE = "java.project.clean.workspace";
5656

57+
export const JAVA_PROJECT_UPDATE = "java.project.update";
58+
5759
export const JAVA_PROJECT_EXPLORER_FOCUS = "javaProjectExplorer.focus";
5860

5961
export const JAVA_PROJECT_ACTIVATE = "java.project.activate";
@@ -80,6 +82,8 @@ export namespace Commands {
8082

8183
export const JAVA_CLEAN_WORKSPACE = "java.clean.workspace";
8284

85+
export const JAVA_PROJECT_CONFIGURATION_UPDATE = "java.projectConfiguration.update";
86+
8387
export const JAVA_RESOLVE_BUILD_FILES = "vscode.java.resolveBuildFiles";
8488
}
8589

src/views/dependencyDataProvider.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import * as _ from "lodash";
55
import {
66
commands, Event, EventEmitter, ExtensionContext, extensions, ProviderResult,
7-
TreeDataProvider, TreeItem, Uri, window, workspace,
7+
RelativePattern, TreeDataProvider, TreeItem, Uri, window, workspace,
88
} from "vscode";
99
import { instrumentOperation, instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper";
1010
import { Commands } from "../commands";
@@ -55,6 +55,18 @@ export class DependencyDataProvider implements TreeDataProvider<ExplorerNode> {
5555
commands.executeCommand(Commands.JAVA_BUILD_WORKSPACE)));
5656
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.JAVA_PROJECT_CLEAN_WORKSPACE, () =>
5757
commands.executeCommand(Commands.JAVA_CLEAN_WORKSPACE)));
58+
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.JAVA_PROJECT_UPDATE, async (node: INodeData) => {
59+
if (!node.uri) {
60+
window.showErrorMessage("The URI of the project is not available, you can try to update the project by right clicking the project configuration file (pom.xml or *.gradle) from the File Explorer.");
61+
return;
62+
}
63+
const pattern: RelativePattern = new RelativePattern(Uri.parse(node.uri).fsPath, "{pom.xml,*.gradle}");
64+
const uris: Uri[] = await workspace.findFiles(pattern, null /*exclude*/, 1 /*maxResults*/);
65+
if (uris.length >= 1) {
66+
commands.executeCommand(Commands.JAVA_PROJECT_CONFIGURATION_UPDATE, uris[0]);
67+
}
68+
}));
69+
5870
Settings.registerConfigurationListener((updatedConfig, oldConfig) => {
5971
if (updatedConfig.refreshDelay !== oldConfig.refreshDelay) {
6072
this.setRefreshDelay(updatedConfig.refreshDelay);

0 commit comments

Comments
 (0)