Skip to content

Commit

Permalink
Merge pull request #2065 from OmniSharp/experiment_download
Browse files Browse the repository at this point in the history
Enable multiple download of omnisharp
  • Loading branch information
akshita31 authored Feb 27, 2018
2 parents e2a191f + 5c78308 commit 0342385
Show file tree
Hide file tree
Showing 15 changed files with 969 additions and 75 deletions.
62 changes: 44 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 13 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"chai": "4.1.2",
"chai-arrays": "2.0.0",
"chai-fs": "2.0.0",
"chai-as-promised": "7.1.1",
"cross-env": "5.1.1",
"del": "3.0.0",
"gulp": "3.9.1",
Expand Down Expand Up @@ -93,7 +94,8 @@
"architectures": [
"x86"
],
"installTestPath": "./.omnisharp/OmniSharp.exe"
"installTestPath": "./.omnisharp/OmniSharp.exe",
"platformId": "win-x86"
},
{
"description": "OmniSharp for Windows (.NET 4.6 / x64)",
Expand All @@ -106,7 +108,8 @@
"architectures": [
"x86_64"
],
"installTestPath": "./.omnisharp/OmniSharp.exe"
"installTestPath": "./.omnisharp/OmniSharp.exe",
"platformId": "win-x64"
},
{
"description": "OmniSharp for OSX",
Expand All @@ -120,7 +123,8 @@
"./mono.osx",
"./run"
],
"installTestPath": "./.omnisharp/mono.osx"
"installTestPath": "./.omnisharp/mono.osx",
"platformId": "osx"
},
{
"description": "OmniSharp for Linux (x86)",
Expand All @@ -138,7 +142,8 @@
"./mono.linux-x86",
"./run"
],
"installTestPath": "./.omnisharp/mono.linux-x86"
"installTestPath": "./.omnisharp/mono.linux-x86",
"platformId": "linux-x86"
},
{
"description": "OmniSharp for Linux (x64)",
Expand All @@ -155,7 +160,8 @@
"./mono.linux-x86_64",
"./run"
],
"installTestPath": "./.omnisharp/mono.linux-x86_64"
"installTestPath": "./.omnisharp/mono.linux-x86_64",
"platformId": "linux-x64"
},
{
"description": ".NET Core Debugger (Windows / x64)",
Expand Down Expand Up @@ -454,7 +460,7 @@
"null"
],
"default": null,
"description": "Specifies the full path to the OmniSharp server."
"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",
Expand Down Expand Up @@ -2590,4 +2596,4 @@
}
]
}
}
}
74 changes: 74 additions & 0 deletions src/OmnisharpDownload.Helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*---------------------------------------------------------------------------------------------
* 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, PackageError } from './packages';
import { PlatformInformation } from './platform';
import { Logger } from './logger';
import TelemetryReporter from 'vscode-extension-telemetry';

export function GetNetworkDependencies() {
const config = vscode.workspace.getConfiguration();
const proxy = config.get<string>('http.proxy');
const strictSSL = config.get('http.proxyStrictSSL', true);
return { Proxy: proxy, StrictSSL: strictSSL };
}

export function SetStatus() {
let statusItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right);
let status: Status = {
setMessage: text => {
statusItem.text = text;
statusItem.show();
},
setDetail: text => {
statusItem.tooltip = text;
statusItem.show();
}
};

return { StatusItem: statusItem, Status: status };
}

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
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();
logger.appendLine(`Failed at stage: ${installationStage}`);
logger.appendLine(errorMessage);
}

export function SendInstallationTelemetry(logger: Logger, reporter: TelemetryReporter, telemetryProps: any, installationStage: string, platformInfo: PlatformInformation) {
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');
logger.appendLine();
}
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
97 changes: 97 additions & 0 deletions src/omnisharp/OmnisharpDownloader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*---------------------------------------------------------------------------------------------
* 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 { PackageManager, Package, Status } from '../packages';
import { PlatformInformation } from '../platform';
import { Logger } from '../logger';
import TelemetryReporter from 'vscode-extension-telemetry';
import { GetPackagesFromVersion, GetVersionFilePackage } from './OmnisharpPackageCreator';
import { SetStatus, 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) {
this.logger.append('Installing Omnisharp Packages...');
this.logger.appendLine();
this.channel.show();

let installationStage = '';

if (this.reporter) {
this.reporter.sendTelemetryEvent("AcquisitionStart");
}

try {
this.logger.appendLine(`Platform: ${this.platformInfo.toString()}`);
this.logger.appendLine();

installationStage = 'getPackageInfo';
let packages: Package[] = GetPackagesFromVersion(version, this.packageJSON.runtimeDependencies, serverUrl, installPath);

installationStage = 'downloadPackages';

// Specify the packages that the package manager needs to download
this.packageManager.SetVersionPackagesForDownload(packages);
await this.packageManager.DownloadPackages(this.logger, this.status, this.proxy, this.strictSSL);

this.logger.appendLine();

installationStage = 'installPackages';
await this.packageManager.InstallPackages(this.logger, this.status);

installationStage = 'completeSuccess';
}
catch (error) {
ReportInstallationError(this.logger, error, this.telemetryProps, installationStage);
throw error;// throw the error up to the server
}
finally {
SendInstallationTelemetry(this.logger, this.reporter, this.telemetryProps, installationStage, this.platformInfo);
this.statusItem.dispose();
}
}

public async GetLatestVersion(serverUrl: string, latestVersionFileServerPath: string): Promise<string> {
let installationStage = 'getLatestVersionInfoFile';
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, latestVersionFileServerPath);
//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;
}
}
}
Loading

0 comments on commit 0342385

Please sign in to comment.