From a1454d3dc643f5f8cd63b73689e6f6c9f15e6a6a Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Mon, 5 Feb 2018 14:34:13 -0800 Subject: [PATCH 01/28] Enable usage of multiple versions --- package.json | 2 +- src/omnisharp/experimentalOmnisharp.ts | 38 ++++++++++++++++++++++++++ src/omnisharp/launcher.ts | 14 +++++----- src/omnisharp/server.ts | 15 +++++++++- 4 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 src/omnisharp/experimentalOmnisharp.ts diff --git a/package.json b/package.json index 121020b79..84a078253 100644 --- a/package.json +++ b/package.json @@ -361,7 +361,7 @@ "null" ], "default": null, - "description": "Specifies the full path to the OmniSharp server." + "description": "Specifies the full path to the OmniSharp server or the string \"latest\" to download the latest version or some version number" }, "omnisharp.useMono": { "type": "boolean", diff --git a/src/omnisharp/experimentalOmnisharp.ts b/src/omnisharp/experimentalOmnisharp.ts new file mode 100644 index 000000000..10608d786 --- /dev/null +++ b/src/omnisharp/experimentalOmnisharp.ts @@ -0,0 +1,38 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import * as util from '../common'; +import * as path from 'path'; +import * as semver from 'semver'; + +export function GetExperimentalOmnisharpPath(optionsPath: string): string{ + // Looks at the options path, installs the dependenices and returns the path to be loaded by the omnisharp server + // To Do : Add the functionality for the latest option + + if (util.fileExists(optionsPath)) { + // The file is a valid file on disk + return optionsPath; + } + + let extensionPath = util.getExtensionPath(); + // If it is not a valid path, it might be a version that the user wants to use + if (IsValidSemver(optionsPath)) { + if (DownloadAndInstallExperimentalVersion(optionsPath)) { + // Download and install completed successfully otherwise the error thrown will be handled by the server + return path.resolve(extensionPath, `.omnisharp/experimental/${optionsPath}`); + } + } + else { + throw new Error('Bad Input to Omnisharp Path'); + } +} + +function IsValidSemver(version: string): boolean { + if (semver.valid(version)) { + return true; + } + + return false; +} \ No newline at end of file diff --git a/src/omnisharp/launcher.ts b/src/omnisharp/launcher.ts index 2a70ac273..0efb3ba8a 100644 --- a/src/omnisharp/launcher.ts +++ b/src/omnisharp/launcher.ts @@ -207,9 +207,9 @@ export interface LaunchResult { usingMono: boolean; } -export function launchOmniSharp(cwd: string, args: string[]): Promise { +export function launchOmniSharp(cwd: string, args: string[], experimentalLaunchPath: string): Promise { return new Promise((resolve, reject) => { - launch(cwd, args) + launch(cwd, args, experimentalLaunchPath) .then(result => { // async error - when target not not ENEOT result.process.on('error', err => { @@ -225,7 +225,7 @@ export function launchOmniSharp(cwd: string, args: string[]): Promise { +function launch(cwd: string, args: string[], experimentalLaunchPath: string): Promise { return PlatformInformation.GetCurrent().then(platformInfo => { const options = Options.Read(); @@ -240,17 +240,17 @@ function launch(cwd: string, args: string[]): Promise { } // If the user has provide a path to OmniSharp, we'll use that. - if (options.path) { + if (experimentalLaunchPath) { if (platformInfo.isWindows()) { - return launchWindows(options.path, cwd, args); + return launchWindows(experimentalLaunchPath, cwd, args); } // If we're launching on macOS/Linux, we have two possibilities: // 1. Launch using Mono // 2. Launch process directly (e.g. a 'run' script) return options.useMono - ? launchNixMono(options.path, cwd, args) - : launchNix(options.path, cwd, args); + ? launchNixMono(experimentalLaunchPath, cwd, args) + : launchNix(experimentalLaunchPath, cwd, args); } // If the user has not provided a path, we'll use the locally-installed OmniSharp diff --git a/src/omnisharp/server.ts b/src/omnisharp/server.ts index bd3b9c8a9..f86ec769c 100644 --- a/src/omnisharp/server.ts +++ b/src/omnisharp/server.ts @@ -19,6 +19,7 @@ import * as protocol from './protocol'; import * as utils from '../common'; import * as vscode from 'vscode'; import { setTimeout } from 'timers'; +import { GetExperimentalOmnisharpPath } from './experimentalOmnisharp'; enum ServerState { Starting, @@ -259,6 +260,18 @@ export class OmniSharpServer { args.push('--debug'); } + let experimentalLaunchPath: string; + if (this._options.path) { + try { + experimentalLaunchPath = GetExperimentalOmnisharpPath(this._options.path); + } + catch (error) { + this._logger.appendLine(`Could not start the server due to ${error}`); + this._logger.appendLine(); + return; + } + } + this._logger.appendLine(`Starting OmniSharp server at ${new Date().toLocaleString()}`); this._logger.increaseIndent(); this._logger.appendLine(`Target: ${solutionPath}`); @@ -267,7 +280,7 @@ export class OmniSharpServer { this._fireEvent(Events.BeforeServerStart, solutionPath); - return launchOmniSharp(cwd, args).then(value => { + return launchOmniSharp(cwd, args, experimentalLaunchPath).then(value => { if (value.usingMono) { this._logger.appendLine(`OmniSharp server started wth Mono`); } From 26da0a6f516171d978c196ebcc290bac855ddb9a Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Mon, 5 Feb 2018 17:02:30 -0800 Subject: [PATCH 02/28] Either load the server from a path or download the version packages --- package.json | 15 ++-- src/downloadHelper.ts | 87 +++++++++++++++++++ src/main.ts | 2 +- src/omnisharp/experimentalOmnisharp.ts | 38 -------- .../experimentalOmnisharpDownloader.ts | 67 ++++++++++++++ src/omnisharp/experimentalOmnisharpManager.ts | 71 +++++++++++++++ src/omnisharp/experimentalPackageCreator.ts | 54 ++++++++++++ src/omnisharp/extension.ts | 5 +- src/omnisharp/server.ts | 16 +++- src/packages.ts | 19 ++-- 10 files changed, 317 insertions(+), 57 deletions(-) create mode 100644 src/downloadHelper.ts delete mode 100644 src/omnisharp/experimentalOmnisharp.ts create mode 100644 src/omnisharp/experimentalOmnisharpDownloader.ts create mode 100644 src/omnisharp/experimentalOmnisharpManager.ts create mode 100644 src/omnisharp/experimentalPackageCreator.ts diff --git a/package.json b/package.json index 84a078253..5f1cf1819 100644 --- a/package.json +++ b/package.json @@ -93,7 +93,8 @@ "architectures": [ "x86" ], - "installTestPath": "./.omnisharp/OmniSharp.exe" + "installTestPath": "./.omnisharp/OmniSharp.exe", + "experimentalPackageId": "win-x86" }, { "description": "OmniSharp for Windows (.NET 4.6 / x64)", @@ -106,7 +107,8 @@ "architectures": [ "x86_64" ], - "installTestPath": "./.omnisharp/OmniSharp.exe" + "installTestPath": "./.omnisharp/OmniSharp.exe", + "experimentalPackageId": "win-x64" }, { "description": "OmniSharp for OSX", @@ -120,7 +122,8 @@ "./mono.osx", "./run" ], - "installTestPath": "./.omnisharp/mono.osx" + "installTestPath": "./.omnisharp/mono.osx", + "experimentalPackageId": "osx" }, { "description": "OmniSharp for Linux (x86)", @@ -138,7 +141,8 @@ "./mono.linux-x86", "./run" ], - "installTestPath": "./.omnisharp/mono.linux-x86" + "installTestPath": "./.omnisharp/mono.linux-x86", + "experimentalPackageId": "linux-x86" }, { "description": "OmniSharp for Linux (x64)", @@ -155,7 +159,8 @@ "./mono.linux-x86_64", "./run" ], - "installTestPath": "./.omnisharp/mono.linux-x86_64" + "installTestPath": "./.omnisharp/mono.linux-x86_64", + "experimentalPackageId": "linux-x64" }, { "description": ".NET Core Debugger (Windows / x64)", diff --git a/src/downloadHelper.ts b/src/downloadHelper.ts new file mode 100644 index 000000000..55c68f047 --- /dev/null +++ b/src/downloadHelper.ts @@ -0,0 +1,87 @@ +/*--------------------------------------------------------------------------------------------- +* Copyright (c) Microsoft Corporation. All rights reserved. +* Licensed under the MIT License. See License.txt in the project root for license information. +*--------------------------------------------------------------------------------------------*/ +import * as fs from 'fs'; +import * as vscode from 'vscode'; +import * as util from './common'; +import { PackageManager, Status, PackageError } from './packages'; +import { PlatformInformation } from './platform'; +import { Logger } from './logger'; +import TelemetryReporter from 'vscode-extension-telemetry'; + +export async function GetDownloadDependencies(reporter: TelemetryReporter, logger: Logger, channel: vscode.OutputChannel, packageJSON: any, platformInfo: PlatformInformation) { + let packageManager = new PackageManager(platformInfo, packageJSON); + const config = vscode.workspace.getConfiguration(); + const proxy = config.get('http.proxy'); + const strictSSL = config.get('http.proxyStrictSSL', true); + return { + Proxy: proxy, StrictSSL: strictSSL, PackageManager: packageManager + }; +} + +export function GetStatus(statusItem: vscode.StatusBarItem): Status { + let status: Status = { + setMessage: text => { + statusItem.text = text; + statusItem.show(); + }, + setDetail: text => { + statusItem.tooltip = text; + statusItem.show(); + } + }; + + return status; +} + +export async function GetPlatformInformation(logger: Logger): Promise { + let platformInfo = await PlatformInformation.GetCurrent(); + logger.appendLine(); + // Display platform information and RID followed by a blank line + logger.appendLine(`Platform: ${platformInfo.toString()}`); + logger.appendLine(); + return platformInfo; +} + +export function ReportError(logger: Logger, error, telemetryProps: any, installationStage: string) { + let errorMessage: string; + if (error instanceof PackageError) { + // we can log the message in a PackageError to telemetry as we do not put PII in PackageError messages + telemetryProps['error.message'] = error.message; + if (error.innerError) { + errorMessage = error.innerError.toString(); + } + else { + errorMessage = error.message; + } + if (error.pkg) { + telemetryProps['error.packageUrl'] = error.pkg.url; + } + } + else { + // do not log raw errorMessage in telemetry as it is likely to contain PII. + errorMessage = error.toString(); + } + + logger.appendLine(`Failed at stage: ${installationStage}`); + logger.appendLine(errorMessage); +} + +export function SendTelemetry(logger: Logger, reporter: TelemetryReporter, telemetryProps: any, installationStage: string, platformInfo: PlatformInformation, statusItem: vscode.StatusBarItem) { + telemetryProps['installStage'] = installationStage; + telemetryProps['platform.architecture'] = platformInfo.architecture; + telemetryProps['platform.platform'] = platformInfo.platform; + if (platformInfo.distribution) { + telemetryProps['platform.distribution'] = platformInfo.distribution.toTelemetryString(); + } + if (reporter) { + reporter.sendTelemetryEvent('Acquisition', telemetryProps); + } + + logger.appendLine(); + installationStage = ''; + logger.appendLine('Finished'); + + statusItem.dispose(); +} \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 7301d7904..ac6ffe997 100644 --- a/src/main.ts +++ b/src/main.ts @@ -32,7 +32,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<{ init let runtimeDependenciesExist = await ensureRuntimeDependencies(extension, logger, reporter); // activate language services - let omniSharpPromise = OmniSharp.activate(context, reporter, _channel); + let omniSharpPromise = OmniSharp.activate(context, reporter, _channel, logger, extension.packageJSON); // register JSON completion & hover providers for project.json context.subscriptions.push(addJSONProviders()); diff --git a/src/omnisharp/experimentalOmnisharp.ts b/src/omnisharp/experimentalOmnisharp.ts deleted file mode 100644 index 10608d786..000000000 --- a/src/omnisharp/experimentalOmnisharp.ts +++ /dev/null @@ -1,38 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import * as util from '../common'; -import * as path from 'path'; -import * as semver from 'semver'; - -export function GetExperimentalOmnisharpPath(optionsPath: string): string{ - // Looks at the options path, installs the dependenices and returns the path to be loaded by the omnisharp server - // To Do : Add the functionality for the latest option - - if (util.fileExists(optionsPath)) { - // The file is a valid file on disk - return optionsPath; - } - - let extensionPath = util.getExtensionPath(); - // If it is not a valid path, it might be a version that the user wants to use - if (IsValidSemver(optionsPath)) { - if (DownloadAndInstallExperimentalVersion(optionsPath)) { - // Download and install completed successfully otherwise the error thrown will be handled by the server - return path.resolve(extensionPath, `.omnisharp/experimental/${optionsPath}`); - } - } - else { - throw new Error('Bad Input to Omnisharp Path'); - } -} - -function IsValidSemver(version: string): boolean { - if (semver.valid(version)) { - return true; - } - - return false; -} \ No newline at end of file diff --git a/src/omnisharp/experimentalOmnisharpDownloader.ts b/src/omnisharp/experimentalOmnisharpDownloader.ts new file mode 100644 index 000000000..75c6b830f --- /dev/null +++ b/src/omnisharp/experimentalOmnisharpDownloader.ts @@ -0,0 +1,67 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import * as vscode from 'vscode'; +import { Status, PackageManager, Package } from '../packages'; +import { PlatformInformation } from '../platform'; +import { Logger } from '../logger'; +import TelemetryReporter from 'vscode-extension-telemetry'; +import { GetDownloadDependencies, GetStatus, GetPlatformInformation, SendTelemetry, ReportError } from '../downloadHelper'; +import { GetPackagesFromVersion } from './experimentalPackageCreator'; + +export class OmnisharpDownloader { + + public constructor( + private channel: vscode.OutputChannel, + private logger: Logger, + private reporter: TelemetryReporter /* optional */, + private packageJSON: any) { + } + + public async DownloadAndInstallExperimentalVersion(version: string, serverUrl: string, installPath: string) { + this.logger.append('Getting the version packages...'); + this.channel.show(); + + let statusItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right); + let status = GetStatus(statusItem); + + let telemetryProps: any = {}; + let installationStage = ''; + let latestVersion: string; + let platformInfo: PlatformInformation; + + if (this.reporter) { + this.reporter.sendTelemetryEvent("AcquisitionStart"); + } + + try { + installationStage = 'getPlatformInfo'; + platformInfo = await GetPlatformInformation(this.logger); + installationStage = 'downloadPackages'; + let dep = await GetDownloadDependencies(this.reporter, this.logger, this.channel, this.packageJSON, platformInfo); + let packageManager = dep.PackageManager; + let proxy = dep.Proxy; + let strictSSL = dep.StrictSSL; + let packages: Package[] = GetPackagesFromVersion(version, this.packageJSON.runtimeDependencies, serverUrl, installPath); + packageManager.SetVersionPackagesForDownload(packages); + await packageManager.DownloadPackages(this.logger, status, proxy, strictSSL); + + this.logger.appendLine(); + + installationStage = 'installPackages'; + await packageManager.InstallPackages(this.logger, status); + + installationStage = 'completeSuccess'; + } + + catch (error) { + ReportError(this.logger, error, telemetryProps, installationStage); + throw error; + } + finally { + SendTelemetry(this.logger, this.reporter, telemetryProps, installationStage, platformInfo, statusItem); + } + } +} diff --git a/src/omnisharp/experimentalOmnisharpManager.ts b/src/omnisharp/experimentalOmnisharpManager.ts new file mode 100644 index 000000000..91b99d195 --- /dev/null +++ b/src/omnisharp/experimentalOmnisharpManager.ts @@ -0,0 +1,71 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import * as util from '../common'; +import * as path from 'path'; +import * as semver from 'semver'; +import * as vscode from 'vscode'; +import { Logger } from '../logger'; +import { OmnisharpDownloader } from './experimentalOmnisharpDownloader'; +import TelemetryReporter from 'vscode-extension-telemetry'; +import { PlatformInformation } from '../platform'; + +export class ExperimentalOmnisharpManager { + public constructor( + private channel: vscode.OutputChannel, + private logger: Logger, + private reporter: TelemetryReporter, + private packageJSON: any + ) { + } + + public async GetExperimentalOmnisharpPath(optionPath: string, useMono: boolean): Promise { + // Looks at the options path, installs the dependencies and returns the path to be loaded by the omnisharp server + // To Do : Add the functionality for the latest option + + if (await util.fileExists(optionPath)) { + return optionPath; + } + + let serverUrl = "https://omnisharpdownload.blob.core.windows.net"; + let installPath = ".omnisharp/experimental"; + let platformInfo = await PlatformInformation.GetCurrent(); + let extensionPath = util.getExtensionPath(); + return await this.InstallVersionAndReturnLaunchPath(optionPath, useMono, serverUrl, installPath, extensionPath, platformInfo); + } + + private async InstallVersionAndReturnLaunchPath(version: string, useMono: boolean, serverUrl: string, installPath: string, extensionPath: string, platformInfo: PlatformInformation) { + if (IsValidSemver(version)) { + let downloader = new OmnisharpDownloader(this.channel, this.logger, this.reporter, this.packageJSON); + await downloader.DownloadAndInstallExperimentalVersion(version, serverUrl, installPath); + + return await GetLaunchPathForVersion(platformInfo, version, installPath, extensionPath, useMono); + } + else { + throw new Error('Bad Input to Omnisharp Path'); + } + } +} + +function IsValidSemver(version: string): boolean { + if (semver.valid(version)) { + return true; + } + + return false; +} + +async function GetLaunchPathForVersion(platformInfo: PlatformInformation, version: string, installPath: string, extensionPath: string, useMono: boolean) { + let basePath = path.resolve(extensionPath, installPath, version); + + if (platformInfo.isWindows()) { + return path.resolve(basePath, 'Omnisharp.exe'); + } + if (useMono) { + return path.resolve(basePath, 'omnisharp', 'OmniSharp.exe'); + } + return path.resolve(basePath, 'run'); +} + diff --git a/src/omnisharp/experimentalPackageCreator.ts b/src/omnisharp/experimentalPackageCreator.ts new file mode 100644 index 000000000..251a07eb6 --- /dev/null +++ b/src/omnisharp/experimentalPackageCreator.ts @@ -0,0 +1,54 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { Package } from "../packages"; +import * as semver from 'semver'; + +export function GetPackagesFromVersion(version: string, runTimeDependencies: Package[], serverUrl: string, installPath: string): Package[] { + // To do: add null check + let versionPackages = new Array(); + for (let inputPackage of runTimeDependencies) { + //we need only the omnisharp packages in experimental download + if (inputPackage.experimentalPackageId) { + versionPackages.push(GetExperimentPackage(inputPackage, serverUrl, version, installPath)); + } + } + + return versionPackages; +} + +export function GetExperimentPackage(inputPackage: Package, serverUrl: string, version: string, installPath: string): Package { + let architectureInfo: string; + let installBinary: string; + if (inputPackage.experimentalPackageId == "win-x86" || inputPackage.experimentalPackageId == "win-x64") { + installBinary = "Omnisharp.exe"; + } + else if (inputPackage.experimentalPackageId == "osx") { + installBinary = "mono.osx"; + } + else if (inputPackage.experimentalPackageId == "linux-x86") { + installBinary = "mono.linux-x86"; + } + else if (inputPackage.experimentalPackageId == "linux-x64") { + installBinary = "mono.linux-x86_64"; + } + + return GetPackageFromArchitecture(inputPackage, serverUrl, version, inputPackage.experimentalPackageId, installPath, installBinary); +} + +export function GetPackageFromArchitecture(inputPackage: Package, serverUrl: string, version: string, architectureInfo: string, installPath: string, installBinary: string): Package { + let versionPackage = { + "description": inputPackage.description, + "url": `${serverUrl}/ext/omnisharp-${architectureInfo}-${version}.zip`, + "installPath": `${installPath}/${version}`, + "platforms": inputPackage.platforms, + "architectures": inputPackage.architectures, + "binaries": inputPackage.binaries, + "installTestPath": `./${installPath}/${version}/${installBinary}`, + "experimentalPackageId": architectureInfo + }; + + return versionPackage; +} \ No newline at end of file diff --git a/src/omnisharp/extension.ts b/src/omnisharp/extension.ts index 968b836b4..9c0301f73 100644 --- a/src/omnisharp/extension.ts +++ b/src/omnisharp/extension.ts @@ -32,10 +32,11 @@ import WorkspaceSymbolProvider from '../features/workspaceSymbolProvider'; import forwardChanges from '../features/changeForwarding'; import registerCommands from '../features/commands'; import reportStatus from '../features/status'; +import { Logger } from '../logger'; export let omnisharp: OmniSharpServer; -export function activate(context: vscode.ExtensionContext, reporter: TelemetryReporter, channel: vscode.OutputChannel) { +export function activate(context: vscode.ExtensionContext, reporter: TelemetryReporter, channel: vscode.OutputChannel, logger: Logger, packageJSON: any) { const documentSelector: vscode.DocumentSelector = { language: 'csharp', scheme: 'file' // only files from disk @@ -43,7 +44,7 @@ export function activate(context: vscode.ExtensionContext, reporter: TelemetryRe const options = Options.Read(); - const server = new OmniSharpServer(reporter); + const server = new OmniSharpServer(reporter, logger, channel, packageJSON); omnisharp = server; const advisor = new Advisor(server); // create before server is started const disposables: vscode.Disposable[] = []; diff --git a/src/omnisharp/server.ts b/src/omnisharp/server.ts index f86ec769c..140465718 100644 --- a/src/omnisharp/server.ts +++ b/src/omnisharp/server.ts @@ -19,7 +19,7 @@ import * as protocol from './protocol'; import * as utils from '../common'; import * as vscode from 'vscode'; import { setTimeout } from 'timers'; -import { GetExperimentalOmnisharpPath } from './experimentalOmnisharp'; +import { ExperimentalOmnisharpManager } from './experimentalOmnisharpManager'; enum ServerState { Starting, @@ -83,7 +83,11 @@ export class OmniSharpServer { private _serverProcess: ChildProcess; private _options: Options; - constructor(reporter: TelemetryReporter) { + private _csharpLogger: Logger; + private _csharpChannel: vscode.OutputChannel; + private _packageJSON: any; + + constructor(reporter: TelemetryReporter, csharpLogger?: Logger, csharpChannel?: vscode.OutputChannel, packageJSON?: any) { this._reporter = reporter; this._channel = vscode.window.createOutputChannel('OmniSharp Log'); @@ -94,6 +98,9 @@ export class OmniSharpServer { : new Logger(message => { }); this._requestQueue = new RequestQueueCollection(logger, 8, request => this._makeRequest(request)); + this._csharpLogger = csharpLogger; + this._csharpChannel = csharpChannel; + this._packageJSON = packageJSON; } public isRunning(): boolean { @@ -239,7 +246,7 @@ export class OmniSharpServer { // --- start, stop, and connect - private _start(launchTarget: LaunchTarget): Promise { + private async _start(launchTarget: LaunchTarget): Promise { this._setState(ServerState.Starting); this._launchTarget = launchTarget; @@ -263,7 +270,8 @@ export class OmniSharpServer { let experimentalLaunchPath: string; if (this._options.path) { try { - experimentalLaunchPath = GetExperimentalOmnisharpPath(this._options.path); + let manager = new ExperimentalOmnisharpManager(this._csharpChannel, this._csharpLogger, this._reporter, this._packageJSON); + experimentalLaunchPath = await manager.GetExperimentalOmnisharpPath(this._options.path, this._options.useMono); } catch (error) { this._logger.appendLine(`Could not start the server due to ${error}`); diff --git a/src/packages.ts b/src/packages.ts index 2e3592d35..a5e15d197 100644 --- a/src/packages.ts +++ b/src/packages.ts @@ -24,6 +24,7 @@ export interface Package { architectures: string[]; binaries: string[]; tmpFile: tmp.SynchrounousResult; + experimentalPackageId?: string; // Path to use to test if the package has already been installed installTestPath?: string; @@ -36,9 +37,9 @@ export interface Status { export class PackageError extends Error { // Do not put PII (personally identifiable information) in the 'message' field as it will be logged to telemetry - constructor(public message: string, - public pkg: Package = null, - public innerError: any = null) { + constructor(public message: string, + public pkg: Package = null, + public innerError: any = null) { super(message); } } @@ -107,6 +108,10 @@ export class PackageManager { }); }); } + + public SetVersionPackagesForDownload(packages: Package[]) { + this.allPackages = packages; + } } function getBaseInstallPath(pkg: Package): string { @@ -139,7 +144,7 @@ function downloadPackage(pkg: Package, logger: Logger, status: Status, proxy: st status = status || getNoopStatus(); logger.append(`Downloading package '${pkg.description}' `); - + status.setMessage("$(cloud-download) Downloading packages"); status.setDetail(`Downloading package '${pkg.description}'...`); @@ -199,7 +204,7 @@ function downloadFile(urlString: string, pkg: Package, logger: Logger, status: S logger.appendLine(`failed (error code '${response.statusCode}')`); return reject(new PackageError(response.statusCode.toString(), pkg)); } - + // Downloading - hook up events let packageSize = parseInt(response.headers['content-length'], 10); let downloadedBytes = 0; @@ -338,7 +343,7 @@ function installPackage(pkg: Package, logger: Logger, status?: Status): Promise< }); } -function doesPackageTestPathExist(pkg: Package) : Promise { +function doesPackageTestPathExist(pkg: Package): Promise { const testPath = getPackageTestPath(pkg); if (testPath) { return util.fileExists(testPath); @@ -347,7 +352,7 @@ function doesPackageTestPathExist(pkg: Package) : Promise { } } -function getPackageTestPath(pkg: Package) : string { +function getPackageTestPath(pkg: Package): string { if (pkg.installTestPath) { return path.join(util.getExtensionPath(), pkg.installTestPath); } else { From e3c702b014ec6944478f0d492fcc2c42c1e4f138 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Mon, 5 Feb 2018 17:11:18 -0800 Subject: [PATCH 03/28] Tests for the package creator --- .../experimentalPackageCreator.test.ts | 311 ++++++++++++++++++ 1 file changed, 311 insertions(+) create mode 100644 test/unitTests/experimentalPackageCreator.test.ts diff --git a/test/unitTests/experimentalPackageCreator.test.ts b/test/unitTests/experimentalPackageCreator.test.ts new file mode 100644 index 000000000..42969dfe3 --- /dev/null +++ b/test/unitTests/experimentalPackageCreator.test.ts @@ -0,0 +1,311 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { assert, should, expect } from "chai"; +import { Package } from "../../src/packages"; +import { GetExperimentPackage, GetPackagesFromVersion } from "../../src/omnisharp/experimentalPackageCreator"; + + +suite("Package Creator - Correct parameters are formed for an input package", () => { + + let serverUrl: string; + let version: string; + let installPath: string; + let inputPackages: any; + + setup(() => { + serverUrl = "http://serverUrl"; + version = "0.0.0"; + installPath = "testPath"; + inputPackages = GetInputPackages(); + should(); + }); + + test('Description, architectures, binaries and platforms do not change', () => { + let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "os-architecture")); + let resultPackage = GetExperimentPackage(testPackage, serverUrl, version, installPath); + + resultPackage.description.should.equal(testPackage.description); + resultPackage.architectures.should.equal(testPackage.architectures); + assert.equal(resultPackage.binaries, testPackage.binaries); + resultPackage.platforms.should.equal(testPackage.platforms); + }); + + test('Download url is calculated using server url and version', () => { + let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "os-architecture")); + let resultPackage = GetExperimentPackage(testPackage, "http://someurl", "1.1.1", installPath); + //rename the url + resultPackage.url.should.equal("http://someurl/ext/omnisharp-os-architecture-1.1.1.zip"); + }); + + test('Install path is calculated using the specified path and version', () => { + let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "os-architecture")); + let resultPackage = GetExperimentPackage(testPackage, serverUrl, "1.2.3", "experimentPath"); + + resultPackage.installPath.should.equal("experimentPath/1.2.3"); + }); + + test('Install test path is calculated using specified path, version and ends with Omnisharp.exe - Windows(x86)', () => { + let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "win-x86")); + let resultPackage = GetExperimentPackage(testPackage, serverUrl, "1.2.3", "experimentPath"); + + resultPackage.installTestPath.should.equal("./experimentPath/1.2.3/Omnisharp.exe"); + }); + + test('Install test path is calculated using specified path, version and ends with Omnisharp.exe - Windows(x64)', () => { + let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "win-x64")); + let resultPackage = GetExperimentPackage(testPackage, serverUrl, "1.2.3", "experimentPath"); + + resultPackage.installTestPath.should.equal("./experimentPath/1.2.3/Omnisharp.exe"); + }); + + test('Install test path is calculated using specified path, version and ends with mono.osx - OSX', () => { + let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "osx")); + let resultPackage = GetExperimentPackage(testPackage, serverUrl, "1.2.3", "experimentPath"); + + resultPackage.installTestPath.should.equal("./experimentPath/1.2.3/mono.osx"); + }); + + test('Install test path is calculated using specified path, version and ends with mono.linux-x86 - Linux(x86)', () => { + let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "linux-x86")); + let resultPackage = GetExperimentPackage(testPackage, serverUrl, "1.2.3", "experimentPath"); + + resultPackage.installTestPath.should.equal("./experimentPath/1.2.3/mono.linux-x86"); + }); + + test('Install test path is calculated using specified path, version and ends with mono.linux-x86_64 - Linux(x64)', () => { + let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "linux-x64")); + let resultPackage = GetExperimentPackage(testPackage, serverUrl, "1.2.3", "experimentPath"); + + resultPackage.installTestPath.should.equal("./experimentPath/1.2.3/mono.linux-x86_64"); + }); +}); + +suite('Package Creator - Gets the experimental omnisharp packages from a set of input packages', () => { + + const serverUrl = "http://serverUrl"; + const installPath = "testPath"; + + suiteSetup(() => { + should(); + }); + + test('Throws exception if the version is null', () => { + let version: string = null; + let inputPackages = GetInputPackages(); + let fn = function () { GetPackagesFromVersion(version, inputPackages, serverUrl, installPath); }; + expect(fn).to.throw('Invalid version'); + }); + + test('Throws exception if the version is empty', () => { + let version = ""; + let inputPackages = GetInputPackages(); + let fn = function () { GetPackagesFromVersion(version, inputPackages, serverUrl, installPath); }; + expect(fn).to.throw('Invalid version'); + }); + + test('Throws exception if the version is not a valid semver version', () => { + let version = "a.b.c"; + let inputPackages = GetInputPackages(); + let fn = function () { GetPackagesFromVersion(version, inputPackages, serverUrl, installPath); }; + expect(fn).to.throw('Invalid version'); + }); + + test('Returns experiment packages with install test path depending on install path and version', () => { + let inputPackages = [ + { + "description": "OmniSharp for Windows (.NET 4.6 / x64)", + "url": "https://download.visualstudio.microsoft.com/download/pr/100505821/c570a9e20dbf7172f79850babd058872/omnisharp-win-x64-1.28.0.zip", + "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-win-x64-1.28.0.zip", + "installPath": ".omnisharp", + "platforms": [ + "win32" + ], + "architectures": [ + "x86_64" + ], + "installTestPath": "./.omnisharp/OmniSharp.exe", + "experimentalPackageId": "win-x64" + }, + { + "description": "OmniSharp for OSX", + "url": "https://download.visualstudio.microsoft.com/download/pr/100505818/6b99c6a86da3221919158ca0f36a3e45/omnisharp-osx-1.28.0.zip", + "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-osx-1.28.0.zip", + "installPath": ".omnisharp", + "platforms": [ + "darwin" + ], + "binaries": [ + "./mono.osx", + "./run" + ], + "installTestPath": "./.omnisharp/mono.osx", + "experimentalPackageId": "osx" + }, + ]; + + let outPackages = GetPackagesFromVersion("1.1.1", inputPackages, serverUrl, "experimentPath"); + outPackages.length.should.equal(2); + outPackages[0].installTestPath.should.equal("./experimentPath/1.1.1/Omnisharp.exe"); + outPackages[1].installTestPath.should.equal("./experimentPath/1.1.1/mono.osx"); + }); + + test('Returns only omnisharp packages with experimentalIds', () => { + let version = "0.0.0"; + let inputPackages = [ + { + "description": "OmniSharp for Windows (.NET 4.6 / x64)", + "url": "https://download.visualstudio.microsoft.com/download/pr/100505821/c570a9e20dbf7172f79850babd058872/omnisharp-win-x64-1.28.0.zip", + "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-win-x64-1.28.0.zip", + "installPath": ".omnisharp", + "platforms": [ + "win32" + ], + "architectures": [ + "x86_64" + ], + "installTestPath": "./.omnisharp/OmniSharp.exe", + "experimentalPackageId": "win-x64" + }, + { + "description": "Some other package - no experimental id", + "url": "https://download.visualstudio.microsoft.com/download/pr/100505818/6b99c6a86da3221919158ca0f36a3e45/omnisharp-osx-1.28.0.zip", + "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-osx-1.28.0.zip", + "installPath": ".omnisharp", + "platforms": [ + "darwin" + ], + "binaries": [ + "./mono.osx", + "./run" + ], + "installTestPath": "./.omnisharp/mono.osx", + }, + ]; + + let outPackages = GetPackagesFromVersion(version, inputPackages, serverUrl, installPath); + outPackages.length.should.equal(1); + outPackages[0].experimentalPackageId.should.equal("win-x64"); + }); +}); + +//ask if these packages should be simplified or remain same to simulate the exact behavior +function GetInputPackages() { + let inputPackages = [ + { + "description": "OmniSharp for Windows (.NET 4.6 / x86)", + "url": "https://download.visualstudio.microsoft.com/download/pr/100505823/5804b7d3b5eeb7e4ae812a7cff03bd52/omnisharp-win-x86-1.28.0.zip", + "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-win-x86-1.28.0.zip", + "installPath": ".omnisharp", + "platforms": [ + "win32" + ], + "architectures": [ + "x86" + ], + "installTestPath": "./.omnisharp/OmniSharp.exe", + "experimentalPackageId": "win-x86" + }, + { + "description": "OmniSharp for Windows (.NET 4.6 / x64)", + "url": "https://download.visualstudio.microsoft.com/download/pr/100505821/c570a9e20dbf7172f79850babd058872/omnisharp-win-x64-1.28.0.zip", + "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-win-x64-1.28.0.zip", + "installPath": ".omnisharp", + "platforms": [ + "win32" + ], + "architectures": [ + "x86_64" + ], + "installTestPath": "./.omnisharp/OmniSharp.exe", + "experimentalPackageId": "win-x64" + }, + { + "description": "OmniSharp for OSX", + "url": "https://download.visualstudio.microsoft.com/download/pr/100505818/6b99c6a86da3221919158ca0f36a3e45/omnisharp-osx-1.28.0.zip", + "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-osx-1.28.0.zip", + "installPath": ".omnisharp", + "platforms": [ + "darwin" + ], + "binaries": [ + "./mono.osx", + "./run" + ], + "installTestPath": "./.omnisharp/mono.osx", + "experimentalPackageId": "osx" + }, + { + "description": "OmniSharp for Linux (x86)", + "url": "https://download.visualstudio.microsoft.com/download/pr/100505817/b710ec9c2bedc0cfdb57da82da166c47/omnisharp-linux-x86-1.28.0.zip", + "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-linux-x86-1.28.0.zip", + "installPath": ".omnisharp", + "platforms": [ + "linux" + ], + "architectures": [ + "x86", + "i686" + ], + "binaries": [ + "./mono.linux-x86", + "./run" + ], + "installTestPath": "./.omnisharp/mono.linux-x86", + "experimentalPackageId": "linux-x86" + }, + { + "description": "OmniSharp for Linux (x64)", + "url": "https://download.visualstudio.microsoft.com/download/pr/100505485/3f8a10409240decebb8a3189429f3fdf/omnisharp-linux-x64-1.28.0.zip", + "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-linux-x64-1.28.0.zip", + "installPath": ".omnisharp", + "platforms": [ + "linux" + ], + "architectures": [ + "x86_64" + ], + "binaries": [ + "./mono.linux-x86_64", + "./run" + ], + "installTestPath": "./.omnisharp/mono.linux-x86_64", + "experimentalPackageId": "linux-x64" + }, + { + "description": "OmniSharp for Test OS(architecture)", + "url": "https://download.visualstudio.microsoft.com/download/pr/100505485/3f8a10409240decebb8a3189429f3fdf/omnisharp-os-architecture-version.zip", + "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-os-architecture-version.zip", + "installPath": ".omnisharp", + "platforms": [ + "platform1" + ], + "architectures": [ + "architecture" + ], + "binaries": [ + "./binary1", + "./binary2" + ], + "installTestPath": "./.omnisharp/binary", + "experimentalPackageId": "os-architecture" + }, + { + "description": "Non omnisharp package without experimentalPackageID", + "url": "https://download.visualstudio.microsoft.com/download/pr/100317420/a30d7e11bc435433d297adc824ee837f/coreclr-debug-win7-x64.zip", + "fallbackUrl": "https://vsdebugger.blob.core.windows.net/coreclr-debug-1-14-4/coreclr-debug-win7-x64.zip", + "installPath": ".debugger", + "platforms": [ + "win32" + ], + "architectures": [ + "x86_64" + ], + "installTestPath": "./.debugger/vsdbg-ui.exe" + } + ]; + + return inputPackages; +} From 58a78ab3aaea8116920e2e0c8060942726fd7521 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Mon, 5 Feb 2018 17:14:45 -0800 Subject: [PATCH 04/28] Added null check and removed semver check in package creator --- src/omnisharp/experimentalPackageCreator.ts | 5 ++++- test/unitTests/experimentalPackageCreator.test.ts | 7 ------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/omnisharp/experimentalPackageCreator.ts b/src/omnisharp/experimentalPackageCreator.ts index 251a07eb6..3416e1453 100644 --- a/src/omnisharp/experimentalPackageCreator.ts +++ b/src/omnisharp/experimentalPackageCreator.ts @@ -7,7 +7,10 @@ import { Package } from "../packages"; import * as semver from 'semver'; export function GetPackagesFromVersion(version: string, runTimeDependencies: Package[], serverUrl: string, installPath: string): Package[] { - // To do: add null check + if (!version) { + throw new Error('Invalid version'); + } + let versionPackages = new Array(); for (let inputPackage of runTimeDependencies) { //we need only the omnisharp packages in experimental download diff --git a/test/unitTests/experimentalPackageCreator.test.ts b/test/unitTests/experimentalPackageCreator.test.ts index 42969dfe3..fae57ae68 100644 --- a/test/unitTests/experimentalPackageCreator.test.ts +++ b/test/unitTests/experimentalPackageCreator.test.ts @@ -106,13 +106,6 @@ suite('Package Creator - Gets the experimental omnisharp packages from a set of expect(fn).to.throw('Invalid version'); }); - test('Throws exception if the version is not a valid semver version', () => { - let version = "a.b.c"; - let inputPackages = GetInputPackages(); - let fn = function () { GetPackagesFromVersion(version, inputPackages, serverUrl, installPath); }; - expect(fn).to.throw('Invalid version'); - }); - test('Returns experiment packages with install test path depending on install path and version', () => { let inputPackages = [ { From 453006b714e189a2534e4c6ba2eb33f6255d7b4b Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Mon, 5 Feb 2018 17:20:15 -0800 Subject: [PATCH 05/28] Test for the experiment omnisharp downloader --- .../experimentalOmnisharpDownloader.ts | 2 +- src/omnisharp/experimentalOmnisharpManager.ts | 4 +- .../experimentalOmnisharpDownloader.test.ts | 55 +++++++++++++++++++ 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 test/unitTests/experimentalOmnisharpDownloader.test.ts diff --git a/src/omnisharp/experimentalOmnisharpDownloader.ts b/src/omnisharp/experimentalOmnisharpDownloader.ts index 75c6b830f..e3df0a5dd 100644 --- a/src/omnisharp/experimentalOmnisharpDownloader.ts +++ b/src/omnisharp/experimentalOmnisharpDownloader.ts @@ -11,7 +11,7 @@ import TelemetryReporter from 'vscode-extension-telemetry'; import { GetDownloadDependencies, GetStatus, GetPlatformInformation, SendTelemetry, ReportError } from '../downloadHelper'; import { GetPackagesFromVersion } from './experimentalPackageCreator'; -export class OmnisharpDownloader { +export class ExperimentalOmnisharpDownloader { public constructor( private channel: vscode.OutputChannel, diff --git a/src/omnisharp/experimentalOmnisharpManager.ts b/src/omnisharp/experimentalOmnisharpManager.ts index 91b99d195..f67d50f10 100644 --- a/src/omnisharp/experimentalOmnisharpManager.ts +++ b/src/omnisharp/experimentalOmnisharpManager.ts @@ -8,7 +8,7 @@ import * as path from 'path'; import * as semver from 'semver'; import * as vscode from 'vscode'; import { Logger } from '../logger'; -import { OmnisharpDownloader } from './experimentalOmnisharpDownloader'; +import { ExperimentalOmnisharpDownloader } from './experimentalOmnisharpDownloader'; import TelemetryReporter from 'vscode-extension-telemetry'; import { PlatformInformation } from '../platform'; @@ -38,7 +38,7 @@ export class ExperimentalOmnisharpManager { private async InstallVersionAndReturnLaunchPath(version: string, useMono: boolean, serverUrl: string, installPath: string, extensionPath: string, platformInfo: PlatformInformation) { if (IsValidSemver(version)) { - let downloader = new OmnisharpDownloader(this.channel, this.logger, this.reporter, this.packageJSON); + let downloader = new ExperimentalOmnisharpDownloader(this.channel, this.logger, this.reporter, this.packageJSON); await downloader.DownloadAndInstallExperimentalVersion(version, serverUrl, installPath); return await GetLaunchPathForVersion(platformInfo, version, installPath, extensionPath, useMono); diff --git a/test/unitTests/experimentalOmnisharpDownloader.test.ts b/test/unitTests/experimentalOmnisharpDownloader.test.ts new file mode 100644 index 000000000..b4cadbdf9 --- /dev/null +++ b/test/unitTests/experimentalOmnisharpDownloader.test.ts @@ -0,0 +1,55 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import * as vscode from 'vscode'; +import * as path from 'path'; +import * as fs from 'fs'; +import * as util from '../../src/common'; +import { should, assert } from 'chai'; +import { Logger } from '../../src/logger'; +import TelemetryReporter from 'vscode-extension-telemetry'; +import { ExperimentalOmnisharpDownloader } from '../../src/omnisharp/experimentalOmnisharpDownloader'; + +suite("Gets the version packages and downloads and installs them", () => { + + test('Packages are downloaded from the specified server url and installed at the specified path', async () => { + /* Download a test package that conatins a install_check_1.2.3.txt file and check whether the + file appears at the expected path */ + let version = "1.2.3"; + let downloader = GetOmnisharpDownloader(); + let serverUrl = "https://roslynomnisharp.blob.core.windows.net"; + let installPath = ".omnisharp/experimental"; + let versionPath = path.resolve(util.getExtensionPath(), `${installPath}/${version}`); + await downloader.DownloadAndInstallExperimentalVersion(version, serverUrl, installPath); + let exists = await util.fileExists(path.resolve(versionPath, `install_check_${version}.txt`)); + DeleteDirectory(versionPath); + exists.should.equal(true); + }); +}); + +function DeleteDirectory(dirPath: string) { + //delete all the files of this directory and then the directory itself + //ask if we need a fucntion to recursively delete the files in a directory + let files = fs.readdirSync(dirPath); + for (let file of files) { + fs.unlinkSync(`${dirPath}/${file}`); + } + + fs.rmdirSync(dirPath); +} + + + +function GetOmnisharpDownloader() { + let channel = vscode.window.createOutputChannel('Experiment Channel'); + let logger = new Logger(text => channel.append(text)); + const extensionId = 'ms-vscode.csharp'; + const extension = vscode.extensions.getExtension(extensionId); + const extensionVersion = extension.packageJSON.version; + const aiKey = extension.packageJSON.contributes.debuggers[0].aiKey; + const reporter = new TelemetryReporter(extensionId, extensionVersion, aiKey); + util.setExtensionPath(extension.extensionPath); + return new ExperimentalOmnisharpDownloader(channel, logger, reporter, extension.packageJSON); +} From a6e8f985471e85a1ffd11510c6ca5fd6362f2609 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Tue, 6 Feb 2018 16:46:02 -0800 Subject: [PATCH 06/28] Added test for package manager --- src/omnisharp/experimentalOmnisharpManager.ts | 14 ++- src/omnisharp/experimentalPackageCreator.ts | 6 +- .../experimentalOmnisharpDownloader.test.ts | 22 +--- .../experimentalOmnisharpManager.test.ts | 117 ++++++++++++++++++ .../experimentalPackageCreator.test.ts | 21 ++-- 5 files changed, 149 insertions(+), 31 deletions(-) create mode 100644 test/unitTests/experimentalOmnisharpManager.test.ts diff --git a/src/omnisharp/experimentalOmnisharpManager.ts b/src/omnisharp/experimentalOmnisharpManager.ts index f67d50f10..ecf23e0ff 100644 --- a/src/omnisharp/experimentalOmnisharpManager.ts +++ b/src/omnisharp/experimentalOmnisharpManager.ts @@ -36,7 +36,7 @@ export class ExperimentalOmnisharpManager { return await this.InstallVersionAndReturnLaunchPath(optionPath, useMono, serverUrl, installPath, extensionPath, platformInfo); } - private async InstallVersionAndReturnLaunchPath(version: string, useMono: boolean, serverUrl: string, installPath: string, extensionPath: string, platformInfo: PlatformInformation) { + public async InstallVersionAndReturnLaunchPath(version: string, useMono: boolean, serverUrl: string, installPath: string, extensionPath: string, platformInfo: PlatformInformation) { if (IsValidSemver(version)) { let downloader = new ExperimentalOmnisharpDownloader(this.channel, this.logger, this.reporter, this.packageJSON); await downloader.DownloadAndInstallExperimentalVersion(version, serverUrl, installPath); @@ -57,15 +57,19 @@ function IsValidSemver(version: string): boolean { return false; } -async function GetLaunchPathForVersion(platformInfo: PlatformInformation, version: string, installPath: string, extensionPath: string, useMono: boolean) { +export async function GetLaunchPathForVersion(platformInfo: PlatformInformation, version: string, installPath: string, extensionPath: string, useMono: boolean) { + if (!version) { + throw new Error('Invalid Version'); + } + let basePath = path.resolve(extensionPath, installPath, version); if (platformInfo.isWindows()) { - return path.resolve(basePath, 'Omnisharp.exe'); + return path.join(basePath, 'OmniSharp.exe'); } if (useMono) { - return path.resolve(basePath, 'omnisharp', 'OmniSharp.exe'); + return path.join(basePath, 'omnisharp', 'OmniSharp.exe'); } - return path.resolve(basePath, 'run'); + return path.join(basePath, 'run'); } diff --git a/src/omnisharp/experimentalPackageCreator.ts b/src/omnisharp/experimentalPackageCreator.ts index 3416e1453..2b1cff705 100644 --- a/src/omnisharp/experimentalPackageCreator.ts +++ b/src/omnisharp/experimentalPackageCreator.ts @@ -10,7 +10,7 @@ export function GetPackagesFromVersion(version: string, runTimeDependencies: Pac if (!version) { throw new Error('Invalid version'); } - + let versionPackages = new Array(); for (let inputPackage of runTimeDependencies) { //we need only the omnisharp packages in experimental download @@ -42,6 +42,10 @@ export function GetExperimentPackage(inputPackage: Package, serverUrl: string, v } export function GetPackageFromArchitecture(inputPackage: Package, serverUrl: string, version: string, architectureInfo: string, installPath: string, installBinary: string): Package { + if (!version) { + throw new Error('Invalid version'); + } + let versionPackage = { "description": inputPackage.description, "url": `${serverUrl}/ext/omnisharp-${architectureInfo}-${version}.zip`, diff --git a/test/unitTests/experimentalOmnisharpDownloader.test.ts b/test/unitTests/experimentalOmnisharpDownloader.test.ts index b4cadbdf9..96fe1807c 100644 --- a/test/unitTests/experimentalOmnisharpDownloader.test.ts +++ b/test/unitTests/experimentalOmnisharpDownloader.test.ts @@ -11,6 +11,7 @@ import { should, assert } from 'chai'; import { Logger } from '../../src/logger'; import TelemetryReporter from 'vscode-extension-telemetry'; import { ExperimentalOmnisharpDownloader } from '../../src/omnisharp/experimentalOmnisharpDownloader'; +import { rimraf } from 'async-file'; suite("Gets the version packages and downloads and installs them", () => { @@ -20,28 +21,15 @@ suite("Gets the version packages and downloads and installs them", () => { let version = "1.2.3"; let downloader = GetOmnisharpDownloader(); let serverUrl = "https://roslynomnisharp.blob.core.windows.net"; - let installPath = ".omnisharp/experimental"; - let versionPath = path.resolve(util.getExtensionPath(), `${installPath}/${version}`); + let installPath = ".omnisharp/experimental/"; + let tempDir = path.resolve(util.getExtensionPath(), `.omnisharp\\experimental\\1.2.3`); await downloader.DownloadAndInstallExperimentalVersion(version, serverUrl, installPath); - let exists = await util.fileExists(path.resolve(versionPath, `install_check_${version}.txt`)); - DeleteDirectory(versionPath); + let exists = await util.fileExists(path.resolve(tempDir, `install_check_1.2.3.txt`)); + await rimraf(tempDir); exists.should.equal(true); }); }); -function DeleteDirectory(dirPath: string) { - //delete all the files of this directory and then the directory itself - //ask if we need a fucntion to recursively delete the files in a directory - let files = fs.readdirSync(dirPath); - for (let file of files) { - fs.unlinkSync(`${dirPath}/${file}`); - } - - fs.rmdirSync(dirPath); -} - - - function GetOmnisharpDownloader() { let channel = vscode.window.createOutputChannel('Experiment Channel'); let logger = new Logger(text => channel.append(text)); diff --git a/test/unitTests/experimentalOmnisharpManager.test.ts b/test/unitTests/experimentalOmnisharpManager.test.ts new file mode 100644 index 000000000..3ca94e92f --- /dev/null +++ b/test/unitTests/experimentalOmnisharpManager.test.ts @@ -0,0 +1,117 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import * as path from 'path'; +import * as vscode from 'vscode'; +import * as util from '../../src/common'; +import { should, expect } from "chai"; +import { PlatformInformation } from "../../src/platform"; +import { GetLaunchPathForVersion, ExperimentalOmnisharpManager } from "../../src/omnisharp/experimentalOmnisharpManager"; +import { Logger } from '../../src/logger'; +import TelemetryReporter from 'vscode-extension-telemetry'; +import { rimraf } from 'async-file'; + +suite('Returns Omnisharp Launch Path based on the specified parameters', () => { + + let platformInfo: PlatformInformation; + let version: string; + let installPath: string; + let extensionPath: string; + let useMono: boolean; + + suiteSetup(() => { + platformInfo = new PlatformInformation("win32", "x86"); + version = "1.1.1"; + installPath = ".omnisharp/experimental"; + useMono = false; + const extension = vscode.extensions.getExtension('ms-vscode.csharp'); + util.setExtensionPath(extension.extensionPath); + extensionPath = util.getExtensionPath(); + should(); + }); + + test("Returns Launch Path based on install path", async () => { + let launchPath = await GetLaunchPathForVersion(platformInfo, version, "somePath", extensionPath, useMono); + launchPath.should.equal(path.resolve(extensionPath, `somePath/1.1.1/OmniSharp.exe`)); + }); + + test("Returns Launch Path based on version", async () => { + let launchPath = await GetLaunchPathForVersion(platformInfo, "0.0.0", installPath, extensionPath, useMono); + launchPath.should.equal(path.resolve(extensionPath,`.omnisharp/experimental/0.0.0/OmniSharp.exe`)); + }); + + test("Returns Launch Path based on platform - Windows", async () => { + let launchPath = await GetLaunchPathForVersion(platformInfo, version, installPath, extensionPath, useMono); + launchPath.should.equal(path.resolve(extensionPath,`.omnisharp/experimental/1.1.1/OmniSharp.exe`)); + }); + + test("Returns Launch Path based on platform - Unix with Mono", async () => { + platformInfo = new PlatformInformation("linux", "x86"); + let launchPath = await GetLaunchPathForVersion(platformInfo, version, installPath, extensionPath, true); + launchPath.should.equal(path.resolve(extensionPath,`.omnisharp/experimental/1.1.1/omnisharp/OmniSharp.exe`)); + }); + + test("Returns Launch Path based on platform - Unix without Mono", async () => { + platformInfo = new PlatformInformation("linux", "x86"); + let launchPath = await GetLaunchPathForVersion(platformInfo, version, installPath, extensionPath, useMono); + launchPath.should.equal(path.resolve(extensionPath,`.omnisharp/experimental/1.1.1/run`)); + }); +}); + +suite('Installs the version packages and returns the launch path', () => { + let version: string; + let serverUrl: string; + let installPath: string; + let useMono: boolean; + let extensionPath: string; + let manager: ExperimentalOmnisharpManager; + + suiteSetup(() => { + version = "1.2.3"; + serverUrl = "https://roslynomnisharp.blob.core.windows.net"; + installPath = ".omnisharp/experimental/"; + useMono = false; + const extension = vscode.extensions.getExtension('ms-vscode.csharp'); + util.setExtensionPath(extension.extensionPath); + extensionPath = util.getExtensionPath(); + manager = GetExperimentalOmnisharpManager(); + should(); + }); + + test('Downloads package and returns launch path based on version', async () => { + let launchPath = await manager.InstallVersionAndReturnLaunchPath("1.2.4", useMono, serverUrl, installPath, extensionPath, new PlatformInformation("win32", "x86")); + let dirPath = path.resolve(extensionPath, `.omnisharp/experimental/1.2.4`); + await rimraf(dirPath); + launchPath.should.equal(path.resolve(extensionPath, '.omnisharp/experimental/1.2.4/OmniSharp.exe')); + }); + + test('Downloads package from given url and installs them at the specified path', async () => { + let launchPath = await manager.InstallVersionAndReturnLaunchPath(version, useMono, serverUrl, installPath, extensionPath, new PlatformInformation("win32", "x86")); + let dirPath = path.resolve(extensionPath, `.omnisharp/experimental/1.2.3`); + + let exists = await util.fileExists(path.resolve(dirPath, `install_check_1.2.3.txt`)); + await rimraf(dirPath); + exists.should.equal(true); + }); + + test('Downloads package and returns launch path based on platform - Not using mono on Linux ', async () => { + let launchPath = await manager.InstallVersionAndReturnLaunchPath(version, useMono, serverUrl, installPath, extensionPath, new PlatformInformation("linux", "x64")); + let dirPath = path.resolve(extensionPath, `.omnisharp/experimental/1.2.3`); + await rimraf(dirPath); + launchPath.should.equal(path.resolve(extensionPath, '.omnisharp/experimental/1.2.3/run')); + }); + +}); + +function GetExperimentalOmnisharpManager() { + let channel = vscode.window.createOutputChannel('Experiment Channel'); + let logger = new Logger(text => channel.append(text)); + const extensionId = 'ms-vscode.csharp'; + const extension = vscode.extensions.getExtension(extensionId); + const extensionVersion = extension.packageJSON.version; + const aiKey = extension.packageJSON.contributes.debuggers[0].aiKey; + const reporter = new TelemetryReporter(extensionId, extensionVersion, aiKey); + return new ExperimentalOmnisharpManager(channel, logger, reporter, extension.packageJSON); +} \ No newline at end of file diff --git a/test/unitTests/experimentalPackageCreator.test.ts b/test/unitTests/experimentalPackageCreator.test.ts index fae57ae68..c3c396cb6 100644 --- a/test/unitTests/experimentalPackageCreator.test.ts +++ b/test/unitTests/experimentalPackageCreator.test.ts @@ -8,7 +8,7 @@ import { Package } from "../../src/packages"; import { GetExperimentPackage, GetPackagesFromVersion } from "../../src/omnisharp/experimentalPackageCreator"; -suite("Package Creator - Correct parameters are formed for an input package", () => { +suite("Experimental Package Creator - Output package depends on the input package and other input parameters like serverUrl", () => { let serverUrl: string; let version: string; @@ -23,6 +23,18 @@ suite("Package Creator - Correct parameters are formed for an input package", () should(); }); + test('Throws exception if version is empty', () => { + let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "os-architecture")); + let fn = function () { GetExperimentPackage(testPackage, serverUrl, "", installPath); }; + expect(fn).to.throw('Invalid version'); + }); + + test('Throws exception if version is null', () => { + let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "os-architecture")); + let fn = function () { GetExperimentPackage(testPackage, serverUrl, null, installPath);}; + expect(fn).to.throw('Invalid version'); + }); + test('Description, architectures, binaries and platforms do not change', () => { let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "os-architecture")); let resultPackage = GetExperimentPackage(testPackage, serverUrl, version, installPath); @@ -36,49 +48,42 @@ suite("Package Creator - Correct parameters are formed for an input package", () test('Download url is calculated using server url and version', () => { let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "os-architecture")); let resultPackage = GetExperimentPackage(testPackage, "http://someurl", "1.1.1", installPath); - //rename the url resultPackage.url.should.equal("http://someurl/ext/omnisharp-os-architecture-1.1.1.zip"); }); test('Install path is calculated using the specified path and version', () => { let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "os-architecture")); let resultPackage = GetExperimentPackage(testPackage, serverUrl, "1.2.3", "experimentPath"); - resultPackage.installPath.should.equal("experimentPath/1.2.3"); }); test('Install test path is calculated using specified path, version and ends with Omnisharp.exe - Windows(x86)', () => { let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "win-x86")); let resultPackage = GetExperimentPackage(testPackage, serverUrl, "1.2.3", "experimentPath"); - resultPackage.installTestPath.should.equal("./experimentPath/1.2.3/Omnisharp.exe"); }); test('Install test path is calculated using specified path, version and ends with Omnisharp.exe - Windows(x64)', () => { let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "win-x64")); let resultPackage = GetExperimentPackage(testPackage, serverUrl, "1.2.3", "experimentPath"); - resultPackage.installTestPath.should.equal("./experimentPath/1.2.3/Omnisharp.exe"); }); test('Install test path is calculated using specified path, version and ends with mono.osx - OSX', () => { let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "osx")); let resultPackage = GetExperimentPackage(testPackage, serverUrl, "1.2.3", "experimentPath"); - resultPackage.installTestPath.should.equal("./experimentPath/1.2.3/mono.osx"); }); test('Install test path is calculated using specified path, version and ends with mono.linux-x86 - Linux(x86)', () => { let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "linux-x86")); let resultPackage = GetExperimentPackage(testPackage, serverUrl, "1.2.3", "experimentPath"); - resultPackage.installTestPath.should.equal("./experimentPath/1.2.3/mono.linux-x86"); }); test('Install test path is calculated using specified path, version and ends with mono.linux-x86_64 - Linux(x64)', () => { let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "linux-x64")); let resultPackage = GetExperimentPackage(testPackage, serverUrl, "1.2.3", "experimentPath"); - resultPackage.installTestPath.should.equal("./experimentPath/1.2.3/mono.linux-x86_64"); }); }); From d77bdd02f630e926e1082818b5743882a06aa3b0 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Tue, 6 Feb 2018 17:07:44 -0800 Subject: [PATCH 07/28] Code clean up --- src/downloadHelper.ts | 2 +- src/omnisharp/experimentalOmnisharpDownloader.ts | 4 ++-- src/omnisharp/experimentalOmnisharpManager.ts | 3 ++- src/omnisharp/experimentalPackageCreator.ts | 4 ++-- test/unitTests/experimentalOmnisharpDownloader.test.ts | 2 +- test/unitTests/experimentalOmnisharpManager.test.ts | 9 ++++----- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/downloadHelper.ts b/src/downloadHelper.ts index 55c68f047..768317f6d 100644 --- a/src/downloadHelper.ts +++ b/src/downloadHelper.ts @@ -10,7 +10,7 @@ import { PlatformInformation } from './platform'; import { Logger } from './logger'; import TelemetryReporter from 'vscode-extension-telemetry'; -export async function GetDownloadDependencies(reporter: TelemetryReporter, logger: Logger, channel: vscode.OutputChannel, packageJSON: any, platformInfo: PlatformInformation) { +export async function GetDownloaderDependencies(reporter: TelemetryReporter, logger: Logger, channel: vscode.OutputChannel, packageJSON: any, platformInfo: PlatformInformation) { let packageManager = new PackageManager(platformInfo, packageJSON); const config = vscode.workspace.getConfiguration(); const proxy = config.get('http.proxy'); diff --git a/src/omnisharp/experimentalOmnisharpDownloader.ts b/src/omnisharp/experimentalOmnisharpDownloader.ts index e3df0a5dd..4dd4d5850 100644 --- a/src/omnisharp/experimentalOmnisharpDownloader.ts +++ b/src/omnisharp/experimentalOmnisharpDownloader.ts @@ -8,7 +8,7 @@ import { Status, PackageManager, Package } from '../packages'; import { PlatformInformation } from '../platform'; import { Logger } from '../logger'; import TelemetryReporter from 'vscode-extension-telemetry'; -import { GetDownloadDependencies, GetStatus, GetPlatformInformation, SendTelemetry, ReportError } from '../downloadHelper'; +import { GetDownloaderDependencies, GetStatus, GetPlatformInformation, SendTelemetry, ReportError } from '../downloadHelper'; import { GetPackagesFromVersion } from './experimentalPackageCreator'; export class ExperimentalOmnisharpDownloader { @@ -40,7 +40,7 @@ export class ExperimentalOmnisharpDownloader { installationStage = 'getPlatformInfo'; platformInfo = await GetPlatformInformation(this.logger); installationStage = 'downloadPackages'; - let dep = await GetDownloadDependencies(this.reporter, this.logger, this.channel, this.packageJSON, platformInfo); + let dep = await GetDownloaderDependencies(this.reporter, this.logger, this.channel, this.packageJSON, platformInfo); let packageManager = dep.PackageManager; let proxy = dep.Proxy; let strictSSL = dep.StrictSSL; diff --git a/src/omnisharp/experimentalOmnisharpManager.ts b/src/omnisharp/experimentalOmnisharpManager.ts index ecf23e0ff..1faa4b354 100644 --- a/src/omnisharp/experimentalOmnisharpManager.ts +++ b/src/omnisharp/experimentalOmnisharpManager.ts @@ -28,7 +28,7 @@ export class ExperimentalOmnisharpManager { if (await util.fileExists(optionPath)) { return optionPath; } - + //If the path is not a valid path on disk, treat it as a version let serverUrl = "https://omnisharpdownload.blob.core.windows.net"; let installPath = ".omnisharp/experimental"; let platformInfo = await PlatformInformation.GetCurrent(); @@ -70,6 +70,7 @@ export async function GetLaunchPathForVersion(platformInfo: PlatformInformation, if (useMono) { return path.join(basePath, 'omnisharp', 'OmniSharp.exe'); } + return path.join(basePath, 'run'); } diff --git a/src/omnisharp/experimentalPackageCreator.ts b/src/omnisharp/experimentalPackageCreator.ts index 2b1cff705..ea3015747 100644 --- a/src/omnisharp/experimentalPackageCreator.ts +++ b/src/omnisharp/experimentalPackageCreator.ts @@ -41,11 +41,11 @@ export function GetExperimentPackage(inputPackage: Package, serverUrl: string, v return GetPackageFromArchitecture(inputPackage, serverUrl, version, inputPackage.experimentalPackageId, installPath, installBinary); } -export function GetPackageFromArchitecture(inputPackage: Package, serverUrl: string, version: string, architectureInfo: string, installPath: string, installBinary: string): Package { +function GetPackageFromArchitecture(inputPackage: Package, serverUrl: string, version: string, architectureInfo: string, installPath: string, installBinary: string): Package { if (!version) { throw new Error('Invalid version'); } - + let versionPackage = { "description": inputPackage.description, "url": `${serverUrl}/ext/omnisharp-${architectureInfo}-${version}.zip`, diff --git a/test/unitTests/experimentalOmnisharpDownloader.test.ts b/test/unitTests/experimentalOmnisharpDownloader.test.ts index 96fe1807c..b22bee8e6 100644 --- a/test/unitTests/experimentalOmnisharpDownloader.test.ts +++ b/test/unitTests/experimentalOmnisharpDownloader.test.ts @@ -22,7 +22,7 @@ suite("Gets the version packages and downloads and installs them", () => { let downloader = GetOmnisharpDownloader(); let serverUrl = "https://roslynomnisharp.blob.core.windows.net"; let installPath = ".omnisharp/experimental/"; - let tempDir = path.resolve(util.getExtensionPath(), `.omnisharp\\experimental\\1.2.3`); + let tempDir = path.resolve(util.getExtensionPath(), `.omnisharp/experimental/1.2.3`); await downloader.DownloadAndInstallExperimentalVersion(version, serverUrl, installPath); let exists = await util.fileExists(path.resolve(tempDir, `install_check_1.2.3.txt`)); await rimraf(tempDir); diff --git a/test/unitTests/experimentalOmnisharpManager.test.ts b/test/unitTests/experimentalOmnisharpManager.test.ts index 3ca94e92f..a5e0fa62e 100644 --- a/test/unitTests/experimentalOmnisharpManager.test.ts +++ b/test/unitTests/experimentalOmnisharpManager.test.ts @@ -39,24 +39,24 @@ suite('Returns Omnisharp Launch Path based on the specified parameters', () => { test("Returns Launch Path based on version", async () => { let launchPath = await GetLaunchPathForVersion(platformInfo, "0.0.0", installPath, extensionPath, useMono); - launchPath.should.equal(path.resolve(extensionPath,`.omnisharp/experimental/0.0.0/OmniSharp.exe`)); + launchPath.should.equal(path.resolve(extensionPath, `.omnisharp/experimental/0.0.0/OmniSharp.exe`)); }); test("Returns Launch Path based on platform - Windows", async () => { let launchPath = await GetLaunchPathForVersion(platformInfo, version, installPath, extensionPath, useMono); - launchPath.should.equal(path.resolve(extensionPath,`.omnisharp/experimental/1.1.1/OmniSharp.exe`)); + launchPath.should.equal(path.resolve(extensionPath, `.omnisharp/experimental/1.1.1/OmniSharp.exe`)); }); test("Returns Launch Path based on platform - Unix with Mono", async () => { platformInfo = new PlatformInformation("linux", "x86"); let launchPath = await GetLaunchPathForVersion(platformInfo, version, installPath, extensionPath, true); - launchPath.should.equal(path.resolve(extensionPath,`.omnisharp/experimental/1.1.1/omnisharp/OmniSharp.exe`)); + launchPath.should.equal(path.resolve(extensionPath, `.omnisharp/experimental/1.1.1/omnisharp/OmniSharp.exe`)); }); test("Returns Launch Path based on platform - Unix without Mono", async () => { platformInfo = new PlatformInformation("linux", "x86"); let launchPath = await GetLaunchPathForVersion(platformInfo, version, installPath, extensionPath, useMono); - launchPath.should.equal(path.resolve(extensionPath,`.omnisharp/experimental/1.1.1/run`)); + launchPath.should.equal(path.resolve(extensionPath, `.omnisharp/experimental/1.1.1/run`)); }); }); @@ -102,7 +102,6 @@ suite('Installs the version packages and returns the launch path', () => { await rimraf(dirPath); launchPath.should.equal(path.resolve(extensionPath, '.omnisharp/experimental/1.2.3/run')); }); - }); function GetExperimentalOmnisharpManager() { From 2026d6ee85beb190226f9aed755cbddcb55c46c4 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Tue, 6 Feb 2018 17:23:53 -0800 Subject: [PATCH 08/28] Added null or empty check for version --- src/omnisharp/experimentalOmnisharpDownloader.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/omnisharp/experimentalOmnisharpDownloader.ts b/src/omnisharp/experimentalOmnisharpDownloader.ts index 4dd4d5850..bf9eb7a4c 100644 --- a/src/omnisharp/experimentalOmnisharpDownloader.ts +++ b/src/omnisharp/experimentalOmnisharpDownloader.ts @@ -21,6 +21,10 @@ export class ExperimentalOmnisharpDownloader { } public async DownloadAndInstallExperimentalVersion(version: string, serverUrl: string, installPath: string) { + if (!version) { + throw new Error('Invalid version'); + } + this.logger.append('Getting the version packages...'); this.channel.show(); @@ -58,7 +62,7 @@ export class ExperimentalOmnisharpDownloader { catch (error) { ReportError(this.logger, error, telemetryProps, installationStage); - throw error; + throw error;// throw the error up to the server } finally { SendTelemetry(this.logger, this.reporter, telemetryProps, installationStage, platformInfo, statusItem); From f160fc2a45a3f9b83c55797d54818d5b6ce24336 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Wed, 7 Feb 2018 13:20:57 -0800 Subject: [PATCH 09/28] Changes --- package-lock.json | 62 +++++++++++++------ package.json | 5 +- .../experimentalOmnisharpManager.test.ts | 33 +++++++++- 3 files changed, 77 insertions(+), 23 deletions(-) diff --git a/package-lock.json b/package-lock.json index 878983cb6..b8ee77a4c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "csharp", - "version": "1.14.0-beta2", + "version": "1.14.0-beta3", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -93,11 +93,6 @@ "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", "dev": true }, - "applicationinsights": { - "version": "0.18.0", - "resolved": "https://registry.npmjs.org/applicationinsights/-/applicationinsights-0.18.0.tgz", - "integrity": "sha1-Fi67SKODQIvE3kTbMrQXMH9Fu8E=" - }, "archy": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/archy/-/archy-1.0.0.tgz", @@ -397,6 +392,14 @@ "integrity": "sha512-jWAvZu1BV8tL3pj0iosBECzzHEg+XB1zSnMjJGX83bGi/1GlGdDO7J/A0sbBBS6KJT0FVqZIzZW9C6WLiMkHpQ==", "dev": true }, + "chai-as-promised": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-7.1.1.tgz", + "integrity": "sha512-azL6xMoi+uxu6z4rhWQ1jbdUhOMhis2PvscD/xjLqNMkv3BPPp2JyyuTHOrf9BOosGpNQ11v6BKv/g57RXbiaA==", + "requires": { + "check-error": "1.0.2" + } + }, "chai-fs": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/chai-fs/-/chai-fs-2.0.0.tgz", @@ -423,8 +426,7 @@ "check-error": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", - "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=", - "dev": true + "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=" }, "cheerio": { "version": "1.0.0-rc.2", @@ -697,6 +699,19 @@ "fs-exists-sync": "0.1.0" } }, + "diagnostic-channel": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/diagnostic-channel/-/diagnostic-channel-0.2.0.tgz", + "integrity": "sha1-zJmvlhLCP7H/8TYSxy8sv6qNWhc=", + "requires": { + "semver": "5.4.1" + } + }, + "diagnostic-channel-publishers": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/diagnostic-channel-publishers/-/diagnostic-channel-publishers-0.2.1.tgz", + "integrity": "sha1-ji1geottef6IC1SLxYzGvrKIxPM=" + }, "diff": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/diff/-/diff-3.2.0.tgz", @@ -5127,12 +5142,23 @@ "integrity": "sha512-e1EUy/5npqa0NlAwRCUu8A9LnVRf6tkwiPQcCLyUFCC9o2GxcAqH5Va4mqXDoxQ58ar3zODivKQeRb3z1KH7WA==" }, "vscode-extension-telemetry": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/vscode-extension-telemetry/-/vscode-extension-telemetry-0.0.8.tgz", - "integrity": "sha1-ImG/+Ya2aQpvH3RqRaxb0fhdKeA=", + "version": "0.0.11", + "resolved": "https://registry.npmjs.org/vscode-extension-telemetry/-/vscode-extension-telemetry-0.0.11.tgz", + "integrity": "sha512-P1ALLofywtfpQy9TB5Sx2edp80fHXby+CGG5pq8P1vPL2zKIUjYy3eK8mFHCOGeljTf2PTTmXJ98DeBV0kCafQ==", "requires": { - "applicationinsights": "0.18.0", - "winreg": "1.2.3" + "applicationinsights": "1.0.1" + }, + "dependencies": { + "applicationinsights": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/applicationinsights/-/applicationinsights-1.0.1.tgz", + "integrity": "sha1-U0Rrgw/o1dYZ7uKieLMdPSUDCSc=", + "requires": { + "diagnostic-channel": "0.2.0", + "diagnostic-channel-publishers": "0.2.1", + "zone.js": "0.7.6" + } + } } }, "vscode-nls": { @@ -5161,11 +5187,6 @@ "isexe": "2.0.0" } }, - "winreg": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/winreg/-/winreg-1.2.3.tgz", - "integrity": "sha1-k60RayaW2ofVj3JlqPzqUlSpZdU=" - }, "wolfy87-eventemitter": { "version": "5.2.4", "resolved": "https://registry.npmjs.org/wolfy87-eventemitter/-/wolfy87-eventemitter-5.2.4.tgz", @@ -5219,6 +5240,11 @@ "requires": { "buffer-crc32": "0.2.13" } + }, + "zone.js": { + "version": "0.7.6", + "resolved": "https://registry.npmjs.org/zone.js/-/zone.js-0.7.6.tgz", + "integrity": "sha1-+7w50+AmHQmG8boGMG6zrrDSIAk=" } } } diff --git a/package.json b/package.json index 5f1cf1819..d106583bc 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "postinstall": "node ./node_modules/vscode/bin/install" }, "dependencies": { + "chai-as-promised": "^7.1.1", "fs-extra": "^5.0.0", "http-proxy-agent": "^2.0.0", "https-proxy-agent": "^2.1.1", @@ -108,7 +109,7 @@ "x86_64" ], "installTestPath": "./.omnisharp/OmniSharp.exe", - "experimentalPackageId": "win-x64" + "experimentalPackageId": "win-x64" }, { "description": "OmniSharp for OSX", @@ -2130,4 +2131,4 @@ } ] } -} \ No newline at end of file +} diff --git a/test/unitTests/experimentalOmnisharpManager.test.ts b/test/unitTests/experimentalOmnisharpManager.test.ts index a5e0fa62e..e78b6e06a 100644 --- a/test/unitTests/experimentalOmnisharpManager.test.ts +++ b/test/unitTests/experimentalOmnisharpManager.test.ts @@ -6,13 +6,18 @@ import * as path from 'path'; import * as vscode from 'vscode'; import * as util from '../../src/common'; -import { should, expect } from "chai"; +import { should } from "chai"; import { PlatformInformation } from "../../src/platform"; import { GetLaunchPathForVersion, ExperimentalOmnisharpManager } from "../../src/omnisharp/experimentalOmnisharpManager"; import { Logger } from '../../src/logger'; import TelemetryReporter from 'vscode-extension-telemetry'; import { rimraf } from 'async-file'; +const chai = require("chai"); +const chaiAsPromised = require("chai-as-promised"); +chai.use(chaiAsPromised); +let expect = chai.expect; + suite('Returns Omnisharp Launch Path based on the specified parameters', () => { let platformInfo: PlatformInformation; @@ -32,6 +37,14 @@ suite('Returns Omnisharp Launch Path based on the specified parameters', () => { should(); }); + test("Throws error when version is null", async () => { + expect(GetLaunchPathForVersion(platformInfo, null, installPath, extensionPath, useMono)).to.be.rejectedWith(Error); + }); + + test("Throws error when version is empty", async () => { + expect(GetLaunchPathForVersion(platformInfo, "", installPath, extensionPath, useMono)).to.be.rejectedWith(Error); + }); + test("Returns Launch Path based on install path", async () => { let launchPath = await GetLaunchPathForVersion(platformInfo, version, "somePath", extensionPath, useMono); launchPath.should.equal(path.resolve(extensionPath, `somePath/1.1.1/OmniSharp.exe`)); @@ -67,6 +80,7 @@ suite('Installs the version packages and returns the launch path', () => { let useMono: boolean; let extensionPath: string; let manager: ExperimentalOmnisharpManager; + let platformInfo: PlatformInformation; suiteSetup(() => { version = "1.2.3"; @@ -77,18 +91,31 @@ suite('Installs the version packages and returns the launch path', () => { util.setExtensionPath(extension.extensionPath); extensionPath = util.getExtensionPath(); manager = GetExperimentalOmnisharpManager(); + platformInfo = new PlatformInformation("win32", "x86"); should(); }); + test('Throws error when version is null', async () => { + expect(manager.InstallVersionAndReturnLaunchPath(null, useMono, serverUrl, installPath, extensionPath, platformInfo)).to.be.rejectedWith(Error); + }); + + test('Throws error when version string is empty', async () => { + expect(manager.InstallVersionAndReturnLaunchPath("", useMono, serverUrl, installPath, extensionPath, platformInfo)).to.be.rejectedWith(Error); + }); + + test('Throws error when version string is invalid semver', async () => { + expect(manager.InstallVersionAndReturnLaunchPath("a.b.c", useMono, serverUrl, installPath, extensionPath, platformInfo)).to.be.rejectedWith(Error); + }); + test('Downloads package and returns launch path based on version', async () => { - let launchPath = await manager.InstallVersionAndReturnLaunchPath("1.2.4", useMono, serverUrl, installPath, extensionPath, new PlatformInformation("win32", "x86")); + let launchPath = await manager.InstallVersionAndReturnLaunchPath("1.2.4", useMono, serverUrl, installPath, extensionPath, platformInfo); let dirPath = path.resolve(extensionPath, `.omnisharp/experimental/1.2.4`); await rimraf(dirPath); launchPath.should.equal(path.resolve(extensionPath, '.omnisharp/experimental/1.2.4/OmniSharp.exe')); }); test('Downloads package from given url and installs them at the specified path', async () => { - let launchPath = await manager.InstallVersionAndReturnLaunchPath(version, useMono, serverUrl, installPath, extensionPath, new PlatformInformation("win32", "x86")); + let launchPath = await manager.InstallVersionAndReturnLaunchPath(version, useMono, serverUrl, installPath, extensionPath, platformInfo); let dirPath = path.resolve(extensionPath, `.omnisharp/experimental/1.2.3`); let exists = await util.fileExists(path.resolve(dirPath, `install_check_1.2.3.txt`)); From 7357cbcbd6315b55f99248cb103aed939982fb28 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Wed, 7 Feb 2018 16:57:58 -0800 Subject: [PATCH 10/28] Modified the description Put the clean up logic in the teardown function --- package.json | 2 +- ... experimentalOmnisharp.Download.Helper.ts} | 23 +-- ...ts => experimentalOmnisharp.Downloader.ts} | 27 +-- ...er.ts => experimentalOmnisharp.Manager.ts} | 9 +- ...> experimentalOmnisharp.PackageCreator.ts} | 3 +- src/omnisharp/server.ts | 20 ++- .../experimentalOmnisharpDownloader.test.ts | 157 ++++++++++++++++-- .../experimentalOmnisharpManager.test.ts | 109 +++++++++--- .../experimentalPackageCreator.test.ts | 140 ++-------------- 9 files changed, 279 insertions(+), 211 deletions(-) rename src/{downloadHelper.ts => experimentalOmnisharp.Download.Helper.ts} (72%) rename src/omnisharp/{experimentalOmnisharpDownloader.ts => experimentalOmnisharp.Downloader.ts} (70%) rename src/omnisharp/{experimentalOmnisharpManager.ts => experimentalOmnisharp.Manager.ts} (90%) rename src/omnisharp/{experimentalPackageCreator.ts => experimentalOmnisharp.PackageCreator.ts} (95%) diff --git a/package.json b/package.json index d106583bc..9b701eea9 100644 --- a/package.json +++ b/package.json @@ -367,7 +367,7 @@ "null" ], "default": null, - "description": "Specifies the full path to the OmniSharp server or the string \"latest\" to download the latest version or some version number" + "description": "Specifies pre-release OmniSharp to use. Can be one of \"latest\", a specific version number, or the absolute path to a local OmniSharp folder." }, "omnisharp.useMono": { "type": "boolean", diff --git a/src/downloadHelper.ts b/src/experimentalOmnisharp.Download.Helper.ts similarity index 72% rename from src/downloadHelper.ts rename to src/experimentalOmnisharp.Download.Helper.ts index 768317f6d..e5bb5d352 100644 --- a/src/downloadHelper.ts +++ b/src/experimentalOmnisharp.Download.Helper.ts @@ -2,22 +2,17 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as fs from 'fs'; import * as vscode from 'vscode'; -import * as util from './common'; -import { PackageManager, Status, PackageError } from './packages'; +import { PackageManager, Status, PackageError, Package } from './packages'; import { PlatformInformation } from './platform'; import { Logger } from './logger'; import TelemetryReporter from 'vscode-extension-telemetry'; -export async function GetDownloaderDependencies(reporter: TelemetryReporter, logger: Logger, channel: vscode.OutputChannel, packageJSON: any, platformInfo: PlatformInformation) { - let packageManager = new PackageManager(platformInfo, packageJSON); +export async function GetDependenciesAndDownloadPackages(packages: Package[],status: Status, platformInfo: PlatformInformation, packageManager: PackageManager,logger: Logger) { const config = vscode.workspace.getConfiguration(); const proxy = config.get('http.proxy'); const strictSSL = config.get('http.proxyStrictSSL', true); - return { - Proxy: proxy, StrictSSL: strictSSL, PackageManager: packageManager - }; + await packageManager.DownloadPackages(logger, status, proxy, strictSSL); } export function GetStatus(statusItem: vscode.StatusBarItem): Status { @@ -35,16 +30,16 @@ export function GetStatus(statusItem: vscode.StatusBarItem): Status { return status; } -export async function GetPlatformInformation(logger: Logger): Promise { +export async function GetAndLogPlatformInformation(logger: Logger): Promise { let platformInfo = await PlatformInformation.GetCurrent(); - logger.appendLine(); - // Display platform information and RID followed by a blank line + logger.appendLine(`Platform: ${platformInfo.toString()}`); logger.appendLine(); + return platformInfo; } -export function ReportError(logger: Logger, error, telemetryProps: any, installationStage: string) { +export function ReportInstallationError(logger: Logger, error, telemetryProps: any, installationStage: string) { let errorMessage: string; if (error instanceof PackageError) { // we can log the message in a PackageError to telemetry as we do not put PII in PackageError messages @@ -63,12 +58,12 @@ export function ReportError(logger: Logger, error, telemetryProps: any, installa // do not log raw errorMessage in telemetry as it is likely to contain PII. errorMessage = error.toString(); } - + logger.appendLine(`Failed at stage: ${installationStage}`); logger.appendLine(errorMessage); } -export function SendTelemetry(logger: Logger, reporter: TelemetryReporter, telemetryProps: any, installationStage: string, platformInfo: PlatformInformation, statusItem: vscode.StatusBarItem) { +export function SendInstallationTelemetry(logger: Logger, reporter: TelemetryReporter, telemetryProps: any, installationStage: string, platformInfo: PlatformInformation, statusItem: vscode.StatusBarItem) { telemetryProps['installStage'] = installationStage; telemetryProps['platform.architecture'] = platformInfo.architecture; telemetryProps['platform.platform'] = platformInfo.platform; diff --git a/src/omnisharp/experimentalOmnisharpDownloader.ts b/src/omnisharp/experimentalOmnisharp.Downloader.ts similarity index 70% rename from src/omnisharp/experimentalOmnisharpDownloader.ts rename to src/omnisharp/experimentalOmnisharp.Downloader.ts index bf9eb7a4c..681908116 100644 --- a/src/omnisharp/experimentalOmnisharpDownloader.ts +++ b/src/omnisharp/experimentalOmnisharp.Downloader.ts @@ -8,8 +8,8 @@ import { Status, PackageManager, Package } from '../packages'; import { PlatformInformation } from '../platform'; import { Logger } from '../logger'; import TelemetryReporter from 'vscode-extension-telemetry'; -import { GetDownloaderDependencies, GetStatus, GetPlatformInformation, SendTelemetry, ReportError } from '../downloadHelper'; -import { GetPackagesFromVersion } from './experimentalPackageCreator'; +import { GetPackagesFromVersion } from './experimentalOmnisharp.PackageCreator'; +import { GetDependenciesAndDownloadPackages, GetStatus, GetAndLogPlatformInformation, ReportInstallationError, SendInstallationTelemetry } from '../experimentalOmnisharp.Download.Helper'; export class ExperimentalOmnisharpDownloader { @@ -24,8 +24,9 @@ export class ExperimentalOmnisharpDownloader { if (!version) { throw new Error('Invalid version'); } - + this.logger.append('Getting the version packages...'); + this.logger.appendLine(); this.channel.show(); let statusItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right); @@ -33,7 +34,6 @@ export class ExperimentalOmnisharpDownloader { let telemetryProps: any = {}; let installationStage = ''; - let latestVersion: string; let platformInfo: PlatformInformation; if (this.reporter) { @@ -42,15 +42,16 @@ export class ExperimentalOmnisharpDownloader { try { installationStage = 'getPlatformInfo'; - platformInfo = await GetPlatformInformation(this.logger); - installationStage = 'downloadPackages'; - let dep = await GetDownloaderDependencies(this.reporter, this.logger, this.channel, this.packageJSON, platformInfo); - let packageManager = dep.PackageManager; - let proxy = dep.Proxy; - let strictSSL = dep.StrictSSL; + platformInfo = await GetAndLogPlatformInformation(this.logger); + + installationStage = 'getPackageInfo'; let packages: Package[] = GetPackagesFromVersion(version, this.packageJSON.runtimeDependencies, serverUrl, installPath); + + installationStage = 'downloadPackages'; + let packageManager = new PackageManager(platformInfo, this.packageJSON); + // Specify the packages that the package manager needs to download packageManager.SetVersionPackagesForDownload(packages); - await packageManager.DownloadPackages(this.logger, status, proxy, strictSSL); + await GetDependenciesAndDownloadPackages(packages,status, platformInfo, packageManager, this.logger); this.logger.appendLine(); @@ -61,11 +62,11 @@ export class ExperimentalOmnisharpDownloader { } catch (error) { - ReportError(this.logger, error, telemetryProps, installationStage); + ReportInstallationError(this.logger, error, telemetryProps, installationStage); throw error;// throw the error up to the server } finally { - SendTelemetry(this.logger, this.reporter, telemetryProps, installationStage, platformInfo, statusItem); + SendInstallationTelemetry(this.logger, this.reporter, telemetryProps, installationStage, platformInfo, statusItem); } } } diff --git a/src/omnisharp/experimentalOmnisharpManager.ts b/src/omnisharp/experimentalOmnisharp.Manager.ts similarity index 90% rename from src/omnisharp/experimentalOmnisharpManager.ts rename to src/omnisharp/experimentalOmnisharp.Manager.ts index 1faa4b354..9db40f735 100644 --- a/src/omnisharp/experimentalOmnisharpManager.ts +++ b/src/omnisharp/experimentalOmnisharp.Manager.ts @@ -8,7 +8,7 @@ import * as path from 'path'; import * as semver from 'semver'; import * as vscode from 'vscode'; import { Logger } from '../logger'; -import { ExperimentalOmnisharpDownloader } from './experimentalOmnisharpDownloader'; +import { ExperimentalOmnisharpDownloader } from './experimentalOmnisharp.Downloader'; import TelemetryReporter from 'vscode-extension-telemetry'; import { PlatformInformation } from '../platform'; @@ -21,7 +21,7 @@ export class ExperimentalOmnisharpManager { ) { } - public async GetExperimentalOmnisharpPath(optionPath: string, useMono: boolean): Promise { + public async GetExperimentalOmnisharpPath(optionPath: string, useMono: boolean, platformInfo: PlatformInformation, serverUrl: string, installPath: string, extensionPath: string): Promise { // Looks at the options path, installs the dependencies and returns the path to be loaded by the omnisharp server // To Do : Add the functionality for the latest option @@ -29,10 +29,7 @@ export class ExperimentalOmnisharpManager { return optionPath; } //If the path is not a valid path on disk, treat it as a version - let serverUrl = "https://omnisharpdownload.blob.core.windows.net"; - let installPath = ".omnisharp/experimental"; - let platformInfo = await PlatformInformation.GetCurrent(); - let extensionPath = util.getExtensionPath(); + return await this.InstallVersionAndReturnLaunchPath(optionPath, useMono, serverUrl, installPath, extensionPath, platformInfo); } diff --git a/src/omnisharp/experimentalPackageCreator.ts b/src/omnisharp/experimentalOmnisharp.PackageCreator.ts similarity index 95% rename from src/omnisharp/experimentalPackageCreator.ts rename to src/omnisharp/experimentalOmnisharp.PackageCreator.ts index ea3015747..52f08f0e5 100644 --- a/src/omnisharp/experimentalPackageCreator.ts +++ b/src/omnisharp/experimentalOmnisharp.PackageCreator.ts @@ -4,7 +4,6 @@ *--------------------------------------------------------------------------------------------*/ import { Package } from "../packages"; -import * as semver from 'semver'; export function GetPackagesFromVersion(version: string, runTimeDependencies: Package[], serverUrl: string, installPath: string): Package[] { if (!version) { @@ -48,7 +47,7 @@ function GetPackageFromArchitecture(inputPackage: Package, serverUrl: string, ve let versionPackage = { "description": inputPackage.description, - "url": `${serverUrl}/ext/omnisharp-${architectureInfo}-${version}.zip`, + "url": `${serverUrl}/releases/${version}/omnisharp-${architectureInfo}.zip`, "installPath": `${installPath}/${version}`, "platforms": inputPackage.platforms, "architectures": inputPackage.architectures, diff --git a/src/omnisharp/server.ts b/src/omnisharp/server.ts index 140465718..dfa6d1546 100644 --- a/src/omnisharp/server.ts +++ b/src/omnisharp/server.ts @@ -19,7 +19,8 @@ import * as protocol from './protocol'; import * as utils from '../common'; import * as vscode from 'vscode'; import { setTimeout } from 'timers'; -import { ExperimentalOmnisharpManager } from './experimentalOmnisharpManager'; +import { ExperimentalOmnisharpManager } from './experimentalOmnisharp.Manager'; +import { PlatformInformation } from '../platform'; enum ServerState { Starting, @@ -85,7 +86,7 @@ export class OmniSharpServer { private _csharpLogger: Logger; private _csharpChannel: vscode.OutputChannel; - private _packageJSON: any; + private _packageJSON: any; constructor(reporter: TelemetryReporter, csharpLogger?: Logger, csharpChannel?: vscode.OutputChannel, packageJSON?: any) { this._reporter = reporter; @@ -107,11 +108,11 @@ export class OmniSharpServer { return this._state === ServerState.Started; } - public async waitForEmptyEventQueue() : Promise { + public async waitForEmptyEventQueue(): Promise { while (!this._requestQueue.isEmpty()) { let p = new Promise((resolve) => setTimeout(resolve, 100)); await p; - } + } } private _getState(): ServerState { @@ -253,7 +254,7 @@ export class OmniSharpServer { const solutionPath = launchTarget.target; const cwd = path.dirname(solutionPath); this._options = Options.Read(); - + let args = [ '-s', solutionPath, '--hostPID', process.pid.toString(), @@ -270,11 +271,16 @@ export class OmniSharpServer { let experimentalLaunchPath: string; if (this._options.path) { try { + let serverUrl = "https://roslynomnisharp.blob.core.windows.net"; + let installPath = ".omnisharp/experimental"; + let extensionPath = utils.getExtensionPath(); let manager = new ExperimentalOmnisharpManager(this._csharpChannel, this._csharpLogger, this._reporter, this._packageJSON); - experimentalLaunchPath = await manager.GetExperimentalOmnisharpPath(this._options.path, this._options.useMono); + let platformInfo = await PlatformInformation.GetCurrent(); + experimentalLaunchPath = await manager.GetExperimentalOmnisharpPath(this._options.path, this._options.useMono, platformInfo, serverUrl, installPath, extensionPath); } catch (error) { - this._logger.appendLine(`Could not start the server due to ${error}`); + this._logger.appendLine('Error occured in loading omnisharp from omnisharp.path'); + this._logger.appendLine(`Could not start the server due to ${error.toString()}`); this._logger.appendLine(); return; } diff --git a/test/unitTests/experimentalOmnisharpDownloader.test.ts b/test/unitTests/experimentalOmnisharpDownloader.test.ts index b22bee8e6..d5c7cca11 100644 --- a/test/unitTests/experimentalOmnisharpDownloader.test.ts +++ b/test/unitTests/experimentalOmnisharpDownloader.test.ts @@ -5,16 +5,24 @@ import * as vscode from 'vscode'; import * as path from 'path'; -import * as fs from 'fs'; import * as util from '../../src/common'; -import { should, assert } from 'chai'; +import { should } from 'chai'; import { Logger } from '../../src/logger'; import TelemetryReporter from 'vscode-extension-telemetry'; -import { ExperimentalOmnisharpDownloader } from '../../src/omnisharp/experimentalOmnisharpDownloader'; +import { ExperimentalOmnisharpDownloader } from '../../src/omnisharp/experimentalOmnisharp.Downloader'; import { rimraf } from 'async-file'; +import { tmpdir } from 'os'; -suite("Gets the version packages and downloads and installs them", () => { +const tmp = require('tmp'); +suite("DownloadAndInstallExperimentalVersion : Gets the version packages, downloads and installs them", () => { + let tmpDir = null; + + setup(() => { + tmpDir = tmp.dirSync(); + util.setExtensionPath(tmpDir.name); + }); + test('Packages are downloaded from the specified server url and installed at the specified path', async () => { /* Download a test package that conatins a install_check_1.2.3.txt file and check whether the file appears at the expected path */ @@ -22,22 +30,143 @@ suite("Gets the version packages and downloads and installs them", () => { let downloader = GetOmnisharpDownloader(); let serverUrl = "https://roslynomnisharp.blob.core.windows.net"; let installPath = ".omnisharp/experimental/"; - let tempDir = path.resolve(util.getExtensionPath(), `.omnisharp/experimental/1.2.3`); await downloader.DownloadAndInstallExperimentalVersion(version, serverUrl, installPath); - let exists = await util.fileExists(path.resolve(tempDir, `install_check_1.2.3.txt`)); - await rimraf(tempDir); + let exists = await util.fileExists(path.resolve(tmpDir.name, installPath, version, `install_check_1.2.3.txt`)); exists.should.equal(true); }); + + teardown(async () => { + if (tmpDir) { + await rimraf(tmpDir.name); + } + + tmpDir = null; + }); }); function GetOmnisharpDownloader() { let channel = vscode.window.createOutputChannel('Experiment Channel'); let logger = new Logger(text => channel.append(text)); - const extensionId = 'ms-vscode.csharp'; - const extension = vscode.extensions.getExtension(extensionId); - const extensionVersion = extension.packageJSON.version; - const aiKey = extension.packageJSON.contributes.debuggers[0].aiKey; - const reporter = new TelemetryReporter(extensionId, extensionVersion, aiKey); - util.setExtensionPath(extension.extensionPath); - return new ExperimentalOmnisharpDownloader(channel, logger, reporter, extension.packageJSON); + return new ExperimentalOmnisharpDownloader(channel, logger, null, GetTestPackageJSON()); +} + +//Since we need only the runtime dependencies of packageJSON for the downloader create a testPackageJSON +//with just that +export function GetTestPackageJSON() { +let testpackageJSON = { + "runtimeDependencies": [ + { + "description": "OmniSharp for Windows (.NET 4.6 / x86)", + "url": "https://download.visualstudio.microsoft.com/download/pr/100505823/5804b7d3b5eeb7e4ae812a7cff03bd52/omnisharp-win-x86-1.28.0.zip", + "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-win-x86-1.28.0.zip", + "installPath": ".omnisharp", + "platforms": [ + "win32" + ], + "architectures": [ + "x86" + ], + "installTestPath": "./.omnisharp/OmniSharp.exe", + "experimentalPackageId": "win-x86" + }, + { + "description": "OmniSharp for Windows (.NET 4.6 / x64)", + "url": "https://download.visualstudio.microsoft.com/download/pr/100505821/c570a9e20dbf7172f79850babd058872/omnisharp-win-x64-1.28.0.zip", + "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-win-x64-1.28.0.zip", + "installPath": ".omnisharp", + "platforms": [ + "win32" + ], + "architectures": [ + "x86_64" + ], + "installTestPath": "./.omnisharp/OmniSharp.exe", + "experimentalPackageId": "win-x64" + }, + { + "description": "OmniSharp for OSX", + "url": "https://download.visualstudio.microsoft.com/download/pr/100505818/6b99c6a86da3221919158ca0f36a3e45/omnisharp-osx-1.28.0.zip", + "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-osx-1.28.0.zip", + "installPath": ".omnisharp", + "platforms": [ + "darwin" + ], + "binaries": [ + "./mono.osx", + "./run" + ], + "installTestPath": "./.omnisharp/mono.osx", + "experimentalPackageId": "osx" + }, + { + "description": "OmniSharp for Linux (x86)", + "url": "https://download.visualstudio.microsoft.com/download/pr/100505817/b710ec9c2bedc0cfdb57da82da166c47/omnisharp-linux-x86-1.28.0.zip", + "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-linux-x86-1.28.0.zip", + "installPath": ".omnisharp", + "platforms": [ + "linux" + ], + "architectures": [ + "x86", + "i686" + ], + "binaries": [ + "./mono.linux-x86", + "./run" + ], + "installTestPath": "./.omnisharp/mono.linux-x86", + "experimentalPackageId": "linux-x86" + }, + { + "description": "OmniSharp for Linux (x64)", + "url": "https://download.visualstudio.microsoft.com/download/pr/100505485/3f8a10409240decebb8a3189429f3fdf/omnisharp-linux-x64-1.28.0.zip", + "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-linux-x64-1.28.0.zip", + "installPath": ".omnisharp", + "platforms": [ + "linux" + ], + "architectures": [ + "x86_64" + ], + "binaries": [ + "./mono.linux-x86_64", + "./run" + ], + "installTestPath": "./.omnisharp/mono.linux-x86_64", + "experimentalPackageId": "linux-x64" + }, + { + "description": "OmniSharp for Test OS(architecture)", + "url": "https://download.visualstudio.microsoft.com/download/pr/100505485/3f8a10409240decebb8a3189429f3fdf/omnisharp-os-architecture-version.zip", + "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-os-architecture-version.zip", + "installPath": ".omnisharp", + "platforms": [ + "platform1" + ], + "architectures": [ + "architecture" + ], + "binaries": [ + "./binary1", + "./binary2" + ], + "installTestPath": "./.omnisharp/binary", + "experimentalPackageId": "os-architecture" + }, + { + "description": "Non omnisharp package without experimentalPackageID", + "url": "https://download.visualstudio.microsoft.com/download/pr/100317420/a30d7e11bc435433d297adc824ee837f/coreclr-debug-win7-x64.zip", + "fallbackUrl": "https://vsdebugger.blob.core.windows.net/coreclr-debug-1-14-4/coreclr-debug-win7-x64.zip", + "installPath": ".debugger", + "platforms": [ + "win32" + ], + "architectures": [ + "x86_64" + ], + "installTestPath": "./.debugger/vsdbg-ui.exe" + } + ]}; + + return testpackageJSON; } diff --git a/test/unitTests/experimentalOmnisharpManager.test.ts b/test/unitTests/experimentalOmnisharpManager.test.ts index e78b6e06a..9fe144bbc 100644 --- a/test/unitTests/experimentalOmnisharpManager.test.ts +++ b/test/unitTests/experimentalOmnisharpManager.test.ts @@ -8,32 +8,78 @@ import * as vscode from 'vscode'; import * as util from '../../src/common'; import { should } from "chai"; import { PlatformInformation } from "../../src/platform"; -import { GetLaunchPathForVersion, ExperimentalOmnisharpManager } from "../../src/omnisharp/experimentalOmnisharpManager"; +import { GetLaunchPathForVersion, ExperimentalOmnisharpManager } from "../../src/omnisharp/experimentalOmnisharp.Manager"; import { Logger } from '../../src/logger'; import TelemetryReporter from 'vscode-extension-telemetry'; import { rimraf } from 'async-file'; +import { GetTestPackageJSON } from './experimentalOmnisharpDownloader.test'; const chai = require("chai"); -const chaiAsPromised = require("chai-as-promised"); -chai.use(chaiAsPromised); +chai.use(require("chai-as-promised")); let expect = chai.expect; -suite('Returns Omnisharp Launch Path based on the specified parameters', () => { +const tmp = require('tmp'); + +suite('GetExperimentalOmnisharpPath : Returns Omnisharp experiment path depending on the path and useMono option', () => { + const platformInfo = new PlatformInformation("win32", "x86"); + const serverUrl = "https://roslynomnisharp.blob.core.windows.net"; + const installPath = ".omnisharp/experimental"; + let extensionPath: string; + let tmpDir : any; + let tmpFile : any; + + suiteSetup(() => should()); + + setup(()=>{ + tmpDir = tmp.dirSync(); + extensionPath = tmpDir.name; + util.setExtensionPath(tmpDir.name); + }); + + test('Returns the same path if absolute path to an existing file is passed', async () => { + tmpFile = tmp.fileSync(); + let manager = GetExperimentalOmnisharpManager(); + + let omnisharpPath = await manager.GetExperimentalOmnisharpPath(tmpFile.name, false, platformInfo, serverUrl, installPath, extensionPath); + omnisharpPath.should.equal(tmpFile.name); + }); + + test('Throws error if the path is neither an absolute path nor a valid semver', async () => { + let manager = GetExperimentalOmnisharpManager(); + expect(manager.GetExperimentalOmnisharpPath("Some incorrect path", false, platformInfo, serverUrl,installPath,extensionPath)).to.be.rejectedWith(Error); + }); + + teardown(async () => { + if (tmpDir) { + await rimraf(tmpDir.name); + } + + if(tmpFile){ + tmpFile.removeCallback(); + } + + tmpFile = null; + tmpDir = null; + }); +}); + +suite('GetLaunchPathForVersion : Returns Omnisharp Launch Path based on the specified parameters', () => { let platformInfo: PlatformInformation; let version: string; let installPath: string; let extensionPath: string; let useMono: boolean; + let tmpDir: any; suiteSetup(() => { platformInfo = new PlatformInformation("win32", "x86"); version = "1.1.1"; installPath = ".omnisharp/experimental"; useMono = false; - const extension = vscode.extensions.getExtension('ms-vscode.csharp'); - util.setExtensionPath(extension.extensionPath); - extensionPath = util.getExtensionPath(); + let tmpDir = tmp.dirSync(); + extensionPath = tmpDir.name; + util.setExtensionPath(tmpDir.name); should(); }); @@ -71,9 +117,17 @@ suite('Returns Omnisharp Launch Path based on the specified parameters', () => { let launchPath = await GetLaunchPathForVersion(platformInfo, version, installPath, extensionPath, useMono); launchPath.should.equal(path.resolve(extensionPath, `.omnisharp/experimental/1.1.1/run`)); }); + + suiteTeardown(async () => { + if (tmpDir) { + await rimraf(tmpDir.name); + } + + tmpDir = null; + }); }); -suite('Installs the version packages and returns the launch path', () => { +suite('InstallVersionAndReturnLaunchPath : Installs the version packages and returns the launch path', () => { let version: string; let serverUrl: string; let installPath: string; @@ -81,20 +135,24 @@ suite('Installs the version packages and returns the launch path', () => { let extensionPath: string; let manager: ExperimentalOmnisharpManager; let platformInfo: PlatformInformation; + let tmpDir = null; suiteSetup(() => { version = "1.2.3"; serverUrl = "https://roslynomnisharp.blob.core.windows.net"; installPath = ".omnisharp/experimental/"; useMono = false; - const extension = vscode.extensions.getExtension('ms-vscode.csharp'); - util.setExtensionPath(extension.extensionPath); - extensionPath = util.getExtensionPath(); manager = GetExperimentalOmnisharpManager(); platformInfo = new PlatformInformation("win32", "x86"); should(); }); + setup(() => { + tmpDir = tmp.dirSync(); + util.setExtensionPath(tmpDir.name); + extensionPath = util.getExtensionPath(); + }); + test('Throws error when version is null', async () => { expect(manager.InstallVersionAndReturnLaunchPath(null, useMono, serverUrl, installPath, extensionPath, platformInfo)).to.be.rejectedWith(Error); }); @@ -109,35 +167,36 @@ suite('Installs the version packages and returns the launch path', () => { test('Downloads package and returns launch path based on version', async () => { let launchPath = await manager.InstallVersionAndReturnLaunchPath("1.2.4", useMono, serverUrl, installPath, extensionPath, platformInfo); - let dirPath = path.resolve(extensionPath, `.omnisharp/experimental/1.2.4`); - await rimraf(dirPath); launchPath.should.equal(path.resolve(extensionPath, '.omnisharp/experimental/1.2.4/OmniSharp.exe')); }); test('Downloads package from given url and installs them at the specified path', async () => { let launchPath = await manager.InstallVersionAndReturnLaunchPath(version, useMono, serverUrl, installPath, extensionPath, platformInfo); - let dirPath = path.resolve(extensionPath, `.omnisharp/experimental/1.2.3`); - - let exists = await util.fileExists(path.resolve(dirPath, `install_check_1.2.3.txt`)); - await rimraf(dirPath); + let exists = await util.fileExists(path.resolve(extensionPath, `.omnisharp/experimental/1.2.3/install_check_1.2.3.txt`)); exists.should.equal(true); }); test('Downloads package and returns launch path based on platform - Not using mono on Linux ', async () => { let launchPath = await manager.InstallVersionAndReturnLaunchPath(version, useMono, serverUrl, installPath, extensionPath, new PlatformInformation("linux", "x64")); - let dirPath = path.resolve(extensionPath, `.omnisharp/experimental/1.2.3`); - await rimraf(dirPath); launchPath.should.equal(path.resolve(extensionPath, '.omnisharp/experimental/1.2.3/run')); }); + + test('Downloads package and returns launch path based on platform - Using mono on Linux ', async () => { + let launchPath = await manager.InstallVersionAndReturnLaunchPath(version, true, serverUrl, installPath, extensionPath, new PlatformInformation("linux", "x64")); + launchPath.should.equal(path.resolve(extensionPath, '.omnisharp/experimental/1.2.3/omnisharp/OmniSharp.exe')); + }); + + teardown(async () => { + if (tmpDir) { + await rimraf(tmpDir.name); + } + + tmpDir = null; + }); }); function GetExperimentalOmnisharpManager() { let channel = vscode.window.createOutputChannel('Experiment Channel'); let logger = new Logger(text => channel.append(text)); - const extensionId = 'ms-vscode.csharp'; - const extension = vscode.extensions.getExtension(extensionId); - const extensionVersion = extension.packageJSON.version; - const aiKey = extension.packageJSON.contributes.debuggers[0].aiKey; - const reporter = new TelemetryReporter(extensionId, extensionVersion, aiKey); - return new ExperimentalOmnisharpManager(channel, logger, reporter, extension.packageJSON); + return new ExperimentalOmnisharpManager(channel, logger, null, GetTestPackageJSON()); } \ No newline at end of file diff --git a/test/unitTests/experimentalPackageCreator.test.ts b/test/unitTests/experimentalPackageCreator.test.ts index c3c396cb6..ca6c1c4bb 100644 --- a/test/unitTests/experimentalPackageCreator.test.ts +++ b/test/unitTests/experimentalPackageCreator.test.ts @@ -5,21 +5,22 @@ import { assert, should, expect } from "chai"; import { Package } from "../../src/packages"; -import { GetExperimentPackage, GetPackagesFromVersion } from "../../src/omnisharp/experimentalPackageCreator"; +import { GetExperimentPackage, GetPackagesFromVersion } from "../../src/omnisharp/experimentalOmnisharp.PackageCreator"; +import { GetTestPackageJSON } from "./experimentalOmnisharpDownloader.test"; - -suite("Experimental Package Creator - Output package depends on the input package and other input parameters like serverUrl", () => { +suite("GetExperimentPackage : Output package depends on the input package and other input parameters like serverUrl", () => { let serverUrl: string; let version: string; let installPath: string; let inputPackages: any; - setup(() => { + suiteSetup(() => { serverUrl = "http://serverUrl"; version = "0.0.0"; installPath = "testPath"; - inputPackages = GetInputPackages(); + let packageJSON = GetTestPackageJSON(); + inputPackages = (packageJSON.runtimeDependencies); should(); }); @@ -48,7 +49,7 @@ suite("Experimental Package Creator - Output package depends on the input packag test('Download url is calculated using server url and version', () => { let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "os-architecture")); let resultPackage = GetExperimentPackage(testPackage, "http://someurl", "1.1.1", installPath); - resultPackage.url.should.equal("http://someurl/ext/omnisharp-os-architecture-1.1.1.zip"); + resultPackage.url.should.equal("http://someurl/releases/1.1.1/omnisharp-os-architecture.zip"); }); test('Install path is calculated using the specified path and version', () => { @@ -88,25 +89,25 @@ suite("Experimental Package Creator - Output package depends on the input packag }); }); -suite('Package Creator - Gets the experimental omnisharp packages from a set of input packages', () => { +suite('GetPackagesFromVersion : Gets the experimental omnisharp packages from a set of input packages', () => { const serverUrl = "http://serverUrl"; const installPath = "testPath"; + let inputPackages : any; suiteSetup(() => { + inputPackages = (GetTestPackageJSON().runtimeDependencies); should(); }); test('Throws exception if the version is null', () => { let version: string = null; - let inputPackages = GetInputPackages(); let fn = function () { GetPackagesFromVersion(version, inputPackages, serverUrl, installPath); }; expect(fn).to.throw('Invalid version'); }); test('Throws exception if the version is empty', () => { let version = ""; - let inputPackages = GetInputPackages(); let fn = function () { GetPackagesFromVersion(version, inputPackages, serverUrl, installPath); }; expect(fn).to.throw('Invalid version'); }); @@ -187,123 +188,4 @@ suite('Package Creator - Gets the experimental omnisharp packages from a set of outPackages.length.should.equal(1); outPackages[0].experimentalPackageId.should.equal("win-x64"); }); -}); - -//ask if these packages should be simplified or remain same to simulate the exact behavior -function GetInputPackages() { - let inputPackages = [ - { - "description": "OmniSharp for Windows (.NET 4.6 / x86)", - "url": "https://download.visualstudio.microsoft.com/download/pr/100505823/5804b7d3b5eeb7e4ae812a7cff03bd52/omnisharp-win-x86-1.28.0.zip", - "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-win-x86-1.28.0.zip", - "installPath": ".omnisharp", - "platforms": [ - "win32" - ], - "architectures": [ - "x86" - ], - "installTestPath": "./.omnisharp/OmniSharp.exe", - "experimentalPackageId": "win-x86" - }, - { - "description": "OmniSharp for Windows (.NET 4.6 / x64)", - "url": "https://download.visualstudio.microsoft.com/download/pr/100505821/c570a9e20dbf7172f79850babd058872/omnisharp-win-x64-1.28.0.zip", - "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-win-x64-1.28.0.zip", - "installPath": ".omnisharp", - "platforms": [ - "win32" - ], - "architectures": [ - "x86_64" - ], - "installTestPath": "./.omnisharp/OmniSharp.exe", - "experimentalPackageId": "win-x64" - }, - { - "description": "OmniSharp for OSX", - "url": "https://download.visualstudio.microsoft.com/download/pr/100505818/6b99c6a86da3221919158ca0f36a3e45/omnisharp-osx-1.28.0.zip", - "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-osx-1.28.0.zip", - "installPath": ".omnisharp", - "platforms": [ - "darwin" - ], - "binaries": [ - "./mono.osx", - "./run" - ], - "installTestPath": "./.omnisharp/mono.osx", - "experimentalPackageId": "osx" - }, - { - "description": "OmniSharp for Linux (x86)", - "url": "https://download.visualstudio.microsoft.com/download/pr/100505817/b710ec9c2bedc0cfdb57da82da166c47/omnisharp-linux-x86-1.28.0.zip", - "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-linux-x86-1.28.0.zip", - "installPath": ".omnisharp", - "platforms": [ - "linux" - ], - "architectures": [ - "x86", - "i686" - ], - "binaries": [ - "./mono.linux-x86", - "./run" - ], - "installTestPath": "./.omnisharp/mono.linux-x86", - "experimentalPackageId": "linux-x86" - }, - { - "description": "OmniSharp for Linux (x64)", - "url": "https://download.visualstudio.microsoft.com/download/pr/100505485/3f8a10409240decebb8a3189429f3fdf/omnisharp-linux-x64-1.28.0.zip", - "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-linux-x64-1.28.0.zip", - "installPath": ".omnisharp", - "platforms": [ - "linux" - ], - "architectures": [ - "x86_64" - ], - "binaries": [ - "./mono.linux-x86_64", - "./run" - ], - "installTestPath": "./.omnisharp/mono.linux-x86_64", - "experimentalPackageId": "linux-x64" - }, - { - "description": "OmniSharp for Test OS(architecture)", - "url": "https://download.visualstudio.microsoft.com/download/pr/100505485/3f8a10409240decebb8a3189429f3fdf/omnisharp-os-architecture-version.zip", - "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-os-architecture-version.zip", - "installPath": ".omnisharp", - "platforms": [ - "platform1" - ], - "architectures": [ - "architecture" - ], - "binaries": [ - "./binary1", - "./binary2" - ], - "installTestPath": "./.omnisharp/binary", - "experimentalPackageId": "os-architecture" - }, - { - "description": "Non omnisharp package without experimentalPackageID", - "url": "https://download.visualstudio.microsoft.com/download/pr/100317420/a30d7e11bc435433d297adc824ee837f/coreclr-debug-win7-x64.zip", - "fallbackUrl": "https://vsdebugger.blob.core.windows.net/coreclr-debug-1-14-4/coreclr-debug-win7-x64.zip", - "installPath": ".debugger", - "platforms": [ - "win32" - ], - "architectures": [ - "x86_64" - ], - "installTestPath": "./.debugger/vsdbg-ui.exe" - } - ]; - - return inputPackages; -} +}); \ No newline at end of file From 80e8959fb3173b59b2995eecf44c8d84a3a4e7ed Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Fri, 9 Feb 2018 14:22:23 -0800 Subject: [PATCH 11/28] Remove comment --- src/omnisharp/experimentalOmnisharp.PackageCreator.ts | 1 - test/unitTests/experimentalOmnisharpManager.test.ts | 2 +- test/unitTests/experimentalPackageCreator.test.ts | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/omnisharp/experimentalOmnisharp.PackageCreator.ts b/src/omnisharp/experimentalOmnisharp.PackageCreator.ts index 52f08f0e5..775e6c589 100644 --- a/src/omnisharp/experimentalOmnisharp.PackageCreator.ts +++ b/src/omnisharp/experimentalOmnisharp.PackageCreator.ts @@ -12,7 +12,6 @@ export function GetPackagesFromVersion(version: string, runTimeDependencies: Pac let versionPackages = new Array(); for (let inputPackage of runTimeDependencies) { - //we need only the omnisharp packages in experimental download if (inputPackage.experimentalPackageId) { versionPackages.push(GetExperimentPackage(inputPackage, serverUrl, version, installPath)); } diff --git a/test/unitTests/experimentalOmnisharpManager.test.ts b/test/unitTests/experimentalOmnisharpManager.test.ts index 9fe144bbc..e5a7628cb 100644 --- a/test/unitTests/experimentalOmnisharpManager.test.ts +++ b/test/unitTests/experimentalOmnisharpManager.test.ts @@ -8,11 +8,11 @@ import * as vscode from 'vscode'; import * as util from '../../src/common'; import { should } from "chai"; import { PlatformInformation } from "../../src/platform"; -import { GetLaunchPathForVersion, ExperimentalOmnisharpManager } from "../../src/omnisharp/experimentalOmnisharp.Manager"; import { Logger } from '../../src/logger'; import TelemetryReporter from 'vscode-extension-telemetry'; import { rimraf } from 'async-file'; import { GetTestPackageJSON } from './experimentalOmnisharpDownloader.test'; +import { GetLaunchPathForVersion, ExperimentalOmnisharpManager } from '../../src/omnisharp/experimentalOmnisharp.Manager'; const chai = require("chai"); chai.use(require("chai-as-promised")); diff --git a/test/unitTests/experimentalPackageCreator.test.ts b/test/unitTests/experimentalPackageCreator.test.ts index ca6c1c4bb..6f39374e5 100644 --- a/test/unitTests/experimentalPackageCreator.test.ts +++ b/test/unitTests/experimentalPackageCreator.test.ts @@ -5,8 +5,8 @@ import { assert, should, expect } from "chai"; import { Package } from "../../src/packages"; -import { GetExperimentPackage, GetPackagesFromVersion } from "../../src/omnisharp/experimentalOmnisharp.PackageCreator"; import { GetTestPackageJSON } from "./experimentalOmnisharpDownloader.test"; +import { GetExperimentPackage, GetPackagesFromVersion } from "../../src/omnisharp/experimentalOmnisharp.PackageCreator"; suite("GetExperimentPackage : Output package depends on the input package and other input parameters like serverUrl", () => { From 9a568c6d1a80be36523b8477a7995fd8299d86da Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Fri, 9 Feb 2018 15:18:37 -0800 Subject: [PATCH 12/28] Remove unnecessary usage --- src/omnisharp/experimentalOmnisharp.Downloader.ts | 2 +- src/omnisharp/experimentalOmnisharp.PackageCreator.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/omnisharp/experimentalOmnisharp.Downloader.ts b/src/omnisharp/experimentalOmnisharp.Downloader.ts index 681908116..5813bf535 100644 --- a/src/omnisharp/experimentalOmnisharp.Downloader.ts +++ b/src/omnisharp/experimentalOmnisharp.Downloader.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as vscode from 'vscode'; -import { Status, PackageManager, Package } from '../packages'; +import { PackageManager, Package } from '../packages'; import { PlatformInformation } from '../platform'; import { Logger } from '../logger'; import TelemetryReporter from 'vscode-extension-telemetry'; diff --git a/src/omnisharp/experimentalOmnisharp.PackageCreator.ts b/src/omnisharp/experimentalOmnisharp.PackageCreator.ts index 775e6c589..6032309a0 100644 --- a/src/omnisharp/experimentalOmnisharp.PackageCreator.ts +++ b/src/omnisharp/experimentalOmnisharp.PackageCreator.ts @@ -21,7 +21,6 @@ export function GetPackagesFromVersion(version: string, runTimeDependencies: Pac } export function GetExperimentPackage(inputPackage: Package, serverUrl: string, version: string, installPath: string): Package { - let architectureInfo: string; let installBinary: string; if (inputPackage.experimentalPackageId == "win-x86" || inputPackage.experimentalPackageId == "win-x64") { installBinary = "Omnisharp.exe"; From 19b04c652b6c68258f6e66ae605df346255bd605 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Tue, 13 Feb 2018 09:33:00 -0800 Subject: [PATCH 13/28] CR comments --- .../experimentalOmnisharp.Downloader.ts | 7 +- .../experimentalOmnisharp.Manager.ts | 35 ++- .../experimentalOmnisharp.PackageCreator.ts | 2 +- .../experimentalOmnisharpDownloader.test.ts | 233 +++++++++--------- .../experimentalOmnisharpManager.test.ts | 14 +- .../experimentalPackageCreator.test.ts | 6 +- 6 files changed, 146 insertions(+), 151 deletions(-) diff --git a/src/omnisharp/experimentalOmnisharp.Downloader.ts b/src/omnisharp/experimentalOmnisharp.Downloader.ts index 5813bf535..ca7c33a85 100644 --- a/src/omnisharp/experimentalOmnisharp.Downloader.ts +++ b/src/omnisharp/experimentalOmnisharp.Downloader.ts @@ -12,12 +12,11 @@ import { GetPackagesFromVersion } from './experimentalOmnisharp.PackageCreator'; import { GetDependenciesAndDownloadPackages, GetStatus, GetAndLogPlatformInformation, ReportInstallationError, SendInstallationTelemetry } from '../experimentalOmnisharp.Download.Helper'; export class ExperimentalOmnisharpDownloader { - public constructor( private channel: vscode.OutputChannel, private logger: Logger, - private reporter: TelemetryReporter /* optional */, - private packageJSON: any) { + private packageJSON: any, + private reporter?: TelemetryReporter) { } public async DownloadAndInstallExperimentalVersion(version: string, serverUrl: string, installPath: string) { @@ -25,7 +24,7 @@ export class ExperimentalOmnisharpDownloader { throw new Error('Invalid version'); } - this.logger.append('Getting the version packages...'); + this.logger.append('Downloading and installing the required omnisharp packages'); this.logger.appendLine(); this.channel.show(); diff --git a/src/omnisharp/experimentalOmnisharp.Manager.ts b/src/omnisharp/experimentalOmnisharp.Manager.ts index 9db40f735..93742466c 100644 --- a/src/omnisharp/experimentalOmnisharp.Manager.ts +++ b/src/omnisharp/experimentalOmnisharp.Manager.ts @@ -16,44 +16,39 @@ export class ExperimentalOmnisharpManager { public constructor( private channel: vscode.OutputChannel, private logger: Logger, - private reporter: TelemetryReporter, - private packageJSON: any - ) { + private packageJSON: any, + private reporter?: TelemetryReporter) { } - public async GetExperimentalOmnisharpPath(optionPath: string, useMono: boolean, platformInfo: PlatformInformation, serverUrl: string, installPath: string, extensionPath: string): Promise { + public async GetExperimentalOmnisharpPath(omnisharpPath: string, useMono: boolean, platformInfo: PlatformInformation, serverUrl: string, installPath: string, extensionPath: string): Promise { // Looks at the options path, installs the dependencies and returns the path to be loaded by the omnisharp server // To Do : Add the functionality for the latest option - if (await util.fileExists(optionPath)) { - return optionPath; + if (path.isAbsolute(omnisharpPath)) { + if (await util.fileExists(omnisharpPath)) { + return omnisharpPath; + } + else { + throw new Error('Could not find the specified file'); + } } - //If the path is not a valid path on disk, treat it as a version - - return await this.InstallVersionAndReturnLaunchPath(optionPath, useMono, serverUrl, installPath, extensionPath, platformInfo); + //If the path is not a valid path on disk, treat it as a version + return await this.InstallVersionAndReturnLaunchPath(omnisharpPath, useMono, serverUrl, installPath, extensionPath, platformInfo); } public async InstallVersionAndReturnLaunchPath(version: string, useMono: boolean, serverUrl: string, installPath: string, extensionPath: string, platformInfo: PlatformInformation) { - if (IsValidSemver(version)) { - let downloader = new ExperimentalOmnisharpDownloader(this.channel, this.logger, this.reporter, this.packageJSON); + if (semver.valid(version)) { + let downloader = new ExperimentalOmnisharpDownloader(this.channel, this.logger, this.packageJSON, this.reporter); await downloader.DownloadAndInstallExperimentalVersion(version, serverUrl, installPath); return await GetLaunchPathForVersion(platformInfo, version, installPath, extensionPath, useMono); } else { - throw new Error('Bad Input to Omnisharp Path'); + throw new Error('Invalid omnisharp version specified'); } } } -function IsValidSemver(version: string): boolean { - if (semver.valid(version)) { - return true; - } - - return false; -} - export async function GetLaunchPathForVersion(platformInfo: PlatformInformation, version: string, installPath: string, extensionPath: string, useMono: boolean) { if (!version) { throw new Error('Invalid Version'); diff --git a/src/omnisharp/experimentalOmnisharp.PackageCreator.ts b/src/omnisharp/experimentalOmnisharp.PackageCreator.ts index 6032309a0..06f25489b 100644 --- a/src/omnisharp/experimentalOmnisharp.PackageCreator.ts +++ b/src/omnisharp/experimentalOmnisharp.PackageCreator.ts @@ -23,7 +23,7 @@ export function GetPackagesFromVersion(version: string, runTimeDependencies: Pac export function GetExperimentPackage(inputPackage: Package, serverUrl: string, version: string, installPath: string): Package { let installBinary: string; if (inputPackage.experimentalPackageId == "win-x86" || inputPackage.experimentalPackageId == "win-x64") { - installBinary = "Omnisharp.exe"; + installBinary = "OmniSharp.exe"; } else if (inputPackage.experimentalPackageId == "osx") { installBinary = "mono.osx"; diff --git a/test/unitTests/experimentalOmnisharpDownloader.test.ts b/test/unitTests/experimentalOmnisharpDownloader.test.ts index d5c7cca11..ad96560a7 100644 --- a/test/unitTests/experimentalOmnisharpDownloader.test.ts +++ b/test/unitTests/experimentalOmnisharpDownloader.test.ts @@ -22,7 +22,7 @@ suite("DownloadAndInstallExperimentalVersion : Gets the version packages, downlo tmpDir = tmp.dirSync(); util.setExtensionPath(tmpDir.name); }); - + test('Packages are downloaded from the specified server url and installed at the specified path', async () => { /* Download a test package that conatins a install_check_1.2.3.txt file and check whether the file appears at the expected path */ @@ -47,126 +47,127 @@ suite("DownloadAndInstallExperimentalVersion : Gets the version packages, downlo function GetOmnisharpDownloader() { let channel = vscode.window.createOutputChannel('Experiment Channel'); let logger = new Logger(text => channel.append(text)); - return new ExperimentalOmnisharpDownloader(channel, logger, null, GetTestPackageJSON()); + return new ExperimentalOmnisharpDownloader(channel, logger, GetTestPackageJSON(), null); } //Since we need only the runtime dependencies of packageJSON for the downloader create a testPackageJSON //with just that export function GetTestPackageJSON() { -let testpackageJSON = { - "runtimeDependencies": [ - { - "description": "OmniSharp for Windows (.NET 4.6 / x86)", - "url": "https://download.visualstudio.microsoft.com/download/pr/100505823/5804b7d3b5eeb7e4ae812a7cff03bd52/omnisharp-win-x86-1.28.0.zip", - "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-win-x86-1.28.0.zip", - "installPath": ".omnisharp", - "platforms": [ - "win32" - ], - "architectures": [ - "x86" - ], - "installTestPath": "./.omnisharp/OmniSharp.exe", - "experimentalPackageId": "win-x86" - }, - { - "description": "OmniSharp for Windows (.NET 4.6 / x64)", - "url": "https://download.visualstudio.microsoft.com/download/pr/100505821/c570a9e20dbf7172f79850babd058872/omnisharp-win-x64-1.28.0.zip", - "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-win-x64-1.28.0.zip", - "installPath": ".omnisharp", - "platforms": [ - "win32" - ], - "architectures": [ - "x86_64" - ], - "installTestPath": "./.omnisharp/OmniSharp.exe", - "experimentalPackageId": "win-x64" - }, - { - "description": "OmniSharp for OSX", - "url": "https://download.visualstudio.microsoft.com/download/pr/100505818/6b99c6a86da3221919158ca0f36a3e45/omnisharp-osx-1.28.0.zip", - "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-osx-1.28.0.zip", - "installPath": ".omnisharp", - "platforms": [ - "darwin" - ], - "binaries": [ - "./mono.osx", - "./run" - ], - "installTestPath": "./.omnisharp/mono.osx", - "experimentalPackageId": "osx" - }, - { - "description": "OmniSharp for Linux (x86)", - "url": "https://download.visualstudio.microsoft.com/download/pr/100505817/b710ec9c2bedc0cfdb57da82da166c47/omnisharp-linux-x86-1.28.0.zip", - "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-linux-x86-1.28.0.zip", - "installPath": ".omnisharp", - "platforms": [ - "linux" - ], - "architectures": [ - "x86", - "i686" - ], - "binaries": [ - "./mono.linux-x86", - "./run" - ], - "installTestPath": "./.omnisharp/mono.linux-x86", - "experimentalPackageId": "linux-x86" - }, - { - "description": "OmniSharp for Linux (x64)", - "url": "https://download.visualstudio.microsoft.com/download/pr/100505485/3f8a10409240decebb8a3189429f3fdf/omnisharp-linux-x64-1.28.0.zip", - "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-linux-x64-1.28.0.zip", - "installPath": ".omnisharp", - "platforms": [ - "linux" - ], - "architectures": [ - "x86_64" - ], - "binaries": [ - "./mono.linux-x86_64", - "./run" - ], - "installTestPath": "./.omnisharp/mono.linux-x86_64", - "experimentalPackageId": "linux-x64" - }, - { - "description": "OmniSharp for Test OS(architecture)", - "url": "https://download.visualstudio.microsoft.com/download/pr/100505485/3f8a10409240decebb8a3189429f3fdf/omnisharp-os-architecture-version.zip", - "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-os-architecture-version.zip", - "installPath": ".omnisharp", - "platforms": [ - "platform1" - ], - "architectures": [ - "architecture" - ], - "binaries": [ - "./binary1", - "./binary2" - ], - "installTestPath": "./.omnisharp/binary", - "experimentalPackageId": "os-architecture" - }, - { - "description": "Non omnisharp package without experimentalPackageID", - "url": "https://download.visualstudio.microsoft.com/download/pr/100317420/a30d7e11bc435433d297adc824ee837f/coreclr-debug-win7-x64.zip", - "fallbackUrl": "https://vsdebugger.blob.core.windows.net/coreclr-debug-1-14-4/coreclr-debug-win7-x64.zip", - "installPath": ".debugger", - "platforms": [ - "win32" - ], - "architectures": [ - "x86_64" - ], - "installTestPath": "./.debugger/vsdbg-ui.exe" - } - ]}; + let testpackageJSON = { + "runtimeDependencies": [ + { + "description": "OmniSharp for Windows (.NET 4.6 / x86)", + "url": "https://download.visualstudio.microsoft.com/download/pr/100505823/5804b7d3b5eeb7e4ae812a7cff03bd52/omnisharp-win-x86-1.28.0.zip", + "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-win-x86-1.28.0.zip", + "installPath": ".omnisharp", + "platforms": [ + "win32" + ], + "architectures": [ + "x86" + ], + "installTestPath": "./.omnisharp/OmniSharp.exe", + "experimentalPackageId": "win-x86" + }, + { + "description": "OmniSharp for Windows (.NET 4.6 / x64)", + "url": "https://download.visualstudio.microsoft.com/download/pr/100505821/c570a9e20dbf7172f79850babd058872/omnisharp-win-x64-1.28.0.zip", + "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-win-x64-1.28.0.zip", + "installPath": ".omnisharp", + "platforms": [ + "win32" + ], + "architectures": [ + "x86_64" + ], + "installTestPath": "./.omnisharp/OmniSharp.exe", + "experimentalPackageId": "win-x64" + }, + { + "description": "OmniSharp for OSX", + "url": "https://download.visualstudio.microsoft.com/download/pr/100505818/6b99c6a86da3221919158ca0f36a3e45/omnisharp-osx-1.28.0.zip", + "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-osx-1.28.0.zip", + "installPath": ".omnisharp", + "platforms": [ + "darwin" + ], + "binaries": [ + "./mono.osx", + "./run" + ], + "installTestPath": "./.omnisharp/mono.osx", + "experimentalPackageId": "osx" + }, + { + "description": "OmniSharp for Linux (x86)", + "url": "https://download.visualstudio.microsoft.com/download/pr/100505817/b710ec9c2bedc0cfdb57da82da166c47/omnisharp-linux-x86-1.28.0.zip", + "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-linux-x86-1.28.0.zip", + "installPath": ".omnisharp", + "platforms": [ + "linux" + ], + "architectures": [ + "x86", + "i686" + ], + "binaries": [ + "./mono.linux-x86", + "./run" + ], + "installTestPath": "./.omnisharp/mono.linux-x86", + "experimentalPackageId": "linux-x86" + }, + { + "description": "OmniSharp for Linux (x64)", + "url": "https://download.visualstudio.microsoft.com/download/pr/100505485/3f8a10409240decebb8a3189429f3fdf/omnisharp-linux-x64-1.28.0.zip", + "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-linux-x64-1.28.0.zip", + "installPath": ".omnisharp", + "platforms": [ + "linux" + ], + "architectures": [ + "x86_64" + ], + "binaries": [ + "./mono.linux-x86_64", + "./run" + ], + "installTestPath": "./.omnisharp/mono.linux-x86_64", + "experimentalPackageId": "linux-x64" + }, + { + "description": "OmniSharp for Test OS(architecture)", + "url": "https://download.visualstudio.microsoft.com/download/pr/100505485/3f8a10409240decebb8a3189429f3fdf/omnisharp-os-architecture-version.zip", + "fallbackUrl": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-os-architecture-version.zip", + "installPath": ".omnisharp", + "platforms": [ + "platform1" + ], + "architectures": [ + "architecture" + ], + "binaries": [ + "./binary1", + "./binary2" + ], + "installTestPath": "./.omnisharp/binary", + "experimentalPackageId": "os-architecture" + }, + { + "description": "Non omnisharp package without experimentalPackageID", + "url": "https://download.visualstudio.microsoft.com/download/pr/100317420/a30d7e11bc435433d297adc824ee837f/coreclr-debug-win7-x64.zip", + "fallbackUrl": "https://vsdebugger.blob.core.windows.net/coreclr-debug-1-14-4/coreclr-debug-win7-x64.zip", + "installPath": ".debugger", + "platforms": [ + "win32" + ], + "architectures": [ + "x86_64" + ], + "installTestPath": "./.debugger/vsdbg-ui.exe" + } + ] + }; return testpackageJSON; } diff --git a/test/unitTests/experimentalOmnisharpManager.test.ts b/test/unitTests/experimentalOmnisharpManager.test.ts index e5a7628cb..05ded06c8 100644 --- a/test/unitTests/experimentalOmnisharpManager.test.ts +++ b/test/unitTests/experimentalOmnisharpManager.test.ts @@ -25,12 +25,12 @@ suite('GetExperimentalOmnisharpPath : Returns Omnisharp experiment path dependin const serverUrl = "https://roslynomnisharp.blob.core.windows.net"; const installPath = ".omnisharp/experimental"; let extensionPath: string; - let tmpDir : any; - let tmpFile : any; + let tmpDir: any; + let tmpFile: any; suiteSetup(() => should()); - setup(()=>{ + setup(() => { tmpDir = tmp.dirSync(); extensionPath = tmpDir.name; util.setExtensionPath(tmpDir.name); @@ -46,7 +46,7 @@ suite('GetExperimentalOmnisharpPath : Returns Omnisharp experiment path dependin test('Throws error if the path is neither an absolute path nor a valid semver', async () => { let manager = GetExperimentalOmnisharpManager(); - expect(manager.GetExperimentalOmnisharpPath("Some incorrect path", false, platformInfo, serverUrl,installPath,extensionPath)).to.be.rejectedWith(Error); + expect(manager.GetExperimentalOmnisharpPath("Some incorrect path", false, platformInfo, serverUrl, installPath, extensionPath)).to.be.rejectedWith(Error); }); teardown(async () => { @@ -54,10 +54,10 @@ suite('GetExperimentalOmnisharpPath : Returns Omnisharp experiment path dependin await rimraf(tmpDir.name); } - if(tmpFile){ + if (tmpFile) { tmpFile.removeCallback(); } - + tmpFile = null; tmpDir = null; }); @@ -198,5 +198,5 @@ suite('InstallVersionAndReturnLaunchPath : Installs the version packages and ret function GetExperimentalOmnisharpManager() { let channel = vscode.window.createOutputChannel('Experiment Channel'); let logger = new Logger(text => channel.append(text)); - return new ExperimentalOmnisharpManager(channel, logger, null, GetTestPackageJSON()); + return new ExperimentalOmnisharpManager(channel, logger, GetTestPackageJSON(), null); } \ No newline at end of file diff --git a/test/unitTests/experimentalPackageCreator.test.ts b/test/unitTests/experimentalPackageCreator.test.ts index 6f39374e5..88300b2f0 100644 --- a/test/unitTests/experimentalPackageCreator.test.ts +++ b/test/unitTests/experimentalPackageCreator.test.ts @@ -61,13 +61,13 @@ suite("GetExperimentPackage : Output package depends on the input package and ot test('Install test path is calculated using specified path, version and ends with Omnisharp.exe - Windows(x86)', () => { let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "win-x86")); let resultPackage = GetExperimentPackage(testPackage, serverUrl, "1.2.3", "experimentPath"); - resultPackage.installTestPath.should.equal("./experimentPath/1.2.3/Omnisharp.exe"); + resultPackage.installTestPath.should.equal("./experimentPath/1.2.3/OmniSharp.exe"); }); test('Install test path is calculated using specified path, version and ends with Omnisharp.exe - Windows(x64)', () => { let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "win-x64")); let resultPackage = GetExperimentPackage(testPackage, serverUrl, "1.2.3", "experimentPath"); - resultPackage.installTestPath.should.equal("./experimentPath/1.2.3/Omnisharp.exe"); + resultPackage.installTestPath.should.equal("./experimentPath/1.2.3/OmniSharp.exe"); }); test('Install test path is calculated using specified path, version and ends with mono.osx - OSX', () => { @@ -147,7 +147,7 @@ suite('GetPackagesFromVersion : Gets the experimental omnisharp packages from a let outPackages = GetPackagesFromVersion("1.1.1", inputPackages, serverUrl, "experimentPath"); outPackages.length.should.equal(2); - outPackages[0].installTestPath.should.equal("./experimentPath/1.1.1/Omnisharp.exe"); + outPackages[0].installTestPath.should.equal("./experimentPath/1.1.1/OmniSharp.exe"); outPackages[1].installTestPath.should.equal("./experimentPath/1.1.1/mono.osx"); }); From 71ab1e256ae4d7504fbdb8bd12ba2592e1edec32 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Tue, 13 Feb 2018 10:09:12 -0800 Subject: [PATCH 14/28] Removed experimental --- package.json | 2 +- ...wnload.Helper.ts => Omnisharp.Download.Helper.ts} | 2 +- ...mnisharp.Downloader.ts => OmnisharpDownloader.ts} | 4 ++-- ...entalOmnisharp.Manager.ts => OmnisharpManager.ts} | 6 +++--- ....PackageCreator.ts => OmnisharpPackageCreator.ts} | 0 src/omnisharp/launcher.ts | 12 ++++++------ src/omnisharp/server.ts | 6 +++--- ...ownloader.test.ts => OmnisharpDownloader.test.ts} | 2 +- ...sharpManager.test.ts => OmnisharpManager.test.ts} | 12 ++++++------ ...eator.test.ts => OmnisharpPackageCreator.test.ts} | 4 ++-- 10 files changed, 25 insertions(+), 25 deletions(-) rename src/{experimentalOmnisharp.Download.Helper.ts => Omnisharp.Download.Helper.ts} (96%) rename src/omnisharp/{experimentalOmnisharp.Downloader.ts => OmnisharpDownloader.ts} (95%) rename src/omnisharp/{experimentalOmnisharp.Manager.ts => OmnisharpManager.ts} (89%) rename src/omnisharp/{experimentalOmnisharp.PackageCreator.ts => OmnisharpPackageCreator.ts} (100%) rename test/unitTests/{experimentalOmnisharpDownloader.test.ts => OmnisharpDownloader.test.ts} (99%) rename test/unitTests/{experimentalOmnisharpManager.test.ts => OmnisharpManager.test.ts} (92%) rename test/unitTests/{experimentalPackageCreator.test.ts => OmnisharpPackageCreator.test.ts} (98%) diff --git a/package.json b/package.json index 652c2ef47..be5b7e0e2 100644 --- a/package.json +++ b/package.json @@ -367,7 +367,7 @@ "null" ], "default": null, - "description": "Specifies pre-release OmniSharp to use. Can be one of \"latest\", a specific version number, or the absolute path to a local OmniSharp folder." + "description": "Specifies the OmniSharp to use. Can be one of \"latest\", a specific version number, or the absolute path to a local OmniSharp folder." }, "omnisharp.useMono": { "type": "boolean", diff --git a/src/experimentalOmnisharp.Download.Helper.ts b/src/Omnisharp.Download.Helper.ts similarity index 96% rename from src/experimentalOmnisharp.Download.Helper.ts rename to src/Omnisharp.Download.Helper.ts index e5bb5d352..77d2028de 100644 --- a/src/experimentalOmnisharp.Download.Helper.ts +++ b/src/Omnisharp.Download.Helper.ts @@ -8,7 +8,7 @@ import { PlatformInformation } from './platform'; import { Logger } from './logger'; import TelemetryReporter from 'vscode-extension-telemetry'; -export async function GetDependenciesAndDownloadPackages(packages: Package[],status: Status, platformInfo: PlatformInformation, packageManager: PackageManager,logger: Logger) { +export async function GetDependenciesAndDownloadPackages(packages: Package[], status: Status, platformInfo: PlatformInformation, packageManager: PackageManager, logger: Logger) { const config = vscode.workspace.getConfiguration(); const proxy = config.get('http.proxy'); const strictSSL = config.get('http.proxyStrictSSL', true); diff --git a/src/omnisharp/experimentalOmnisharp.Downloader.ts b/src/omnisharp/OmnisharpDownloader.ts similarity index 95% rename from src/omnisharp/experimentalOmnisharp.Downloader.ts rename to src/omnisharp/OmnisharpDownloader.ts index ca7c33a85..a24cbc392 100644 --- a/src/omnisharp/experimentalOmnisharp.Downloader.ts +++ b/src/omnisharp/OmnisharpDownloader.ts @@ -8,8 +8,8 @@ import { PackageManager, Package } from '../packages'; import { PlatformInformation } from '../platform'; import { Logger } from '../logger'; import TelemetryReporter from 'vscode-extension-telemetry'; -import { GetPackagesFromVersion } from './experimentalOmnisharp.PackageCreator'; -import { GetDependenciesAndDownloadPackages, GetStatus, GetAndLogPlatformInformation, ReportInstallationError, SendInstallationTelemetry } from '../experimentalOmnisharp.Download.Helper'; +import { GetPackagesFromVersion } from './OmnisharpPackageCreator'; +import { GetDependenciesAndDownloadPackages, GetStatus, GetAndLogPlatformInformation, ReportInstallationError, SendInstallationTelemetry } from '../Omnisharp.Download.Helper'; export class ExperimentalOmnisharpDownloader { public constructor( diff --git a/src/omnisharp/experimentalOmnisharp.Manager.ts b/src/omnisharp/OmnisharpManager.ts similarity index 89% rename from src/omnisharp/experimentalOmnisharp.Manager.ts rename to src/omnisharp/OmnisharpManager.ts index 93742466c..127a519c3 100644 --- a/src/omnisharp/experimentalOmnisharp.Manager.ts +++ b/src/omnisharp/OmnisharpManager.ts @@ -8,11 +8,11 @@ import * as path from 'path'; import * as semver from 'semver'; import * as vscode from 'vscode'; import { Logger } from '../logger'; -import { ExperimentalOmnisharpDownloader } from './experimentalOmnisharp.Downloader'; +import { ExperimentalOmnisharpDownloader } from './OmnisharpDownloader'; import TelemetryReporter from 'vscode-extension-telemetry'; import { PlatformInformation } from '../platform'; -export class ExperimentalOmnisharpManager { +export class OmnisharpManager { public constructor( private channel: vscode.OutputChannel, private logger: Logger, @@ -20,7 +20,7 @@ export class ExperimentalOmnisharpManager { private reporter?: TelemetryReporter) { } - public async GetExperimentalOmnisharpPath(omnisharpPath: string, useMono: boolean, platformInfo: PlatformInformation, serverUrl: string, installPath: string, extensionPath: string): Promise { + public async GetOmnisharpPath(omnisharpPath: string, useMono: boolean, platformInfo: PlatformInformation, serverUrl: string, installPath: string, extensionPath: string): Promise { // Looks at the options path, installs the dependencies and returns the path to be loaded by the omnisharp server // To Do : Add the functionality for the latest option diff --git a/src/omnisharp/experimentalOmnisharp.PackageCreator.ts b/src/omnisharp/OmnisharpPackageCreator.ts similarity index 100% rename from src/omnisharp/experimentalOmnisharp.PackageCreator.ts rename to src/omnisharp/OmnisharpPackageCreator.ts diff --git a/src/omnisharp/launcher.ts b/src/omnisharp/launcher.ts index 0efb3ba8a..bd49e9fbd 100644 --- a/src/omnisharp/launcher.ts +++ b/src/omnisharp/launcher.ts @@ -225,7 +225,7 @@ export function launchOmniSharp(cwd: string, args: string[], experimentalLaunchP }); } -function launch(cwd: string, args: string[], experimentalLaunchPath: string): Promise { +function launch(cwd: string, args: string[], launchPath: string): Promise { return PlatformInformation.GetCurrent().then(platformInfo => { const options = Options.Read(); @@ -239,18 +239,18 @@ function launch(cwd: string, args: string[], experimentalLaunchPath: string): Pr args.push(`formattingOptions:indentationSize=${getConfigurationValue(globalConfig, csharpConfig, 'editor.tabSize', 4)}`); } - // If the user has provide a path to OmniSharp, we'll use that. - if (experimentalLaunchPath) { + // If the user has provided a path to OmniSharp, we'll use that. + if (launchPath) { if (platformInfo.isWindows()) { - return launchWindows(experimentalLaunchPath, cwd, args); + return launchWindows(launchPath, cwd, args); } // If we're launching on macOS/Linux, we have two possibilities: // 1. Launch using Mono // 2. Launch process directly (e.g. a 'run' script) return options.useMono - ? launchNixMono(experimentalLaunchPath, cwd, args) - : launchNix(experimentalLaunchPath, cwd, args); + ? launchNixMono(launchPath, cwd, args) + : launchNix(launchPath, cwd, args); } // If the user has not provided a path, we'll use the locally-installed OmniSharp diff --git a/src/omnisharp/server.ts b/src/omnisharp/server.ts index dfa6d1546..9ccb2579c 100644 --- a/src/omnisharp/server.ts +++ b/src/omnisharp/server.ts @@ -19,7 +19,7 @@ import * as protocol from './protocol'; import * as utils from '../common'; import * as vscode from 'vscode'; import { setTimeout } from 'timers'; -import { ExperimentalOmnisharpManager } from './experimentalOmnisharp.Manager'; +import { OmnisharpManager } from './OmnisharpManager'; import { PlatformInformation } from '../platform'; enum ServerState { @@ -274,9 +274,9 @@ export class OmniSharpServer { let serverUrl = "https://roslynomnisharp.blob.core.windows.net"; let installPath = ".omnisharp/experimental"; let extensionPath = utils.getExtensionPath(); - let manager = new ExperimentalOmnisharpManager(this._csharpChannel, this._csharpLogger, this._reporter, this._packageJSON); + let manager = new OmnisharpManager(this._csharpChannel, this._csharpLogger, this._reporter, this._packageJSON); let platformInfo = await PlatformInformation.GetCurrent(); - experimentalLaunchPath = await manager.GetExperimentalOmnisharpPath(this._options.path, this._options.useMono, platformInfo, serverUrl, installPath, extensionPath); + experimentalLaunchPath = await manager.GetOmnisharpPath(this._options.path, this._options.useMono, platformInfo, serverUrl, installPath, extensionPath); } catch (error) { this._logger.appendLine('Error occured in loading omnisharp from omnisharp.path'); diff --git a/test/unitTests/experimentalOmnisharpDownloader.test.ts b/test/unitTests/OmnisharpDownloader.test.ts similarity index 99% rename from test/unitTests/experimentalOmnisharpDownloader.test.ts rename to test/unitTests/OmnisharpDownloader.test.ts index ad96560a7..f8aa3ecbd 100644 --- a/test/unitTests/experimentalOmnisharpDownloader.test.ts +++ b/test/unitTests/OmnisharpDownloader.test.ts @@ -9,7 +9,7 @@ import * as util from '../../src/common'; import { should } from 'chai'; import { Logger } from '../../src/logger'; import TelemetryReporter from 'vscode-extension-telemetry'; -import { ExperimentalOmnisharpDownloader } from '../../src/omnisharp/experimentalOmnisharp.Downloader'; +import { ExperimentalOmnisharpDownloader } from '../../src/omnisharp/OmnisharpDownloader'; import { rimraf } from 'async-file'; import { tmpdir } from 'os'; diff --git a/test/unitTests/experimentalOmnisharpManager.test.ts b/test/unitTests/OmnisharpManager.test.ts similarity index 92% rename from test/unitTests/experimentalOmnisharpManager.test.ts rename to test/unitTests/OmnisharpManager.test.ts index 05ded06c8..ee6b24eac 100644 --- a/test/unitTests/experimentalOmnisharpManager.test.ts +++ b/test/unitTests/OmnisharpManager.test.ts @@ -11,8 +11,8 @@ import { PlatformInformation } from "../../src/platform"; import { Logger } from '../../src/logger'; import TelemetryReporter from 'vscode-extension-telemetry'; import { rimraf } from 'async-file'; -import { GetTestPackageJSON } from './experimentalOmnisharpDownloader.test'; -import { GetLaunchPathForVersion, ExperimentalOmnisharpManager } from '../../src/omnisharp/experimentalOmnisharp.Manager'; +import { GetTestPackageJSON } from './OmnisharpDownloader.test'; +import { GetLaunchPathForVersion, OmnisharpManager } from '../../src/omnisharp/OmnisharpManager'; const chai = require("chai"); chai.use(require("chai-as-promised")); @@ -40,13 +40,13 @@ suite('GetExperimentalOmnisharpPath : Returns Omnisharp experiment path dependin tmpFile = tmp.fileSync(); let manager = GetExperimentalOmnisharpManager(); - let omnisharpPath = await manager.GetExperimentalOmnisharpPath(tmpFile.name, false, platformInfo, serverUrl, installPath, extensionPath); + let omnisharpPath = await manager.GetOmnisharpPath(tmpFile.name, false, platformInfo, serverUrl, installPath, extensionPath); omnisharpPath.should.equal(tmpFile.name); }); test('Throws error if the path is neither an absolute path nor a valid semver', async () => { let manager = GetExperimentalOmnisharpManager(); - expect(manager.GetExperimentalOmnisharpPath("Some incorrect path", false, platformInfo, serverUrl, installPath, extensionPath)).to.be.rejectedWith(Error); + expect(manager.GetOmnisharpPath("Some incorrect path", false, platformInfo, serverUrl, installPath, extensionPath)).to.be.rejectedWith(Error); }); teardown(async () => { @@ -133,7 +133,7 @@ suite('InstallVersionAndReturnLaunchPath : Installs the version packages and ret let installPath: string; let useMono: boolean; let extensionPath: string; - let manager: ExperimentalOmnisharpManager; + let manager: OmnisharpManager; let platformInfo: PlatformInformation; let tmpDir = null; @@ -198,5 +198,5 @@ suite('InstallVersionAndReturnLaunchPath : Installs the version packages and ret function GetExperimentalOmnisharpManager() { let channel = vscode.window.createOutputChannel('Experiment Channel'); let logger = new Logger(text => channel.append(text)); - return new ExperimentalOmnisharpManager(channel, logger, GetTestPackageJSON(), null); + return new OmnisharpManager(channel, logger, GetTestPackageJSON(), null); } \ No newline at end of file diff --git a/test/unitTests/experimentalPackageCreator.test.ts b/test/unitTests/OmnisharpPackageCreator.test.ts similarity index 98% rename from test/unitTests/experimentalPackageCreator.test.ts rename to test/unitTests/OmnisharpPackageCreator.test.ts index 88300b2f0..7121de931 100644 --- a/test/unitTests/experimentalPackageCreator.test.ts +++ b/test/unitTests/OmnisharpPackageCreator.test.ts @@ -5,8 +5,8 @@ import { assert, should, expect } from "chai"; import { Package } from "../../src/packages"; -import { GetTestPackageJSON } from "./experimentalOmnisharpDownloader.test"; -import { GetExperimentPackage, GetPackagesFromVersion } from "../../src/omnisharp/experimentalOmnisharp.PackageCreator"; +import { GetTestPackageJSON } from "./OmnisharpDownloader.test"; +import { GetExperimentPackage, GetPackagesFromVersion } from "../../src/omnisharp/OmnisharpPackageCreator"; suite("GetExperimentPackage : Output package depends on the input package and other input parameters like serverUrl", () => { From 3c2e1c8840d3a396856e277a367988cefcc912f6 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Tue, 13 Feb 2018 11:12:39 -0800 Subject: [PATCH 15/28] Modified launcher --- src/Omnisharp.Download.Helper.ts | 5 ++-- src/omnisharp/OmnisharpDownloader.ts | 9 ++++--- src/omnisharp/launcher.ts | 40 +++++++++++++--------------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Omnisharp.Download.Helper.ts b/src/Omnisharp.Download.Helper.ts index 77d2028de..1fcb7326e 100644 --- a/src/Omnisharp.Download.Helper.ts +++ b/src/Omnisharp.Download.Helper.ts @@ -15,7 +15,8 @@ export async function GetDependenciesAndDownloadPackages(packages: Package[], st await packageManager.DownloadPackages(logger, status, proxy, strictSSL); } -export function GetStatus(statusItem: vscode.StatusBarItem): Status { +export function SetStatus() { + let statusItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right); let status: Status = { setMessage: text => { statusItem.text = text; @@ -27,7 +28,7 @@ export function GetStatus(statusItem: vscode.StatusBarItem): Status { } }; - return status; + return { StatusItem: statusItem, Status: status }; } export async function GetAndLogPlatformInformation(logger: Logger): Promise { diff --git a/src/omnisharp/OmnisharpDownloader.ts b/src/omnisharp/OmnisharpDownloader.ts index a24cbc392..24c894796 100644 --- a/src/omnisharp/OmnisharpDownloader.ts +++ b/src/omnisharp/OmnisharpDownloader.ts @@ -9,7 +9,7 @@ import { PlatformInformation } from '../platform'; import { Logger } from '../logger'; import TelemetryReporter from 'vscode-extension-telemetry'; import { GetPackagesFromVersion } from './OmnisharpPackageCreator'; -import { GetDependenciesAndDownloadPackages, GetStatus, GetAndLogPlatformInformation, ReportInstallationError, SendInstallationTelemetry } from '../Omnisharp.Download.Helper'; +import { GetDependenciesAndDownloadPackages, SetStatus, GetAndLogPlatformInformation, ReportInstallationError, SendInstallationTelemetry } from '../Omnisharp.Download.Helper'; export class ExperimentalOmnisharpDownloader { public constructor( @@ -28,8 +28,9 @@ export class ExperimentalOmnisharpDownloader { this.logger.appendLine(); this.channel.show(); - let statusItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right); - let status = GetStatus(statusItem); + let statusObject = SetStatus(); + let status = statusObject.Status; + let statusItem = statusObject.StatusItem; let telemetryProps: any = {}; let installationStage = ''; @@ -48,7 +49,7 @@ export class ExperimentalOmnisharpDownloader { installationStage = 'downloadPackages'; let packageManager = new PackageManager(platformInfo, this.packageJSON); - // Specify the packages that the package manager needs to download + // Specify the packages that the package manager needs to download packageManager.SetVersionPackagesForDownload(packages); await GetDependenciesAndDownloadPackages(packages,status, platformInfo, packageManager, this.logger); diff --git a/src/omnisharp/launcher.ts b/src/omnisharp/launcher.ts index bd49e9fbd..3c00a6bdb 100644 --- a/src/omnisharp/launcher.ts +++ b/src/omnisharp/launcher.ts @@ -46,7 +46,7 @@ export function findLaunchTargets(): Thenable { const options = Options.Read(); return vscode.workspace.findFiles( - /*include*/ '{**/*.sln,**/*.csproj,**/project.json,**/*.csx,**/*.cake}', + /*include*/ '{**/*.sln,**/*.csproj,**/project.json,**/*.csx,**/*.cake}', /*exclude*/ '{**/node_modules/**,**/.git/**,**/bower_components/**}', /*maxResults*/ options.maxProjectResults) .then(resourcesToLaunchTargets); @@ -88,8 +88,7 @@ function resourcesToLaunchTargets(resources: vscode.Uri[]): LaunchTarget[] { let targets: LaunchTarget[] = []; - workspaceFolderToUriMap.forEach((resources, folderIndex) => - { + workspaceFolderToUriMap.forEach((resources, folderIndex) => { let hasCsProjFiles = false, hasSlnFile = false, hasProjectJson = false, @@ -98,15 +97,15 @@ function resourcesToLaunchTargets(resources: vscode.Uri[]): LaunchTarget[] { hasCake = false; hasCsProjFiles = resources.some(isCSharpProject); - + let folder = vscode.workspace.workspaceFolders[folderIndex]; let folderPath = folder.uri.fsPath; - + resources.forEach(resource => { // Add .sln files if there are .csproj files if (hasCsProjFiles && isSolution(resource)) { hasSlnFile = true; - + targets.push({ label: path.basename(resource.fsPath), description: vscode.workspace.asRelativePath(path.dirname(resource.fsPath)), @@ -115,13 +114,13 @@ function resourcesToLaunchTargets(resources: vscode.Uri[]): LaunchTarget[] { kind: LaunchTargetKind.Solution }); } - + // Add project.json files if (isProjectJson(resource)) { const dirname = path.dirname(resource.fsPath); hasProjectJson = true; hasProjectJsonAtRoot = hasProjectJsonAtRoot || dirname === folderPath; - + targets.push({ label: path.basename(resource.fsPath), description: vscode.workspace.asRelativePath(path.dirname(resource.fsPath)), @@ -130,18 +129,18 @@ function resourcesToLaunchTargets(resources: vscode.Uri[]): LaunchTarget[] { kind: LaunchTargetKind.ProjectJson }); } - + // Discover if there is any CSX file if (!hasCSX && isCsx(resource)) { hasCSX = true; } - + // Discover if there is any Cake file if (!hasCake && isCake(resource)) { hasCake = true; } }); - + // Add the root folder under the following circumstances: // * If there are .csproj files, but no .sln file, and none in the root. // * If there are project.json files, but none in the root. @@ -154,7 +153,7 @@ function resourcesToLaunchTargets(resources: vscode.Uri[]): LaunchTarget[] { kind: LaunchTargetKind.Folder }); } - + // if we noticed any CSX file(s), add a single CSX-specific target pointing at the root folder if (hasCSX) { targets.push({ @@ -165,7 +164,7 @@ function resourcesToLaunchTargets(resources: vscode.Uri[]): LaunchTarget[] { kind: LaunchTargetKind.Csx }); } - + // if we noticed any Cake file(s), add a single Cake-specific target pointing at the root folder if (hasCake) { targets.push({ @@ -207,9 +206,9 @@ export interface LaunchResult { usingMono: boolean; } -export function launchOmniSharp(cwd: string, args: string[], experimentalLaunchPath: string): Promise { +export function launchOmniSharp(cwd: string, args: string[], launchPath: string): Promise { return new Promise((resolve, reject) => { - launch(cwd, args, experimentalLaunchPath) + launch(cwd, args, launchPath) .then(result => { // async error - when target not not ENEOT result.process.on('error', err => { @@ -229,8 +228,7 @@ function launch(cwd: string, args: string[], launchPath: string): Promise { const options = Options.Read(); - if (options.useEditorFormattingSettings) - { + if (options.useEditorFormattingSettings) { let globalConfig = vscode.workspace.getConfiguration(); let csharpConfig = vscode.workspace.getConfiguration('[csharp]'); @@ -239,7 +237,7 @@ function launch(cwd: string, args: string[], launchPath: string): Promise Date: Tue, 13 Feb 2018 11:49:52 -0800 Subject: [PATCH 16/28] Removed experimental --- src/omnisharp/OmnisharpDownloader.ts | 6 ++--- src/omnisharp/OmnisharpManager.ts | 8 +++---- src/omnisharp/OmnisharpPackageCreator.ts | 4 ++-- src/omnisharp/server.ts | 2 +- test/unitTests/OmnisharpDownloader.test.ts | 6 ++--- .../unitTests/OmnisharpPackageCreator.test.ts | 24 +++++++++---------- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/omnisharp/OmnisharpDownloader.ts b/src/omnisharp/OmnisharpDownloader.ts index 24c894796..ae7b4c916 100644 --- a/src/omnisharp/OmnisharpDownloader.ts +++ b/src/omnisharp/OmnisharpDownloader.ts @@ -11,7 +11,7 @@ import TelemetryReporter from 'vscode-extension-telemetry'; import { GetPackagesFromVersion } from './OmnisharpPackageCreator'; import { GetDependenciesAndDownloadPackages, SetStatus, GetAndLogPlatformInformation, ReportInstallationError, SendInstallationTelemetry } from '../Omnisharp.Download.Helper'; -export class ExperimentalOmnisharpDownloader { +export class OmnisharpDownloader { public constructor( private channel: vscode.OutputChannel, private logger: Logger, @@ -19,12 +19,12 @@ export class ExperimentalOmnisharpDownloader { private reporter?: TelemetryReporter) { } - public async DownloadAndInstallExperimentalVersion(version: string, serverUrl: string, installPath: string) { + public async DownloadAndInstallOmnisharp(version: string, serverUrl: string, installPath: string) { if (!version) { throw new Error('Invalid version'); } - this.logger.append('Downloading and installing the required omnisharp packages'); + this.logger.append('Downloading and installing the required omnisharp packages...'); this.logger.appendLine(); this.channel.show(); diff --git a/src/omnisharp/OmnisharpManager.ts b/src/omnisharp/OmnisharpManager.ts index 127a519c3..071343d8a 100644 --- a/src/omnisharp/OmnisharpManager.ts +++ b/src/omnisharp/OmnisharpManager.ts @@ -8,7 +8,7 @@ import * as path from 'path'; import * as semver from 'semver'; import * as vscode from 'vscode'; import { Logger } from '../logger'; -import { ExperimentalOmnisharpDownloader } from './OmnisharpDownloader'; +import { OmnisharpDownloader } from './OmnisharpDownloader'; import TelemetryReporter from 'vscode-extension-telemetry'; import { PlatformInformation } from '../platform'; @@ -29,7 +29,7 @@ export class OmnisharpManager { return omnisharpPath; } else { - throw new Error('Could not find the specified file'); + throw new Error('Invalid path specified'); } } //If the path is not a valid path on disk, treat it as a version @@ -38,8 +38,8 @@ export class OmnisharpManager { public async InstallVersionAndReturnLaunchPath(version: string, useMono: boolean, serverUrl: string, installPath: string, extensionPath: string, platformInfo: PlatformInformation) { if (semver.valid(version)) { - let downloader = new ExperimentalOmnisharpDownloader(this.channel, this.logger, this.packageJSON, this.reporter); - await downloader.DownloadAndInstallExperimentalVersion(version, serverUrl, installPath); + let downloader = new OmnisharpDownloader(this.channel, this.logger, this.packageJSON, this.reporter); + await downloader.DownloadAndInstallOmnisharp(version, serverUrl, installPath); return await GetLaunchPathForVersion(platformInfo, version, installPath, extensionPath, useMono); } diff --git a/src/omnisharp/OmnisharpPackageCreator.ts b/src/omnisharp/OmnisharpPackageCreator.ts index 06f25489b..e6783301b 100644 --- a/src/omnisharp/OmnisharpPackageCreator.ts +++ b/src/omnisharp/OmnisharpPackageCreator.ts @@ -13,14 +13,14 @@ export function GetPackagesFromVersion(version: string, runTimeDependencies: Pac let versionPackages = new Array(); for (let inputPackage of runTimeDependencies) { if (inputPackage.experimentalPackageId) { - versionPackages.push(GetExperimentPackage(inputPackage, serverUrl, version, installPath)); + versionPackages.push(GetOmnisharpPackage(inputPackage, serverUrl, version, installPath)); } } return versionPackages; } -export function GetExperimentPackage(inputPackage: Package, serverUrl: string, version: string, installPath: string): Package { +export function GetOmnisharpPackage(inputPackage: Package, serverUrl: string, version: string, installPath: string): Package { let installBinary: string; if (inputPackage.experimentalPackageId == "win-x86" || inputPackage.experimentalPackageId == "win-x64") { installBinary = "OmniSharp.exe"; diff --git a/src/omnisharp/server.ts b/src/omnisharp/server.ts index 9ccb2579c..ace0f58bd 100644 --- a/src/omnisharp/server.ts +++ b/src/omnisharp/server.ts @@ -274,7 +274,7 @@ export class OmniSharpServer { let serverUrl = "https://roslynomnisharp.blob.core.windows.net"; let installPath = ".omnisharp/experimental"; let extensionPath = utils.getExtensionPath(); - let manager = new OmnisharpManager(this._csharpChannel, this._csharpLogger, this._reporter, this._packageJSON); + let manager = new OmnisharpManager(this._csharpChannel, this._csharpLogger, this._packageJSON, this._reporter); let platformInfo = await PlatformInformation.GetCurrent(); experimentalLaunchPath = await manager.GetOmnisharpPath(this._options.path, this._options.useMono, platformInfo, serverUrl, installPath, extensionPath); } diff --git a/test/unitTests/OmnisharpDownloader.test.ts b/test/unitTests/OmnisharpDownloader.test.ts index f8aa3ecbd..b575925e6 100644 --- a/test/unitTests/OmnisharpDownloader.test.ts +++ b/test/unitTests/OmnisharpDownloader.test.ts @@ -9,7 +9,7 @@ import * as util from '../../src/common'; import { should } from 'chai'; import { Logger } from '../../src/logger'; import TelemetryReporter from 'vscode-extension-telemetry'; -import { ExperimentalOmnisharpDownloader } from '../../src/omnisharp/OmnisharpDownloader'; +import { OmnisharpDownloader } from '../../src/omnisharp/OmnisharpDownloader'; import { rimraf } from 'async-file'; import { tmpdir } from 'os'; @@ -30,7 +30,7 @@ suite("DownloadAndInstallExperimentalVersion : Gets the version packages, downlo let downloader = GetOmnisharpDownloader(); let serverUrl = "https://roslynomnisharp.blob.core.windows.net"; let installPath = ".omnisharp/experimental/"; - await downloader.DownloadAndInstallExperimentalVersion(version, serverUrl, installPath); + await downloader.DownloadAndInstallOmnisharp(version, serverUrl, installPath); let exists = await util.fileExists(path.resolve(tmpDir.name, installPath, version, `install_check_1.2.3.txt`)); exists.should.equal(true); }); @@ -47,7 +47,7 @@ suite("DownloadAndInstallExperimentalVersion : Gets the version packages, downlo function GetOmnisharpDownloader() { let channel = vscode.window.createOutputChannel('Experiment Channel'); let logger = new Logger(text => channel.append(text)); - return new ExperimentalOmnisharpDownloader(channel, logger, GetTestPackageJSON(), null); + return new OmnisharpDownloader(channel, logger, GetTestPackageJSON(), null); } //Since we need only the runtime dependencies of packageJSON for the downloader create a testPackageJSON diff --git a/test/unitTests/OmnisharpPackageCreator.test.ts b/test/unitTests/OmnisharpPackageCreator.test.ts index 7121de931..42e33a69a 100644 --- a/test/unitTests/OmnisharpPackageCreator.test.ts +++ b/test/unitTests/OmnisharpPackageCreator.test.ts @@ -6,9 +6,9 @@ import { assert, should, expect } from "chai"; import { Package } from "../../src/packages"; import { GetTestPackageJSON } from "./OmnisharpDownloader.test"; -import { GetExperimentPackage, GetPackagesFromVersion } from "../../src/omnisharp/OmnisharpPackageCreator"; +import { GetOmnisharpPackage, GetPackagesFromVersion } from "../../src/omnisharp/OmnisharpPackageCreator"; -suite("GetExperimentPackage : Output package depends on the input package and other input parameters like serverUrl", () => { +suite("GetOmnisharpPackage : Output package depends on the input package and other input parameters like serverUrl", () => { let serverUrl: string; let version: string; @@ -26,19 +26,19 @@ suite("GetExperimentPackage : Output package depends on the input package and ot test('Throws exception if version is empty', () => { let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "os-architecture")); - let fn = function () { GetExperimentPackage(testPackage, serverUrl, "", installPath); }; + let fn = function () { GetOmnisharpPackage(testPackage, serverUrl, "", installPath); }; expect(fn).to.throw('Invalid version'); }); test('Throws exception if version is null', () => { let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "os-architecture")); - let fn = function () { GetExperimentPackage(testPackage, serverUrl, null, installPath);}; + let fn = function () { GetOmnisharpPackage(testPackage, serverUrl, null, installPath);}; expect(fn).to.throw('Invalid version'); }); test('Description, architectures, binaries and platforms do not change', () => { let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "os-architecture")); - let resultPackage = GetExperimentPackage(testPackage, serverUrl, version, installPath); + let resultPackage = GetOmnisharpPackage(testPackage, serverUrl, version, installPath); resultPackage.description.should.equal(testPackage.description); resultPackage.architectures.should.equal(testPackage.architectures); @@ -48,43 +48,43 @@ suite("GetExperimentPackage : Output package depends on the input package and ot test('Download url is calculated using server url and version', () => { let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "os-architecture")); - let resultPackage = GetExperimentPackage(testPackage, "http://someurl", "1.1.1", installPath); + let resultPackage = GetOmnisharpPackage(testPackage, "http://someurl", "1.1.1", installPath); resultPackage.url.should.equal("http://someurl/releases/1.1.1/omnisharp-os-architecture.zip"); }); test('Install path is calculated using the specified path and version', () => { let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "os-architecture")); - let resultPackage = GetExperimentPackage(testPackage, serverUrl, "1.2.3", "experimentPath"); + let resultPackage = GetOmnisharpPackage(testPackage, serverUrl, "1.2.3", "experimentPath"); resultPackage.installPath.should.equal("experimentPath/1.2.3"); }); test('Install test path is calculated using specified path, version and ends with Omnisharp.exe - Windows(x86)', () => { let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "win-x86")); - let resultPackage = GetExperimentPackage(testPackage, serverUrl, "1.2.3", "experimentPath"); + let resultPackage = GetOmnisharpPackage(testPackage, serverUrl, "1.2.3", "experimentPath"); resultPackage.installTestPath.should.equal("./experimentPath/1.2.3/OmniSharp.exe"); }); test('Install test path is calculated using specified path, version and ends with Omnisharp.exe - Windows(x64)', () => { let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "win-x64")); - let resultPackage = GetExperimentPackage(testPackage, serverUrl, "1.2.3", "experimentPath"); + let resultPackage = GetOmnisharpPackage(testPackage, serverUrl, "1.2.3", "experimentPath"); resultPackage.installTestPath.should.equal("./experimentPath/1.2.3/OmniSharp.exe"); }); test('Install test path is calculated using specified path, version and ends with mono.osx - OSX', () => { let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "osx")); - let resultPackage = GetExperimentPackage(testPackage, serverUrl, "1.2.3", "experimentPath"); + let resultPackage = GetOmnisharpPackage(testPackage, serverUrl, "1.2.3", "experimentPath"); resultPackage.installTestPath.should.equal("./experimentPath/1.2.3/mono.osx"); }); test('Install test path is calculated using specified path, version and ends with mono.linux-x86 - Linux(x86)', () => { let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "linux-x86")); - let resultPackage = GetExperimentPackage(testPackage, serverUrl, "1.2.3", "experimentPath"); + let resultPackage = GetOmnisharpPackage(testPackage, serverUrl, "1.2.3", "experimentPath"); resultPackage.installTestPath.should.equal("./experimentPath/1.2.3/mono.linux-x86"); }); test('Install test path is calculated using specified path, version and ends with mono.linux-x86_64 - Linux(x64)', () => { let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "linux-x64")); - let resultPackage = GetExperimentPackage(testPackage, serverUrl, "1.2.3", "experimentPath"); + let resultPackage = GetOmnisharpPackage(testPackage, serverUrl, "1.2.3", "experimentPath"); resultPackage.installTestPath.should.equal("./experimentPath/1.2.3/mono.linux-x86_64"); }); }); From b743558e63ce5b3eb6cfe833b20e0eb273790d1c Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Tue, 13 Feb 2018 13:32:20 -0800 Subject: [PATCH 17/28] Modified tests --- src/omnisharp/OmnisharpManager.ts | 2 +- src/omnisharp/server.ts | 2 +- test/unitTests/OmnisharpManager.test.ts | 155 +++++------------------- 3 files changed, 32 insertions(+), 127 deletions(-) diff --git a/src/omnisharp/OmnisharpManager.ts b/src/omnisharp/OmnisharpManager.ts index 071343d8a..61dff1ec0 100644 --- a/src/omnisharp/OmnisharpManager.ts +++ b/src/omnisharp/OmnisharpManager.ts @@ -20,7 +20,7 @@ export class OmnisharpManager { private reporter?: TelemetryReporter) { } - public async GetOmnisharpPath(omnisharpPath: string, useMono: boolean, platformInfo: PlatformInformation, serverUrl: string, installPath: string, extensionPath: string): Promise { + public async GetOmnisharpPath(omnisharpPath: string, useMono: boolean, serverUrl: string, installPath: string, extensionPath: string, platformInfo: PlatformInformation): Promise { // Looks at the options path, installs the dependencies and returns the path to be loaded by the omnisharp server // To Do : Add the functionality for the latest option diff --git a/src/omnisharp/server.ts b/src/omnisharp/server.ts index ace0f58bd..fa4e5ea85 100644 --- a/src/omnisharp/server.ts +++ b/src/omnisharp/server.ts @@ -276,7 +276,7 @@ export class OmniSharpServer { let extensionPath = utils.getExtensionPath(); let manager = new OmnisharpManager(this._csharpChannel, this._csharpLogger, this._packageJSON, this._reporter); let platformInfo = await PlatformInformation.GetCurrent(); - experimentalLaunchPath = await manager.GetOmnisharpPath(this._options.path, this._options.useMono, platformInfo, serverUrl, installPath, extensionPath); + experimentalLaunchPath = await manager.GetOmnisharpPath(this._options.path, this._options.useMono, serverUrl, installPath, extensionPath, platformInfo); } catch (error) { this._logger.appendLine('Error occured in loading omnisharp from omnisharp.path'); diff --git a/test/unitTests/OmnisharpManager.test.ts b/test/unitTests/OmnisharpManager.test.ts index ee6b24eac..c8911be9e 100644 --- a/test/unitTests/OmnisharpManager.test.ts +++ b/test/unitTests/OmnisharpManager.test.ts @@ -24,6 +24,8 @@ suite('GetExperimentalOmnisharpPath : Returns Omnisharp experiment path dependin const platformInfo = new PlatformInformation("win32", "x86"); const serverUrl = "https://roslynomnisharp.blob.core.windows.net"; const installPath = ".omnisharp/experimental"; + const useMono = false; + const manager = GetTestOmnisharpManager(); let extensionPath: string; let tmpDir: any; let tmpFile: any; @@ -36,166 +38,69 @@ suite('GetExperimentalOmnisharpPath : Returns Omnisharp experiment path dependin util.setExtensionPath(tmpDir.name); }); - test('Returns the same path if absolute path to an existing file is passed', async () => { - tmpFile = tmp.fileSync(); - let manager = GetExperimentalOmnisharpManager(); - - let omnisharpPath = await manager.GetOmnisharpPath(tmpFile.name, false, platformInfo, serverUrl, installPath, extensionPath); - omnisharpPath.should.equal(tmpFile.name); - }); - test('Throws error if the path is neither an absolute path nor a valid semver', async () => { - let manager = GetExperimentalOmnisharpManager(); - expect(manager.GetOmnisharpPath("Some incorrect path", false, platformInfo, serverUrl, installPath, extensionPath)).to.be.rejectedWith(Error); - }); - - teardown(async () => { - if (tmpDir) { - await rimraf(tmpDir.name); - } - - if (tmpFile) { - tmpFile.removeCallback(); - } - - tmpFile = null; - tmpDir = null; - }); -}); - -suite('GetLaunchPathForVersion : Returns Omnisharp Launch Path based on the specified parameters', () => { - - let platformInfo: PlatformInformation; - let version: string; - let installPath: string; - let extensionPath: string; - let useMono: boolean; - let tmpDir: any; - - suiteSetup(() => { - platformInfo = new PlatformInformation("win32", "x86"); - version = "1.1.1"; - installPath = ".omnisharp/experimental"; - useMono = false; - let tmpDir = tmp.dirSync(); - extensionPath = tmpDir.name; - util.setExtensionPath(tmpDir.name); - should(); - }); - - test("Throws error when version is null", async () => { - expect(GetLaunchPathForVersion(platformInfo, null, installPath, extensionPath, useMono)).to.be.rejectedWith(Error); - }); - - test("Throws error when version is empty", async () => { - expect(GetLaunchPathForVersion(platformInfo, "", installPath, extensionPath, useMono)).to.be.rejectedWith(Error); - }); - - test("Returns Launch Path based on install path", async () => { - let launchPath = await GetLaunchPathForVersion(platformInfo, version, "somePath", extensionPath, useMono); - launchPath.should.equal(path.resolve(extensionPath, `somePath/1.1.1/OmniSharp.exe`)); - }); - - test("Returns Launch Path based on version", async () => { - let launchPath = await GetLaunchPathForVersion(platformInfo, "0.0.0", installPath, extensionPath, useMono); - launchPath.should.equal(path.resolve(extensionPath, `.omnisharp/experimental/0.0.0/OmniSharp.exe`)); + expect(manager.GetOmnisharpPath("Some incorrect path", useMono, serverUrl, installPath, extensionPath, platformInfo)).to.be.rejectedWith(Error); }); - test("Returns Launch Path based on platform - Windows", async () => { - let launchPath = await GetLaunchPathForVersion(platformInfo, version, installPath, extensionPath, useMono); - launchPath.should.equal(path.resolve(extensionPath, `.omnisharp/experimental/1.1.1/OmniSharp.exe`)); + test('Throws error when the specified path is null', async () => { + expect(manager.GetOmnisharpPath(null, useMono, serverUrl, installPath, extensionPath, platformInfo)).to.be.rejectedWith(Error); }); - test("Returns Launch Path based on platform - Unix with Mono", async () => { - platformInfo = new PlatformInformation("linux", "x86"); - let launchPath = await GetLaunchPathForVersion(platformInfo, version, installPath, extensionPath, true); - launchPath.should.equal(path.resolve(extensionPath, `.omnisharp/experimental/1.1.1/omnisharp/OmniSharp.exe`)); + test('Throws error when the specified path is empty', async () => { + expect(manager.GetOmnisharpPath("", useMono, serverUrl, installPath, extensionPath, platformInfo)).to.be.rejectedWith(Error); }); - test("Returns Launch Path based on platform - Unix without Mono", async () => { - platformInfo = new PlatformInformation("linux", "x86"); - let launchPath = await GetLaunchPathForVersion(platformInfo, version, installPath, extensionPath, useMono); - launchPath.should.equal(path.resolve(extensionPath, `.omnisharp/experimental/1.1.1/run`)); + test('Throws error when the specified path is an invalid semver', async () => { + expect(manager.GetOmnisharpPath("a.b.c", useMono, serverUrl, installPath, extensionPath, platformInfo)).to.be.rejectedWith(Error); }); - suiteTeardown(async () => { - if (tmpDir) { - await rimraf(tmpDir.name); - } - - tmpDir = null; - }); -}); - -suite('InstallVersionAndReturnLaunchPath : Installs the version packages and returns the launch path', () => { - let version: string; - let serverUrl: string; - let installPath: string; - let useMono: boolean; - let extensionPath: string; - let manager: OmnisharpManager; - let platformInfo: PlatformInformation; - let tmpDir = null; - - suiteSetup(() => { - version = "1.2.3"; - serverUrl = "https://roslynomnisharp.blob.core.windows.net"; - installPath = ".omnisharp/experimental/"; - useMono = false; - manager = GetExperimentalOmnisharpManager(); - platformInfo = new PlatformInformation("win32", "x86"); - should(); - }); - - setup(() => { - tmpDir = tmp.dirSync(); - util.setExtensionPath(tmpDir.name); - extensionPath = util.getExtensionPath(); - }); - - test('Throws error when version is null', async () => { - expect(manager.InstallVersionAndReturnLaunchPath(null, useMono, serverUrl, installPath, extensionPath, platformInfo)).to.be.rejectedWith(Error); - }); - - test('Throws error when version string is empty', async () => { - expect(manager.InstallVersionAndReturnLaunchPath("", useMono, serverUrl, installPath, extensionPath, platformInfo)).to.be.rejectedWith(Error); - }); - - test('Throws error when version string is invalid semver', async () => { - expect(manager.InstallVersionAndReturnLaunchPath("a.b.c", useMono, serverUrl, installPath, extensionPath, platformInfo)).to.be.rejectedWith(Error); + test('Returns the same path if absolute path to an existing file is passed', async () => { + tmpFile = tmp.fileSync(); + let omnisharpPath = await manager.GetOmnisharpPath(tmpFile.name, useMono, serverUrl, installPath, extensionPath, platformInfo); + omnisharpPath.should.equal(tmpFile.name); }); - test('Downloads package and returns launch path based on version', async () => { - let launchPath = await manager.InstallVersionAndReturnLaunchPath("1.2.4", useMono, serverUrl, installPath, extensionPath, platformInfo); - launchPath.should.equal(path.resolve(extensionPath, '.omnisharp/experimental/1.2.4/OmniSharp.exe')); + test('Installs the test version and returns the launch path based on the version and platform', async () => { + let omnisharpPath = await manager.GetOmnisharpPath("1.2.3", useMono, serverUrl, installPath, extensionPath, platformInfo); + omnisharpPath.should.equal(path.resolve(extensionPath, `.omnisharp/experimental/1.2.3/OmniSharp.exe`)); }); test('Downloads package from given url and installs them at the specified path', async () => { - let launchPath = await manager.InstallVersionAndReturnLaunchPath(version, useMono, serverUrl, installPath, extensionPath, platformInfo); + let launchPath = await manager.GetOmnisharpPath("1.2.3", useMono, serverUrl, installPath, extensionPath, platformInfo); let exists = await util.fileExists(path.resolve(extensionPath, `.omnisharp/experimental/1.2.3/install_check_1.2.3.txt`)); exists.should.equal(true); }); test('Downloads package and returns launch path based on platform - Not using mono on Linux ', async () => { - let launchPath = await manager.InstallVersionAndReturnLaunchPath(version, useMono, serverUrl, installPath, extensionPath, new PlatformInformation("linux", "x64")); + let launchPath = await manager.GetOmnisharpPath("1.2.3", useMono, serverUrl, installPath, extensionPath, new PlatformInformation("linux", "x64")); launchPath.should.equal(path.resolve(extensionPath, '.omnisharp/experimental/1.2.3/run')); }); test('Downloads package and returns launch path based on platform - Using mono on Linux ', async () => { - let launchPath = await manager.InstallVersionAndReturnLaunchPath(version, true, serverUrl, installPath, extensionPath, new PlatformInformation("linux", "x64")); + let launchPath = await manager.InstallVersionAndReturnLaunchPath("1.2.3", true, serverUrl, installPath, extensionPath, new PlatformInformation("linux", "x64")); launchPath.should.equal(path.resolve(extensionPath, '.omnisharp/experimental/1.2.3/omnisharp/OmniSharp.exe')); }); + test('Downloads package and returns launch path based on install path ', async () => { + let launchPath = await manager.InstallVersionAndReturnLaunchPath("1.2.3", true, serverUrl, "installHere", extensionPath, platformInfo); + launchPath.should.equal(path.resolve(extensionPath, 'installHere/1.2.3/OmniSharp.exe')); + }); + teardown(async () => { if (tmpDir) { await rimraf(tmpDir.name); } + if (tmpFile) { + tmpFile.removeCallback(); + } + + tmpFile = null; tmpDir = null; }); }); -function GetExperimentalOmnisharpManager() { +function GetTestOmnisharpManager() { let channel = vscode.window.createOutputChannel('Experiment Channel'); let logger = new Logger(text => channel.append(text)); return new OmnisharpManager(channel, logger, GetTestPackageJSON(), null); From 29347f9f2356d8d556da7c48e898ee63496083cd Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Tue, 13 Feb 2018 13:42:55 -0800 Subject: [PATCH 18/28] Modified package description to include version information --- src/omnisharp/OmnisharpPackageCreator.ts | 2 +- test/unitTests/OmnisharpPackageCreator.test.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/omnisharp/OmnisharpPackageCreator.ts b/src/omnisharp/OmnisharpPackageCreator.ts index e6783301b..66fe6abeb 100644 --- a/src/omnisharp/OmnisharpPackageCreator.ts +++ b/src/omnisharp/OmnisharpPackageCreator.ts @@ -44,7 +44,7 @@ function GetPackageFromArchitecture(inputPackage: Package, serverUrl: string, ve } let versionPackage = { - "description": inputPackage.description, + "description": `${inputPackage.description}, Version = ${version}`, "url": `${serverUrl}/releases/${version}/omnisharp-${architectureInfo}.zip`, "installPath": `${installPath}/${version}`, "platforms": inputPackage.platforms, diff --git a/test/unitTests/OmnisharpPackageCreator.test.ts b/test/unitTests/OmnisharpPackageCreator.test.ts index 42e33a69a..34c97403d 100644 --- a/test/unitTests/OmnisharpPackageCreator.test.ts +++ b/test/unitTests/OmnisharpPackageCreator.test.ts @@ -36,16 +36,22 @@ suite("GetOmnisharpPackage : Output package depends on the input package and oth expect(fn).to.throw('Invalid version'); }); - test('Description, architectures, binaries and platforms do not change', () => { + test('Architectures, binaries and platforms do not change', () => { let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "os-architecture")); let resultPackage = GetOmnisharpPackage(testPackage, serverUrl, version, installPath); - resultPackage.description.should.equal(testPackage.description); resultPackage.architectures.should.equal(testPackage.architectures); assert.equal(resultPackage.binaries, testPackage.binaries); resultPackage.platforms.should.equal(testPackage.platforms); }); + test('Version information is appended to the description', () => { + let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "os-architecture")); + let resultPackage = GetOmnisharpPackage(testPackage, serverUrl, "1.2.3", installPath); + + resultPackage.description.should.equal(`${testPackage.description}, Version = 1.2.3`); + }); + test('Download url is calculated using server url and version', () => { let testPackage = inputPackages.find(element => (element.experimentalPackageId && element.experimentalPackageId == "os-architecture")); let resultPackage = GetOmnisharpPackage(testPackage, "http://someurl", "1.1.1", installPath); From 7d96e6041a4831068f7679320d9c7241e3d6771b Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Tue, 13 Feb 2018 13:46:37 -0800 Subject: [PATCH 19/28] Renamed launch path --- src/omnisharp/server.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/omnisharp/server.ts b/src/omnisharp/server.ts index fa4e5ea85..5c62d14e7 100644 --- a/src/omnisharp/server.ts +++ b/src/omnisharp/server.ts @@ -268,7 +268,7 @@ export class OmniSharpServer { args.push('--debug'); } - let experimentalLaunchPath: string; + let launchPath: string; if (this._options.path) { try { let serverUrl = "https://roslynomnisharp.blob.core.windows.net"; @@ -276,7 +276,7 @@ export class OmniSharpServer { let extensionPath = utils.getExtensionPath(); let manager = new OmnisharpManager(this._csharpChannel, this._csharpLogger, this._packageJSON, this._reporter); let platformInfo = await PlatformInformation.GetCurrent(); - experimentalLaunchPath = await manager.GetOmnisharpPath(this._options.path, this._options.useMono, serverUrl, installPath, extensionPath, platformInfo); + launchPath = await manager.GetOmnisharpPath(this._options.path, this._options.useMono, serverUrl, installPath, extensionPath, platformInfo); } catch (error) { this._logger.appendLine('Error occured in loading omnisharp from omnisharp.path'); @@ -294,7 +294,7 @@ export class OmniSharpServer { this._fireEvent(Events.BeforeServerStart, solutionPath); - return launchOmniSharp(cwd, args, experimentalLaunchPath).then(value => { + return launchOmniSharp(cwd, args, launchPath).then(value => { if (value.usingMono) { this._logger.appendLine(`OmniSharp server started wth Mono`); } From fcfd5dc6f29248b4cb970f6c0139fbbaf6648282 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Tue, 13 Feb 2018 14:00:01 -0800 Subject: [PATCH 20/28] Add more tests --- ....Helper.ts => OmnisharpDownload.Helper.ts} | 0 src/omnisharp/OmnisharpDownloader.ts | 4 +-- test/unitTests/OmnisharpDownloader.test.ts | 25 ++++++++++++++----- test/unitTests/OmnisharpManager.test.ts | 1 - 4 files changed, 21 insertions(+), 9 deletions(-) rename src/{Omnisharp.Download.Helper.ts => OmnisharpDownload.Helper.ts} (100%) diff --git a/src/Omnisharp.Download.Helper.ts b/src/OmnisharpDownload.Helper.ts similarity index 100% rename from src/Omnisharp.Download.Helper.ts rename to src/OmnisharpDownload.Helper.ts diff --git a/src/omnisharp/OmnisharpDownloader.ts b/src/omnisharp/OmnisharpDownloader.ts index ae7b4c916..356aeb617 100644 --- a/src/omnisharp/OmnisharpDownloader.ts +++ b/src/omnisharp/OmnisharpDownloader.ts @@ -9,7 +9,7 @@ import { PlatformInformation } from '../platform'; import { Logger } from '../logger'; import TelemetryReporter from 'vscode-extension-telemetry'; import { GetPackagesFromVersion } from './OmnisharpPackageCreator'; -import { GetDependenciesAndDownloadPackages, SetStatus, GetAndLogPlatformInformation, ReportInstallationError, SendInstallationTelemetry } from '../Omnisharp.Download.Helper'; +import { GetDependenciesAndDownloadPackages, SetStatus, GetAndLogPlatformInformation, ReportInstallationError, SendInstallationTelemetry } from '../OmnisharpDownload.Helper'; export class OmnisharpDownloader { public constructor( @@ -24,7 +24,7 @@ export class OmnisharpDownloader { throw new Error('Invalid version'); } - this.logger.append('Downloading and installing the required omnisharp packages...'); + this.logger.append('Installing Omnisharp Packages...'); this.logger.appendLine(); this.channel.show(); diff --git a/test/unitTests/OmnisharpDownloader.test.ts b/test/unitTests/OmnisharpDownloader.test.ts index b575925e6..84678cd49 100644 --- a/test/unitTests/OmnisharpDownloader.test.ts +++ b/test/unitTests/OmnisharpDownloader.test.ts @@ -8,28 +8,41 @@ import * as path from 'path'; import * as util from '../../src/common'; import { should } from 'chai'; import { Logger } from '../../src/logger'; -import TelemetryReporter from 'vscode-extension-telemetry'; import { OmnisharpDownloader } from '../../src/omnisharp/OmnisharpDownloader'; import { rimraf } from 'async-file'; -import { tmpdir } from 'os'; const tmp = require('tmp'); +const chai = require("chai"); +chai.use(require("chai-as-promised")); +let expect = chai.expect; suite("DownloadAndInstallExperimentalVersion : Gets the version packages, downloads and installs them", () => { let tmpDir = null; + const version = "1.2.3"; + const downloader = GetOmnisharpDownloader(); + const serverUrl = "https://roslynomnisharp.blob.core.windows.net"; + const installPath = ".omnisharp/experimental/"; setup(() => { tmpDir = tmp.dirSync(); util.setExtensionPath(tmpDir.name); }); + test('Throws error if version is null', () => { + expect(downloader.DownloadAndInstallOmnisharp(null, serverUrl, installPath)).to.be.rejectedWith(Error); + }); + + test('Throws error if version is empty string', () => { + expect(downloader.DownloadAndInstallOmnisharp("", serverUrl, installPath)).to.be.rejectedWith(Error); + }); + + test('Throws error if request is made for a version that doesnot exist on the server', () => { + expect(downloader.DownloadAndInstallOmnisharp("1.00000001.0000", serverUrl, installPath)).to.be.rejectedWith(Error); + }); + test('Packages are downloaded from the specified server url and installed at the specified path', async () => { /* Download a test package that conatins a install_check_1.2.3.txt file and check whether the file appears at the expected path */ - let version = "1.2.3"; - let downloader = GetOmnisharpDownloader(); - let serverUrl = "https://roslynomnisharp.blob.core.windows.net"; - let installPath = ".omnisharp/experimental/"; await downloader.DownloadAndInstallOmnisharp(version, serverUrl, installPath); let exists = await util.fileExists(path.resolve(tmpDir.name, installPath, version, `install_check_1.2.3.txt`)); exists.should.equal(true); diff --git a/test/unitTests/OmnisharpManager.test.ts b/test/unitTests/OmnisharpManager.test.ts index c8911be9e..1593baec7 100644 --- a/test/unitTests/OmnisharpManager.test.ts +++ b/test/unitTests/OmnisharpManager.test.ts @@ -9,7 +9,6 @@ import * as util from '../../src/common'; import { should } from "chai"; import { PlatformInformation } from "../../src/platform"; import { Logger } from '../../src/logger'; -import TelemetryReporter from 'vscode-extension-telemetry'; import { rimraf } from 'async-file'; import { GetTestPackageJSON } from './OmnisharpDownloader.test'; import { GetLaunchPathForVersion, OmnisharpManager } from '../../src/omnisharp/OmnisharpManager'; From 8a3fdc29a6975ecd6f430db8a16fdd12e463f57c Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Tue, 13 Feb 2018 14:56:56 -0800 Subject: [PATCH 21/28] Changed the description in package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index be5b7e0e2..a1e69404f 100644 --- a/package.json +++ b/package.json @@ -367,7 +367,7 @@ "null" ], "default": null, - "description": "Specifies the OmniSharp to use. Can be one of \"latest\", a specific version number, or the absolute path to a local OmniSharp folder." + "description": "Specifies how to acquire the OmniSharp to use. Can be one of \"latest\", a specific version number, or the absolute path to a local OmniSharp folder." }, "omnisharp.useMono": { "type": "boolean", From b4755349e7379fce4c0412a0b64220475535a19d Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Wed, 14 Feb 2018 13:38:15 -0800 Subject: [PATCH 22/28] Getting latest version info --- src/OmnisharpDownload.Helper.ts | 10 ++----- src/omnisharp/OmnisharpDownloader.ts | 34 +++++++++++++++------- src/omnisharp/OmnisharpManager.ts | 4 +-- src/omnisharp/OmnisharpPackageCreator.ts | 11 ++++++- src/packages.ts | 15 ++++++++++ test/unitTests/OmnisharpDownloader.test.ts | 14 +++++---- test/unitTests/OmnisharpManager.test.ts | 4 +-- 7 files changed, 64 insertions(+), 28 deletions(-) diff --git a/src/OmnisharpDownload.Helper.ts b/src/OmnisharpDownload.Helper.ts index 1fcb7326e..583a937e7 100644 --- a/src/OmnisharpDownload.Helper.ts +++ b/src/OmnisharpDownload.Helper.ts @@ -8,11 +8,11 @@ import { PlatformInformation } from './platform'; import { Logger } from './logger'; import TelemetryReporter from 'vscode-extension-telemetry'; -export async function GetDependenciesAndDownloadPackages(packages: Package[], status: Status, platformInfo: PlatformInformation, packageManager: PackageManager, logger: Logger) { +export function GetNetworkDependencies() { const config = vscode.workspace.getConfiguration(); const proxy = config.get('http.proxy'); const strictSSL = config.get('http.proxyStrictSSL', true); - await packageManager.DownloadPackages(logger, status, proxy, strictSSL); + return { Proxy: proxy, StrictSSL: strictSSL }; } export function SetStatus() { @@ -31,13 +31,9 @@ export function SetStatus() { return { StatusItem: statusItem, Status: status }; } -export async function GetAndLogPlatformInformation(logger: Logger): Promise { - let platformInfo = await PlatformInformation.GetCurrent(); - +export function LogPlatformInformation(logger: Logger, platformInfo: PlatformInformation) { logger.appendLine(`Platform: ${platformInfo.toString()}`); logger.appendLine(); - - return platformInfo; } export function ReportInstallationError(logger: Logger, error, telemetryProps: any, installationStage: string) { diff --git a/src/omnisharp/OmnisharpDownloader.ts b/src/omnisharp/OmnisharpDownloader.ts index 356aeb617..0823c896b 100644 --- a/src/omnisharp/OmnisharpDownloader.ts +++ b/src/omnisharp/OmnisharpDownloader.ts @@ -8,8 +8,8 @@ import { PackageManager, Package } from '../packages'; import { PlatformInformation } from '../platform'; import { Logger } from '../logger'; import TelemetryReporter from 'vscode-extension-telemetry'; -import { GetPackagesFromVersion } from './OmnisharpPackageCreator'; -import { GetDependenciesAndDownloadPackages, SetStatus, GetAndLogPlatformInformation, ReportInstallationError, SendInstallationTelemetry } from '../OmnisharpDownload.Helper'; +import { GetPackagesFromVersion, GetVersionFilePackage } from './OmnisharpPackageCreator'; +import { SetStatus, LogPlatformInformation, ReportInstallationError, SendInstallationTelemetry, GetNetworkDependencies } from '../OmnisharpDownload.Helper'; export class OmnisharpDownloader { public constructor( @@ -19,12 +19,12 @@ export class OmnisharpDownloader { private reporter?: TelemetryReporter) { } - public async DownloadAndInstallOmnisharp(version: string, serverUrl: string, installPath: string) { + public async DownloadAndInstallOmnisharp(version: string, serverUrl: string, installPath: string, platformInfo: PlatformInformation) { if (!version) { throw new Error('Invalid version'); } - this.logger.append('Installing Omnisharp Packages...'); + this.logger.appendLine('Installing Omnisharp Packages...'); this.logger.appendLine(); this.channel.show(); @@ -32,26 +32,41 @@ export class OmnisharpDownloader { let status = statusObject.Status; let statusItem = statusObject.StatusItem; + let networkObject = GetNetworkDependencies(); + let proxy = networkObject.Proxy; + let strictSSL = networkObject.StrictSSL; + let telemetryProps: any = {}; let installationStage = ''; - let platformInfo: PlatformInformation; if (this.reporter) { this.reporter.sendTelemetryEvent("AcquisitionStart"); } try { - installationStage = 'getPlatformInfo'; - platformInfo = await GetAndLogPlatformInformation(this.logger); + LogPlatformInformation(this.logger, platformInfo); + let packageManager = new PackageManager(platformInfo, this.packageJSON); + + if (version == "latest") { + installationStage = 'getLatestVersionInfoFile'; + + this.logger.appendLine('Getting latest build information...'); + this.logger.appendLine(); + + + let filePackage = GetVersionFilePackage(serverUrl); + //Fetch the latest version information from the file + version = await packageManager.GetLatestVersionFromFile(this.logger, status, proxy, strictSSL, filePackage); + } installationStage = 'getPackageInfo'; let packages: Package[] = GetPackagesFromVersion(version, this.packageJSON.runtimeDependencies, serverUrl, installPath); installationStage = 'downloadPackages'; - let packageManager = new PackageManager(platformInfo, this.packageJSON); + // Specify the packages that the package manager needs to download packageManager.SetVersionPackagesForDownload(packages); - await GetDependenciesAndDownloadPackages(packages,status, platformInfo, packageManager, this.logger); + await packageManager.DownloadPackages(this.logger, status, proxy, strictSSL); this.logger.appendLine(); @@ -60,7 +75,6 @@ export class OmnisharpDownloader { installationStage = 'completeSuccess'; } - catch (error) { ReportInstallationError(this.logger, error, telemetryProps, installationStage); throw error;// throw the error up to the server diff --git a/src/omnisharp/OmnisharpManager.ts b/src/omnisharp/OmnisharpManager.ts index 61dff1ec0..d3b6e2a91 100644 --- a/src/omnisharp/OmnisharpManager.ts +++ b/src/omnisharp/OmnisharpManager.ts @@ -37,9 +37,9 @@ export class OmnisharpManager { } public async InstallVersionAndReturnLaunchPath(version: string, useMono: boolean, serverUrl: string, installPath: string, extensionPath: string, platformInfo: PlatformInformation) { - if (semver.valid(version)) { + if (semver.valid(version) || version == "latest") { let downloader = new OmnisharpDownloader(this.channel, this.logger, this.packageJSON, this.reporter); - await downloader.DownloadAndInstallOmnisharp(version, serverUrl, installPath); + await downloader.DownloadAndInstallOmnisharp(version, serverUrl, installPath, platformInfo); return await GetLaunchPathForVersion(platformInfo, version, installPath, extensionPath, useMono); } diff --git a/src/omnisharp/OmnisharpPackageCreator.ts b/src/omnisharp/OmnisharpPackageCreator.ts index 66fe6abeb..44df853f8 100644 --- a/src/omnisharp/OmnisharpPackageCreator.ts +++ b/src/omnisharp/OmnisharpPackageCreator.ts @@ -55,4 +55,13 @@ function GetPackageFromArchitecture(inputPackage: Package, serverUrl: string, ve }; return versionPackage; -} \ No newline at end of file +} + +export function GetVersionFilePackage(serverUrl: string): Package { + let filePackage = { + "description": "Latest version information file", + "url": `${serverUrl}/releases/versioninfo.txt` + }; + + return filePackage; +} diff --git a/src/packages.ts b/src/packages.ts index a5e15d197..c75c946d0 100644 --- a/src/packages.ts +++ b/src/packages.ts @@ -112,6 +112,21 @@ export class PackageManager { public SetVersionPackagesForDownload(packages: Package[]) { this.allPackages = packages; } + + public async GetLatestVersionFromFile(logger: Logger, status: Status, proxy: string, strictSSL: boolean, filePackage: Package): Promise { + try { + let latestVersion: string; + await maybeDownloadPackage(filePackage, logger, status, proxy, strictSSL); + if (filePackage.tmpFile) { + latestVersion = fs.readFileSync(filePackage.tmpFile.name, 'utf8'); + } + + return latestVersion; + } + catch (error) { + throw new Error(`Could not download the latest version info file due to ${error.toString()}`); + } + } } function getBaseInstallPath(pkg: Package): string { diff --git a/test/unitTests/OmnisharpDownloader.test.ts b/test/unitTests/OmnisharpDownloader.test.ts index 84678cd49..9ab6ec097 100644 --- a/test/unitTests/OmnisharpDownloader.test.ts +++ b/test/unitTests/OmnisharpDownloader.test.ts @@ -10,6 +10,7 @@ import { should } from 'chai'; import { Logger } from '../../src/logger'; import { OmnisharpDownloader } from '../../src/omnisharp/OmnisharpDownloader'; import { rimraf } from 'async-file'; +import { PlatformInformation } from '../../src/platform'; const tmp = require('tmp'); const chai = require("chai"); @@ -19,9 +20,10 @@ let expect = chai.expect; suite("DownloadAndInstallExperimentalVersion : Gets the version packages, downloads and installs them", () => { let tmpDir = null; const version = "1.2.3"; - const downloader = GetOmnisharpDownloader(); + const downloader = GetTestOmnisharpDownloader(); const serverUrl = "https://roslynomnisharp.blob.core.windows.net"; const installPath = ".omnisharp/experimental/"; + const platformInfo = new PlatformInformation("win32", "x86"); setup(() => { tmpDir = tmp.dirSync(); @@ -29,21 +31,21 @@ suite("DownloadAndInstallExperimentalVersion : Gets the version packages, downlo }); test('Throws error if version is null', () => { - expect(downloader.DownloadAndInstallOmnisharp(null, serverUrl, installPath)).to.be.rejectedWith(Error); + expect(downloader.DownloadAndInstallOmnisharp(null, serverUrl, installPath, platformInfo)).to.be.rejectedWith(Error); }); test('Throws error if version is empty string', () => { - expect(downloader.DownloadAndInstallOmnisharp("", serverUrl, installPath)).to.be.rejectedWith(Error); + expect(downloader.DownloadAndInstallOmnisharp("", serverUrl, installPath, platformInfo)).to.be.rejectedWith(Error); }); test('Throws error if request is made for a version that doesnot exist on the server', () => { - expect(downloader.DownloadAndInstallOmnisharp("1.00000001.0000", serverUrl, installPath)).to.be.rejectedWith(Error); + expect(downloader.DownloadAndInstallOmnisharp("1.00000001.0000", serverUrl, installPath, platformInfo)).to.be.rejectedWith(Error); }); test('Packages are downloaded from the specified server url and installed at the specified path', async () => { /* Download a test package that conatins a install_check_1.2.3.txt file and check whether the file appears at the expected path */ - await downloader.DownloadAndInstallOmnisharp(version, serverUrl, installPath); + await downloader.DownloadAndInstallOmnisharp(version, serverUrl, installPath, platformInfo); let exists = await util.fileExists(path.resolve(tmpDir.name, installPath, version, `install_check_1.2.3.txt`)); exists.should.equal(true); }); @@ -57,7 +59,7 @@ suite("DownloadAndInstallExperimentalVersion : Gets the version packages, downlo }); }); -function GetOmnisharpDownloader() { +function GetTestOmnisharpDownloader() { let channel = vscode.window.createOutputChannel('Experiment Channel'); let logger = new Logger(text => channel.append(text)); return new OmnisharpDownloader(channel, logger, GetTestPackageJSON(), null); diff --git a/test/unitTests/OmnisharpManager.test.ts b/test/unitTests/OmnisharpManager.test.ts index 1593baec7..849f6ceda 100644 --- a/test/unitTests/OmnisharpManager.test.ts +++ b/test/unitTests/OmnisharpManager.test.ts @@ -76,12 +76,12 @@ suite('GetExperimentalOmnisharpPath : Returns Omnisharp experiment path dependin }); test('Downloads package and returns launch path based on platform - Using mono on Linux ', async () => { - let launchPath = await manager.InstallVersionAndReturnLaunchPath("1.2.3", true, serverUrl, installPath, extensionPath, new PlatformInformation("linux", "x64")); + let launchPath = await manager.GetOmnisharpPath("1.2.3", true, serverUrl, installPath, extensionPath, new PlatformInformation("linux", "x64")); launchPath.should.equal(path.resolve(extensionPath, '.omnisharp/experimental/1.2.3/omnisharp/OmniSharp.exe')); }); test('Downloads package and returns launch path based on install path ', async () => { - let launchPath = await manager.InstallVersionAndReturnLaunchPath("1.2.3", true, serverUrl, "installHere", extensionPath, platformInfo); + let launchPath = await manager.GetOmnisharpPath("1.2.3", true, serverUrl, "installHere", extensionPath, platformInfo); launchPath.should.equal(path.resolve(extensionPath, 'installHere/1.2.3/OmniSharp.exe')); }); From abed66727ff68049780fca99ca6c63bed2f75b77 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Wed, 14 Feb 2018 15:43:27 -0800 Subject: [PATCH 23/28] Refactored code and added tests --- package.json | 2 +- src/omnisharp/OmnisharpDownloader.ts | 75 +++++++++++-------- src/omnisharp/OmnisharpManager.ts | 28 ++++--- src/omnisharp/OmnisharpPackageCreator.ts | 4 +- src/omnisharp/server.ts | 3 +- src/packages.ts | 4 +- test/unitTests/OmnisharpDownloader.test.ts | 11 ++- test/unitTests/OmnisharpManager.test.ts | 26 ++++--- .../unitTests/OmnisharpPackageCreator.test.ts | 14 +++- 9 files changed, 103 insertions(+), 64 deletions(-) diff --git a/package.json b/package.json index a1e69404f..f04ec3b54 100644 --- a/package.json +++ b/package.json @@ -367,7 +367,7 @@ "null" ], "default": null, - "description": "Specifies how to acquire the OmniSharp to use. Can be one of \"latest\", a specific version number, or the absolute path to a local OmniSharp folder." + "description": "Specifies the path to OmniSharp. This can be the absolute path to an OmniSharp executable, a specific version number, or \"latest\". If a version number or \"latest\" is specified, the appropriate version of OmniSharp will be downloaded on your behalf." }, "omnisharp.useMono": { "type": "boolean", diff --git a/src/omnisharp/OmnisharpDownloader.ts b/src/omnisharp/OmnisharpDownloader.ts index 0823c896b..6a39d3768 100644 --- a/src/omnisharp/OmnisharpDownloader.ts +++ b/src/omnisharp/OmnisharpDownloader.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as vscode from 'vscode'; -import { PackageManager, Package } from '../packages'; +import { PackageManager, Package, Status } from '../packages'; import { PlatformInformation } from '../platform'; import { Logger } from '../logger'; import TelemetryReporter from 'vscode-extension-telemetry'; @@ -12,14 +12,33 @@ import { GetPackagesFromVersion, GetVersionFilePackage } from './OmnisharpPackag import { SetStatus, LogPlatformInformation, ReportInstallationError, SendInstallationTelemetry, GetNetworkDependencies } from '../OmnisharpDownload.Helper'; export class OmnisharpDownloader { + private status: Status; + private statusItem: vscode.StatusBarItem; + private proxy: string; + private strictSSL: boolean; + private packageManager: PackageManager; + private telemetryProps: any; + public constructor( private channel: vscode.OutputChannel, private logger: Logger, private packageJSON: any, + private platformInfo: PlatformInformation, private reporter?: TelemetryReporter) { + + let statusObject = SetStatus(); + this.status = statusObject.Status; + this.statusItem = statusObject.StatusItem; + + let networkObject = GetNetworkDependencies(); + this.proxy = networkObject.Proxy; + this.strictSSL = networkObject.StrictSSL; + + this.telemetryProps = {}; + this.packageManager = new PackageManager(this.platformInfo, this.packageJSON); } - public async DownloadAndInstallOmnisharp(version: string, serverUrl: string, installPath: string, platformInfo: PlatformInformation) { + public async DownloadAndInstallOmnisharp(version: string, serverUrl: string, installPath: string) { if (!version) { throw new Error('Invalid version'); } @@ -28,15 +47,6 @@ export class OmnisharpDownloader { this.logger.appendLine(); this.channel.show(); - let statusObject = SetStatus(); - let status = statusObject.Status; - let statusItem = statusObject.StatusItem; - - let networkObject = GetNetworkDependencies(); - let proxy = networkObject.Proxy; - let strictSSL = networkObject.StrictSSL; - - let telemetryProps: any = {}; let installationStage = ''; if (this.reporter) { @@ -44,43 +54,46 @@ export class OmnisharpDownloader { } try { - LogPlatformInformation(this.logger, platformInfo); - let packageManager = new PackageManager(platformInfo, this.packageJSON); - - if (version == "latest") { - installationStage = 'getLatestVersionInfoFile'; - - this.logger.appendLine('Getting latest build information...'); - this.logger.appendLine(); - - - let filePackage = GetVersionFilePackage(serverUrl); - //Fetch the latest version information from the file - version = await packageManager.GetLatestVersionFromFile(this.logger, status, proxy, strictSSL, filePackage); - } + LogPlatformInformation(this.logger, this.platformInfo); installationStage = 'getPackageInfo'; let packages: Package[] = GetPackagesFromVersion(version, this.packageJSON.runtimeDependencies, serverUrl, installPath); installationStage = 'downloadPackages'; - + // Specify the packages that the package manager needs to download - packageManager.SetVersionPackagesForDownload(packages); - await packageManager.DownloadPackages(this.logger, status, proxy, strictSSL); + this.packageManager.SetVersionPackagesForDownload(packages); + await this.packageManager.DownloadPackages(this.logger, this.status, this.proxy, this.strictSSL); this.logger.appendLine(); installationStage = 'installPackages'; - await packageManager.InstallPackages(this.logger, status); + await this.packageManager.InstallPackages(this.logger, this.status); installationStage = 'completeSuccess'; } catch (error) { - ReportInstallationError(this.logger, error, telemetryProps, installationStage); + ReportInstallationError(this.logger, error, this.telemetryProps, installationStage); throw error;// throw the error up to the server } finally { - SendInstallationTelemetry(this.logger, this.reporter, telemetryProps, installationStage, platformInfo, statusItem); + SendInstallationTelemetry(this.logger, this.reporter, this.telemetryProps, installationStage, this.platformInfo, this.statusItem); + } + } + + public async GetLatestVersion(serverUrl: string, versionFilePathInServer): Promise { + let installationStage = 'getLatestVersionInfoFile'; + try { + this.logger.appendLine('Getting latest build information...'); + this.logger.appendLine(); + + let filePackage = GetVersionFilePackage(serverUrl, versionFilePathInServer); + //Fetch the latest version information from the file + return await this.packageManager.GetLatestVersionFromFile(this.logger, this.status, this.proxy, this.strictSSL, filePackage); + } + catch (error) { + ReportInstallationError(this.logger, error, this.telemetryProps, installationStage); + throw error; } } } diff --git a/src/omnisharp/OmnisharpManager.ts b/src/omnisharp/OmnisharpManager.ts index d3b6e2a91..4055b8137 100644 --- a/src/omnisharp/OmnisharpManager.ts +++ b/src/omnisharp/OmnisharpManager.ts @@ -20,10 +20,9 @@ export class OmnisharpManager { private reporter?: TelemetryReporter) { } - public async GetOmnisharpPath(omnisharpPath: string, useMono: boolean, serverUrl: string, installPath: string, extensionPath: string, platformInfo: PlatformInformation): Promise { + public async GetOmnisharpPath(omnisharpPath: string, useMono: boolean, serverUrl: string, versionFilePathInServer: string, installPath: string, extensionPath: string, platformInfo: PlatformInformation): Promise { // Looks at the options path, installs the dependencies and returns the path to be loaded by the omnisharp server - // To Do : Add the functionality for the latest option - + let downloader = new OmnisharpDownloader(this.channel, this.logger, this.packageJSON, platformInfo, this.reporter); if (path.isAbsolute(omnisharpPath)) { if (await util.fileExists(omnisharpPath)) { return omnisharpPath; @@ -32,16 +31,23 @@ export class OmnisharpManager { throw new Error('Invalid path specified'); } } - //If the path is not a valid path on disk, treat it as a version - return await this.InstallVersionAndReturnLaunchPath(omnisharpPath, useMono, serverUrl, installPath, extensionPath, platformInfo); + else if (omnisharpPath == "latest") { + return await this.LatestInstallAndReturnLaunchPath(downloader, useMono, serverUrl, versionFilePathInServer, installPath, extensionPath, platformInfo); + } + //If the path is neither a valid path on disk not the string "latest", treat it as a version + return await this.InstallVersionAndReturnLaunchPath(downloader, omnisharpPath, useMono, serverUrl, installPath, extensionPath, platformInfo); } - public async InstallVersionAndReturnLaunchPath(version: string, useMono: boolean, serverUrl: string, installPath: string, extensionPath: string, platformInfo: PlatformInformation) { - if (semver.valid(version) || version == "latest") { - let downloader = new OmnisharpDownloader(this.channel, this.logger, this.packageJSON, this.reporter); - await downloader.DownloadAndInstallOmnisharp(version, serverUrl, installPath, platformInfo); + public async LatestInstallAndReturnLaunchPath(downloader: OmnisharpDownloader, useMono: boolean, serverUrl: string, versionFilePathInServer: string, installPath: string, extensionPath: string, platformInfo: PlatformInformation) { + let version = await downloader.GetLatestVersion(serverUrl, versionFilePathInServer); + await downloader.DownloadAndInstallOmnisharp(version, serverUrl, installPath); + return GetLaunchPathForVersion(platformInfo, version, installPath, extensionPath, useMono); + } - return await GetLaunchPathForVersion(platformInfo, version, installPath, extensionPath, useMono); + public async InstallVersionAndReturnLaunchPath(downloader: OmnisharpDownloader, version: string, useMono: boolean, serverUrl: string, installPath: string, extensionPath: string, platformInfo: PlatformInformation) { + if (semver.valid(version)) { + await downloader.DownloadAndInstallOmnisharp(version, serverUrl, installPath); + return GetLaunchPathForVersion(platformInfo, version, installPath, extensionPath, useMono); } else { throw new Error('Invalid omnisharp version specified'); @@ -49,7 +55,7 @@ export class OmnisharpManager { } } -export async function GetLaunchPathForVersion(platformInfo: PlatformInformation, version: string, installPath: string, extensionPath: string, useMono: boolean) { +export function GetLaunchPathForVersion(platformInfo: PlatformInformation, version: string, installPath: string, extensionPath: string, useMono: boolean) { if (!version) { throw new Error('Invalid Version'); } diff --git a/src/omnisharp/OmnisharpPackageCreator.ts b/src/omnisharp/OmnisharpPackageCreator.ts index 44df853f8..dc866e2e5 100644 --- a/src/omnisharp/OmnisharpPackageCreator.ts +++ b/src/omnisharp/OmnisharpPackageCreator.ts @@ -57,10 +57,10 @@ function GetPackageFromArchitecture(inputPackage: Package, serverUrl: string, ve return versionPackage; } -export function GetVersionFilePackage(serverUrl: string): Package { +export function GetVersionFilePackage(serverUrl: string, pathInServer: string): Package { let filePackage = { "description": "Latest version information file", - "url": `${serverUrl}/releases/versioninfo.txt` + "url": `${serverUrl}/${pathInServer}` }; return filePackage; diff --git a/src/omnisharp/server.ts b/src/omnisharp/server.ts index 5c62d14e7..bd1a269e6 100644 --- a/src/omnisharp/server.ts +++ b/src/omnisharp/server.ts @@ -274,9 +274,10 @@ export class OmniSharpServer { let serverUrl = "https://roslynomnisharp.blob.core.windows.net"; let installPath = ".omnisharp/experimental"; let extensionPath = utils.getExtensionPath(); + let versionFilePathInServer = 'releases/versioninfo.txt'; let manager = new OmnisharpManager(this._csharpChannel, this._csharpLogger, this._packageJSON, this._reporter); let platformInfo = await PlatformInformation.GetCurrent(); - launchPath = await manager.GetOmnisharpPath(this._options.path, this._options.useMono, serverUrl, installPath, extensionPath, platformInfo); + launchPath = await manager.GetOmnisharpPath(this._options.path, this._options.useMono, serverUrl, versionFilePathInServer,installPath, extensionPath, platformInfo); } catch (error) { this._logger.appendLine('Error occured in loading omnisharp from omnisharp.path'); diff --git a/src/packages.ts b/src/packages.ts index c75c946d0..8a76fe107 100644 --- a/src/packages.ts +++ b/src/packages.ts @@ -119,12 +119,14 @@ export class PackageManager { await maybeDownloadPackage(filePackage, logger, status, proxy, strictSSL); if (filePackage.tmpFile) { latestVersion = fs.readFileSync(filePackage.tmpFile.name, 'utf8'); + //Delete the temporary file created + filePackage.tmpFile.removeCallback(); } return latestVersion; } catch (error) { - throw new Error(`Could not download the latest version info file due to ${error.toString()}`); + throw new Error(`Could not download the latest version file due to ${error.toString()}`); } } } diff --git a/test/unitTests/OmnisharpDownloader.test.ts b/test/unitTests/OmnisharpDownloader.test.ts index 9ab6ec097..1709be753 100644 --- a/test/unitTests/OmnisharpDownloader.test.ts +++ b/test/unitTests/OmnisharpDownloader.test.ts @@ -23,7 +23,6 @@ suite("DownloadAndInstallExperimentalVersion : Gets the version packages, downlo const downloader = GetTestOmnisharpDownloader(); const serverUrl = "https://roslynomnisharp.blob.core.windows.net"; const installPath = ".omnisharp/experimental/"; - const platformInfo = new PlatformInformation("win32", "x86"); setup(() => { tmpDir = tmp.dirSync(); @@ -31,21 +30,21 @@ suite("DownloadAndInstallExperimentalVersion : Gets the version packages, downlo }); test('Throws error if version is null', () => { - expect(downloader.DownloadAndInstallOmnisharp(null, serverUrl, installPath, platformInfo)).to.be.rejectedWith(Error); + expect(downloader.DownloadAndInstallOmnisharp(null, serverUrl, installPath)).to.be.rejectedWith(Error); }); test('Throws error if version is empty string', () => { - expect(downloader.DownloadAndInstallOmnisharp("", serverUrl, installPath, platformInfo)).to.be.rejectedWith(Error); + expect(downloader.DownloadAndInstallOmnisharp("", serverUrl, installPath)).to.be.rejectedWith(Error); }); test('Throws error if request is made for a version that doesnot exist on the server', () => { - expect(downloader.DownloadAndInstallOmnisharp("1.00000001.0000", serverUrl, installPath, platformInfo)).to.be.rejectedWith(Error); + expect(downloader.DownloadAndInstallOmnisharp("1.00000001.0000", serverUrl, installPath)).to.be.rejectedWith(Error); }); test('Packages are downloaded from the specified server url and installed at the specified path', async () => { /* Download a test package that conatins a install_check_1.2.3.txt file and check whether the file appears at the expected path */ - await downloader.DownloadAndInstallOmnisharp(version, serverUrl, installPath, platformInfo); + await downloader.DownloadAndInstallOmnisharp(version, serverUrl, installPath); let exists = await util.fileExists(path.resolve(tmpDir.name, installPath, version, `install_check_1.2.3.txt`)); exists.should.equal(true); }); @@ -62,7 +61,7 @@ suite("DownloadAndInstallExperimentalVersion : Gets the version packages, downlo function GetTestOmnisharpDownloader() { let channel = vscode.window.createOutputChannel('Experiment Channel'); let logger = new Logger(text => channel.append(text)); - return new OmnisharpDownloader(channel, logger, GetTestPackageJSON(), null); + return new OmnisharpDownloader(channel, logger, GetTestPackageJSON(), new PlatformInformation("win32", "x86"), null); } //Since we need only the runtime dependencies of packageJSON for the downloader create a testPackageJSON diff --git a/test/unitTests/OmnisharpManager.test.ts b/test/unitTests/OmnisharpManager.test.ts index 849f6ceda..b0329d393 100644 --- a/test/unitTests/OmnisharpManager.test.ts +++ b/test/unitTests/OmnisharpManager.test.ts @@ -23,6 +23,7 @@ suite('GetExperimentalOmnisharpPath : Returns Omnisharp experiment path dependin const platformInfo = new PlatformInformation("win32", "x86"); const serverUrl = "https://roslynomnisharp.blob.core.windows.net"; const installPath = ".omnisharp/experimental"; + const versionFilepathInServer = "testVersionInfo.txt"; const useMono = false; const manager = GetTestOmnisharpManager(); let extensionPath: string; @@ -38,50 +39,55 @@ suite('GetExperimentalOmnisharpPath : Returns Omnisharp experiment path dependin }); test('Throws error if the path is neither an absolute path nor a valid semver', async () => { - expect(manager.GetOmnisharpPath("Some incorrect path", useMono, serverUrl, installPath, extensionPath, platformInfo)).to.be.rejectedWith(Error); + expect(manager.GetOmnisharpPath("Some incorrect path", useMono, serverUrl, versionFilepathInServer, installPath, extensionPath, platformInfo)).to.be.rejectedWith(Error); }); test('Throws error when the specified path is null', async () => { - expect(manager.GetOmnisharpPath(null, useMono, serverUrl, installPath, extensionPath, platformInfo)).to.be.rejectedWith(Error); + expect(manager.GetOmnisharpPath(null, useMono, serverUrl, versionFilepathInServer, installPath, extensionPath, platformInfo)).to.be.rejectedWith(Error); }); test('Throws error when the specified path is empty', async () => { - expect(manager.GetOmnisharpPath("", useMono, serverUrl, installPath, extensionPath, platformInfo)).to.be.rejectedWith(Error); + expect(manager.GetOmnisharpPath("", useMono, serverUrl, versionFilepathInServer, installPath, extensionPath, platformInfo)).to.be.rejectedWith(Error); }); test('Throws error when the specified path is an invalid semver', async () => { - expect(manager.GetOmnisharpPath("a.b.c", useMono, serverUrl, installPath, extensionPath, platformInfo)).to.be.rejectedWith(Error); + expect(manager.GetOmnisharpPath("a.b.c", useMono, serverUrl, versionFilepathInServer, installPath, extensionPath, platformInfo)).to.be.rejectedWith(Error); }); test('Returns the same path if absolute path to an existing file is passed', async () => { tmpFile = tmp.fileSync(); - let omnisharpPath = await manager.GetOmnisharpPath(tmpFile.name, useMono, serverUrl, installPath, extensionPath, platformInfo); + let omnisharpPath = await manager.GetOmnisharpPath(tmpFile.name, useMono, serverUrl, versionFilepathInServer, installPath, extensionPath, platformInfo); omnisharpPath.should.equal(tmpFile.name); }); + test('Installs the latest version and returns the launch path based on the version and platform', async () => { + let omnisharpPath = await manager.GetOmnisharpPath("latest", useMono, serverUrl, versionFilepathInServer, installPath, extensionPath, platformInfo); + omnisharpPath.should.equal(path.resolve(extensionPath, `.omnisharp/experimental/1.2.3/OmniSharp.exe`)); + }); + test('Installs the test version and returns the launch path based on the version and platform', async () => { - let omnisharpPath = await manager.GetOmnisharpPath("1.2.3", useMono, serverUrl, installPath, extensionPath, platformInfo); + let omnisharpPath = await manager.GetOmnisharpPath("1.2.3", useMono, serverUrl, versionFilepathInServer, installPath, extensionPath, platformInfo); omnisharpPath.should.equal(path.resolve(extensionPath, `.omnisharp/experimental/1.2.3/OmniSharp.exe`)); }); test('Downloads package from given url and installs them at the specified path', async () => { - let launchPath = await manager.GetOmnisharpPath("1.2.3", useMono, serverUrl, installPath, extensionPath, platformInfo); + let launchPath = await manager.GetOmnisharpPath("1.2.3", useMono, serverUrl, versionFilepathInServer, installPath, extensionPath, platformInfo); let exists = await util.fileExists(path.resolve(extensionPath, `.omnisharp/experimental/1.2.3/install_check_1.2.3.txt`)); exists.should.equal(true); }); test('Downloads package and returns launch path based on platform - Not using mono on Linux ', async () => { - let launchPath = await manager.GetOmnisharpPath("1.2.3", useMono, serverUrl, installPath, extensionPath, new PlatformInformation("linux", "x64")); + let launchPath = await manager.GetOmnisharpPath("1.2.3", useMono, serverUrl, versionFilepathInServer, installPath, extensionPath, new PlatformInformation("linux", "x64")); launchPath.should.equal(path.resolve(extensionPath, '.omnisharp/experimental/1.2.3/run')); }); test('Downloads package and returns launch path based on platform - Using mono on Linux ', async () => { - let launchPath = await manager.GetOmnisharpPath("1.2.3", true, serverUrl, installPath, extensionPath, new PlatformInformation("linux", "x64")); + let launchPath = await manager.GetOmnisharpPath("1.2.3", true, serverUrl, versionFilepathInServer, installPath, extensionPath, new PlatformInformation("linux", "x64")); launchPath.should.equal(path.resolve(extensionPath, '.omnisharp/experimental/1.2.3/omnisharp/OmniSharp.exe')); }); test('Downloads package and returns launch path based on install path ', async () => { - let launchPath = await manager.GetOmnisharpPath("1.2.3", true, serverUrl, "installHere", extensionPath, platformInfo); + let launchPath = await manager.GetOmnisharpPath("1.2.3", true, serverUrl, versionFilepathInServer, "installHere", extensionPath, platformInfo); launchPath.should.equal(path.resolve(extensionPath, 'installHere/1.2.3/OmniSharp.exe')); }); diff --git a/test/unitTests/OmnisharpPackageCreator.test.ts b/test/unitTests/OmnisharpPackageCreator.test.ts index 34c97403d..b06f56990 100644 --- a/test/unitTests/OmnisharpPackageCreator.test.ts +++ b/test/unitTests/OmnisharpPackageCreator.test.ts @@ -6,7 +6,7 @@ import { assert, should, expect } from "chai"; import { Package } from "../../src/packages"; import { GetTestPackageJSON } from "./OmnisharpDownloader.test"; -import { GetOmnisharpPackage, GetPackagesFromVersion } from "../../src/omnisharp/OmnisharpPackageCreator"; +import { GetOmnisharpPackage, GetPackagesFromVersion, GetVersionFilePackage } from "../../src/omnisharp/OmnisharpPackageCreator"; suite("GetOmnisharpPackage : Output package depends on the input package and other input parameters like serverUrl", () => { @@ -194,4 +194,16 @@ suite('GetPackagesFromVersion : Gets the experimental omnisharp packages from a outPackages.length.should.equal(1); outPackages[0].experimentalPackageId.should.equal("win-x64"); }); +}); + +suite('GetVersionFilePackage : Gives the package for the latest file download', () => { + test('Contains the expected description', () => { + let testPackage = GetVersionFilePackage("someUrl", "somePath"); + expect(testPackage.description).to.equal('Latest version information file'); + }); + + test('Contains the url based on serverUrl and the pathInServer', () => { + let testPackage = GetVersionFilePackage("someUrl", "somePath"); + expect(testPackage.url).to.equal('someUrl/somePath'); + }); }); \ No newline at end of file From 36512eeecf57406dea571966aad2849a675ce0cd Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Wed, 14 Feb 2018 16:22:29 -0800 Subject: [PATCH 24/28] Remove unnecessary using --- src/OmnisharpDownload.Helper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OmnisharpDownload.Helper.ts b/src/OmnisharpDownload.Helper.ts index 583a937e7..9cb911f82 100644 --- a/src/OmnisharpDownload.Helper.ts +++ b/src/OmnisharpDownload.Helper.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import * as vscode from 'vscode'; -import { PackageManager, Status, PackageError, Package } from './packages'; +import { Status, PackageError } from './packages'; import { PlatformInformation } from './platform'; import { Logger } from './logger'; import TelemetryReporter from 'vscode-extension-telemetry'; From 9f5528538e8f999c66bc6c59a345a0f80de9be2d Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Thu, 15 Feb 2018 09:48:54 -0800 Subject: [PATCH 25/28] CR comments --- src/omnisharp/OmnisharpDownloader.ts | 2 +- src/omnisharp/OmnisharpManager.ts | 3 ++- src/omnisharp/OmnisharpPackageCreator.ts | 4 +--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/omnisharp/OmnisharpDownloader.ts b/src/omnisharp/OmnisharpDownloader.ts index 6a39d3768..abb223833 100644 --- a/src/omnisharp/OmnisharpDownloader.ts +++ b/src/omnisharp/OmnisharpDownloader.ts @@ -86,7 +86,7 @@ export class OmnisharpDownloader { try { this.logger.appendLine('Getting latest build information...'); this.logger.appendLine(); - + //The package manager needs a package format to download, hence we form a package for the latest version file let filePackage = GetVersionFilePackage(serverUrl, versionFilePathInServer); //Fetch the latest version information from the file return await this.packageManager.GetLatestVersionFromFile(this.logger, this.status, this.proxy, this.strictSSL, filePackage); diff --git a/src/omnisharp/OmnisharpManager.ts b/src/omnisharp/OmnisharpManager.ts index 4055b8137..d4e9d4d0c 100644 --- a/src/omnisharp/OmnisharpManager.ts +++ b/src/omnisharp/OmnisharpManager.ts @@ -28,12 +28,13 @@ export class OmnisharpManager { return omnisharpPath; } else { - throw new Error('Invalid path specified'); + throw new Error('The system could not find the specified path'); } } else if (omnisharpPath == "latest") { return await this.LatestInstallAndReturnLaunchPath(downloader, useMono, serverUrl, versionFilePathInServer, installPath, extensionPath, platformInfo); } + //If the path is neither a valid path on disk not the string "latest", treat it as a version return await this.InstallVersionAndReturnLaunchPath(downloader, omnisharpPath, useMono, serverUrl, installPath, extensionPath, platformInfo); } diff --git a/src/omnisharp/OmnisharpPackageCreator.ts b/src/omnisharp/OmnisharpPackageCreator.ts index dc866e2e5..a645311da 100644 --- a/src/omnisharp/OmnisharpPackageCreator.ts +++ b/src/omnisharp/OmnisharpPackageCreator.ts @@ -58,10 +58,8 @@ function GetPackageFromArchitecture(inputPackage: Package, serverUrl: string, ve } export function GetVersionFilePackage(serverUrl: string, pathInServer: string): Package { - let filePackage = { + return { "description": "Latest version information file", "url": `${serverUrl}/${pathInServer}` }; - - return filePackage; } From a8602ca31e7be4dba20a2f0b0af0114b9ca87973 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Thu, 15 Feb 2018 11:16:40 -0800 Subject: [PATCH 26/28] Use common function for latest download --- src/omnisharp/OmnisharpManager.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/omnisharp/OmnisharpManager.ts b/src/omnisharp/OmnisharpManager.ts index d4e9d4d0c..3ef632564 100644 --- a/src/omnisharp/OmnisharpManager.ts +++ b/src/omnisharp/OmnisharpManager.ts @@ -41,8 +41,7 @@ export class OmnisharpManager { public async LatestInstallAndReturnLaunchPath(downloader: OmnisharpDownloader, useMono: boolean, serverUrl: string, versionFilePathInServer: string, installPath: string, extensionPath: string, platformInfo: PlatformInformation) { let version = await downloader.GetLatestVersion(serverUrl, versionFilePathInServer); - await downloader.DownloadAndInstallOmnisharp(version, serverUrl, installPath); - return GetLaunchPathForVersion(platformInfo, version, installPath, extensionPath, useMono); + return await this.InstallVersionAndReturnLaunchPath(downloader, version, useMono, serverUrl, installPath, extensionPath, platformInfo); } public async InstallVersionAndReturnLaunchPath(downloader: OmnisharpDownloader, version: string, useMono: boolean, serverUrl: string, installPath: string, extensionPath: string, platformInfo: PlatformInformation) { From 71ffd3d419a50efb791f2e60fdb3a75d74bf9cff Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Fri, 23 Feb 2018 14:40:01 -0800 Subject: [PATCH 27/28] Add new line --- src/OmnisharpDownload.Helper.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OmnisharpDownload.Helper.ts b/src/OmnisharpDownload.Helper.ts index 9cb911f82..3281d38d5 100644 --- a/src/OmnisharpDownload.Helper.ts +++ b/src/OmnisharpDownload.Helper.ts @@ -56,6 +56,7 @@ export function ReportInstallationError(logger: Logger, error, telemetryProps: a errorMessage = error.toString(); } + logger.appendLine(); logger.appendLine(`Failed at stage: ${installationStage}`); logger.appendLine(errorMessage); } From 97b9b03e4872e294ec68fbe0a6f1978bfa458bc1 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Fri, 23 Feb 2018 14:42:41 -0800 Subject: [PATCH 28/28] Resolve binaries on linux --- src/packages.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/packages.ts b/src/packages.ts index 8a76fe107..64a2ebbd2 100644 --- a/src/packages.ts +++ b/src/packages.ts @@ -78,11 +78,7 @@ export class PackageManager { this.allPackages = this.packageJSON.runtimeDependencies; // Convert relative binary paths to absolute - for (let pkg of this.allPackages) { - if (pkg.binaries) { - pkg.binaries = pkg.binaries.map(value => path.resolve(getBaseInstallPath(pkg), value)); - } - } + resolvePackageBinaries(this.allPackages); resolve(this.allPackages); } @@ -111,6 +107,7 @@ export class PackageManager { public SetVersionPackagesForDownload(packages: Package[]) { this.allPackages = packages; + resolvePackageBinaries(this.allPackages); } public async GetLatestVersionFromFile(logger: Logger, status: Status, proxy: string, strictSSL: boolean, filePackage: Package): Promise { @@ -131,6 +128,15 @@ export class PackageManager { } } +function resolvePackageBinaries(packages: Package[]) { + // Convert relative binary paths to absolute + for (let pkg of packages) { + if (pkg.binaries) { + pkg.binaries = pkg.binaries.map(value => path.resolve(getBaseInstallPath(pkg), value)); + } + } +} + function getBaseInstallPath(pkg: Package): string { let basePath = util.getExtensionPath(); if (pkg.installPath) {