Automatically detect functionAppName on java deploy (#75)
This commit is contained in:
Родитель
3d5893b9af
Коммит
a72cce4233
10
package.json
10
package.json
|
@ -252,8 +252,9 @@
|
|||
"@types/fs-extra": "^4.0.3",
|
||||
"@types/mocha": "^2.2.32",
|
||||
"@types/node": "^8.0.28",
|
||||
"@types/request-promise": "4.1.38",
|
||||
"@types/request": "2.0.7",
|
||||
"@types/request-promise": "4.1.38",
|
||||
"@types/xml2js": "^0.4.2",
|
||||
"mocha": "^2.3.3",
|
||||
"tslint": "^5.7.0",
|
||||
"tslint-microsoft-contrib": "5.0.1",
|
||||
|
@ -263,16 +264,17 @@
|
|||
"dependencies": {
|
||||
"azure-arm-cosmosdb": "^1.0.0-preview",
|
||||
"azure-arm-resource": "^2.0.0-preview",
|
||||
"azure-arm-website": "^1.0.0-preview",
|
||||
"azure-arm-storage": "^3.1.0",
|
||||
"azure-arm-website": "^1.0.0-preview",
|
||||
"fs-extra": "^4.0.2",
|
||||
"ms-rest": "^2.2.2",
|
||||
"ms-rest-azure": "^2.3.1",
|
||||
"request-promise": "^4.2.2",
|
||||
"vscode-azureappservice": "^0.4.0",
|
||||
"vscode-azureextensionui": "~0.2.0",
|
||||
"vscode-extension-telemetry": "^0.0.6",
|
||||
"vscode-nls": "^2.0.2",
|
||||
"vscode-azureextensionui": "~0.2.0",
|
||||
"vscode-azureappservice": "^0.4.0"
|
||||
"xml2js": "^0.4.19"
|
||||
},
|
||||
"extensionDependencies": [
|
||||
"ms-vscode.azure-account"
|
||||
|
|
|
@ -12,9 +12,9 @@ import * as vscode from 'vscode';
|
|||
import { MessageItem } from 'vscode';
|
||||
import { SiteWrapper } from 'vscode-azureappservice';
|
||||
import { AzureTreeDataProvider, IAzureNode, UserCancelledError } from 'vscode-azureextensionui';
|
||||
import * as xml2js from 'xml2js';
|
||||
import { DialogResponses } from '../DialogResponses';
|
||||
import { NoPackagedJavaFunctionError } from '../errors';
|
||||
import { IUserInterface, Pick } from '../IUserInterface';
|
||||
import { IUserInterface } from '../IUserInterface';
|
||||
import { localize } from '../localize';
|
||||
import { TemplateLanguage } from '../templates/Template';
|
||||
import { FunctionAppTreeItem } from '../tree/FunctionAppTreeItem';
|
||||
|
@ -48,27 +48,22 @@ export async function deploy(tree: AzureTreeDataProvider, outputChannel: vscode.
|
|||
async function getJavaFolderPath(outputChannel: vscode.OutputChannel, basePath: string, ui: IUserInterface): Promise<string> {
|
||||
outputChannel.show();
|
||||
await cpUtils.executeCommand(outputChannel, basePath, 'mvn', 'clean', 'package', '-B');
|
||||
const targetFolder: string = path.join(basePath, 'target', 'azure-functions');
|
||||
if (!await fse.pathExists(targetFolder)) {
|
||||
throw new NoPackagedJavaFunctionError();
|
||||
}
|
||||
const packagedFolders: string[] = fse.readdirSync(targetFolder);
|
||||
if (packagedFolders.length === 0) {
|
||||
throw new NoPackagedJavaFunctionError();
|
||||
} else if (packagedFolders.length === 1) {
|
||||
return path.join(targetFolder, packagedFolders[0]);
|
||||
const pomLocation: string = path.join(basePath, 'pom.xml');
|
||||
const functionAppName: string | undefined = await getFunctionAppNameInPom(pomLocation);
|
||||
const targetFolder: string = functionAppName ? path.join(basePath, 'target', 'azure-functions', functionAppName) : '';
|
||||
if (functionAppName && await fse.pathExists(targetFolder)) {
|
||||
return targetFolder;
|
||||
} else {
|
||||
return path.join(targetFolder, await promptForPackagedFolder(ui, packagedFolders));
|
||||
const message: string = localize('azFunc.cannotFindPackageFolder', 'Cannot find the packaged function folder, would you like to specify the folder location?');
|
||||
const result: MessageItem | undefined = await vscode.window.showWarningMessage(message, DialogResponses.yes, DialogResponses.cancel);
|
||||
if (result === DialogResponses.yes) {
|
||||
return await ui.showFolderDialog();
|
||||
} else {
|
||||
throw new UserCancelledError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function promptForPackagedFolder(ui: IUserInterface, folders: string[]): Promise<string> {
|
||||
const picks: Pick[] = folders.map((f: string) => new Pick(f));
|
||||
|
||||
const placeHolder: string = localize('azFunc.PackagedFolderPlaceholder', 'Select packaged folder you want to deploy');
|
||||
return (await ui.showQuickPick(picks, placeHolder, false)).label;
|
||||
}
|
||||
|
||||
async function verifyBetaRuntime(outputChannel: vscode.OutputChannel, client: WebSiteManagementClient, siteWrapper: SiteWrapper): Promise<void> {
|
||||
const appSettings: StringDictionary = await client.webApps.listApplicationSettings(siteWrapper.resourceGroup, siteWrapper.appName);
|
||||
if (appSettings.properties && appSettings.properties.FUNCTIONS_EXTENSION_VERSION !== 'beta') {
|
||||
|
@ -82,8 +77,26 @@ async function verifyBetaRuntime(outputChannel: vscode.OutputChannel, client: We
|
|||
siteWrapper.appName,
|
||||
appSettings
|
||||
);
|
||||
} else if (result === undefined) {
|
||||
} else {
|
||||
throw new UserCancelledError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function getFunctionAppNameInPom(pomLocation: string): Promise<string | undefined> {
|
||||
const pomString: string = await fse.readFile(pomLocation, 'utf-8');
|
||||
return await new Promise((resolve: (ret: string | undefined) => void): void => {
|
||||
// tslint:disable-next-line:no-any
|
||||
xml2js.parseString(pomString, { explicitArray: false }, (err: any, result: any): void => {
|
||||
if (result && !err) {
|
||||
// tslint:disable-next-line:no-string-literal no-unsafe-any
|
||||
if (result['project'] && result['project']['properties']) {
|
||||
// tslint:disable-next-line:no-string-literal no-unsafe-any
|
||||
resolve(result['project']['properties']['functionAppName']);
|
||||
return;
|
||||
}
|
||||
}
|
||||
resolve(undefined);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -20,7 +20,3 @@ export class ArgumentError extends Error {
|
|||
export class NoSubscriptionError extends Error {
|
||||
public message: string = localize('azFunc.noSubscriptionError', 'You must be signed in to Azure to perform this operation.');
|
||||
}
|
||||
|
||||
export class NoPackagedJavaFunctionError extends Error {
|
||||
public message: string = localize('azFunc.noPackagedJavaFunctionError', 'Cannot find packaged Java functions.');
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ are grateful to these developers for their contribution to open source.
|
|||
|
||||
1. fs-extra (https://github.com/jprichardson/node-fs-extra)
|
||||
2. request-promise (https://github.com/request/request-promise)
|
||||
3. xml2js (https://github.com/Leonidas-from-XIV/node-xml2js)
|
||||
|
||||
fs-extra NOTICES BEGIN HERE
|
||||
=============================
|
||||
|
@ -51,3 +52,29 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
END OF request-promise NOTICES AND INFORMATION
|
||||
==================================
|
||||
|
||||
xml2js NOTICES BEGIN HERE
|
||||
=============================
|
||||
|
||||
Copyright 2010, 2011, 2012, 2013. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to
|
||||
deal in the Software without restriction, including without limitation the
|
||||
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
IN THE SOFTWARE.
|
||||
|
||||
END OF xml2js NOTICES AND INFORMATION
|
||||
==================================
|
||||
|
|
Загрузка…
Ссылка в новой задаче