Allow to manually refresh plugin goals. (#158)

* Make the filename legal in Windows.

* Can refresh tree item.

* Reuse the MavenProject node to avoid extra calculation of effective-pom

* Rename maven.project.refreshAll to maven.explorer.refresh
This commit is contained in:
Yan Zhang 2018-12-05 15:57:18 +08:00
Родитель 3120dc1a9a
Коммит 0f1714aba9
10 изменённых файлов: 46 добавлений и 19 удалений

Просмотреть файл

@ -25,7 +25,7 @@
},
"activationEvents": [
"workspaceContains:**/pom.xml",
"onCommand:maven.project.refreshAll",
"onCommand:maven.explorer.refresh",
"onCommand:maven.goal.clean",
"onCommand:maven.goal.validate",
"onCommand:maven.goal.compile",
@ -48,8 +48,8 @@
"contributes": {
"commands": [
{
"command": "maven.project.refreshAll",
"title": "%contributes.commands.maven.project.refreshAll%",
"command": "maven.explorer.refresh",
"title": "%contributes.commands.maven.explorer.refresh%",
"category": "Maven",
"icon": {
"light": "resources/light/refresh.svg",
@ -198,7 +198,7 @@
"when": "never"
},
{
"command": "maven.project.refreshAll",
"command": "maven.explorer.refresh",
"when": "never"
},
{
@ -219,7 +219,7 @@
],
"view/title": [
{
"command": "maven.project.refreshAll",
"command": "maven.explorer.refresh",
"when": "view == mavenProjects",
"group": "navigation@2"
}
@ -289,6 +289,16 @@
"command": "maven.plugin.execute",
"when": "view == mavenProjects && viewItem == PluginGoal",
"group": "1@1"
},
{
"command": "maven.explorer.refresh",
"when": "view == mavenProjects && viewItem == MavenPlugin",
"group": "1@1"
},
{
"command": "maven.explorer.refresh",
"when": "view == mavenProjects && viewItem == Menu",
"group": "1@1"
}
]
},

Просмотреть файл

@ -1,6 +1,6 @@
{
"description": "Manage Maven projects, execute goals, generate project from archetype, improve user experience for Java developers.",
"contributes.commands.maven.project.refreshAll": "Refresh",
"contributes.commands.maven.explorer.refresh": "Refresh",
"contributes.commands.maven.goal.custom": "Custom goals ... ",
"contributes.commands.maven.project.effectivePom": "Effective POM",
"contributes.commands.maven.project.openPom": "Open POM file",

Просмотреть файл

@ -1,6 +1,6 @@
{
"description": "管理Maven项目执行命令从原型生成项目改善Java开发人员的用户体验。",
"contributes.commands.maven.project.refreshAll": "刷新",
"contributes.commands.maven.explorer.refresh": "刷新",
"contributes.commands.maven.goal.custom": "自定义 ... ",
"contributes.commands.maven.project.effectivePom": "有效的POM",
"contributes.commands.maven.project.openPom": "打开POM文件",

Просмотреть файл

@ -344,7 +344,7 @@ export namespace Utils {
}
export async function getPluginDescription(pluginId: string, pomPath: string): Promise<string> {
const outputPath: string = path.join(os.tmpdir(), EXTENSION_NAME, md5(pomPath), pluginId);
const outputPath: string = path.join(os.tmpdir(), EXTENSION_NAME, md5(pluginId));
try {
await Utils.executeInBackground(`help:describe -Dplugin=${pluginId} -Doutput="${outputPath}"`, pomPath);
const content: string = await Utils.readFileIfExists(outputPath);

Просмотреть файл

@ -34,13 +34,16 @@ class MavenExplorerProvider implements TreeDataProvider<ITreeItem> {
if (element === undefined) {
return this._workspaceFolderNodes;
} else {
return element.getChildren();
return element.getChildren && element.getChildren();
}
}
public refresh(): void {
public refresh(item?: ITreeItem): void {
this._updateWorkspaceFolderNodes();
this._onDidChangeTreeData.fire();
if (item && item.removeChildren) {
item.removeChildren();
}
this._onDidChangeTreeData.fire(item);
}
private _updateWorkspaceFolderNodes(): void {

Просмотреть файл

@ -2,8 +2,18 @@
// Licensed under the MIT license.
import * as vscode from "vscode";
export interface ITreeItem {
getContextValue(): string;
getTreeItem(): vscode.TreeItem | Thenable<vscode.TreeItem>;
getChildren(): vscode.ProviderResult<ITreeItem[]>;
/**
* If implemented, it will be triggered to get children items.
*/
getChildren?(): vscode.ProviderResult<ITreeItem[]>;
/**
* If implemented, it will be triggered before manual refreshing current tree item.
*/
removeChildren?(): void | Thenable<void>;
}

Просмотреть файл

@ -47,6 +47,10 @@ export class MavenPlugin implements ITreeItem {
return this.goals.map(goal => new PluginGoal(this, goal));
}
public removeChildren(): void {
this.goals = undefined;
}
private async loadMetadata(): Promise<void> {
if (this.prefix !== undefined && this.goals !== undefined) {
return;

Просмотреть файл

@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import { mavenExplorerProvider } from "../MavenExplorerProvider";
import { ITreeItem } from "./ITreeItem";
import { MavenProject } from "./MavenProject";
import { Menu } from "./Menu";
@ -12,6 +13,8 @@ export class ModulesMenu extends Menu implements ITreeItem {
}
public getChildren() : MavenProject[] {
return this._project.modules.map(modulePomPath => new MavenProject(modulePomPath));
return this._project.modules.map(modulePomPath => {
return mavenExplorerProvider.mavenProjectNodes.find(elem => elem.pomPath === modulePomPath) || new MavenProject(modulePomPath);
});
}
}

Просмотреть файл

@ -20,8 +20,4 @@ export class PluginGoal implements ITreeItem {
public getTreeItem(): vscode.TreeItem {
return new vscode.TreeItem(this.name, vscode.TreeItemCollapsibleState.None);
}
public getChildren(): ITreeItem[] {
return null;
}
}

Просмотреть файл

@ -8,6 +8,7 @@ import { dispose as disposeTelemetryWrapper, initializeFromJsonFile, instrumentO
import { ArchetypeModule } from "./archetype/ArchetypeModule";
import { OperationCanceledError } from "./Errors";
import { mavenExplorerProvider } from "./explorer/MavenExplorerProvider";
import { ITreeItem } from "./explorer/model/ITreeItem";
import { MavenProject } from "./explorer/model/MavenProject";
import { PluginGoal } from "./explorer/model/PluginGoal";
import { Settings } from "./Settings";
@ -65,8 +66,8 @@ async function doActivate(_operationId: string, context: vscode.ExtensionContext
});
});
registerCommand(context, "maven.project.refreshAll", (): void => {
mavenExplorerProvider.refresh();
registerCommand(context, "maven.explorer.refresh", (item?: ITreeItem): void => {
mavenExplorerProvider.refresh(item);
});
registerCommand(context, "maven.project.effectivePom", async (node: Uri | MavenProject) => {