Skip to content

Commit

Permalink
check maven is installed or not
Browse files Browse the repository at this point in the history
  • Loading branch information
jdneo authored and ejizba committed Dec 1, 2017
1 parent a59dcc1 commit 08d3cc0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/commands/createFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import * as fse from 'fs-extra';
import * as path from 'path';
import * as vscode from 'vscode';
import { MessageItem } from 'vscode';
import { UserCancelledError } from 'vscode-azureextensionui';
import { AzureAccount } from '../azure-account.api';
import { DialogResponses } from '../DialogResponses';
Expand All @@ -20,6 +19,7 @@ import { TemplateData } from '../templates/TemplateData';
import { cpUtils } from '../utils/cpUtils';
import * as fsUtil from '../utils/fs';
import { getJavaClassName, validateJavaFunctionName, validatePackageName } from '../utils/javaNameUtils';
import { mavenUtils } from '../utils/mavenUtils';
import { projectUtils } from '../utils/projectUtils';
import * as workspaceUtil from '../utils/workspace';
import { VSCodeUI } from '../VSCodeUI';
Expand Down Expand Up @@ -54,7 +54,7 @@ function validateTemplateName(rootPath: string, name: string | undefined, langua
async function validateIsFunctionApp(telemetryProperties: { [key: string]: string; }, outputChannel: vscode.OutputChannel, functionAppPath: string, ui: IUserInterface): Promise<void> {
if (requiredFunctionAppFiles.find((file: string) => !fse.existsSync(path.join(functionAppPath, file))) !== undefined) {
const message: string = localize('azFunc.notFunctionApp', 'The selected folder is not a function app project. Initialize Project?');
const result: MessageItem | undefined = await vscode.window.showWarningMessage(message, DialogResponses.yes, DialogResponses.skipForNow, DialogResponses.cancel);
const result: vscode.MessageItem | undefined = await vscode.window.showWarningMessage(message, DialogResponses.yes, DialogResponses.skipForNow, DialogResponses.cancel);
if (result === DialogResponses.yes) {
await createNewProject(telemetryProperties, outputChannel, functionAppPath, false, ui);
} else if (result === undefined) {
Expand Down Expand Up @@ -166,6 +166,9 @@ export async function createFunction(

let newFilePath: string;
if (languageType === TemplateLanguage.Java) {
if (!(await mavenUtils.isMavenInstalled(functionAppPath))) {
throw new Error(localize('azFunc.mvnNotFound', 'Failed to find "maven" on path.'));
}
outputChannel.show();
await cpUtils.executeCommand(
outputChannel,
Expand Down
4 changes: 4 additions & 0 deletions src/commands/createNewProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { confirmOverwriteFile } from '../utils/fs';
import * as fsUtil from '../utils/fs';
import { gitUtils } from '../utils/gitUtils';
import { validateMavenIdentifier, validatePackageName } from '../utils/javaNameUtils';
import { mavenUtils } from '../utils/mavenUtils';
import * as workspaceUtil from '../utils/workspace';
import { VSCodeUI } from '../VSCodeUI';

Expand Down Expand Up @@ -179,6 +180,9 @@ async function promotForMavenParameters(ui: IUserInterface, functionAppPath: str
}

async function createJavaFunctionProject(outputChannel: OutputChannel, functionAppPath: string, ui: IUserInterface): Promise<string> {
if (!(await mavenUtils.isMavenInstalled(functionAppPath))) {
throw new Error(localize('azFunc.mvnNotFound', 'Failed to find "maven" on path.'));
}
// Get parameters for Maven command
const { groupId, artifactId, version, packageName, appName } = await promotForMavenParameters(ui, functionAppPath);
const tempFolder: string = path.join(os.tmpdir(), fsUtil.getRandomHexString());
Expand Down
4 changes: 4 additions & 0 deletions src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { localize } from '../localize';
import { TemplateLanguage } from '../templates/Template';
import { FunctionAppTreeItem } from '../tree/FunctionAppTreeItem';
import { cpUtils } from '../utils/cpUtils';
import { mavenUtils } from '../utils/mavenUtils';
import { nodeUtils } from '../utils/nodeUtils';
import { projectUtils } from '../utils/projectUtils';
import * as workspaceUtil from '../utils/workspace';
Expand Down Expand Up @@ -46,6 +47,9 @@ export async function deploy(tree: AzureTreeDataProvider, outputChannel: vscode.
}

async function getJavaFolderPath(outputChannel: vscode.OutputChannel, basePath: string, ui: IUserInterface): Promise<string> {
if (!(await mavenUtils.isMavenInstalled(basePath))) {
throw new Error(localize('azFunc.mvnNotFound', 'Failed to find "maven" on path.'));
}
outputChannel.show();
await cpUtils.executeCommand(outputChannel, basePath, 'mvn', 'clean', 'package', '-B');
const pomLocation: string = path.join(basePath, 'pom.xml');
Expand Down
18 changes: 18 additions & 0 deletions src/utils/mavenUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { cpUtils } from './cpUtils';

export namespace mavenUtils {
const mvnCommand: string = 'mvn';
export async function isMavenInstalled(workingDirectory: string): Promise<boolean> {
try {
await cpUtils.executeCommand(undefined, workingDirectory, mvnCommand, '--version');
return true;
} catch {
return false;
}
}
}

0 comments on commit 08d3cc0

Please sign in to comment.