From 653ea8ea14267b0f4a1cfb2c70a5611c8eaa529f Mon Sep 17 00:00:00 2001 From: Yan Zhang Date: Tue, 3 Jul 2018 16:29:30 +0800 Subject: [PATCH 1/2] Guide users to setup correct mvn executable path --- FAQ.md | 41 +++++++++++++++++++++++++++++++++++++++++ src/Utils.ts | 18 ++++++++++++++++++ src/extension.ts | 28 +++++++++++++++++++++++++++- tslint.json | 4 ++-- 4 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 FAQ.md diff --git a/FAQ.md b/FAQ.md new file mode 100644 index 00000000..8fadf9c2 --- /dev/null +++ b/FAQ.md @@ -0,0 +1,41 @@ +# FAQ + +## Requirements + +### Available Maven executable +By default, `mvn` command is executed directly in the terminal, which requires `mvn` can be found in system envronment `PATH`. +If you do not want to add it into `PATH`, you can specify maven executable path in settings: + ``` + { + "maven.executable.path": "/some-path-to-maven-home/bin/mvn" + } + ``` + +#### Possible error messages +* Maven executable file not found/set. + ``` + Command failed: mvn --version 'mvn' is not recognized as an internal or external command, operable program or batch file. + ``` + In this case, please follow above instructions to set available maven executable path. + + +* `M2_HOME` not correctly set. + ``` + Error: Command failed: mvn help:effective-pom -f "xxxxxxxxxxxx\pom.xml" -Doutput="xxxxxxxxxxxxxxx\effective-pom.xml" + Error: M2_HOME is set to an invalid directory. + M2_HOME = "xxxxxxxxx\apache-maven-3.3.9\bin" + Please set the M2_HOME variable in your environment to match the + location of the Maven installation + ``` + In this case, please follow the error message to reset a correct `M2_HOME`. + +### Available Java Runtime (required by Maven) + +#### Possible error messages +* `JAVA_HOME` not correctly set. + ``` + The JAVA_HOME environment variable is not defined correctly + This environment variable is needed to run this program + NB: JAVA_HOME should point to a JDK not a JRE + ``` + In this case, please specify a correct JAVA_HOME environment variable, or re-install JRE/JDK if necessary. \ No newline at end of file diff --git a/src/Utils.ts b/src/Utils.ts index be666742..47a15424 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +import * as child_process from "child_process"; import * as fse from "fs-extra"; import * as http from "http"; import * as https from "https"; @@ -333,4 +334,21 @@ export namespace Utils { return filepath; } } + + export function getMavenVersion(): Promise { + return new Promise((resolve, reject) => { + const customEnv: {} = VSCodeUI.setupEnvironment(); + const execOptions: child_process.ExecOptions = { + env: Object.assign({}, process.env, customEnv) + }; + child_process.exec( + `${Utils.getMavenExecutable()} --version`, execOptions, (error: Error, _stdout: string, _stderr: string): void => { + if (error) { + reject(error); + } else { + resolve(); + } + }); + }); + } } diff --git a/src/extension.ts b/src/extension.ts index b3adb2c7..1814604c 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -28,6 +28,7 @@ export async function activate(context: vscode.ExtensionContext): Promise watcher.onDidDelete(() => mavenProjectsTreeDataProvider.refreshTree()); context.subscriptions.push(watcher); + // register commands. ["clean", "validate", "compile", "test", "package", "verify", "install", "site", "deploy"].forEach((goal: string) => { context.subscriptions.push(TelemetryWrapper.registerCommand(`maven.goal.${goal}`, async (item: ProjectItem) => { await mavenProjectsTreeDataProvider.executeGoal(item, goal); @@ -76,8 +77,9 @@ export async function activate(context: vscode.ExtensionContext): Promise VSCodeUI.onDidCloseTerminal(closedTerminal); })); - // close all terminals with outdated Envs + // configuration change listener vscode.workspace.onDidChangeConfiguration((e: vscode.ConfigurationChangeEvent) => { + // close all terminals with outdated JAVA related Envs if (e.affectsConfiguration("maven.terminal.useJavaHome") || e.affectsConfiguration("maven.terminal.customEnv")) { VSCodeUI.closeAllTerminals(); } else { @@ -86,9 +88,33 @@ export async function activate(context: vscode.ExtensionContext): Promise VSCodeUI.closeAllTerminals(); } } + checkMavenAvailablility(); }); + + // check maven executable file + checkMavenAvailablility(); } export function deactivate(): void { // this method is called when your extension is deactivated } + +// private helpers +async function checkMavenAvailablility(): Promise { + try { + await Utils.getMavenVersion(); + } catch (error) { + const OPTION_SHOW_DETAILS: string = "Show details"; + const OPTION_GUIDE: string = "Guidance"; + const choice: string = await vscode.window.showErrorMessage("Unable to execute Maven commands. Please make sure Maven is either in the PATH, or that 'maven.executable.path' is pointed to its installed location. Also make sure JAVA_HOME is specified either in environment variables or settings.", OPTION_SHOW_DETAILS); + if (choice === OPTION_SHOW_DETAILS) { + const choice2: string = await vscode.window.showErrorMessage(error.message, OPTION_GUIDE); + if (choice2 === OPTION_GUIDE) { + // open FAQ + const readmeFilePath: string = Utils.getPathToExtensionRoot("FAQ.md"); + vscode.commands.executeCommand("markdown.showPreview", vscode.Uri.file(readmeFilePath)); + } + } + } + +} diff --git a/tslint.json b/tslint.json index e04af839..ca097720 100644 --- a/tslint.json +++ b/tslint.json @@ -185,9 +185,9 @@ "typedef": [ true, "call-signature", - "arrow-call-signature", + // "arrow-call-signature", "parameter", - "arrow-parameter", + // "arrow-parameter", "property-declaration", "variable-declaration", "member-variable-declaration" From 325458cd313cd592f403782c866b26da825ccd19 Mon Sep 17 00:00:00 2001 From: Yan Zhang Date: Wed, 4 Jul 2018 10:13:11 +0800 Subject: [PATCH 2/2] Update extension.ts --- src/extension.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 1814604c..24cb3227 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -106,10 +106,10 @@ async function checkMavenAvailablility(): Promise { } catch (error) { const OPTION_SHOW_DETAILS: string = "Show details"; const OPTION_GUIDE: string = "Guidance"; - const choice: string = await vscode.window.showErrorMessage("Unable to execute Maven commands. Please make sure Maven is either in the PATH, or that 'maven.executable.path' is pointed to its installed location. Also make sure JAVA_HOME is specified either in environment variables or settings.", OPTION_SHOW_DETAILS); - if (choice === OPTION_SHOW_DETAILS) { - const choice2: string = await vscode.window.showErrorMessage(error.message, OPTION_GUIDE); - if (choice2 === OPTION_GUIDE) { + const choiceForDetails: string = await vscode.window.showErrorMessage("Unable to execute Maven commands. Please make sure Maven is either in the PATH, or that 'maven.executable.path' is pointed to its installed location. Also make sure JAVA_HOME is specified either in environment variables or settings.", OPTION_SHOW_DETAILS); + if (choiceForDetails === OPTION_SHOW_DETAILS) { + const choiceForGuide: string = await vscode.window.showErrorMessage(error.message, OPTION_GUIDE); + if (choiceForGuide === OPTION_GUIDE) { // open FAQ const readmeFilePath: string = Utils.getPathToExtensionRoot("FAQ.md"); vscode.commands.executeCommand("markdown.showPreview", vscode.Uri.file(readmeFilePath));