Skip to content

Commit

Permalink
Added support for more platforms (#400)
Browse files Browse the repository at this point in the history
* Added support for more platforms
  • Loading branch information
llali authored Nov 23, 2016
1 parent f1dcce6 commit 3ac8451
Show file tree
Hide file tree
Showing 12 changed files with 439 additions and 151 deletions.
18 changes: 9 additions & 9 deletions src/configurations/dev.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"downloadUrl": "https://github.com/Microsoft/sqltoolsservice/releases/download/v{#version#}/microsoft.sqltools.servicelayer-{#fileName#}",
"version": "0.1.4",
"downloadFileNames": {
"Windows": "win-x64-netcoreapp1.0.zip",
"OSX": "osx-x64-netcoreapp1.0.tar.gz",
"CentOS": "centos-x64-netcoreapp1.0.tar.gz",
"Debian": "debian-x64-netcoreapp1.0.tar.gz",
"Fedora": "fedora-x64-netcoreapp1.0.tar.gz",
"OpenSUSE": "opensuse-x64-netcoreapp1.0.tar.gz",
"RHEL": "rhel-x64-netcoreapp1.0.tar.gz",
"Ubuntu14": "ubuntu14-x64-netcoreapp1.0.tar.gz",
"Ubuntu16": "ubuntu16-x64-netcoreapp1.0.tar.gz"
"Windows_7_64": "win-x64-netcoreapp1.0.zip",
"OSX_10_11_64": "osx-x64-netcoreapp1.0.tar.gz",
"CentOS_7": "centos-x64-netcoreapp1.0.tar.gz",
"Debian_8": "debian-x64-netcoreapp1.0.tar.gz",
"Fedora_23": "fedora-x64-netcoreapp1.0.tar.gz",
"OpenSUSE_13_2": "opensuse-x64-netcoreapp1.0.tar.gz",
"RHEL_7": "rhel-x64-netcoreapp1.0.tar.gz",
"Ubuntu_14": "ubuntu14-x64-netcoreapp1.0.tar.gz",
"Ubuntu_16": "ubuntu16-x64-netcoreapp1.0.tar.gz"
},
"installDir": "../sqltoolsservice/{#version#}/{#platform#}",
"executableFiles": ["Microsoft.SqlTools.ServiceLayer.exe", "Microsoft.SqlTools.ServiceLayer", "Microsoft.SqlTools.ServiceLayer.dll"]
Expand Down
18 changes: 9 additions & 9 deletions src/configurations/production.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"downloadUrl": "https://github.com/Microsoft/sqltoolsservice/releases/download/v{#version#}/microsoft.sqltools.servicelayer-{#fileName#}",
"version": "0.1.4",
"downloadFileNames": {
"Windows": "win-x64-netcoreapp1.0.zip",
"OSX": "osx-x64-netcoreapp1.0.tar.gz",
"CentOS": "centos-x64-netcoreapp1.0.tar.gz",
"Debian": "debian-x64-netcoreapp1.0.tar.gz",
"Fedora": "fedora-x64-netcoreapp1.0.tar.gz",
"OpenSUSE": "opensuse-x64-netcoreapp1.0.tar.gz",
"RHEL": "rhel-x64-netcoreapp1.0.tar.gz",
"Ubuntu14": "ubuntu14-x64-netcoreapp1.0.tar.gz",
"Ubuntu16": "ubuntu16-x64-netcoreapp1.0.tar.gz"
"Windows_7_64": "win-x64-netcoreapp1.0.zip",
"OSX_10_11_64": "osx-x64-netcoreapp1.0.tar.gz",
"CentOS_7": "centos-x64-netcoreapp1.0.tar.gz",
"Debian_8": "debian-x64-netcoreapp1.0.tar.gz",
"Fedora_23": "fedora-x64-netcoreapp1.0.tar.gz",
"OpenSUSE_13_2": "opensuse-x64-netcoreapp1.0.tar.gz",
"RHEL_7": "rhel-x64-netcoreapp1.0.tar.gz",
"Ubuntu_14": "ubuntu14-x64-netcoreapp1.0.tar.gz",
"Ubuntu_16": "ubuntu16-x64-netcoreapp1.0.tar.gz"
},
"installDir": "../sqltoolsservice/{#version#}/{#platform#}",
"executableFiles": ["Microsoft.SqlTools.ServiceLayer.exe", "Microsoft.SqlTools.ServiceLayer", "Microsoft.SqlTools.ServiceLayer.dll"]
Expand Down
27 changes: 15 additions & 12 deletions src/controllers/connectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { IPrompter } from '../prompts/question';
import Telemetry from '../models/telemetry';
import VscodeWrapper from './vscodeWrapper';
import {NotificationHandler} from 'vscode-languageclient';
import {Platform, getCurrentPlatform} from '../models/platform';
import {Runtime, PlatformInformation} from '../models/platform';

let opener = require('opener');

Expand Down Expand Up @@ -289,17 +289,20 @@ export default class ConnectionManager {
Utils.showErrorMsg(Utils.formatString(Constants.msgConnectionError, result.errorNumber, result.errorMessage));
}
} else {
let platform: Platform = getCurrentPlatform();
if (platform === Platform.OSX && result.messages.indexOf('Unable to load DLL \'System.Security.Cryptography.Native\'') !== -1) {
this.vscodeWrapper.showErrorMessage(Utils.formatString(Constants.msgConnectionError2,
Constants.macOpenSslErrorMessage), Constants.macOpenSslHelpButton).then(action => {
if (action && action === Constants.macOpenSslHelpButton) {
opener(Constants.macOpenSslHelpLink);
}
});
} else {
Utils.showErrorMsg(Utils.formatString(Constants.msgConnectionError2, result.messages));
}
PlatformInformation.GetCurrent().then( platformInfo => {
if (platformInfo.runtimeId === Runtime.OSX_10_11_64 &&
result.messages.indexOf('Unable to load DLL \'System.Security.Cryptography.Native\'') !== -1) {
this.vscodeWrapper.showErrorMessage(Utils.formatString(Constants.msgConnectionError2,
Constants.macOpenSslErrorMessage), Constants.macOpenSslHelpButton).then(action => {
if (action && action === Constants.macOpenSslHelpButton) {
opener(Constants.macOpenSslHelpLink);
}
});
} else {
Utils.showErrorMsg(Utils.formatString(Constants.msgConnectionError2, result.messages));
}
});

}
this.statusView.connectError(fileUri, connection.credentials, result);
this.vscodeWrapper.logToOutputChannel(
Expand Down
17 changes: 6 additions & 11 deletions src/languageservice/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as https from 'https';
import * as http from 'http';
import * as stream from 'stream';
import {parse} from 'url';
import {Platform, getCurrentPlatform} from '../models/platform';
import {Runtime, getRuntimeDisplayName} from '../models/platform';
import {getProxyAgent} from './proxy';
import * as path from 'path';
import {IConfig, ILogger} from './interfaces';
Expand All @@ -33,7 +33,7 @@ export default class ServiceDownloadProvider {
/**
* Returns the download url for given platfotm
*/
public getDownloadFileName(platform: Platform): string {
public getDownloadFileName(platform: Runtime): string {
let fileNamesJson = this._config.getSqlToolsConfigValue('downloadFileNames');
let fileName = fileNamesJson[platform.toString()];

Expand Down Expand Up @@ -98,14 +98,12 @@ export default class ServiceDownloadProvider {
/**
* Returns SQL tools service installed folder.
*/
public getInstallDirectory(platform?: Platform): string {
if (platform === undefined) {
platform = getCurrentPlatform();
}
public getInstallDirectory(platform: Runtime): string {

let basePath = this.getInstallDirectoryRoot();
let versionFromConfig = this._config.getSqlToolsPackageVersion();
basePath = basePath.replace('{#version#}', versionFromConfig);
basePath = basePath.replace('{#platform#}', platform.toString());
basePath = basePath.replace('{#platform#}', getRuntimeDisplayName(platform));
fse.mkdirsSync(basePath);
return basePath;
}
Expand Down Expand Up @@ -136,12 +134,9 @@ export default class ServiceDownloadProvider {
/**
* Downloads the SQL tools service and decompress it in the install folder.
*/
public go(platform?: Platform): Promise<boolean> {
public go(platform: Runtime): Promise<boolean> {
const proxy = <string>this._config.getWorkspaceConfig('http.proxy');
const strictSSL = this._config.getWorkspaceConfig('http.proxyStrictSSL', true);
if (platform === undefined) {
platform = getCurrentPlatform();
}

return new Promise<boolean>((resolve, reject) => {
const fileName = this.getDownloadFileName( platform);
Expand Down
26 changes: 17 additions & 9 deletions src/languageservice/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

import * as path from 'path';
import {Platform, getCurrentPlatform} from '../models/platform';
import {Runtime, PlatformInformation} from '../models/platform';
import ServiceDownloadProvider from './download';
import {IConfig, IStatusView, IExtensionWrapper} from './interfaces';
let fs = require('fs-extra-promise');
Expand Down Expand Up @@ -54,20 +54,28 @@ export default class ServerProvider {
/**
* Download the SQL tools service if doesn't exist and returns the file path.
*/
public getServerPath(platform: Platform): Promise<string> {
public getServerPath(runtime?: Runtime): Promise<string> {

if (platform === undefined) {
platform = getCurrentPlatform();
if (runtime === undefined) {
return PlatformInformation.GetCurrent().then( currentPlatform => {
return this.getServerPathForPlatform(currentPlatform.runtimeId);
});
} else {
return this.getServerPathForPlatform(runtime);
}

}

private getServerPathForPlatform(runtime: Runtime): Promise<string> {
// Attempt to find launch file path first from options, and then from the default install location.
// If SQL tools service can't be found, download it.

const installDirectory = this._downloadProvider.getInstallDirectory(platform);
const installDirectory = this._downloadProvider.getInstallDirectory(runtime);

return new Promise<string>((resolve, reject) => {
return this.findServerPath(installDirectory).then(result => {
if (result === undefined) {
return this.downloadServerFiles(platform).then ( downloadResult => {
return this.downloadServerFiles(runtime).then ( downloadResult => {
resolve(downloadResult);
});
} else {
Expand All @@ -81,11 +89,11 @@ export default class ServerProvider {
});
}

private downloadServerFiles(platform: Platform): Promise<string> {
const installDirectory = this._downloadProvider.getInstallDirectory(platform);
private downloadServerFiles(runtime: Runtime): Promise<string> {
const installDirectory = this._downloadProvider.getInstallDirectory(runtime);
let currentFileUrl = this._vsCodeExtention.getActiveTextEditorUri();
this._statusView.installingService(currentFileUrl);
return this._downloadProvider.go(platform).then( _ => {
return this._downloadProvider.go(runtime).then( _ => {
return this.findServerPath(installDirectory).then ( result => {
this._statusView.serviceInstalled(currentFileUrl);
return result;
Expand Down
6 changes: 3 additions & 3 deletions src/languageservice/serviceInstallerUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import {Platform} from '../models/platform';
import * as Platform from '../models/platform';
import Config from '../configurations/config';
import ServiceDownloadProvider from './download';
import ServerProvider from './server';
Expand Down Expand Up @@ -41,7 +41,7 @@ const stubVsCode = new StubVsCode();
/*
* Installs the service for the given platform if it's not already installed.
*/
export function installService(platform: Platform): Promise<String> {
export function installService(platform: Platform.Runtime): Promise<String> {
let downloadProvider = new ServiceDownloadProvider(config, logger);
let serverProvider = new ServerProvider(downloadProvider, config, statusView, stubVsCode);
return serverProvider.getServerPath(platform);
Expand All @@ -50,7 +50,7 @@ export function installService(platform: Platform): Promise<String> {
/*
* Returns the install folder path for given platform.
*/
export function getServiceInstallDirectory(platform: Platform): string {
export function getServiceInstallDirectory(platform: Platform.Runtime): string {
let downloadProvider = new ServiceDownloadProvider(config, logger);
return downloadProvider.getInstallDirectory(platform);
}
Expand Down
16 changes: 11 additions & 5 deletions src/languageservice/serviceclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import ServiceDownloadProvider from './download';
import {ExtensionWrapper, Logger} from './extUtil';
import ExtConfig from '../configurations/extConfig';
import StatusView from '../views/statusView';
import {Platform, getCurrentPlatform} from '../models/platform';
import {Runtime, PlatformInformation} from '../models/platform';

// The Service Client class handles communication with the VS Code LanguageClient
export default class SqlToolsServiceClient {
Expand Down Expand Up @@ -55,12 +55,18 @@ export default class SqlToolsServiceClient {
// initialize the SQL Tools Service Client instance by launching
// out-of-proc server through the LanguageClient
public initialize(context: ExtensionContext): Promise<boolean> {
return new Promise<boolean>( (resolve, reject) => {
const platform = getCurrentPlatform();
if (platform === Platform.Unknown) {
return PlatformInformation.GetCurrent().then( platformInfo => {
if (platformInfo.runtimeId === Runtime.UnknownRuntime) {
throw new Error('Invalid Platform');
} else {
return this.initializeService(platformInfo.runtimeId, context);
}
this._server.getServerPath(platform).then(serverPath => {
});
}

private initializeService(runtime: Runtime, context: ExtensionContext): Promise<boolean> {
return new Promise<boolean>( (resolve, reject) => {
this._server.getServerPath(runtime).then(serverPath => {
let serverArgs = [];
let serverCommand = serverPath;
if (serverPath === undefined) {
Expand Down
Loading

0 comments on commit 3ac8451

Please sign in to comment.