change wording & support more windows terminals
This commit is contained in:
Родитель
23be969e77
Коммит
2f362c8a9d
|
@ -14,6 +14,7 @@ All notable changes to the "vscode-maven" extension will be documented in this f
|
|||
- [0.0.1](#001)
|
||||
|
||||
## Unreleased
|
||||
- Support different integrated terminals in Windows, namely `Git Bash`, `CMD`, `PowerShell`.
|
||||
|
||||
## Released
|
||||
### 0.1.2
|
||||
|
|
|
@ -13,7 +13,7 @@ export function activate(context: vscode.ExtensionContext) {
|
|||
["clean", "validate", "compile", "test", "package", "verify", "install", "site", "deploy"].forEach((goal) => {
|
||||
const commandMavenGoal = vscode.commands.registerCommand(`mavenGoal.${goal}`, (item) => {
|
||||
const cmd = `mvn ${goal} -f "${item.pomXmlFilePath}"`;
|
||||
VSCodeUI.runInTerminal(cmd, true, `Maven-${item.params.projectName}`);
|
||||
VSCodeUI.runInTerminal(cmd, { name: `Maven-${item.params.projectName}` });
|
||||
});
|
||||
context.subscriptions.push(commandMavenGoal);
|
||||
});
|
||||
|
@ -67,19 +67,17 @@ async function generateFromArchetype(entry) {
|
|||
cwd = Utils.nearestDirPath(entry.fsPath);
|
||||
}
|
||||
const archetypeList = Utils.getArchetypeList();
|
||||
const selectedArchetype = await vscode.window.showQuickPick(archetypeList, { matchOnDescription: true });
|
||||
const selectedArchetype = await vscode.window.showQuickPick(archetypeList,
|
||||
{ matchOnDescription: true, placeHolder: "Select archetype with <groupId>:<artifactId> ..." });
|
||||
if (selectedArchetype) {
|
||||
const { artifactId, groupId, versions } = selectedArchetype;
|
||||
const version = await vscode.window.showQuickPick(versions);
|
||||
const version = await vscode.window.showQuickPick(versions, {placeHolder: "Select version ..."});
|
||||
if (version) {
|
||||
const cmd = ["mvn archetype:generate",
|
||||
`-DarchetypeArtifactId="${artifactId}"`,
|
||||
`-DarchetypeGroupId="${groupId}"`,
|
||||
`-DarchetypeVersion="${version}"`].join(" ");
|
||||
if (cwd) {
|
||||
VSCodeUI.runInTerminal(`cd "${cwd}"`, true, "Maven");
|
||||
}
|
||||
VSCodeUI.runInTerminal(cmd, true, "Maven");
|
||||
VSCodeUI.runInTerminal(cmd, { cwd, name: "Maven-Archetype" });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import { Utils } from "./utils";
|
|||
import { VSCodeUI } from "./vscodeUI";
|
||||
|
||||
const ENTRY_NEW_GOALS: string = "New ...";
|
||||
const ENTRY_OPEN_HIST: string = "View all historical commands";
|
||||
const ENTRY_OPEN_HIST: string = "Edit ...";
|
||||
|
||||
export class MavenProjectsTreeDataProvider implements vscode.TreeDataProvider<vscode.TreeItem> {
|
||||
|
||||
|
@ -83,8 +83,8 @@ export class MavenProjectsTreeDataProvider implements vscode.TreeDataProvider<vs
|
|||
|
||||
public executeGoal(item: MavenProjectTreeItem): void {
|
||||
const cmd = `mvn ${item.label} -f "${item.pomXmlFilePath}"`;
|
||||
const terminal = `Maven-${item.params.projectName}`;
|
||||
VSCodeUI.runInTerminal(cmd, true, terminal);
|
||||
const name = `Maven-${item.params.projectName}`;
|
||||
VSCodeUI.runInTerminal(cmd, { name });
|
||||
}
|
||||
|
||||
public async effectivePom(item: MavenProjectTreeItem | any): Promise<void> {
|
||||
|
@ -112,22 +112,24 @@ export class MavenProjectsTreeDataProvider implements vscode.TreeDataProvider<vs
|
|||
|
||||
public async customGoal(item: MavenProjectTreeItem): Promise<void> {
|
||||
const cmdlist: string[] = Utils.loadCmdHistory(item.pomXmlFilePath);
|
||||
const selectedGoal = await vscode.window.showQuickPick(cmdlist.concat([ENTRY_NEW_GOALS, ENTRY_OPEN_HIST]));
|
||||
const selectedGoal = await vscode.window.showQuickPick(cmdlist.concat([ENTRY_NEW_GOALS, ENTRY_OPEN_HIST]), {
|
||||
placeHolder: "Select the custom command ... ",
|
||||
});
|
||||
if (selectedGoal === ENTRY_NEW_GOALS) {
|
||||
const inputGoals = await vscode.window.showInputBox();
|
||||
const inputGoals = await vscode.window.showInputBox({placeHolder: "e.g. clean package -DskipTests"});
|
||||
const trimedGoals = inputGoals && inputGoals.trim();
|
||||
if (trimedGoals) {
|
||||
Utils.saveCmdHistory(item.pomXmlFilePath, Utils.withLRUItemAhead(cmdlist, trimedGoals));
|
||||
VSCodeUI.runInTerminal(`mvn ${trimedGoals} -f "${item.pomXmlFilePath}"`, true,
|
||||
`Maven-${item.params.projectName}`);
|
||||
VSCodeUI.runInTerminal(`mvn ${trimedGoals} -f "${item.pomXmlFilePath}"`,
|
||||
{ name: `Maven-${item.params.projectName}` });
|
||||
}
|
||||
} else if (selectedGoal === ENTRY_OPEN_HIST) {
|
||||
const historicalFilePath = Utils.getCommandHistoryCachePath(item.pomXmlFilePath);
|
||||
vscode.window.showTextDocument(vscode.Uri.file(historicalFilePath));
|
||||
} else if (selectedGoal) {
|
||||
Utils.saveCmdHistory(item.pomXmlFilePath, Utils.withLRUItemAhead(cmdlist, selectedGoal));
|
||||
VSCodeUI.runInTerminal(`mvn ${selectedGoal} -f "${item.pomXmlFilePath}"`, true,
|
||||
`Maven-${item.params.projectName}`);
|
||||
VSCodeUI.runInTerminal(`mvn ${selectedGoal} -f "${item.pomXmlFilePath}"`,
|
||||
{ name: `Maven-${item.params.projectName}` });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,35 @@
|
|||
import * as fs from "fs";
|
||||
import * as os from "os";
|
||||
import * as vscode from "vscode";
|
||||
|
||||
export class VSCodeUI {
|
||||
public static runInTerminal(command: string, addNewLine: boolean = true, terminal: string = "Maven"): void {
|
||||
if (this.terminals[terminal] === undefined) {
|
||||
this.terminals[terminal] = vscode.window.createTerminal(terminal);
|
||||
public static runInTerminal(command: string, options?: ITerminalOptions): void {
|
||||
const defaultOptions: ITerminalOptions = { addNewLine: true, name: "Maven" };
|
||||
const { addNewLine, name, cwd } = Object.assign(defaultOptions, options);
|
||||
if (this.terminals[name] === undefined) {
|
||||
this.terminals[name] = vscode.window.createTerminal({ name });
|
||||
}
|
||||
this.terminals[name].show();
|
||||
if (cwd) {
|
||||
this.terminals[name].sendText(this.getCDCommand(cwd), true);
|
||||
}
|
||||
this.terminals[name].sendText(command, addNewLine);
|
||||
}
|
||||
|
||||
public static getCDCommand(cwd: string): string {
|
||||
if (os.platform() === "win32") {
|
||||
const windowsShell = vscode.workspace.getConfiguration("terminal").get<string>("integrated.shell.windows")
|
||||
.toLowerCase();
|
||||
if (windowsShell && windowsShell.indexOf("bash.exe") > -1 && windowsShell.indexOf("git") > -1) {
|
||||
return `cd "${cwd.replace(/\\+$/, "")}"`; // Git Bash: remove trailing '\'
|
||||
} else if (windowsShell && windowsShell.indexOf("powershell.exe") > -1) {
|
||||
return `cd "${cwd}"`; // PowerShell
|
||||
} else if (windowsShell && windowsShell.indexOf("cmd.exe") > -1) {
|
||||
return `cd /d "${cwd}"`; // CMD
|
||||
}
|
||||
} else {
|
||||
return `cd "${cwd}"`;
|
||||
}
|
||||
this.terminals[terminal].show();
|
||||
this.terminals[terminal].sendText(command, addNewLine);
|
||||
}
|
||||
|
||||
public static onDidCloseTerminal(closedTerminal: vscode.Terminal): void {
|
||||
|
@ -36,3 +58,9 @@ export class VSCodeUI {
|
|||
|
||||
private static terminals: { [id: string]: vscode.Terminal } = {};
|
||||
}
|
||||
|
||||
interface ITerminalOptions {
|
||||
addNewLine?: boolean;
|
||||
name?: string;
|
||||
cwd?: string;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче