Skip to content

Commit 08d3cc0

Browse files
jdneoejizba
authored andcommitted
check maven is installed or not
1 parent a59dcc1 commit 08d3cc0

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

src/commands/createFunction.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import * as fse from 'fs-extra';
77
import * as path from 'path';
88
import * as vscode from 'vscode';
9-
import { MessageItem } from 'vscode';
109
import { UserCancelledError } from 'vscode-azureextensionui';
1110
import { AzureAccount } from '../azure-account.api';
1211
import { DialogResponses } from '../DialogResponses';
@@ -20,6 +19,7 @@ import { TemplateData } from '../templates/TemplateData';
2019
import { cpUtils } from '../utils/cpUtils';
2120
import * as fsUtil from '../utils/fs';
2221
import { getJavaClassName, validateJavaFunctionName, validatePackageName } from '../utils/javaNameUtils';
22+
import { mavenUtils } from '../utils/mavenUtils';
2323
import { projectUtils } from '../utils/projectUtils';
2424
import * as workspaceUtil from '../utils/workspace';
2525
import { VSCodeUI } from '../VSCodeUI';
@@ -54,7 +54,7 @@ function validateTemplateName(rootPath: string, name: string | undefined, langua
5454
async function validateIsFunctionApp(telemetryProperties: { [key: string]: string; }, outputChannel: vscode.OutputChannel, functionAppPath: string, ui: IUserInterface): Promise<void> {
5555
if (requiredFunctionAppFiles.find((file: string) => !fse.existsSync(path.join(functionAppPath, file))) !== undefined) {
5656
const message: string = localize('azFunc.notFunctionApp', 'The selected folder is not a function app project. Initialize Project?');
57-
const result: MessageItem | undefined = await vscode.window.showWarningMessage(message, DialogResponses.yes, DialogResponses.skipForNow, DialogResponses.cancel);
57+
const result: vscode.MessageItem | undefined = await vscode.window.showWarningMessage(message, DialogResponses.yes, DialogResponses.skipForNow, DialogResponses.cancel);
5858
if (result === DialogResponses.yes) {
5959
await createNewProject(telemetryProperties, outputChannel, functionAppPath, false, ui);
6060
} else if (result === undefined) {
@@ -166,6 +166,9 @@ export async function createFunction(
166166

167167
let newFilePath: string;
168168
if (languageType === TemplateLanguage.Java) {
169+
if (!(await mavenUtils.isMavenInstalled(functionAppPath))) {
170+
throw new Error(localize('azFunc.mvnNotFound', 'Failed to find "maven" on path.'));
171+
}
169172
outputChannel.show();
170173
await cpUtils.executeCommand(
171174
outputChannel,

src/commands/createNewProject.ts

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { confirmOverwriteFile } from '../utils/fs';
1616
import * as fsUtil from '../utils/fs';
1717
import { gitUtils } from '../utils/gitUtils';
1818
import { validateMavenIdentifier, validatePackageName } from '../utils/javaNameUtils';
19+
import { mavenUtils } from '../utils/mavenUtils';
1920
import * as workspaceUtil from '../utils/workspace';
2021
import { VSCodeUI } from '../VSCodeUI';
2122

@@ -179,6 +180,9 @@ async function promotForMavenParameters(ui: IUserInterface, functionAppPath: str
179180
}
180181

181182
async function createJavaFunctionProject(outputChannel: OutputChannel, functionAppPath: string, ui: IUserInterface): Promise<string> {
183+
if (!(await mavenUtils.isMavenInstalled(functionAppPath))) {
184+
throw new Error(localize('azFunc.mvnNotFound', 'Failed to find "maven" on path.'));
185+
}
182186
// Get parameters for Maven command
183187
const { groupId, artifactId, version, packageName, appName } = await promotForMavenParameters(ui, functionAppPath);
184188
const tempFolder: string = path.join(os.tmpdir(), fsUtil.getRandomHexString());

src/commands/deploy.ts

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { localize } from '../localize';
1919
import { TemplateLanguage } from '../templates/Template';
2020
import { FunctionAppTreeItem } from '../tree/FunctionAppTreeItem';
2121
import { cpUtils } from '../utils/cpUtils';
22+
import { mavenUtils } from '../utils/mavenUtils';
2223
import { nodeUtils } from '../utils/nodeUtils';
2324
import { projectUtils } from '../utils/projectUtils';
2425
import * as workspaceUtil from '../utils/workspace';
@@ -46,6 +47,9 @@ export async function deploy(tree: AzureTreeDataProvider, outputChannel: vscode.
4647
}
4748

4849
async function getJavaFolderPath(outputChannel: vscode.OutputChannel, basePath: string, ui: IUserInterface): Promise<string> {
50+
if (!(await mavenUtils.isMavenInstalled(basePath))) {
51+
throw new Error(localize('azFunc.mvnNotFound', 'Failed to find "maven" on path.'));
52+
}
4953
outputChannel.show();
5054
await cpUtils.executeCommand(outputChannel, basePath, 'mvn', 'clean', 'package', '-B');
5155
const pomLocation: string = path.join(basePath, 'pom.xml');

src/utils/mavenUtils.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { cpUtils } from './cpUtils';
7+
8+
export namespace mavenUtils {
9+
const mvnCommand: string = 'mvn';
10+
export async function isMavenInstalled(workingDirectory: string): Promise<boolean> {
11+
try {
12+
await cpUtils.executeCommand(undefined, workingDirectory, mvnCommand, '--version');
13+
return true;
14+
} catch {
15+
return false;
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)