-
Notifications
You must be signed in to change notification settings - Fork 677
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2065 from OmniSharp/experiment_download
Enable multiple download of omnisharp
- Loading branch information
Showing
15 changed files
with
969 additions
and
75 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
Oops, something went wrong.