add lifecycle into maven explorer (#601)

* add lifecycle into maven explorer

Signed-off-by: Yan Zhang <yanzh@microsoft.com>

* fix tslint

Signed-off-by: Yan Zhang <yanzh@microsoft.com>

* rename LifecycleItem to LifecyclePhase

Signed-off-by: Yan Zhang <yanzh@microsoft.com>
This commit is contained in:
Yan Zhang 2021-03-30 13:24:31 +08:00 коммит произвёл GitHub
Родитель 8359f06ee9
Коммит 2830414185
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 99 добавлений и 33 удалений

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

@ -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"
}
]
},

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

@ -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<LifecyclePhase[]> {
return ["clean", "validate", "compile", "test", "package", "verify", "install", "site", "deploy"].map(goal => new LifecyclePhase(this.project, goal));
}
public getTreeItem(): vscode.TreeItem | Thenable<vscode.TreeItem> {
const treeItem: vscode.TreeItem = new vscode.TreeItem(this.name, vscode.TreeItemCollapsibleState.Collapsed);
treeItem.iconPath = new vscode.ThemeIcon("sync");
return treeItem;
}
}

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

@ -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<vscode.TreeItem> {
const treeItem: vscode.TreeItem = new vscode.TreeItem(this.phase, vscode.TreeItemCollapsibleState.None);
treeItem.iconPath = new vscode.ThemeIcon("gear");
return treeItem;
}
}

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

@ -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[] = <MavenProject[]>this.modules.map(m => mavenExplorerProvider.getMavenProject(m)).filter(Boolean);

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

@ -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());

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

@ -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<void> {
// 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 {

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

@ -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,