Skip to content

Commit

Permalink
Allow to specify/execute favorite Maven commands. (#267)
Browse files Browse the repository at this point in the history
* Allow to specify/execute favorite Maven commands.

* Make the config ready for nls

* Fix for refactored APIs.
  • Loading branch information
Eskibear authored Mar 4, 2019
1 parent f462c7a commit 5dee227
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Change Log
All notable changes to the "vscode-maven" extension will be documented in this file.

#### Added
- Allow to specify and execute "favorite" Maven commands. [#72](https://github.com/Microsoft/vscode-maven/issues/72) [#259](https://github.com/Microsoft/vscode-maven/issues/259)

## 0.14.2
#### Fixed
- Use a simple and robust way to inject custom environment variables into terminals. [PR#240](https://github.com/Microsoft/vscode-maven/pull/240)
Expand Down
17 changes: 17 additions & 0 deletions TestPlan.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@
1. It lists recently executed maven commands **for this project**, with information of goals and pom file path.
2. Select one of them, it should execute the corresponding command.

### Maven Favorite Command
1. Specify a favorite command in settings, e.g.
```
{
"maven.terminal.favorite": [
{
"alias": "full-build without tests"
"value": "clean package -DskipTests"
}
]
}
```
2. Right-click on project item, click `Favorite ...`
3. Verify:
1. It should show favorite commands in a drop-down list.
2. Click one, it should execute the corresponding maven command.
## Maven Archetypes
### Generate project from maven archetypes
1. Right-click a target folder in file explorer view.
Expand Down
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@
"command": "maven.project.addDependency",
"title": "%contributes.commands.maven.project.addDependency%",
"category": "Maven"
},
{
"command": "maven.favorites",
"title": "Favorites ...",
"category": "Maven"
}
],
"views": {
Expand Down Expand Up @@ -278,6 +283,11 @@
"when": "view == mavenProjects && viewItem == MavenProject",
"group": "1-lifecycle@5"
},
{
"command": "maven.favorites",
"when": "view == mavenProjects && viewItem == MavenProject",
"group": "1-lifecycle@3"
},
{
"command": "maven.history",
"when": "view == mavenProjects && viewItem == MavenProject",
Expand Down Expand Up @@ -409,6 +419,26 @@
"description": "%configuration.maven.terminal.customEnv%",
"scope": "window"
},
"maven.terminal.favorites" :{
"type": "array",
"items": {
"type": "object",
"title": "Favorite commands",
"properties": {
"alias": {
"type": "string",
"description": "%configuration.maven.terminal.favorites.alias%"
},
"command": {
"type": "string",
"description": "%configuration.maven.terminal.favorites.command%"
}
}
},
"default": [],
"description": "%configuration.maven.terminal.favorites%",
"scope": "resource"
},
"maven.view": {
"type": "string",
"enum": [
Expand Down
5 changes: 4 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@
"configuration.maven.terminal.customEnv": "Specifies an array of environment variable names and values. These environment variable values will be added to the terminal session before Maven is first executed.",
"configuration.maven.terminal.customEnv.environmentVariable": "Name of the environment variable to set.",
"configuration.maven.terminal.customEnv.value": "Value of the environment variable to set.",
"configuration.maven.view": "Specifies the way of viewing Maven projects."
"configuration.maven.view": "Specifies the way of viewing Maven projects.",
"configuration.maven.terminal.favorite": "Specify pre-defined favorite commands to execute.",
"configuration.maven.terminal.favorite.alias": "A short name for the command.",
"configuration.maven.terminal.favorite.command": "Content of the favorite command."
}
4 changes: 4 additions & 0 deletions src/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export namespace Settings {
}[] {
return _getMavenSection("terminal.customEnv");
}

export function favorites(resource: Uri): {alias: string; command: string}[] {
return _getMavenSection("terminal.favorites", resource);
}
}
export namespace Executable {
export function path(resource: Uri): string {
Expand Down
3 changes: 3 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { MavenProject } from "./explorer/model/MavenProject";
import { PluginGoal } from "./explorer/model/PluginGoal";
import { pluginInfoProvider } from "./explorer/pluginInfoProvider";
import { addDependencyHandler } from "./handlers/addDependencyHandler";
import { runFavoriteCommandsHandler } from "./handlers/runFavoriteCommandsHandler";
import {hoverProvider} from "./hover/hoverProvider";
import { mavenOutputChannel } from "./mavenOutputChannel";
import { mavenTerminal } from "./mavenTerminal";
Expand Down Expand Up @@ -53,6 +54,7 @@ function registerCommand(context: vscode.ExtensionContext, commandName: string,
context.subscriptions.push(vscode.commands.registerCommand(commandName, callbackWithTroubleshooting));
}

// tslint:disable-next-line:max-func-body-length
async function doActivate(_operationId: string, context: vscode.ExtensionContext): Promise<void> {
pluginInfoProvider.initialize(context);
context.subscriptions.push(vscode.window.registerTreeDataProvider("mavenProjects", mavenExplorerProvider));
Expand Down Expand Up @@ -109,6 +111,7 @@ async function doActivate(_operationId: string, context: vscode.ExtensionContext
await Utils.executeHistoricalGoals(mavenExplorerProvider.mavenProjectNodes.map(_node => _node.pomPath));
}
});
registerCommand(context, "maven.favorites", async (item: MavenProject | undefined) => await runFavoriteCommandsHandler(item));
registerCommand(context, "maven.goal.execute", async () => await Utils.executeMavenCommand());
registerCommand(context, "maven.plugin.execute", async (node: PluginGoal) => {
if (node &&
Expand Down
55 changes: 55 additions & 0 deletions src/handlers/runFavoriteCommandsHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import * as _ from "lodash";
import * as vscode from "vscode";
import { mavenExplorerProvider } from "../explorer/mavenExplorerProvider";
import { MavenProject } from "../explorer/model/MavenProject";
import { Settings } from "../Settings";
import { executeInTerminal } from "../utils/mavenUtils";

type FavoriteCommand = { command: string, alias: string };
export async function runFavoriteCommandsHandler(project: MavenProject | undefined): Promise<void> {
let selectedProject: MavenProject = project;
if (!selectedProject) {
selectedProject = await vscode.window.showQuickPick(
mavenExplorerProvider.mavenProjectNodes.map(item => ({
value: item,
label: `$(primitive-dot) ${item.name}`,
description: undefined,
detail: item.pomPath
})),
{ placeHolder: "Select a Maven project ...", ignoreFocusOut: true }
).then(item => item ? item.value : undefined);
if (!selectedProject) {
return;
}
}

const favorites: FavoriteCommand[] = Settings.Terminal.favorites(vscode.Uri.file(selectedProject.pomPath));
if (_.isEmpty(favorites)) {
const BUTTON_OPEN_SETTINGS: string = "Open Settings";
const choice: string = await vscode.window.showInformationMessage("Found no favorite commands. You can specify `maven.terminal.favorites` in Settings.", BUTTON_OPEN_SETTINGS);
if (choice === BUTTON_OPEN_SETTINGS) {
await vscode.commands.executeCommand("workbench.action.openSettings");
}
return;
}

const selectedCommand: FavoriteCommand = await vscode.window.showQuickPick(
favorites.map(item => ({
value: item,
label: item.alias,
description: item.command
})), {
ignoreFocusOut: true,
placeHolder: "Select a favorite command ...",
matchOnDescription: true
}
).then(item => item ? item.value : undefined);
if (!selectedCommand) {
return;
}

await executeInTerminal(selectedCommand.command, selectedProject.pomPath);
}
23 changes: 15 additions & 8 deletions src/utils/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,20 +204,27 @@ export namespace Utils {
return;
}

const LABEL_CUSTOM: string = "Custom goals ...";
const LABEL_FAVORITES: string = "Favorites ...";
// select a command
const selectedCommand: string = await window.showQuickPick(
["custom", "clean", "validate", "compile", "test", "package", "verify", "install", "site", "deploy"].map(item => ({
label: item === "custom" ? "Custom goals ..." : item,
value: item,
description: undefined
})),
[LABEL_FAVORITES, LABEL_CUSTOM, "clean", "validate", "compile", "test", "package", "verify", "install", "site", "deploy"],
{ placeHolder: "Select the goal to execute ...", ignoreFocusOut: true }
).then(item => item && item.value);
);
if (!selectedCommand) {
return;
}

// execute
await commands.executeCommand(`maven.goal.${selectedCommand}`, selectedProject);
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;
}
}
}

0 comments on commit 5dee227

Please sign in to comment.