Remove OperatingSystem enum in favor of PlatformInformation helpers

This commit is contained in:
Dustin Campbell 2016-11-02 11:26:37 -07:00
Родитель b202b76438
Коммит 94bde368d0
5 изменённых файлов: 22 добавлений и 25 удалений

Просмотреть файл

@ -13,7 +13,7 @@ import * as OmniSharp from './omnisharp/extension';
import * as util from './common';
import { Logger } from './logger';
import { PackageManager, Status } from './packages';
import { PlatformInformation, OperatingSystem } from './platform';
import { PlatformInformation } from './platform';
export function activate(context: vscode.ExtensionContext): any {
@ -110,7 +110,7 @@ function installRuntimeDependencies(extension: vscode.Extension<any>): Promise<v
function allowExecution(filePath: string, platformInfo: PlatformInformation, logger: Logger): Promise<void> {
return new Promise<void>((resolve, reject) => {
if (platformInfo.operatingSystem !== OperatingSystem.Windows) {
if (!platformInfo.isWindows()) {
util.fileExists(filePath)
.then(exists => {
if (exists) {

Просмотреть файл

@ -5,9 +5,9 @@
'use strict';
import {spawn, ChildProcess} from 'child_process';
import {satisfies} from 'semver';
import {PlatformInformation, OperatingSystem} from '../platform';
import { spawn, ChildProcess } from 'child_process';
import { satisfies } from 'semver';
import { PlatformInformation } from '../platform';
import * as path from 'path';
import * as vscode from 'vscode';
import * as util from '../common';
@ -165,7 +165,7 @@ function launch(cwd: string, args: string[], kind: LaunchTargetKind): Promise<La
const launchPath = options.path || getLaunchPath(platformInfo, kind);
if (platformInfo.operatingSystem === OperatingSystem.Windows) {
if (platformInfo.isWindows()) {
return launchWindows(launchPath, cwd, args);
}
else {
@ -176,7 +176,7 @@ function launch(cwd: string, args: string[], kind: LaunchTargetKind): Promise<La
function getLaunchPath(platformInfo: PlatformInformation, kind: LaunchTargetKind): string {
if (kind === LaunchTargetKind.Solution) {
if (platformInfo.operatingSystem === OperatingSystem.Windows) {
if (platformInfo.isWindows()) {
return path.join(util.getExtensionPath(), '.omnisharp-desktop', 'OmniSharp.exe');
}
@ -184,7 +184,7 @@ function getLaunchPath(platformInfo: PlatformInformation, kind: LaunchTargetKind
}
let basePath = path.join(util.getExtensionPath(), '.omnisharp-coreclr');
if (platformInfo.operatingSystem === OperatingSystem.Windows) {
if (platformInfo.isWindows()) {
return path.join(basePath, 'OmniSharp.exe');
}
else {

Просмотреть файл

@ -15,7 +15,7 @@ import {Options} from './options';
import {Logger} from '../logger';
import {DelayTracker} from './delayTracker';
import {LaunchTarget, findLaunchTargets} from './launcher';
import {PlatformInformation, OperatingSystem} from '../platform';
import {PlatformInformation} from '../platform';
import TelemetryReporter from 'vscode-extension-telemetry';
import * as vscode from 'vscode';

Просмотреть файл

@ -87,7 +87,6 @@ export enum OperatingSystem {
}
export class PlatformInformation {
public operatingSystem: OperatingSystem;
public runtimeId: string;
public constructor(
@ -95,20 +94,6 @@ export class PlatformInformation {
public architecture: string,
public distribution: LinuxDistribution = null)
{
switch (platform) {
case 'win32':
this.operatingSystem = OperatingSystem.Windows;
break;
case 'darwin':
this.operatingSystem = OperatingSystem.MacOS;
break;
case 'linux':
this.operatingSystem = OperatingSystem.Linux;
break;
}
try {
this.runtimeId = PlatformInformation.getRuntimeId(platform, architecture, distribution);
}
@ -117,6 +102,18 @@ export class PlatformInformation {
}
}
public isWindows(): boolean {
return this.platform === 'win32';
}
public isMacOS(): boolean {
return this.platform === 'darwin';
}
public isLinux(): boolean {
return this.platform === 'linux';
}
public toString(): string {
let result = this.platform;

Просмотреть файл

@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { should } from 'chai';
import { LinuxDistribution, PlatformInformation, OperatingSystem } from '../src/platform';
import { LinuxDistribution, PlatformInformation } from '../src/platform';
suite("Platform", () => {
before(() => should());