From 2830414185f4ddaa1772e2f2330df3e9631bbbc7 Mon Sep 17 00:00:00 2001 From: Yan Zhang Date: Tue, 30 Mar 2021 13:24:31 +0800 Subject: [PATCH] add lifecycle into maven explorer (#601) * add lifecycle into maven explorer Signed-off-by: Yan Zhang * fix tslint Signed-off-by: Yan Zhang * rename LifecycleItem to LifecyclePhase Signed-off-by: Yan Zhang --- package.json | 23 ++++++++++--- src/explorer/model/LifecycleMenu.ts | 25 ++++++++++++++ src/explorer/model/LifecyclePhase.ts | 21 ++++++++++++ src/explorer/model/MavenProject.ts | 3 +- src/extension.ts | 1 + src/utils/Utils.ts | 51 ++++++++++++++++------------ tslint.json | 8 +---- 7 files changed, 99 insertions(+), 33 deletions(-) create mode 100644 src/explorer/model/LifecycleMenu.ts create mode 100644 src/explorer/model/LifecyclePhase.ts diff --git a/package.json b/package.json index 8037c56..abc7a8f 100644 --- a/package.json +++ b/package.json @@ -147,6 +147,12 @@ "title": "Run Maven Commands...", "category": "Maven" }, + { + "command": "maven.goal.execute.fromLifecycleMenu", + "title": "%contributes.commands.maven.plugin.execute%", + "category": "Maven", + "icon": "$(play)" + }, { "command": "maven.plugin.execute", "title": "%contributes.commands.maven.plugin.execute%", @@ -252,6 +258,14 @@ "command": "maven.project.openPom", "when": "never" }, + { + "command": "maven.goal.execute.fromProjectManager", + "when": "never" + }, + { + "command": "maven.goal.execute.fromLifecycleMenu", + "when": "never" + }, { "command": "maven.plugin.execute", "when": "never" @@ -264,10 +278,6 @@ "command": "maven.project.showDependencies", "when": "never" }, - { - "command": "maven.goal.execute.fromProjectManager", - "when": "never" - }, { "command": "maven.archetype.generate", "when": "!java:projectManagerActivated" @@ -422,6 +432,11 @@ "command": "maven.goal.execute.fromProjectManager", "when": "view == javaProjectExplorer && viewItem =~ /java:project(?=.*?\\b\\+maven\\b)(?=.*?\\b\\+uri\\b)/", "group": "maven" + }, + { + "command": "maven.goal.execute.fromLifecycleMenu", + "when": "view == mavenProjects && viewItem == Lifecycle", + "group": "inline" } ] }, diff --git a/src/explorer/model/LifecycleMenu.ts b/src/explorer/model/LifecycleMenu.ts new file mode 100644 index 0000000..47a2684 --- /dev/null +++ b/src/explorer/model/LifecycleMenu.ts @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. + +import * as vscode from "vscode"; +import { ITreeItem } from "./ITreeItem"; +import { LifecyclePhase } from "./LifecyclePhase"; +import { MavenProject } from "./MavenProject"; +import { Menu } from "./Menu"; + +export class LifecycleMenu extends Menu implements ITreeItem { + constructor(project: MavenProject) { + super(project); + this.name = "Lifecycle"; + } + + public async getChildren() : Promise { + return ["clean", "validate", "compile", "test", "package", "verify", "install", "site", "deploy"].map(goal => new LifecyclePhase(this.project, goal)); + } + + public getTreeItem(): vscode.TreeItem | Thenable { + const treeItem: vscode.TreeItem = new vscode.TreeItem(this.name, vscode.TreeItemCollapsibleState.Collapsed); + treeItem.iconPath = new vscode.ThemeIcon("sync"); + return treeItem; + } +} diff --git a/src/explorer/model/LifecyclePhase.ts b/src/explorer/model/LifecyclePhase.ts new file mode 100644 index 0000000..38f1fba --- /dev/null +++ b/src/explorer/model/LifecyclePhase.ts @@ -0,0 +1,21 @@ + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. + +import * as vscode from "vscode"; +import { ITreeItem } from "./ITreeItem"; +import { MavenProject } from "./MavenProject"; + +export class LifecyclePhase implements ITreeItem { + constructor(public project: MavenProject, public phase: string) { + } + + public getContextValue(): string { + return "Lifecycle"; + } + public getTreeItem(): vscode.TreeItem | Thenable { + const treeItem: vscode.TreeItem = new vscode.TreeItem(this.phase, vscode.TreeItemCollapsibleState.None); + treeItem.iconPath = new vscode.ThemeIcon("gear"); + return treeItem; + } +} diff --git a/src/explorer/model/MavenProject.ts b/src/explorer/model/MavenProject.ts index 9ea5a31..775d562 100644 --- a/src/explorer/model/MavenProject.ts +++ b/src/explorer/model/MavenProject.ts @@ -13,9 +13,9 @@ import { EffectivePomProvider } from "../EffectivePomProvider"; import { mavenExplorerProvider } from "../mavenExplorerProvider"; import { IEffectivePom } from "./IEffectivePom"; import { ITreeItem } from "./ITreeItem"; +import { LifecycleMenu } from "./LifecycleMenu"; import { MavenPlugin } from "./MavenPlugin"; import { PluginsMenu } from "./PluginsMenu"; - const CONTEXT_VALUE: string = "MavenProject"; export class MavenProject implements ITreeItem { @@ -128,6 +128,7 @@ export class MavenProject implements ITreeItem { public getChildren(): ITreeItem[] { const ret: ITreeItem[] = []; + ret.push(new LifecycleMenu(this)); ret.push(new PluginsMenu(this)); if (this.moduleNames.length > 0 && Settings.viewType() === "hierarchical") { const projects: MavenProject[] = this.modules.map(m => mavenExplorerProvider.getMavenProject(m)).filter(Boolean); diff --git a/src/extension.ts b/src/extension.ts index 3fb5325..83fe6a4 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -71,6 +71,7 @@ async function doActivate(_operationId: string, context: vscode.ExtensionContext registerCommand(context, "maven.favorites", runFavoriteCommandsHandler); registerCommand(context, "maven.goal.execute", Utils.executeMavenCommand); registerCommand(context, "maven.goal.execute.fromProjectManager", Utils.executeMavenCommand); + registerCommand(context, "maven.goal.execute.fromLifecycleMenu", Utils.executeMavenCommand); registerCommand(context, "maven.plugin.execute", async (pluginGoal: PluginGoal) => await executeInTerminal({ command: pluginGoal.name, pomfile: pluginGoal.plugin.project.pomPath })); registerCommand(context, "maven.view.flat", () => Settings.changeToFlatView()); registerCommand(context, "maven.view.hierarchical", () => Settings.changeToHierarchicalView()); diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index d7fea65..90e31eb 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -12,6 +12,7 @@ import { createUuid, setUserError } from "vscode-extension-telemetry-wrapper"; import * as xml2js from "xml2js"; import { mavenExplorerProvider } from "../explorer/mavenExplorerProvider"; import { IEffectivePom } from "../explorer/model/IEffectivePom"; +import { LifecyclePhase } from "../explorer/model/LifecyclePhase"; import { MavenProject } from "../explorer/model/MavenProject"; import { Settings } from "../Settings"; import { getExtensionVersion, getPathToTempFolder, getPathToWorkspaceStorage } from "./contextUtils"; @@ -234,12 +235,17 @@ export namespace Utils { } export async function executeMavenCommand(node?: any): Promise { - // for nodes from Project Manager let selectedProject: MavenProject | undefined; - if (node && node.uri) { + let selectedCommand: string | undefined; + if (node instanceof LifecyclePhase) { + selectedProject = node.project; + selectedCommand = node.phase; + } else if (node && node.uri) { + // for nodes from Project Manager const pomPath: string = path.join(Uri.parse(node.uri).fsPath, "pom.xml"); selectedProject = mavenExplorerProvider.mavenProjectNodes.find(project => project.pomPath.toLowerCase() === pomPath.toLowerCase()); } + // select a project(pomfile) if (!selectedProject) { selectedProject = await selectProjectIfNecessary(); @@ -249,28 +255,31 @@ export namespace Utils { return; } - const LABEL_CUSTOM: string = "Custom ..."; - const LABEL_FAVORITES: string = "Favorites ..."; - // select a command - const selectedCommand: string | undefined = await window.showQuickPick( - [LABEL_FAVORITES, LABEL_CUSTOM, "clean", "validate", "compile", "test", "package", "verify", "install", "site", "deploy"], - { placeHolder: "Select the goal to execute ...", ignoreFocusOut: true } - ); + // select a command if not provided if (!selectedCommand) { - return; + const LABEL_CUSTOM: string = "Custom ..."; + const LABEL_FAVORITES: string = "Favorites ..."; + selectedCommand = await window.showQuickPick( + [LABEL_FAVORITES, LABEL_CUSTOM, "clean", "validate", "compile", "test", "package", "verify", "install", "site", "deploy"], + { placeHolder: "Select the goal to execute ...", ignoreFocusOut: true } + ); + if (!selectedCommand) { + return; + } + + switch (selectedCommand) { + case LABEL_CUSTOM: + await commands.executeCommand("maven.goal.custom", selectedProject); + break; + case LABEL_FAVORITES: + await commands.executeCommand("maven.favorites", selectedProject); + break; + default: + break; + } } - switch (selectedCommand) { - case LABEL_CUSTOM: - await commands.executeCommand("maven.goal.custom", selectedProject); - break; - case LABEL_FAVORITES: - await commands.executeCommand("maven.favorites", selectedProject); - break; - default: - await commands.executeCommand(`maven.goal.${selectedCommand}`, selectedProject); - break; - } + await commands.executeCommand(`maven.goal.${selectedCommand}`, selectedProject); } export function settingsFilePath(): string | undefined { diff --git a/tslint.json b/tslint.json index 268c1a0..6848110 100644 --- a/tslint.json +++ b/tslint.json @@ -136,12 +136,7 @@ 140 ], "member-access": true, - "member-ordering": [ - true, - { - "order": "fields-first" - } - ], + "missing-jsdoc": false, "mocha-unneeded-done": true, "new-parens": true, @@ -152,7 +147,6 @@ "no-inferrable-types": false, "no-multiline-string": true, "no-null-keyword": false, - "no-parameter-properties": true, "no-relative-imports": false, "no-require-imports": true, "no-shadowed-variable": true,