mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Initial VS Code 1.19 source merge (#571)
* Initial 1.19 xcopy * Fix yarn build * Fix numerous build breaks * Next batch of build break fixes * More build break fixes * Runtime breaks * Additional post merge fixes * Fix windows setup file * Fix test failures. * Update license header blocks to refer to source eula
This commit is contained in:
@@ -8,13 +8,14 @@ import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { distinct, coalesce } from 'vs/base/common/arrays';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { IExtensionManagementService, DidUninstallExtensionEvent, IExtensionEnablementService, IExtensionIdentifier } from 'vs/platform/extensionManagement/common/extensionManagement';
|
||||
import { adoptToGalleryExtensionId, getIdAndVersionFromLocalExtensionId, areSameExtensions } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
|
||||
import { IExtensionManagementService, DidUninstallExtensionEvent, IExtensionEnablementService, IExtensionIdentifier, EnablementState } from 'vs/platform/extensionManagement/common/extensionManagement';
|
||||
import { adoptToGalleryExtensionId, getIdFromLocalExtensionId, areSameExtensions } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
|
||||
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
|
||||
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
|
||||
const DISABLED_EXTENSIONS_STORAGE_PATH = 'extensionsIdentifiers/disabled';
|
||||
const ENABLED_EXTENSIONS_STORAGE_PATH = 'extensionsIdentifiers/enabled';
|
||||
|
||||
export class ExtensionEnablementService implements IExtensionEnablementService {
|
||||
|
||||
@@ -29,110 +30,221 @@ export class ExtensionEnablementService implements IExtensionEnablementService {
|
||||
@IStorageService private storageService: IStorageService,
|
||||
@IWorkspaceContextService private contextService: IWorkspaceContextService,
|
||||
@IEnvironmentService private environmentService: IEnvironmentService,
|
||||
@IExtensionManagementService private extensionManagementService: IExtensionManagementService
|
||||
@IExtensionManagementService extensionManagementService: IExtensionManagementService
|
||||
) {
|
||||
extensionManagementService.onDidUninstallExtension(this.onDidUninstallExtension, this, this.disposables);
|
||||
extensionManagementService.onDidUninstallExtension(this._onDidUninstallExtension, this, this.disposables);
|
||||
}
|
||||
|
||||
private get hasWorkspace(): boolean {
|
||||
return this.contextService.getWorkbenchState() !== WorkbenchState.EMPTY;
|
||||
}
|
||||
|
||||
getGloballyDisabledExtensions(): IExtensionIdentifier[] {
|
||||
return this.getDisabledExtensions(StorageScope.GLOBAL);
|
||||
getDisabledExtensions(): TPromise<IExtensionIdentifier[]> {
|
||||
|
||||
let result = this._getDisabledExtensions(StorageScope.GLOBAL);
|
||||
|
||||
if (this.hasWorkspace) {
|
||||
for (const e of this._getDisabledExtensions(StorageScope.WORKSPACE)) {
|
||||
if (!result.some(r => areSameExtensions(r, e))) {
|
||||
result.push(e);
|
||||
}
|
||||
}
|
||||
const workspaceEnabledExtensions = this._getEnabledExtensions(StorageScope.WORKSPACE);
|
||||
if (workspaceEnabledExtensions.length) {
|
||||
result = result.filter(r => !workspaceEnabledExtensions.some(e => areSameExtensions(e, r)));
|
||||
}
|
||||
}
|
||||
|
||||
return TPromise.as(result);
|
||||
}
|
||||
|
||||
getWorkspaceDisabledExtensions(): IExtensionIdentifier[] {
|
||||
return this.getDisabledExtensions(StorageScope.WORKSPACE);
|
||||
}
|
||||
|
||||
canEnable(identifier: IExtensionIdentifier): boolean {
|
||||
getEnablementState(identifier: IExtensionIdentifier): EnablementState {
|
||||
if (this.environmentService.disableExtensions) {
|
||||
return false;
|
||||
return EnablementState.Disabled;
|
||||
}
|
||||
if (this.getGloballyDisabledExtensions().some(d => areSameExtensions(d, identifier))) {
|
||||
return true;
|
||||
if (this.hasWorkspace) {
|
||||
if (this._getEnabledExtensions(StorageScope.WORKSPACE).filter(e => areSameExtensions(e, identifier))[0]) {
|
||||
return EnablementState.WorkspaceEnabled;
|
||||
}
|
||||
|
||||
if (this._getDisabledExtensions(StorageScope.WORKSPACE).filter(e => areSameExtensions(e, identifier))[0]) {
|
||||
return EnablementState.WorkspaceDisabled;
|
||||
}
|
||||
}
|
||||
if (this.getWorkspaceDisabledExtensions().some(d => areSameExtensions(d, identifier))) {
|
||||
return true;
|
||||
if (this._getDisabledExtensions(StorageScope.GLOBAL).filter(e => areSameExtensions(e, identifier))[0]) {
|
||||
return EnablementState.Disabled;
|
||||
}
|
||||
return false;
|
||||
return EnablementState.Enabled;
|
||||
}
|
||||
|
||||
setEnablement(identifier: IExtensionIdentifier, enable: boolean, workspace: boolean = false): TPromise<boolean> {
|
||||
if (workspace && !this.hasWorkspace) {
|
||||
return TPromise.wrapError<boolean>(new Error(localize('noWorkspace', "No workspace.")));
|
||||
}
|
||||
canChangeEnablement(): boolean {
|
||||
return !this.environmentService.disableExtensions;
|
||||
}
|
||||
|
||||
setEnablement(identifier: IExtensionIdentifier, newState: EnablementState): TPromise<boolean> {
|
||||
if (this.environmentService.disableExtensions) {
|
||||
return TPromise.wrap(false);
|
||||
}
|
||||
|
||||
if (enable) {
|
||||
if (workspace) {
|
||||
return this.enableExtension(identifier, StorageScope.WORKSPACE);
|
||||
} else {
|
||||
return this.enableExtension(identifier, StorageScope.GLOBAL);
|
||||
}
|
||||
} else {
|
||||
if (workspace) {
|
||||
return this.disableExtension(identifier, StorageScope.WORKSPACE);
|
||||
} else {
|
||||
return this.disableExtension(identifier, StorageScope.GLOBAL);
|
||||
}
|
||||
const workspace = newState === EnablementState.WorkspaceDisabled || newState === EnablementState.WorkspaceEnabled;
|
||||
if (workspace && !this.hasWorkspace) {
|
||||
return TPromise.wrapError<boolean>(new Error(localize('noWorkspace', "No workspace.")));
|
||||
}
|
||||
|
||||
const currentState = this.getEnablementState(identifier);
|
||||
|
||||
if (currentState === newState) {
|
||||
return TPromise.as(false);
|
||||
}
|
||||
|
||||
|
||||
switch (newState) {
|
||||
case EnablementState.Enabled:
|
||||
this._enableExtension(identifier);
|
||||
break;
|
||||
case EnablementState.Disabled:
|
||||
this._disableExtension(identifier);
|
||||
break;
|
||||
case EnablementState.WorkspaceEnabled:
|
||||
this._enableExtensionInWorkspace(identifier);
|
||||
break;
|
||||
case EnablementState.WorkspaceDisabled:
|
||||
this._disableExtensionInWorkspace(identifier);
|
||||
break;
|
||||
}
|
||||
|
||||
this._onEnablementChanged.fire(identifier);
|
||||
return TPromise.as(true);
|
||||
}
|
||||
|
||||
isEnabled(identifier: IExtensionIdentifier): boolean {
|
||||
const enablementState = this.getEnablementState(identifier);
|
||||
return enablementState === EnablementState.WorkspaceEnabled || enablementState === EnablementState.Enabled;
|
||||
}
|
||||
|
||||
migrateToIdentifiers(installed: IExtensionIdentifier[]): void {
|
||||
this.migrateDisabledExtensions(installed, StorageScope.GLOBAL);
|
||||
this._migrateDisabledExtensions(installed, StorageScope.GLOBAL);
|
||||
if (this.hasWorkspace) {
|
||||
this.migrateDisabledExtensions(installed, StorageScope.WORKSPACE);
|
||||
this._migrateDisabledExtensions(installed, StorageScope.WORKSPACE);
|
||||
}
|
||||
}
|
||||
|
||||
private disableExtension(identifier: IExtensionIdentifier, scope: StorageScope): TPromise<boolean> {
|
||||
let disabledExtensions = this.getDisabledExtensions(scope);
|
||||
private _enableExtension(identifier: IExtensionIdentifier): void {
|
||||
this._removeFromDisabledExtensions(identifier, StorageScope.WORKSPACE);
|
||||
this._removeFromEnabledExtensions(identifier, StorageScope.WORKSPACE);
|
||||
this._removeFromDisabledExtensions(identifier, StorageScope.GLOBAL);
|
||||
}
|
||||
|
||||
private _disableExtension(identifier: IExtensionIdentifier): void {
|
||||
this._removeFromDisabledExtensions(identifier, StorageScope.WORKSPACE);
|
||||
this._removeFromEnabledExtensions(identifier, StorageScope.WORKSPACE);
|
||||
this._addToDisabledExtensions(identifier, StorageScope.GLOBAL);
|
||||
}
|
||||
|
||||
private _enableExtensionInWorkspace(identifier: IExtensionIdentifier): void {
|
||||
this._removeFromDisabledExtensions(identifier, StorageScope.WORKSPACE);
|
||||
this._addToEnabledExtensions(identifier, StorageScope.WORKSPACE);
|
||||
}
|
||||
|
||||
private _disableExtensionInWorkspace(identifier: IExtensionIdentifier): void {
|
||||
this._addToDisabledExtensions(identifier, StorageScope.WORKSPACE);
|
||||
this._removeFromEnabledExtensions(identifier, StorageScope.WORKSPACE);
|
||||
}
|
||||
|
||||
private _addToDisabledExtensions(identifier: IExtensionIdentifier, scope: StorageScope): TPromise<boolean> {
|
||||
if (scope === StorageScope.WORKSPACE && !this.hasWorkspace) {
|
||||
return TPromise.wrap(false);
|
||||
}
|
||||
let disabledExtensions = this._getDisabledExtensions(scope);
|
||||
if (disabledExtensions.every(e => !areSameExtensions(e, identifier))) {
|
||||
disabledExtensions.push(identifier);
|
||||
this.setDisabledExtensions(disabledExtensions, scope, identifier);
|
||||
this._setDisabledExtensions(disabledExtensions, scope, identifier);
|
||||
return TPromise.wrap(true);
|
||||
}
|
||||
return TPromise.wrap(false);
|
||||
}
|
||||
|
||||
private enableExtension(identifier: IExtensionIdentifier, scope: StorageScope, fireEvent = true): TPromise<boolean> {
|
||||
let disabledExtensions = this.getDisabledExtensions(scope);
|
||||
private _removeFromDisabledExtensions(identifier: IExtensionIdentifier, scope: StorageScope): boolean {
|
||||
if (scope === StorageScope.WORKSPACE && !this.hasWorkspace) {
|
||||
return false;
|
||||
}
|
||||
let disabledExtensions = this._getDisabledExtensions(scope);
|
||||
for (let index = 0; index < disabledExtensions.length; index++) {
|
||||
const disabledExtension = disabledExtensions[index];
|
||||
if (areSameExtensions(disabledExtension, identifier)) {
|
||||
disabledExtensions.splice(index, 1);
|
||||
this.setDisabledExtensions(disabledExtensions, scope, identifier, fireEvent);
|
||||
return TPromise.wrap(true);
|
||||
this._setDisabledExtensions(disabledExtensions, scope, identifier);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return TPromise.wrap(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
private getDisabledExtensions(scope: StorageScope): IExtensionIdentifier[] {
|
||||
private _addToEnabledExtensions(identifier: IExtensionIdentifier, scope: StorageScope): boolean {
|
||||
if (scope === StorageScope.WORKSPACE && !this.hasWorkspace) {
|
||||
return false;
|
||||
}
|
||||
let enabledExtensions = this._getEnabledExtensions(scope);
|
||||
if (enabledExtensions.every(e => !areSameExtensions(e, identifier))) {
|
||||
enabledExtensions.push(identifier);
|
||||
this._setEnabledExtensions(enabledExtensions, scope, identifier);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private _removeFromEnabledExtensions(identifier: IExtensionIdentifier, scope: StorageScope): boolean {
|
||||
if (scope === StorageScope.WORKSPACE && !this.hasWorkspace) {
|
||||
return false;
|
||||
}
|
||||
let enabledExtensions = this._getEnabledExtensions(scope);
|
||||
for (let index = 0; index < enabledExtensions.length; index++) {
|
||||
const disabledExtension = enabledExtensions[index];
|
||||
if (areSameExtensions(disabledExtension, identifier)) {
|
||||
enabledExtensions.splice(index, 1);
|
||||
this._setEnabledExtensions(enabledExtensions, scope, identifier);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private _getEnabledExtensions(scope: StorageScope): IExtensionIdentifier[] {
|
||||
return this._getExtensions(ENABLED_EXTENSIONS_STORAGE_PATH, scope);
|
||||
}
|
||||
|
||||
private _setEnabledExtensions(enabledExtensions: IExtensionIdentifier[], scope: StorageScope, extension: IExtensionIdentifier): void {
|
||||
this._setExtensions(ENABLED_EXTENSIONS_STORAGE_PATH, enabledExtensions, scope, extension);
|
||||
}
|
||||
|
||||
private _getDisabledExtensions(scope: StorageScope): IExtensionIdentifier[] {
|
||||
return this._getExtensions(DISABLED_EXTENSIONS_STORAGE_PATH, scope);
|
||||
}
|
||||
|
||||
private _setDisabledExtensions(disabledExtensions: IExtensionIdentifier[], scope: StorageScope, extension: IExtensionIdentifier, fireEvent = true): void {
|
||||
this._setExtensions(DISABLED_EXTENSIONS_STORAGE_PATH, disabledExtensions, scope, extension, fireEvent);
|
||||
}
|
||||
|
||||
private _getExtensions(storageId: string, scope: StorageScope): IExtensionIdentifier[] {
|
||||
if (scope === StorageScope.WORKSPACE && !this.hasWorkspace) {
|
||||
return [];
|
||||
}
|
||||
const value = this.storageService.get(DISABLED_EXTENSIONS_STORAGE_PATH, scope, '');
|
||||
const value = this.storageService.get(storageId, scope, '');
|
||||
return value ? JSON.parse(value) : [];
|
||||
}
|
||||
|
||||
private setDisabledExtensions(disabledExtensions: IExtensionIdentifier[], scope: StorageScope, extension: IExtensionIdentifier, fireEvent = true): void {
|
||||
if (disabledExtensions.length) {
|
||||
this.storageService.store(DISABLED_EXTENSIONS_STORAGE_PATH, JSON.stringify(disabledExtensions.map(({ id, uuid }) => (<IExtensionIdentifier>{ id, uuid }))), scope);
|
||||
private _setExtensions(storageId: string, extensions: IExtensionIdentifier[], scope: StorageScope, extension: IExtensionIdentifier, fireEvent = true): void {
|
||||
if (extensions.length) {
|
||||
this.storageService.store(storageId, JSON.stringify(extensions.map(({ id, uuid }) => (<IExtensionIdentifier>{ id, uuid }))), scope);
|
||||
} else {
|
||||
this.storageService.remove(DISABLED_EXTENSIONS_STORAGE_PATH, scope);
|
||||
this.storageService.remove(storageId, scope);
|
||||
}
|
||||
if (fireEvent) {
|
||||
this._onEnablementChanged.fire(extension);
|
||||
}
|
||||
}
|
||||
|
||||
private migrateDisabledExtensions(installedExtensions: IExtensionIdentifier[], scope: StorageScope): void {
|
||||
private _migrateDisabledExtensions(installedExtensions: IExtensionIdentifier[], scope: StorageScope): void {
|
||||
const oldValue = this.storageService.get('extensions/disabled', scope, '');
|
||||
if (oldValue) {
|
||||
const extensionIdentifiers = coalesce(distinct(oldValue.split(',')).map(id => {
|
||||
@@ -147,13 +259,14 @@ export class ExtensionEnablementService implements IExtensionEnablementService {
|
||||
this.storageService.remove('extensions/disabled', scope);
|
||||
}
|
||||
|
||||
private onDidUninstallExtension({ identifier, error }: DidUninstallExtensionEvent): void {
|
||||
private _onDidUninstallExtension({ identifier, error }: DidUninstallExtensionEvent): void {
|
||||
if (!error) {
|
||||
const id = getIdAndVersionFromLocalExtensionId(identifier.id).id;
|
||||
const id = getIdFromLocalExtensionId(identifier.id);
|
||||
if (id) {
|
||||
const extension = { id, uuid: identifier.uuid };
|
||||
this.enableExtension(extension, StorageScope.WORKSPACE, false);
|
||||
this.enableExtension(extension, StorageScope.GLOBAL, false);
|
||||
this._removeFromDisabledExtensions(extension, StorageScope.WORKSPACE);
|
||||
this._removeFromEnabledExtensions(extension, StorageScope.WORKSPACE);
|
||||
this._removeFromDisabledExtensions(extension, StorageScope.GLOBAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,6 +133,7 @@ export interface IGalleryExtensionAssets {
|
||||
download: IGalleryExtensionAsset;
|
||||
icon: IGalleryExtensionAsset;
|
||||
license: IGalleryExtensionAsset;
|
||||
repository: IGalleryExtensionAsset;
|
||||
}
|
||||
|
||||
export interface IExtensionIdentifier {
|
||||
@@ -156,6 +157,7 @@ export interface IGalleryExtension {
|
||||
assets: IGalleryExtensionAssets;
|
||||
properties: IGalleryExtensionProperties;
|
||||
telemetryData: any;
|
||||
preview: boolean;
|
||||
}
|
||||
|
||||
export interface IGalleryMetadata {
|
||||
@@ -213,6 +215,11 @@ export enum StatisticType {
|
||||
Uninstall = 'uninstall'
|
||||
}
|
||||
|
||||
export interface IReportedExtension {
|
||||
id: IExtensionIdentifier;
|
||||
malicious: boolean;
|
||||
}
|
||||
|
||||
export interface IExtensionGalleryService {
|
||||
_serviceBrand: any;
|
||||
isEnabled(): boolean;
|
||||
@@ -223,7 +230,8 @@ export interface IExtensionGalleryService {
|
||||
getManifest(extension: IGalleryExtension): TPromise<IExtensionManifest>;
|
||||
getChangelog(extension: IGalleryExtension): TPromise<string>;
|
||||
loadCompatibleVersion(extension: IGalleryExtension): TPromise<IGalleryExtension>;
|
||||
getAllDependencies(extension: IGalleryExtension): TPromise<IGalleryExtension[]>;
|
||||
loadAllDependencies(dependencies: IExtensionIdentifier[]): TPromise<IGalleryExtension[]>;
|
||||
getExtensionsReport(): TPromise<IReportedExtension[]>;
|
||||
}
|
||||
|
||||
export interface InstallExtensionEvent {
|
||||
@@ -257,10 +265,18 @@ export interface IExtensionManagementService {
|
||||
installFromGallery(extension: IGalleryExtension): TPromise<void>;
|
||||
uninstall(extension: ILocalExtension, force?: boolean): TPromise<void>;
|
||||
getInstalled(type?: LocalExtensionType): TPromise<ILocalExtension[]>;
|
||||
getExtensionsReport(): TPromise<IReportedExtension[]>;
|
||||
|
||||
updateMetadata(local: ILocalExtension, metadata: IGalleryMetadata): TPromise<ILocalExtension>;
|
||||
}
|
||||
|
||||
export enum EnablementState {
|
||||
Disabled,
|
||||
WorkspaceDisabled,
|
||||
Enabled,
|
||||
WorkspaceEnabled
|
||||
}
|
||||
|
||||
export const IExtensionEnablementService = createDecorator<IExtensionEnablementService>('extensionEnablementService');
|
||||
|
||||
// TODO: @sandy: Merge this into IExtensionManagementService when we have a storage service available in Shared process
|
||||
@@ -273,21 +289,25 @@ export interface IExtensionEnablementService {
|
||||
onEnablementChanged: Event<IExtensionIdentifier>;
|
||||
|
||||
/**
|
||||
* Returns all globally disabled extension identifiers.
|
||||
* Returns an empty array if none exist.
|
||||
* Returns all disabled extension identifiers for current workspace
|
||||
* Returns an empty array if none exist
|
||||
*/
|
||||
getGloballyDisabledExtensions(): IExtensionIdentifier[];
|
||||
getDisabledExtensions(): TPromise<IExtensionIdentifier[]>;
|
||||
|
||||
/**
|
||||
* Returns all workspace disabled extension identifiers.
|
||||
* Returns an empty array if none exist or workspace does not exist.
|
||||
* Returns the enablement state for the given extension
|
||||
*/
|
||||
getWorkspaceDisabledExtensions(): IExtensionIdentifier[];
|
||||
getEnablementState(identifier: IExtensionIdentifier): EnablementState;
|
||||
|
||||
/**
|
||||
* Returns `true` if given extension can be enabled by calling `setEnablement`, otherwise false`.
|
||||
* Returns `true` if the enablement can be changed.
|
||||
*/
|
||||
canEnable(identifier: IExtensionIdentifier): boolean;
|
||||
canChangeEnablement(): boolean;
|
||||
|
||||
/**
|
||||
* Returns `true` if the given extension identifier is enabled.
|
||||
*/
|
||||
isEnabled(identifier: IExtensionIdentifier): boolean;
|
||||
|
||||
/**
|
||||
* Enable or disable the given extension.
|
||||
@@ -298,7 +318,7 @@ export interface IExtensionEnablementService {
|
||||
*
|
||||
* Throws error if enablement is requested for workspace and there is no workspace
|
||||
*/
|
||||
setEnablement(identifier: IExtensionIdentifier, enable: boolean, workspace?: boolean): TPromise<boolean>;
|
||||
setEnablement(identifier: IExtensionIdentifier, state: EnablementState): TPromise<boolean>;
|
||||
|
||||
migrateToIdentifiers(installed: IExtensionIdentifier[]): void;
|
||||
}
|
||||
@@ -318,4 +338,4 @@ export interface IExtensionTipsService {
|
||||
|
||||
export const ExtensionsLabel = localize('extensions', "Extensions");
|
||||
export const ExtensionsChannelId = 'extensions';
|
||||
export const PreferencesLabel = localize('preferences', "Preferences");
|
||||
export const PreferencesLabel = localize('preferences', "Preferences");
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IChannel, eventToCall, eventFromCall } from 'vs/base/parts/ipc/common/ipc';
|
||||
import { IExtensionManagementService, ILocalExtension, InstallExtensionEvent, DidInstallExtensionEvent, IGalleryExtension, LocalExtensionType, DidUninstallExtensionEvent, IExtensionIdentifier, IGalleryMetadata } from './extensionManagement';
|
||||
import { IExtensionManagementService, ILocalExtension, InstallExtensionEvent, DidInstallExtensionEvent, IGalleryExtension, LocalExtensionType, DidUninstallExtensionEvent, IExtensionIdentifier, IGalleryMetadata, IReportedExtension } from './extensionManagement';
|
||||
import Event, { buffer } from 'vs/base/common/event';
|
||||
|
||||
export interface IExtensionManagementChannel extends IChannel {
|
||||
@@ -19,6 +19,7 @@ export interface IExtensionManagementChannel extends IChannel {
|
||||
call(command: 'installFromGallery', extension: IGalleryExtension): TPromise<void>;
|
||||
call(command: 'uninstall', args: [ILocalExtension, boolean]): TPromise<void>;
|
||||
call(command: 'getInstalled'): TPromise<ILocalExtension[]>;
|
||||
call(command: 'getExtensionsReport'): TPromise<IReportedExtension[]>;
|
||||
call(command: string, arg?: any): TPromise<any>;
|
||||
}
|
||||
|
||||
@@ -47,6 +48,7 @@ export class ExtensionManagementChannel implements IExtensionManagementChannel {
|
||||
case 'uninstall': return this.service.uninstall(arg[0], arg[1]);
|
||||
case 'getInstalled': return this.service.getInstalled(arg);
|
||||
case 'updateMetadata': return this.service.updateMetadata(arg[0], arg[1]);
|
||||
case 'getExtensionsReport': return this.service.getExtensionsReport();
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
@@ -89,4 +91,8 @@ export class ExtensionManagementChannelClient implements IExtensionManagementSer
|
||||
updateMetadata(local: ILocalExtension, metadata: IGalleryMetadata): TPromise<ILocalExtension> {
|
||||
return this.channel.call('updateMetadata', [local, metadata]);
|
||||
}
|
||||
|
||||
getExtensionsReport(): TPromise<IReportedExtension[]> {
|
||||
return this.channel.call('getExtensionsReport');
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import { ILocalExtension, IGalleryExtension, EXTENSION_IDENTIFIER_REGEX, IExtensionEnablementService, IExtensionIdentifier } from 'vs/platform/extensionManagement/common/extensionManagement';
|
||||
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
|
||||
import { ILocalExtension, IGalleryExtension, EXTENSION_IDENTIFIER_REGEX, IExtensionIdentifier, IReportedExtension } from 'vs/platform/extensionManagement/common/extensionManagement';
|
||||
|
||||
export function areSameExtensions(a: IExtensionIdentifier, b: IExtensionIdentifier): boolean {
|
||||
if (a.uuid && b.uuid) {
|
||||
@@ -26,15 +25,14 @@ export function getGalleryExtensionIdFromLocal(local: ILocalExtension): string {
|
||||
return getGalleryExtensionId(local.manifest.publisher, local.manifest.name);
|
||||
}
|
||||
|
||||
export function getIdAndVersionFromLocalExtensionId(localExtensionId: string): { id: string, version: string } {
|
||||
const matches = /^([^.]+\..+)-(\d+\.\d+\.\d+)$/.exec(localExtensionId);
|
||||
if (matches && matches[1] && matches[2]) {
|
||||
return { id: adoptToGalleryExtensionId(matches[1]), version: matches[2] };
|
||||
export const LOCAL_EXTENSION_ID_REGEX = /^([^.]+\..+)-(\d+\.\d+\.\d+(-.*)?)$/;
|
||||
|
||||
export function getIdFromLocalExtensionId(localExtensionId: string): string {
|
||||
const matches = LOCAL_EXTENSION_ID_REGEX.exec(localExtensionId);
|
||||
if (matches && matches[1]) {
|
||||
return adoptToGalleryExtensionId(matches[1]);
|
||||
}
|
||||
return {
|
||||
id: adoptToGalleryExtensionId(localExtensionId),
|
||||
version: null
|
||||
};
|
||||
return adoptToGalleryExtensionId(localExtensionId);
|
||||
}
|
||||
|
||||
export function adoptToGalleryExtensionId(id: string): string {
|
||||
@@ -81,23 +79,17 @@ export function getGalleryExtensionTelemetryData(extension: IGalleryExtension):
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
const BetterMergeCheckKey = 'extensions/bettermergecheck';
|
||||
export const BetterMergeDisabledNowKey = 'extensions/bettermergedisablednow';
|
||||
export const BetterMergeId = 'pprice.better-merge';
|
||||
|
||||
/**
|
||||
* Globally disabled extensions, taking care of disabling obsolete extensions.
|
||||
*/
|
||||
export function getGloballyDisabledExtensions(extensionEnablementService: IExtensionEnablementService, storageService: IStorageService, installedExtensions: { id: string; }[]) {
|
||||
const globallyDisabled = extensionEnablementService.getGloballyDisabledExtensions();
|
||||
if (!storageService.getBoolean(BetterMergeCheckKey, StorageScope.GLOBAL, false)) {
|
||||
storageService.store(BetterMergeCheckKey, true);
|
||||
if (globallyDisabled.every(disabled => disabled.id !== BetterMergeId) && installedExtensions.some(d => d.id === BetterMergeId)) {
|
||||
globallyDisabled.push({ id: BetterMergeId });
|
||||
extensionEnablementService.setEnablement({ id: BetterMergeId }, false);
|
||||
storageService.store(BetterMergeDisabledNowKey, true);
|
||||
export function getMaliciousExtensionsSet(report: IReportedExtension[]): Set<string> {
|
||||
const result = new Set<string>();
|
||||
|
||||
for (const extension of report) {
|
||||
if (extension.malicious) {
|
||||
result.add(extension.id.id);
|
||||
}
|
||||
}
|
||||
return globallyDisabled;
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
import { cloneAndChange } from 'vs/base/common/objects';
|
||||
import { IExtensionManifest } from 'vs/platform/extensionManagement/common/extensionManagement';
|
||||
|
||||
const nlsRegex = /^%([\w\d.]+)%$/i;
|
||||
const nlsRegex = /^%([\w\d.-]+)%$/i;
|
||||
|
||||
export interface ITranslations {
|
||||
[key: string]: string;
|
||||
|
||||
@@ -7,21 +7,23 @@ import { localize } from 'vs/nls';
|
||||
import { tmpdir } from 'os';
|
||||
import * as path from 'path';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import * as uuid from 'vs/base/common/uuid';
|
||||
import { distinct } from 'vs/base/common/arrays';
|
||||
import { getErrorMessage, isPromiseCanceledError } from 'vs/base/common/errors';
|
||||
import { StatisticType, IGalleryExtension, IExtensionGalleryService, IGalleryExtensionAsset, IQueryOptions, SortBy, SortOrder, IExtensionManifest } from 'vs/platform/extensionManagement/common/extensionManagement';
|
||||
import { StatisticType, IGalleryExtension, IExtensionGalleryService, IGalleryExtensionAsset, IQueryOptions, SortBy, SortOrder, IExtensionManifest, IExtensionIdentifier, IReportedExtension } from 'vs/platform/extensionManagement/common/extensionManagement';
|
||||
import { getGalleryExtensionId, getGalleryExtensionTelemetryData, adoptToGalleryExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
|
||||
import { assign, getOrDefault } from 'vs/base/common/objects';
|
||||
import { IRequestService } from 'vs/platform/request/node/request';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { IPager } from 'vs/base/common/paging';
|
||||
import { IRequestOptions, IRequestContext, download, asJson, asText } from 'vs/base/node/request';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import pkg from 'vs/platform/node/package';
|
||||
import product from 'vs/platform/node/product';
|
||||
import { isVersionValid } from 'vs/platform/extensions/node/extensionValidator';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import { readFile } from 'vs/base/node/pfs';
|
||||
import { writeFileAndFlushSync } from 'vs/base/node/extfs';
|
||||
import { generateUuid, isUUID } from 'vs/base/common/uuid';
|
||||
import { values } from 'vs/base/common/map';
|
||||
|
||||
interface IRawGalleryExtensionFile {
|
||||
assetType: string;
|
||||
@@ -55,6 +57,7 @@ interface IRawGalleryExtension {
|
||||
publisher: { displayName: string, publisherId: string, publisherName: string; };
|
||||
versions: IRawGalleryExtensionVersion[];
|
||||
statistics: IRawGalleryExtensionStatistics[];
|
||||
flags: string;
|
||||
}
|
||||
|
||||
interface IRawGalleryQueryResult {
|
||||
@@ -107,6 +110,7 @@ const AssetType = {
|
||||
Manifest: 'Microsoft.VisualStudio.Code.Manifest',
|
||||
VSIX: 'Microsoft.VisualStudio.Services.VSIXPackage',
|
||||
License: 'Microsoft.VisualStudio.Services.Content.License',
|
||||
Repository: 'Microsoft.VisualStudio.Services.Links.Source'
|
||||
};
|
||||
|
||||
const PropertyType = {
|
||||
@@ -200,6 +204,26 @@ function getStatistic(statistics: IRawGalleryExtensionStatistics[], name: string
|
||||
function getVersionAsset(version: IRawGalleryExtensionVersion, type: string): IGalleryExtensionAsset {
|
||||
const result = version.files.filter(f => f.assetType === type)[0];
|
||||
|
||||
if (type === AssetType.Repository) {
|
||||
if (version.properties) {
|
||||
const results = version.properties.filter(p => p.key === type);
|
||||
const gitRegExp = new RegExp('((git|ssh|http(s)?)|(git@[\w\.]+))(:(//)?)([\w\.@\:/\-~]+)(\.git)(/)?');
|
||||
|
||||
const uri = results.filter(r => gitRegExp.test(r.value))[0];
|
||||
if (!uri) {
|
||||
return {
|
||||
uri: null,
|
||||
fallbackUri: null
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
uri: uri.value,
|
||||
fallbackUri: uri.value,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
if (type === AssetType.Icon) {
|
||||
const uri = require.toUrl('./media/defaultIcon.png');
|
||||
@@ -233,6 +257,10 @@ function getEngine(version: IRawGalleryExtensionVersion): string {
|
||||
return (values.length > 0 && values[0].value) || '';
|
||||
}
|
||||
|
||||
function getIsPreview(flags: string): boolean {
|
||||
return flags.indexOf('preview') !== -1;
|
||||
}
|
||||
|
||||
function toExtension(galleryExtension: IRawGalleryExtension, extensionsGalleryUrl: string, index: number, query: Query, querySource?: string): IGalleryExtension {
|
||||
const [version] = galleryExtension.versions;
|
||||
const assets = {
|
||||
@@ -241,7 +269,8 @@ function toExtension(galleryExtension: IRawGalleryExtension, extensionsGalleryUr
|
||||
changelog: getVersionAsset(version, AssetType.Changelog),
|
||||
download: getVersionAsset(version, AssetType.VSIX),
|
||||
icon: getVersionAsset(version, AssetType.Icon),
|
||||
license: getVersionAsset(version, AssetType.License)
|
||||
license: getVersionAsset(version, AssetType.License),
|
||||
repository: getVersionAsset(version, AssetType.Repository),
|
||||
};
|
||||
|
||||
return {
|
||||
@@ -276,31 +305,34 @@ function toExtension(galleryExtension: IRawGalleryExtension, extensionsGalleryUr
|
||||
index: ((query.pageNumber - 1) * query.pageSize) + index,
|
||||
searchText: query.searchText,
|
||||
querySource
|
||||
}
|
||||
},
|
||||
preview: getIsPreview(galleryExtension.flags)
|
||||
};
|
||||
}
|
||||
|
||||
interface IRawExtensionsReport {
|
||||
malicious: string[];
|
||||
slow: string[];
|
||||
}
|
||||
|
||||
export class ExtensionGalleryService implements IExtensionGalleryService {
|
||||
|
||||
_serviceBrand: any;
|
||||
|
||||
private extensionsGalleryUrl: string;
|
||||
private extensionsControlUrl: string;
|
||||
|
||||
private readonly commonHTTPHeaders: { [key: string]: string; };
|
||||
private readonly commonHeadersPromise: TPromise<{ [key: string]: string; }>;
|
||||
|
||||
constructor(
|
||||
@IRequestService private requestService: IRequestService,
|
||||
@IEnvironmentService private environmentService: IEnvironmentService,
|
||||
@ITelemetryService private telemetryService: ITelemetryService,
|
||||
@IConfigurationService private configurationService: IConfigurationService
|
||||
@ITelemetryService private telemetryService: ITelemetryService
|
||||
) {
|
||||
const config = product.extensionsGallery;
|
||||
this.extensionsGalleryUrl = config && config.serviceUrl;
|
||||
this.commonHTTPHeaders = {
|
||||
'X-Market-Client-Id': `VSCode ${pkg.version}`,
|
||||
'User-Agent': `VSCode ${pkg.version}`,
|
||||
'X-Market-User-Id': this.environmentService.machineUUID
|
||||
};
|
||||
this.extensionsControlUrl = config && config.controlUrl;
|
||||
this.commonHeadersPromise = resolveMarketplaceHeaders(this.environmentService);
|
||||
}
|
||||
|
||||
private api(path = ''): string {
|
||||
@@ -386,33 +418,34 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
|
||||
}
|
||||
|
||||
private queryGallery(query: Query): TPromise<{ galleryExtensions: IRawGalleryExtension[], total: number; }> {
|
||||
const commonHeaders = this.commonHTTPHeaders;
|
||||
const data = JSON.stringify(query.raw);
|
||||
const headers = assign({}, commonHeaders, {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json;api-version=3.0-preview.1',
|
||||
'Accept-Encoding': 'gzip',
|
||||
'Content-Length': data.length
|
||||
});
|
||||
return this.commonHeadersPromise.then(commonHeaders => {
|
||||
const data = JSON.stringify(query.raw);
|
||||
const headers = assign({}, commonHeaders, {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json;api-version=3.0-preview.1',
|
||||
'Accept-Encoding': 'gzip',
|
||||
'Content-Length': data.length
|
||||
});
|
||||
|
||||
return this.requestService.request({
|
||||
type: 'POST',
|
||||
url: this.api('/extensionquery'),
|
||||
data,
|
||||
headers
|
||||
}).then(context => {
|
||||
return this.requestService.request({
|
||||
type: 'POST',
|
||||
url: this.api('/extensionquery'),
|
||||
data,
|
||||
headers
|
||||
}).then(context => {
|
||||
|
||||
if (context.res.statusCode >= 400 && context.res.statusCode < 500) {
|
||||
return { galleryExtensions: [], total: 0 };
|
||||
}
|
||||
if (context.res.statusCode >= 400 && context.res.statusCode < 500) {
|
||||
return { galleryExtensions: [], total: 0 };
|
||||
}
|
||||
|
||||
return asJson<IRawGalleryQueryResult>(context).then(result => {
|
||||
const r = result.results[0];
|
||||
const galleryExtensions = r.extensions;
|
||||
const resultCount = r.resultMetadata && r.resultMetadata.filter(m => m.metadataType === 'ResultCount')[0];
|
||||
const total = resultCount && resultCount.metadataItems.filter(i => i.name === 'TotalCount')[0].count || 0;
|
||||
return asJson<IRawGalleryQueryResult>(context).then(result => {
|
||||
const r = result.results[0];
|
||||
const galleryExtensions = r.extensions;
|
||||
const resultCount = r.resultMetadata && r.resultMetadata.filter(m => m.metadataType === 'ResultCount')[0];
|
||||
const total = resultCount && resultCount.metadataItems.filter(i => i.name === 'TotalCount')[0].count || 0;
|
||||
|
||||
return { galleryExtensions, total };
|
||||
return { galleryExtensions, total };
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -422,35 +455,41 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
|
||||
return TPromise.as(null);
|
||||
}
|
||||
|
||||
const headers = { ...this.commonHTTPHeaders, Accept: '*/*;api-version=4.0-preview.1' };
|
||||
return this.commonHeadersPromise.then(commonHeaders => {
|
||||
const headers = { ...commonHeaders, Accept: '*/*;api-version=4.0-preview.1' };
|
||||
|
||||
return this.requestService.request({
|
||||
type: 'POST',
|
||||
url: this.api(`/publishers/${publisher}/extensions/${name}/${version}/stats?statType=${type}`),
|
||||
headers
|
||||
}).then(null, () => null);
|
||||
return this.requestService.request({
|
||||
type: 'POST',
|
||||
url: this.api(`/publishers/${publisher}/extensions/${name}/${version}/stats?statType=${type}`),
|
||||
headers
|
||||
}).then(null, () => null);
|
||||
});
|
||||
}
|
||||
|
||||
download(extension: IGalleryExtension): TPromise<string> {
|
||||
return this.loadCompatibleVersion(extension).then(extension => {
|
||||
const zipPath = path.join(tmpdir(), uuid.generateUuid());
|
||||
const data = getGalleryExtensionTelemetryData(extension);
|
||||
const startTime = new Date().getTime();
|
||||
/* __GDPR__
|
||||
"galleryService:downloadVSIX" : {
|
||||
"duration": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" },
|
||||
"${include}": [
|
||||
"${GalleryExtensionTelemetryData}"
|
||||
]
|
||||
return this.loadCompatibleVersion(extension)
|
||||
.then(extension => {
|
||||
if (!extension) {
|
||||
return TPromise.wrapError(new Error(localize('notCompatibleDownload', "Unable to download because the extension compatible with current version '{0}' of VS Code is not found.", pkg.version)));
|
||||
}
|
||||
*/
|
||||
const log = (duration: number) => this.telemetryService.publicLog('galleryService:downloadVSIX', assign(data, { duration }));
|
||||
const zipPath = path.join(tmpdir(), generateUuid());
|
||||
const data = getGalleryExtensionTelemetryData(extension);
|
||||
const startTime = new Date().getTime();
|
||||
/* __GDPR__
|
||||
"galleryService:downloadVSIX" : {
|
||||
"duration": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" },
|
||||
"${include}": [
|
||||
"${GalleryExtensionTelemetryData}"
|
||||
]
|
||||
}
|
||||
*/
|
||||
const log = (duration: number) => this.telemetryService.publicLog('galleryService:downloadVSIX', assign(data, { duration }));
|
||||
|
||||
return this.getAsset(extension.assets.download)
|
||||
.then(context => download(zipPath, context))
|
||||
.then(() => log(new Date().getTime() - startTime))
|
||||
.then(() => zipPath);
|
||||
});
|
||||
return this.getAsset(extension.assets.download)
|
||||
.then(context => download(zipPath, context))
|
||||
.then(() => log(new Date().getTime() - startTime))
|
||||
.then(() => zipPath);
|
||||
});
|
||||
}
|
||||
|
||||
getReadme(extension: IGalleryExtension): TPromise<string> {
|
||||
@@ -469,9 +508,8 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
|
||||
.then(asText);
|
||||
}
|
||||
|
||||
getAllDependencies(extension: IGalleryExtension): TPromise<IGalleryExtension[]> {
|
||||
return this.loadCompatibleVersion(<IGalleryExtension>extension)
|
||||
.then(compatible => this.getDependenciesReccursively(compatible.properties.dependencies, [], extension));
|
||||
loadAllDependencies(extensions: IExtensionIdentifier[]): TPromise<IGalleryExtension[]> {
|
||||
return this.getDependenciesReccursively(extensions.map(e => e.id), []);
|
||||
}
|
||||
|
||||
loadCompatibleVersion(extension: IGalleryExtension): TPromise<IGalleryExtension> {
|
||||
@@ -487,22 +525,26 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
|
||||
.withAssetTypes(AssetType.Manifest, AssetType.VSIX)
|
||||
.withFilter(FilterType.ExtensionId, extension.identifier.uuid);
|
||||
|
||||
return this.queryGallery(query).then(({ galleryExtensions }) => {
|
||||
const [rawExtension] = galleryExtensions;
|
||||
return this.queryGallery(query)
|
||||
.then(({ galleryExtensions }) => {
|
||||
const [rawExtension] = galleryExtensions;
|
||||
|
||||
if (!rawExtension) {
|
||||
return TPromise.wrapError<IGalleryExtension>(new Error(localize('notFound', "Extension not found")));
|
||||
}
|
||||
if (!rawExtension) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.getLastValidExtensionVersion(rawExtension, rawExtension.versions)
|
||||
.then(rawVersion => {
|
||||
extension.properties.dependencies = getDependencies(rawVersion);
|
||||
extension.properties.engine = getEngine(rawVersion);
|
||||
extension.assets.download = getVersionAsset(rawVersion, AssetType.VSIX);
|
||||
extension.version = rawVersion.version;
|
||||
return extension;
|
||||
});
|
||||
});
|
||||
return this.getLastValidExtensionVersion(rawExtension, rawExtension.versions)
|
||||
.then(rawVersion => {
|
||||
if (rawVersion) {
|
||||
extension.properties.dependencies = getDependencies(rawVersion);
|
||||
extension.properties.engine = getEngine(rawVersion);
|
||||
extension.assets.download = getVersionAsset(rawVersion, AssetType.VSIX);
|
||||
extension.version = rawVersion.version;
|
||||
return extension;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private loadDependencies(extensionNames: string[]): TPromise<IGalleryExtension[]> {
|
||||
@@ -533,13 +575,10 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
|
||||
});
|
||||
}
|
||||
|
||||
private getDependenciesReccursively(toGet: string[], result: IGalleryExtension[], root: IGalleryExtension): TPromise<IGalleryExtension[]> {
|
||||
private getDependenciesReccursively(toGet: string[], result: IGalleryExtension[]): TPromise<IGalleryExtension[]> {
|
||||
if (!toGet || !toGet.length) {
|
||||
return TPromise.wrap(result);
|
||||
}
|
||||
if (toGet.indexOf(`${root.publisher}.${root.name}`) !== -1 && result.indexOf(root) === -1) {
|
||||
result.push(root);
|
||||
}
|
||||
toGet = result.length ? toGet.filter(e => !ExtensionGalleryService.hasExtensionByName(result, e)) : toGet;
|
||||
if (!toGet.length) {
|
||||
return TPromise.wrap(result);
|
||||
@@ -556,52 +595,30 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
|
||||
result = distinct(result.concat(loadedDependencies), d => d.identifier.uuid);
|
||||
const dependencies: string[] = [];
|
||||
dependenciesSet.forEach(d => !ExtensionGalleryService.hasExtensionByName(result, d) && dependencies.push(d));
|
||||
return this.getDependenciesReccursively(dependencies, result, root);
|
||||
return this.getDependenciesReccursively(dependencies, result);
|
||||
});
|
||||
}
|
||||
|
||||
private getAsset(asset: IGalleryExtensionAsset, options: IRequestOptions = {}): TPromise<IRequestContext> {
|
||||
const baseOptions = { type: 'GET' };
|
||||
const headers = assign({}, this.commonHTTPHeaders, options.headers || {});
|
||||
options = assign({}, options, baseOptions, { headers });
|
||||
return this.commonHeadersPromise.then(commonHeaders => {
|
||||
const baseOptions = { type: 'GET' };
|
||||
const headers = assign({}, commonHeaders, options.headers || {});
|
||||
options = assign({}, options, baseOptions, { headers });
|
||||
|
||||
const url = asset.uri;
|
||||
const fallbackUrl = asset.fallbackUri;
|
||||
const firstOptions = assign({}, options, { url });
|
||||
const url = asset.uri;
|
||||
const fallbackUrl = asset.fallbackUri;
|
||||
const firstOptions = assign({}, options, { url });
|
||||
|
||||
return this.requestService.request(firstOptions)
|
||||
.then(context => {
|
||||
if (context.res.statusCode === 200) {
|
||||
return TPromise.as(context);
|
||||
}
|
||||
|
||||
return asText(context)
|
||||
.then(message => TPromise.wrapError<IRequestContext>(new Error(`Expected 200, got back ${context.res.statusCode} instead.\n\n${message}`)));
|
||||
})
|
||||
.then(null, err => {
|
||||
if (isPromiseCanceledError(err)) {
|
||||
return TPromise.wrapError<IRequestContext>(err);
|
||||
}
|
||||
|
||||
const message = getErrorMessage(err);
|
||||
/* __GDPR__
|
||||
"galleryService:requestError" : {
|
||||
"url" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
|
||||
"cdn": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
|
||||
"message": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
|
||||
return this.requestService.request(firstOptions)
|
||||
.then(context => {
|
||||
if (context.res.statusCode === 200) {
|
||||
return TPromise.as(context);
|
||||
}
|
||||
*/
|
||||
this.telemetryService.publicLog('galleryService:requestError', { url, cdn: true, message });
|
||||
/* __GDPR__
|
||||
"galleryService:cdnFallback" : {
|
||||
"url" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
|
||||
"message": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
|
||||
}
|
||||
*/
|
||||
this.telemetryService.publicLog('galleryService:cdnFallback', { url, message });
|
||||
|
||||
const fallbackOptions = assign({}, options, { url: fallbackUrl });
|
||||
return this.requestService.request(fallbackOptions).then(null, err => {
|
||||
return asText(context)
|
||||
.then(message => TPromise.wrapError<IRequestContext>(new Error(`Expected 200, got back ${context.res.statusCode} instead.\n\n${message}`)));
|
||||
})
|
||||
.then(null, err => {
|
||||
if (isPromiseCanceledError(err)) {
|
||||
return TPromise.wrapError<IRequestContext>(err);
|
||||
}
|
||||
@@ -614,10 +631,34 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
|
||||
"message": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
|
||||
}
|
||||
*/
|
||||
this.telemetryService.publicLog('galleryService:requestError', { url: fallbackUrl, cdn: false, message });
|
||||
return TPromise.wrapError<IRequestContext>(err);
|
||||
this.telemetryService.publicLog('galleryService:requestError', { url, cdn: true, message });
|
||||
/* __GDPR__
|
||||
"galleryService:cdnFallback" : {
|
||||
"url" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
|
||||
"message": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
|
||||
}
|
||||
*/
|
||||
this.telemetryService.publicLog('galleryService:cdnFallback', { url, message });
|
||||
|
||||
const fallbackOptions = assign({}, options, { url: fallbackUrl });
|
||||
return this.requestService.request(fallbackOptions).then(null, err => {
|
||||
if (isPromiseCanceledError(err)) {
|
||||
return TPromise.wrapError<IRequestContext>(err);
|
||||
}
|
||||
|
||||
const message = getErrorMessage(err);
|
||||
/* __GDPR__
|
||||
"galleryService:requestError" : {
|
||||
"url" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
|
||||
"cdn": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
|
||||
"message": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
|
||||
}
|
||||
*/
|
||||
this.telemetryService.publicLog('galleryService:requestError', { url: fallbackUrl, cdn: false, message });
|
||||
return TPromise.wrapError<IRequestContext>(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private getLastValidExtensionVersion(extension: IRawGalleryExtension, versions: IRawGalleryExtensionVersion[]): TPromise<IRawGalleryExtensionVersion> {
|
||||
@@ -643,7 +684,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
|
||||
|
||||
private getLastValidExtensionVersionReccursively(extension: IRawGalleryExtension, versions: IRawGalleryExtensionVersion[]): TPromise<IRawGalleryExtensionVersion> {
|
||||
if (!versions.length) {
|
||||
return TPromise.wrapError<IRawGalleryExtensionVersion>(new Error(localize('noCompatible', "Couldn't find a compatible version of {0} with this version of Code.", extension.displayName || extension.extensionName)));
|
||||
return null;
|
||||
}
|
||||
|
||||
const version = versions[0];
|
||||
@@ -678,4 +719,62 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
getExtensionsReport(): TPromise<IReportedExtension[]> {
|
||||
if (!this.isEnabled()) {
|
||||
return TPromise.wrapError(new Error('No extension gallery service configured.'));
|
||||
}
|
||||
|
||||
if (!this.extensionsControlUrl) {
|
||||
return TPromise.as([]);
|
||||
}
|
||||
|
||||
return this.requestService.request({ type: 'GET', url: this.extensionsControlUrl }).then(context => {
|
||||
if (context.res.statusCode !== 200) {
|
||||
return TPromise.wrapError(new Error('Could not get extensions report.'));
|
||||
}
|
||||
|
||||
return asJson<IRawExtensionsReport>(context).then(result => {
|
||||
const map = new Map<string, IReportedExtension>();
|
||||
|
||||
for (const id of result.malicious) {
|
||||
const ext = map.get(id) || { id: { id }, malicious: true, slow: false };
|
||||
ext.malicious = true;
|
||||
map.set(id, ext);
|
||||
}
|
||||
|
||||
return TPromise.as(values(map));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function resolveMarketplaceHeaders(environmentService: IEnvironmentService): TPromise<{ [key: string]: string; }> {
|
||||
const marketplaceMachineIdFile = path.join(environmentService.userDataPath, 'machineid');
|
||||
|
||||
return readFile(marketplaceMachineIdFile, 'utf8').then(contents => {
|
||||
if (isUUID(contents)) {
|
||||
return contents;
|
||||
}
|
||||
|
||||
return TPromise.wrap(null); // invalid marketplace UUID
|
||||
}, error => {
|
||||
return TPromise.wrap(null); // error reading ID file
|
||||
}).then(uuid => {
|
||||
if (!uuid) {
|
||||
uuid = generateUuid();
|
||||
|
||||
try {
|
||||
writeFileAndFlushSync(marketplaceMachineIdFile, uuid);
|
||||
} catch (error) {
|
||||
//noop
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
'X-Market-Client-Id': `VSCode ${pkg.version}`,
|
||||
'User-Agent': `VSCode ${pkg.version}`,
|
||||
'X-Market-User-Id': uuid
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -19,9 +19,11 @@ import {
|
||||
IGalleryExtension, IExtensionManifest, IGalleryMetadata,
|
||||
InstallExtensionEvent, DidInstallExtensionEvent, DidUninstallExtensionEvent, LocalExtensionType,
|
||||
StatisticType,
|
||||
IExtensionIdentifier
|
||||
IExtensionIdentifier,
|
||||
IReportedExtension
|
||||
} from 'vs/platform/extensionManagement/common/extensionManagement';
|
||||
import { getGalleryExtensionIdFromLocal, getIdAndVersionFromLocalExtensionId, adoptToGalleryExtensionId, areSameExtensions, getGalleryExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
|
||||
import { getGalleryExtensionIdFromLocal, adoptToGalleryExtensionId, areSameExtensions, getGalleryExtensionId, getMaliciousExtensionsSet } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
|
||||
import { getIdAndVersionFromLocalExtensionId } from 'vs/platform/extensionManagement/node/extensionManagementUtil';
|
||||
import { localizeManifest } from '../common/extensionNls';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import { Limiter } from 'vs/base/common/async';
|
||||
@@ -30,11 +32,26 @@ import * as semver from 'semver';
|
||||
import { groupBy, values } from 'vs/base/common/collections';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { IChoiceService, Severity } from 'vs/platform/message/common/message';
|
||||
import pkg from 'vs/platform/node/package';
|
||||
import { isMacintosh } from 'vs/base/common/platform';
|
||||
import { MANIFEST_CACHE_FOLDER, USER_MANIFEST_CACHE_FILE } from 'vs/platform/extensions/common/extensions';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
|
||||
const SystemExtensionsRoot = path.normalize(path.join(URI.parse(require.toUrl('')).fsPath, '..', 'extensions'));
|
||||
const INSTALL_ERROR_OBSOLETE = 'obsolete';
|
||||
const INSTALL_ERROR_INCOMPATIBLE = 'incompatible';
|
||||
const INSTALL_ERROR_DOWNLOADING = 'downloading';
|
||||
const INSTALL_ERROR_VALIDATING = 'validating';
|
||||
const INSTALL_ERROR_GALLERY = 'gallery';
|
||||
const INSTALL_ERROR_LOCAL = 'local';
|
||||
const INSTALL_ERROR_EXTRACTING = 'extracting';
|
||||
const INSTALL_ERROR_UNKNOWN = 'unknown';
|
||||
|
||||
export class InstallationError extends Error {
|
||||
constructor(message: string, readonly code: string) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
function parseManifest(raw: string): TPromise<{ manifest: IExtensionManifest; metadata: IGalleryMetadata; }> {
|
||||
return new TPromise((c, e) => {
|
||||
@@ -49,7 +66,7 @@ function parseManifest(raw: string): TPromise<{ manifest: IExtensionManifest; me
|
||||
});
|
||||
}
|
||||
|
||||
function validate(zipPath: string): TPromise<IExtensionManifest> {
|
||||
export function validateLocalExtension(zipPath: string): TPromise<IExtensionManifest> {
|
||||
return buffer(zipPath, 'extension/package.json')
|
||||
.then(buffer => parseManifest(buffer.toString('utf8')))
|
||||
.then(({ manifest }) => TPromise.as(manifest));
|
||||
@@ -75,7 +92,7 @@ function readManifest(extensionPath: string): TPromise<{ manifest: IExtensionMan
|
||||
interface InstallableExtension {
|
||||
zipPath: string;
|
||||
id: string;
|
||||
metadata: IGalleryMetadata;
|
||||
metadata?: IGalleryMetadata;
|
||||
current?: ILocalExtension;
|
||||
}
|
||||
|
||||
@@ -86,6 +103,8 @@ export class ExtensionManagementService implements IExtensionManagementService {
|
||||
private extensionsPath: string;
|
||||
private obsoletePath: string;
|
||||
private obsoleteFileLimiter: Limiter<void>;
|
||||
private reportedExtensions: TPromise<IReportedExtension[]> | undefined;
|
||||
private lastReportTimestamp = 0;
|
||||
private disposables: IDisposable[] = [];
|
||||
|
||||
private _onInstallExtension = new Emitter<InstallExtensionEvent>();
|
||||
@@ -103,93 +122,171 @@ export class ExtensionManagementService implements IExtensionManagementService {
|
||||
constructor(
|
||||
@IEnvironmentService private environmentService: IEnvironmentService,
|
||||
@IChoiceService private choiceService: IChoiceService,
|
||||
@IExtensionGalleryService private galleryService: IExtensionGalleryService
|
||||
@IExtensionGalleryService private galleryService: IExtensionGalleryService,
|
||||
@ILogService private logService: ILogService
|
||||
) {
|
||||
this.extensionsPath = environmentService.extensionsPath;
|
||||
this.obsoletePath = path.join(this.extensionsPath, '.obsolete');
|
||||
this.obsoleteFileLimiter = new Limiter(1);
|
||||
}
|
||||
|
||||
private deleteExtensionsManifestCache(): void {
|
||||
const cacheFolder = path.join(this.environmentService.userDataPath, MANIFEST_CACHE_FOLDER);
|
||||
const cacheFile = path.join(cacheFolder, USER_MANIFEST_CACHE_FILE);
|
||||
|
||||
pfs.del(cacheFile).done(() => { }, () => { });
|
||||
}
|
||||
|
||||
install(zipPath: string): TPromise<void> {
|
||||
this.deleteExtensionsManifestCache();
|
||||
|
||||
zipPath = path.resolve(zipPath);
|
||||
|
||||
return validate(zipPath).then<void>(manifest => {
|
||||
const identifier = { id: getLocalExtensionIdFromManifest(manifest) };
|
||||
|
||||
return this.isObsolete(identifier.id).then(isObsolete => {
|
||||
if (isObsolete) {
|
||||
return TPromise.wrapError(new Error(nls.localize('restartCodeLocal', "Please restart Code before reinstalling {0}.", manifest.displayName || manifest.name)));
|
||||
}
|
||||
|
||||
this._onInstallExtension.fire({ identifier, zipPath });
|
||||
|
||||
// {{SQL CARBON EDIT}}
|
||||
// Until there's a gallery for SQL Ops Studio, skip retrieving the metadata from the gallery
|
||||
return this.installExtension({ zipPath, id: identifier.id, metadata: null })
|
||||
.then(
|
||||
local => this._onDidInstallExtension.fire({ identifier, zipPath, local }),
|
||||
error => { this._onDidInstallExtension.fire({ identifier, zipPath, error }); return TPromise.wrapError(error); }
|
||||
);
|
||||
/*
|
||||
return this.galleryService.query({ names: [getGalleryExtensionId(manifest.publisher, manifest.name)], pageSize: 1 })
|
||||
.then(galleryResult => {
|
||||
const galleryExtension = galleryResult.firstPage[0];
|
||||
const metadata = galleryExtension ? <IGalleryMetadata>{ id: galleryExtension.identifier.uuid, publisherDisplayName: galleryExtension.publisherDisplayName, publisherId: galleryExtension.publisherId } : null;
|
||||
return this.installExtension({ zipPath, id: identifier.id, metadata })
|
||||
.then(
|
||||
local => this._onDidInstallExtension.fire({ identifier, zipPath, local }),
|
||||
error => { this._onDidInstallExtension.fire({ identifier, zipPath, error }); return TPromise.wrapError(error); }
|
||||
);
|
||||
return validateLocalExtension(zipPath)
|
||||
.then(manifest => {
|
||||
const identifier = { id: getLocalExtensionIdFromManifest(manifest) };
|
||||
return this.isObsolete(identifier.id)
|
||||
.then(isObsolete => {
|
||||
if (isObsolete) {
|
||||
return TPromise.wrapError(new Error(nls.localize('restartCodeLocal', "Please restart Code before reinstalling {0}.", manifest.displayName || manifest.name)));
|
||||
}
|
||||
return this.checkOutdated(manifest)
|
||||
.then(validated => {
|
||||
if (validated) {
|
||||
this._onInstallExtension.fire({ identifier, zipPath });
|
||||
|
||||
// {{SQL CARBON EDIT}}
|
||||
// Until there's a gallery for SQL Ops Studio, skip retrieving the metadata from the gallery
|
||||
return this.installExtension({ zipPath, id: identifier.id, metadata: null })
|
||||
.then(
|
||||
local => this._onDidInstallExtension.fire({ identifier, zipPath, local }),
|
||||
error => { this._onDidInstallExtension.fire({ identifier, zipPath, error }); return TPromise.wrapError(error); }
|
||||
);
|
||||
/*
|
||||
return this.getMetadata(getGalleryExtensionId(manifest.publisher, manifest.name))
|
||||
.then(
|
||||
metadata => this.installFromZipPath(identifier, zipPath, metadata, manifest),
|
||||
error => this.installFromZipPath(identifier, zipPath, null, manifest));
|
||||
*/
|
||||
}
|
||||
return null;
|
||||
});
|
||||
});
|
||||
*/
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
installFromGallery(extension: IGalleryExtension): TPromise<void> {
|
||||
return this.prepareAndCollectExtensionsToInstall(extension)
|
||||
.then(extensionsToInstall => this.downloadAndInstallExtensions(extensionsToInstall)
|
||||
.then(local => this.onDidInstallExtensions(extensionsToInstall, local)));
|
||||
private checkOutdated(manifest: IExtensionManifest): TPromise<boolean> {
|
||||
const extensionIdentifier = { id: getGalleryExtensionId(manifest.publisher, manifest.name) };
|
||||
return this.getInstalled()
|
||||
.then(installedExtensions => {
|
||||
const newer = installedExtensions.filter(local => areSameExtensions(extensionIdentifier, { id: getGalleryExtensionIdFromLocal(local) }) && semver.gt(local.manifest.version, manifest.version))[0];
|
||||
if (newer) {
|
||||
const message = nls.localize('installingOutdatedExtension', "A newer version of this extension is already installed. Would you like to override this with the older version?");
|
||||
const options = [
|
||||
nls.localize('override', "Override"),
|
||||
nls.localize('cancel', "Cancel")
|
||||
];
|
||||
return this.choiceService.choose(Severity.Info, message, options, 1, true)
|
||||
.then<boolean>(value => {
|
||||
if (value === 0) {
|
||||
return this.uninstall(newer, true).then(() => true);
|
||||
}
|
||||
return TPromise.wrapError(errors.canceled());
|
||||
});
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
private prepareAndCollectExtensionsToInstall(extension: IGalleryExtension): TPromise<IGalleryExtension[]> {
|
||||
this.onInstallExtensions([extension]);
|
||||
return this.collectExtensionsToInstall(extension)
|
||||
private installFromZipPath(identifier: IExtensionIdentifier, zipPath: string, metadata: IGalleryMetadata, manifest: IExtensionManifest): TPromise<void> {
|
||||
return this.installExtension({ zipPath, id: identifier.id, metadata })
|
||||
.then(local => {
|
||||
if (this.galleryService.isEnabled() && local.manifest.extensionDependencies && local.manifest.extensionDependencies.length) {
|
||||
return this.getDependenciesToInstall(local.manifest.extensionDependencies)
|
||||
.then(dependenciesToInstall => this.downloadAndInstallExtensions(metadata ? dependenciesToInstall.filter(d => d.identifier.uuid !== metadata.id) : dependenciesToInstall))
|
||||
.then(() => local, error => {
|
||||
this.uninstallExtension(local.identifier);
|
||||
return TPromise.wrapError(error);
|
||||
});
|
||||
}
|
||||
return local;
|
||||
})
|
||||
.then(
|
||||
extensionsToInstall => this.checkForObsolete(extensionsToInstall)
|
||||
.then(
|
||||
extensionsToInstall => {
|
||||
if (extensionsToInstall.length > 1) {
|
||||
this.onInstallExtensions(extensionsToInstall.slice(1));
|
||||
}
|
||||
return extensionsToInstall;
|
||||
},
|
||||
error => this.onDidInstallExtensions([extension], null, INSTALL_ERROR_OBSOLETE, error)
|
||||
),
|
||||
error => this.onDidInstallExtensions([extension], null, INSTALL_ERROR_GALLERY, error)
|
||||
local => this._onDidInstallExtension.fire({ identifier, zipPath, local }),
|
||||
error => { this._onDidInstallExtension.fire({ identifier, zipPath, error }); return TPromise.wrapError(error); }
|
||||
);
|
||||
}
|
||||
|
||||
private downloadAndInstallExtensions(extensions: IGalleryExtension[]): TPromise<ILocalExtension[]> {
|
||||
return this.getInstalled(LocalExtensionType.User)
|
||||
.then(installed => TPromise.join(extensions.map(extensionToInstall => this.downloadInstallableExtension(extensionToInstall, installed)))
|
||||
.then(
|
||||
installableExtensions => TPromise.join(installableExtensions.map(installableExtension => this.installExtension(installableExtension)))
|
||||
.then(null, error => this.rollback(extensions).then(() => this.onDidInstallExtensions(extensions, null, INSTALL_ERROR_LOCAL, error))),
|
||||
error => this.onDidInstallExtensions(extensions, null, INSTALL_ERROR_GALLERY, error)));
|
||||
installFromGallery(extension: IGalleryExtension): TPromise<void> {
|
||||
this.deleteExtensionsManifestCache();
|
||||
|
||||
this.onInstallExtensions([extension]);
|
||||
return this.collectExtensionsToInstall(extension)
|
||||
.then(
|
||||
extensionsToInstall => {
|
||||
if (extensionsToInstall.length > 1) {
|
||||
this.onInstallExtensions(extensionsToInstall.slice(1));
|
||||
}
|
||||
return this.downloadAndInstallExtensions(extensionsToInstall)
|
||||
.then(
|
||||
locals => this.onDidInstallExtensions(extensionsToInstall, locals, []),
|
||||
errors => this.onDidInstallExtensions(extensionsToInstall, [], errors));
|
||||
},
|
||||
error => this.onDidInstallExtensions([extension], [], [error]));
|
||||
}
|
||||
|
||||
private collectExtensionsToInstall(extension: IGalleryExtension): TPromise<IGalleryExtension[]> {
|
||||
return this.galleryService.loadCompatibleVersion(extension)
|
||||
.then(extensionToInstall => this.galleryService.getAllDependencies(extension)
|
||||
.then(allDependencies => this.filterDependenciesToInstall(extension, allDependencies))
|
||||
.then(dependenciesToInstall => [extensionToInstall, ...dependenciesToInstall]));
|
||||
.then(compatible => {
|
||||
if (!compatible) {
|
||||
return TPromise.wrapError<IGalleryExtension[]>(new InstallationError(nls.localize('notFoundCompatible', "Unable to install because, the extension '{0}' compatible with current version '{1}' of VS Code is not found.", extension.identifier.id, pkg.version), INSTALL_ERROR_INCOMPATIBLE));
|
||||
}
|
||||
return this.getDependenciesToInstall(compatible.properties.dependencies)
|
||||
.then(
|
||||
dependenciesToInstall => {
|
||||
const extensionsToInstall = [compatible, ...dependenciesToInstall.filter(d => d.identifier.uuid !== compatible.identifier.uuid)];
|
||||
return this.checkForObsolete(extensionsToInstall)
|
||||
.then(
|
||||
extensionsToInstall => extensionsToInstall,
|
||||
error => TPromise.wrapError<IGalleryExtension[]>(new InstallationError(this.joinErrors(error).message, INSTALL_ERROR_OBSOLETE))
|
||||
);
|
||||
},
|
||||
error => TPromise.wrapError<IGalleryExtension[]>(new InstallationError(this.joinErrors(error).message, INSTALL_ERROR_GALLERY)));
|
||||
},
|
||||
error => TPromise.wrapError<IGalleryExtension[]>(new InstallationError(this.joinErrors(error).message, INSTALL_ERROR_GALLERY)));
|
||||
}
|
||||
|
||||
private downloadAndInstallExtensions(extensions: IGalleryExtension[]): TPromise<ILocalExtension[]> {
|
||||
return this.getInstalled(LocalExtensionType.User)
|
||||
.then(
|
||||
installed => TPromise.join(extensions.map(extensionToInstall =>
|
||||
this.downloadAndInstallExtension(extensionToInstall, installed)
|
||||
)).then(null, errors => this.rollback(extensions).then(() => TPromise.wrapError(errors), () => TPromise.wrapError(errors))),
|
||||
error => TPromise.wrapError<ILocalExtension[]>(new InstallationError(this.joinErrors(error).message, INSTALL_ERROR_LOCAL)));
|
||||
}
|
||||
|
||||
private downloadAndInstallExtension(extensionToInstall: IGalleryExtension, installed: ILocalExtension[]): TPromise<ILocalExtension> {
|
||||
return this.getExtensionsReport().then(report => {
|
||||
if (getMaliciousExtensionsSet(report).has(extensionToInstall.identifier.id)) {
|
||||
throw new Error(nls.localize('malicious extension', "Can't install extension since it was reported to be malicious."));
|
||||
}
|
||||
|
||||
return this.downloadInstallableExtension(extensionToInstall, installed)
|
||||
.then(installableExtension => this.installExtension(installableExtension).then(null, e => TPromise.wrapError(new InstallationError(this.joinErrors(e).message, INSTALL_ERROR_EXTRACTING))));
|
||||
});
|
||||
}
|
||||
|
||||
private checkForObsolete(extensionsToInstall: IGalleryExtension[]): TPromise<IGalleryExtension[]> {
|
||||
return this.filterObsolete(...extensionsToInstall.map(i => getLocalExtensionIdFromGallery(i, i.version)))
|
||||
.then(obsolete => obsolete.length ? TPromise.wrapError<IGalleryExtension[]>(new Error(nls.localize('restartCodeGallery', "Please restart Code before reinstalling."))) : extensionsToInstall);
|
||||
.then(obsolete => {
|
||||
if (obsolete.length) {
|
||||
if (isMacintosh) {
|
||||
return TPromise.wrapError<IGalleryExtension[]>(new Error(nls.localize('quitCode', "Unable to install because an obsolete instance of the extension is still running. Please Quit and Start VS Code before reinstalling.")));
|
||||
}
|
||||
return TPromise.wrapError<IGalleryExtension[]>(new Error(nls.localize('exitCode', "Unable to install because an obsolete instance of the extension is still running. Please Exit and Start VS Code before reinstalling.")));
|
||||
}
|
||||
return extensionsToInstall;
|
||||
});
|
||||
}
|
||||
|
||||
private downloadInstallableExtension(extension: IGalleryExtension, installed: ILocalExtension[]): TPromise<InstallableExtension> {
|
||||
@@ -200,8 +297,24 @@ export class ExtensionManagementService implements IExtensionManagementService {
|
||||
publisherId: extension.publisherId,
|
||||
publisherDisplayName: extension.publisherDisplayName,
|
||||
};
|
||||
return this.galleryService.download(extension)
|
||||
.then(zipPath => validate(zipPath).then(() => (<InstallableExtension>{ zipPath, id, metadata, current })));
|
||||
|
||||
return this.galleryService.loadCompatibleVersion(extension)
|
||||
.then(
|
||||
compatible => {
|
||||
if (compatible) {
|
||||
return this.galleryService.download(extension)
|
||||
.then(
|
||||
zipPath => validateLocalExtension(zipPath)
|
||||
.then(
|
||||
() => (<InstallableExtension>{ zipPath, id, metadata, current }),
|
||||
error => TPromise.wrapError(new InstallationError(this.joinErrors(error).message, INSTALL_ERROR_VALIDATING))
|
||||
),
|
||||
error => TPromise.wrapError(new InstallationError(this.joinErrors(error).message, INSTALL_ERROR_DOWNLOADING)));
|
||||
} else {
|
||||
return TPromise.wrapError<InstallableExtension>(new InstallationError(nls.localize('notFoundCompatibleDependency', "Unable to install because, the depending extension '{0}' compatible with current version '{1}' of VS Code is not found.", extension.identifier.id, pkg.version), INSTALL_ERROR_INCOMPATIBLE));
|
||||
}
|
||||
},
|
||||
error => TPromise.wrapError<InstallableExtension>(new InstallationError(this.joinErrors(error).message, INSTALL_ERROR_GALLERY)));
|
||||
}
|
||||
|
||||
private rollback(extensions: IGalleryExtension[]): TPromise<void> {
|
||||
@@ -217,29 +330,33 @@ export class ExtensionManagementService implements IExtensionManagementService {
|
||||
}
|
||||
}
|
||||
|
||||
private onDidInstallExtensions(extensions: IGalleryExtension[], local: ILocalExtension[], errorCode?: string, error?: any): TPromise<any> {
|
||||
private onDidInstallExtensions(extensions: IGalleryExtension[], locals: ILocalExtension[], errors: Error[]): TPromise<any> {
|
||||
extensions.forEach((gallery, index) => {
|
||||
const identifier = { id: getLocalExtensionIdFromGallery(gallery, gallery.version), uuid: gallery.identifier.uuid };
|
||||
if (errorCode) {
|
||||
this._onDidInstallExtension.fire({ identifier, gallery, error: errorCode });
|
||||
const local = locals[index];
|
||||
const error = errors[index];
|
||||
if (local) {
|
||||
this._onDidInstallExtension.fire({ identifier, gallery, local });
|
||||
} else {
|
||||
this._onDidInstallExtension.fire({ identifier, gallery, local: local[index] });
|
||||
const errorCode = error && (<InstallationError>error).code ? (<InstallationError>error).code : INSTALL_ERROR_UNKNOWN;
|
||||
this._onDidInstallExtension.fire({ identifier, gallery, error: errorCode });
|
||||
}
|
||||
});
|
||||
return error ? TPromise.wrapError(Array.isArray(error) ? this.joinErrors(error) : error) : TPromise.as(null);
|
||||
return errors.length ? TPromise.wrapError(this.joinErrors(errors)) : TPromise.as(null);
|
||||
}
|
||||
|
||||
private filterDependenciesToInstall(extension: IGalleryExtension, dependencies: IGalleryExtension[]): TPromise<IGalleryExtension[]> {
|
||||
return this.getInstalled()
|
||||
.then(local => {
|
||||
return dependencies.filter(d => {
|
||||
if (extension.identifier.uuid === d.identifier.uuid) {
|
||||
return false;
|
||||
}
|
||||
const extensionId = getLocalExtensionIdFromGallery(d, d.version);
|
||||
return local.every(({ identifier }) => identifier.id !== extensionId);
|
||||
});
|
||||
});
|
||||
private getDependenciesToInstall(dependencies: string[]): TPromise<IGalleryExtension[]> {
|
||||
if (dependencies.length) {
|
||||
return this.galleryService.loadAllDependencies(dependencies.map(id => (<IExtensionIdentifier>{ id })))
|
||||
.then(allDependencies => this.getInstalled()
|
||||
.then(local => {
|
||||
return allDependencies.filter(d => {
|
||||
const extensionId = getLocalExtensionIdFromGallery(d, d.version);
|
||||
return local.every(({ identifier }) => identifier.id !== extensionId);
|
||||
});
|
||||
}));
|
||||
}
|
||||
return TPromise.as([]);
|
||||
}
|
||||
|
||||
private filterOutUninstalled(extensions: IGalleryExtension[]): TPromise<ILocalExtension[]> {
|
||||
@@ -278,6 +395,8 @@ export class ExtensionManagementService implements IExtensionManagementService {
|
||||
}
|
||||
|
||||
uninstall(extension: ILocalExtension, force = false): TPromise<void> {
|
||||
this.deleteExtensionsManifestCache();
|
||||
|
||||
return this.removeOutdatedExtensions()
|
||||
.then(() =>
|
||||
this.scanUserExtensions()
|
||||
@@ -285,12 +404,14 @@ export class ExtensionManagementService implements IExtensionManagementService {
|
||||
const promises = installed
|
||||
.filter(e => e.manifest.publisher === extension.manifest.publisher && e.manifest.name === extension.manifest.name)
|
||||
.map(e => this.checkForDependenciesAndUninstall(e, installed, force));
|
||||
return TPromise.join(promises).then(null, error => TPromise.wrapError(Array.isArray(error) ? this.joinErrors(error) : error));
|
||||
return TPromise.join(promises).then(null, error => TPromise.wrapError(this.joinErrors(error)));
|
||||
}))
|
||||
.then(() => { /* drop resolved value */ });
|
||||
}
|
||||
|
||||
updateMetadata(local: ILocalExtension, metadata: IGalleryMetadata): TPromise<ILocalExtension> {
|
||||
this.deleteExtensionsManifestCache();
|
||||
|
||||
local.metadata = metadata;
|
||||
return this.saveMetadataForLocalExtension(local);
|
||||
}
|
||||
@@ -307,20 +428,27 @@ export class ExtensionManagementService implements IExtensionManagementService {
|
||||
.then(() => local);
|
||||
}
|
||||
|
||||
private getMetadata(extensionName: string): TPromise<IGalleryMetadata> {
|
||||
return this.galleryService.query({ names: [extensionName], pageSize: 1 })
|
||||
.then(galleryResult => {
|
||||
const galleryExtension = galleryResult.firstPage[0];
|
||||
return galleryExtension ? <IGalleryMetadata>{ id: galleryExtension.identifier.uuid, publisherDisplayName: galleryExtension.publisherDisplayName, publisherId: galleryExtension.publisherId } : null;
|
||||
});
|
||||
}
|
||||
|
||||
private checkForRename(currentExtension: ILocalExtension, newExtension: ILocalExtension): TPromise<void> {
|
||||
// Check if the gallery id for current and new exensions are same, if not, remove the current one.
|
||||
if (currentExtension && getGalleryExtensionIdFromLocal(currentExtension) !== getGalleryExtensionIdFromLocal(newExtension)) {
|
||||
// return this.uninstallExtension(currentExtension.identifier);
|
||||
return this.setObsolete(currentExtension.identifier.id);
|
||||
}
|
||||
return TPromise.as(null);
|
||||
}
|
||||
|
||||
private joinErrors(errors: (Error | string)[]): Error {
|
||||
private joinErrors(errorOrErrors: (Error | string) | ((Error | string)[])): Error {
|
||||
const errors = Array.isArray(errorOrErrors) ? errorOrErrors : [errorOrErrors];
|
||||
if (errors.length === 1) {
|
||||
return errors[0] instanceof Error ? <Error>errors[0] : new Error(<string>errors[0]);
|
||||
}
|
||||
|
||||
return errors.reduce<Error>((previousValue: Error, currentValue: Error | string) => {
|
||||
return new Error(`${previousValue.message}${previousValue.message ? ',' : ''}${currentValue instanceof Error ? currentValue.message : currentValue}`);
|
||||
}, new Error(''));
|
||||
@@ -537,8 +665,9 @@ export class ExtensionManagementService implements IExtensionManagementService {
|
||||
|
||||
removeDeprecatedExtensions(): TPromise<any> {
|
||||
return TPromise.join([
|
||||
this.removeOutdatedExtensions(),
|
||||
this.removeObsoleteExtensions()
|
||||
// Remove obsolte extensions first to avoid removing installed older extension. See #38609.
|
||||
this.removeObsoleteExtensions(),
|
||||
this.removeOutdatedExtensions()
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -621,6 +750,30 @@ export class ExtensionManagementService implements IExtensionManagementService {
|
||||
});
|
||||
}
|
||||
|
||||
getExtensionsReport(): TPromise<IReportedExtension[]> {
|
||||
const now = new Date().getTime();
|
||||
|
||||
if (!this.reportedExtensions || now - this.lastReportTimestamp > 1000 * 60 * 5) { // 5 minute cache freshness
|
||||
this.reportedExtensions = this.updateReportCache();
|
||||
this.lastReportTimestamp = now;
|
||||
}
|
||||
|
||||
return this.reportedExtensions;
|
||||
}
|
||||
|
||||
private updateReportCache(): TPromise<IReportedExtension[]> {
|
||||
this.logService.trace('ExtensionManagementService.refreshReportedCache');
|
||||
|
||||
return this.galleryService.getExtensionsReport()
|
||||
.then(result => {
|
||||
this.logService.trace(`ExtensionManagementService.refreshReportedCache - got ${result.length} reported extensions from service`);
|
||||
return result;
|
||||
}, err => {
|
||||
this.logService.trace('ExtensionManagementService.refreshReportedCache - failed to get extension report');
|
||||
return [];
|
||||
});
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this.disposables = dispose(this.disposables);
|
||||
}
|
||||
@@ -636,4 +789,4 @@ export function getLocalExtensionIdFromManifest(manifest: IExtensionManifest): s
|
||||
|
||||
function getLocalExtensionId(id: string, version: string): string {
|
||||
return `${id}-${version}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as semver from 'semver';
|
||||
import { adoptToGalleryExtensionId, LOCAL_EXTENSION_ID_REGEX } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
|
||||
|
||||
export function getIdAndVersionFromLocalExtensionId(localExtensionId: string): { id: string, version: string } {
|
||||
const matches = LOCAL_EXTENSION_ID_REGEX.exec(localExtensionId);
|
||||
if (matches && matches[1] && matches[2]) {
|
||||
const version = semver.valid(matches[2]);
|
||||
if (version) {
|
||||
return { id: adoptToGalleryExtensionId(matches[1]), version };
|
||||
}
|
||||
}
|
||||
return {
|
||||
id: adoptToGalleryExtensionId(localExtensionId),
|
||||
version: null
|
||||
};
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
import * as assert from 'assert';
|
||||
import * as sinon from 'sinon';
|
||||
import { IExtensionManagementService, IExtensionEnablementService, DidUninstallExtensionEvent } from 'vs/platform/extensionManagement/common/extensionManagement';
|
||||
import { IExtensionManagementService, IExtensionEnablementService, DidUninstallExtensionEvent, EnablementState } from 'vs/platform/extensionManagement/common/extensionManagement';
|
||||
import { ExtensionEnablementService } from 'vs/platform/extensionManagement/common/extensionEnablementService';
|
||||
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
@@ -14,6 +14,7 @@ import { StorageService, InMemoryLocalStorage } from 'vs/platform/storage/common
|
||||
import { IStorageService } from 'vs/platform/storage/common/storage';
|
||||
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
|
||||
function storageService(instantiationService: TestInstantiationService): IStorageService {
|
||||
let service = instantiationService.get(IStorageService);
|
||||
@@ -33,13 +34,12 @@ function storageService(instantiationService: TestInstantiationService): IStorag
|
||||
export class TestExtensionEnablementService extends ExtensionEnablementService {
|
||||
constructor(instantiationService: TestInstantiationService) {
|
||||
super(storageService(instantiationService), instantiationService.get(IWorkspaceContextService),
|
||||
instantiationService.get(IEnvironmentService) || instantiationService.stub(IEnvironmentService, <IEnvironmentService>{}),
|
||||
instantiationService.get(IEnvironmentService) || instantiationService.stub(IEnvironmentService, {} as IEnvironmentService),
|
||||
instantiationService.get(IExtensionManagementService) || instantiationService.stub(IExtensionManagementService, { onDidUninstallExtension: new Emitter() }));
|
||||
}
|
||||
|
||||
public reset(): void {
|
||||
this.getGloballyDisabledExtensions().forEach(d => this.setEnablement(d, true));
|
||||
this.getWorkspaceDisabledExtensions().forEach(d => this.setEnablement(d, true, true));
|
||||
public reset(): TPromise<void> {
|
||||
return this.getDisabledExtensions().then(extensions => extensions.forEach(d => this.setEnablement(d, EnablementState.Enabled)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,216 +60,268 @@ suite('ExtensionEnablementService Test', () => {
|
||||
(<ExtensionEnablementService>testObject).dispose();
|
||||
});
|
||||
|
||||
test('test when no extensions are disabled globally', () => {
|
||||
assert.deepEqual([], testObject.getGloballyDisabledExtensions());
|
||||
test('test when no extensions are disabled', () => {
|
||||
return testObject.getDisabledExtensions().then(extensions => assert.deepEqual([], extensions));
|
||||
});
|
||||
|
||||
test('test when no extensions are disabled for workspace', () => {
|
||||
assert.deepEqual([], testObject.getWorkspaceDisabledExtensions());
|
||||
});
|
||||
|
||||
test('test when no extensions are disabled for workspace when there is no workspace', (done) => {
|
||||
testObject.setEnablement({ id: 'pub.a' }, false, true)
|
||||
test('test when no extensions are disabled for workspace when there is no workspace', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled)
|
||||
.then(() => {
|
||||
instantiationService.stub(IWorkspaceContextService, 'getWorkbenchState', WorkbenchState.EMPTY);
|
||||
assert.deepEqual([], testObject.getWorkspaceDisabledExtensions());
|
||||
})
|
||||
.then(done, done);
|
||||
return testObject.getDisabledExtensions().then(extensions => assert.deepEqual([], extensions));
|
||||
});
|
||||
});
|
||||
|
||||
test('test disable an extension globally', (done) => {
|
||||
testObject.setEnablement({ id: 'pub.a' }, false)
|
||||
.then(() => assert.deepEqual([{ id: 'pub.a' }], testObject.getGloballyDisabledExtensions()))
|
||||
.then(done, done);
|
||||
test('test disable an extension globally', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.Disabled)
|
||||
.then(() => testObject.getDisabledExtensions())
|
||||
.then(extensions => assert.deepEqual([{ id: 'pub.a' }], extensions));
|
||||
});
|
||||
|
||||
test('test disable an extension globally should return truthy promise', (done) => {
|
||||
testObject.setEnablement({ id: 'pub.a' }, false)
|
||||
.then(value => assert.ok(value))
|
||||
.then(done, done);
|
||||
test('test disable an extension globally should return truthy promise', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.Disabled)
|
||||
.then(value => assert.ok(value));
|
||||
});
|
||||
|
||||
test('test disable an extension globally triggers the change event', (done) => {
|
||||
test('test disable an extension globally triggers the change event', () => {
|
||||
const target = sinon.spy();
|
||||
testObject.onEnablementChanged(target);
|
||||
testObject.setEnablement({ id: 'pub.a' }, false)
|
||||
.then(() => assert.ok(target.calledWithExactly({ id: 'pub.a' })))
|
||||
.then(done, done);
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.Disabled)
|
||||
.then(() => assert.ok(target.calledWithExactly({ id: 'pub.a' })));
|
||||
});
|
||||
|
||||
test('test disable an extension globally again should return a falsy promise', (done) => {
|
||||
testObject.setEnablement({ id: 'pub.a' }, false)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, false))
|
||||
.then(value => assert.ok(!value))
|
||||
.then(done, done);
|
||||
test('test disable an extension globally again should return a falsy promise', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.Disabled)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.Disabled))
|
||||
.then(value => assert.ok(!value));
|
||||
});
|
||||
|
||||
test('test disable an extension for workspace', (done) => {
|
||||
testObject.setEnablement({ id: 'pub.a' }, false, true)
|
||||
.then(() => assert.deepEqual([{ id: 'pub.a' }], testObject.getWorkspaceDisabledExtensions()))
|
||||
.then(done, done);
|
||||
test('test state of globally disabled extension', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.Disabled)
|
||||
.then(() => assert.equal(testObject.getEnablementState({ id: 'pub.a' }), EnablementState.Disabled));
|
||||
});
|
||||
|
||||
test('test disable an extension for workspace returns a truthy promise', (done) => {
|
||||
testObject.setEnablement({ id: 'pub.a' }, false, true)
|
||||
.then(value => assert.ok(value))
|
||||
.then(done, done);
|
||||
test('test state of globally enabled extension', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.Disabled)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.Enabled))
|
||||
.then(() => assert.equal(testObject.getEnablementState({ id: 'pub.a' }), EnablementState.Enabled));
|
||||
});
|
||||
|
||||
test('test disable an extension for workspace again should return a falsy promise', (done) => {
|
||||
testObject.setEnablement({ id: 'pub.a' }, false, true)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, false, true))
|
||||
.then(value => assert.ok(!value))
|
||||
.then(done, done);
|
||||
test('test disable an extension for workspace', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled)
|
||||
.then(() => testObject.getDisabledExtensions())
|
||||
.then(extensions => assert.deepEqual([{ id: 'pub.a' }], extensions));
|
||||
});
|
||||
|
||||
test('test disable an extension for workspace and then globally', (done) => {
|
||||
testObject.setEnablement({ id: 'pub.a' }, false, true)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, false))
|
||||
.then(() => {
|
||||
assert.deepEqual([{ id: 'pub.a' }], testObject.getWorkspaceDisabledExtensions());
|
||||
assert.deepEqual([{ id: 'pub.a' }], testObject.getGloballyDisabledExtensions());
|
||||
})
|
||||
.then(done, done);
|
||||
test('test disable an extension for workspace returns a truthy promise', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled)
|
||||
.then(value => assert.ok(value));
|
||||
});
|
||||
|
||||
test('test disable an extension for workspace and then globally return a truthy promise', (done) => {
|
||||
testObject.setEnablement({ id: 'pub.a' }, false, true)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, false))
|
||||
.then(value => assert.ok(value))
|
||||
.then(done, done);
|
||||
test('test disable an extension for workspace again should return a falsy promise', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled))
|
||||
.then(value => assert.ok(!value));
|
||||
});
|
||||
|
||||
test('test disable an extension for workspace and then globally triggers the change event', (done) => {
|
||||
test('test state of workspace disabled extension', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled)
|
||||
.then(() => assert.equal(testObject.getEnablementState({ id: 'pub.a' }), EnablementState.WorkspaceDisabled));
|
||||
});
|
||||
|
||||
test('test state of workspace and globally disabled extension', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.Disabled)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled))
|
||||
.then(() => assert.equal(testObject.getEnablementState({ id: 'pub.a' }), EnablementState.WorkspaceDisabled));
|
||||
});
|
||||
|
||||
test('test state of workspace enabled extension', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceEnabled))
|
||||
.then(() => assert.equal(testObject.getEnablementState({ id: 'pub.a' }), EnablementState.WorkspaceEnabled));
|
||||
});
|
||||
|
||||
test('test state of globally disabled and workspace enabled extension', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.Disabled)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled))
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceEnabled))
|
||||
.then(() => assert.equal(testObject.getEnablementState({ id: 'pub.a' }), EnablementState.WorkspaceEnabled));
|
||||
});
|
||||
|
||||
test('test state of an extension when disabled for workspace from workspace enabled', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceEnabled))
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled))
|
||||
.then(() => assert.equal(testObject.getEnablementState({ id: 'pub.a' }), EnablementState.WorkspaceDisabled));
|
||||
});
|
||||
|
||||
test('test state of an extension when disabled globally from workspace enabled', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceEnabled))
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.Disabled))
|
||||
.then(() => assert.equal(testObject.getEnablementState({ id: 'pub.a' }), EnablementState.Disabled));
|
||||
});
|
||||
|
||||
test('test state of an extension when disabled globally from workspace disabled', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.Disabled))
|
||||
.then(() => assert.equal(testObject.getEnablementState({ id: 'pub.a' }), EnablementState.Disabled));
|
||||
});
|
||||
|
||||
test('test state of an extension when enabled globally from workspace enabled', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceEnabled))
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.Enabled))
|
||||
.then(() => assert.equal(testObject.getEnablementState({ id: 'pub.a' }), EnablementState.Enabled));
|
||||
});
|
||||
|
||||
test('test state of an extension when enabled globally from workspace disabled', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.Enabled))
|
||||
.then(() => assert.equal(testObject.getEnablementState({ id: 'pub.a' }), EnablementState.Enabled));
|
||||
});
|
||||
|
||||
test('test disable an extension for workspace and then globally', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.Disabled))
|
||||
.then(() => testObject.getDisabledExtensions())
|
||||
.then(extensions => assert.deepEqual([{ id: 'pub.a' }], extensions));
|
||||
});
|
||||
|
||||
test('test disable an extension for workspace and then globally return a truthy promise', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.Disabled))
|
||||
.then(value => assert.ok(value));
|
||||
});
|
||||
|
||||
test('test disable an extension for workspace and then globally trigger the change event', () => {
|
||||
const target = sinon.spy();
|
||||
testObject.setEnablement({ id: 'pub.a' }, false, true)
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled)
|
||||
.then(() => testObject.onEnablementChanged(target))
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, false))
|
||||
.then(() => assert.ok(target.calledWithExactly({ id: 'pub.a' })))
|
||||
.then(done, done);
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.Disabled))
|
||||
.then(() => assert.ok(target.calledWithExactly({ id: 'pub.a' })));
|
||||
});
|
||||
|
||||
test('test disable an extension globally and then for workspace', (done) => {
|
||||
testObject.setEnablement({ id: 'pub.a' }, false)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, false, true))
|
||||
.then(() => {
|
||||
assert.deepEqual([{ id: 'pub.a' }], testObject.getWorkspaceDisabledExtensions());
|
||||
assert.deepEqual([{ id: 'pub.a' }], testObject.getGloballyDisabledExtensions());
|
||||
})
|
||||
.then(done, done);
|
||||
test('test disable an extension globally and then for workspace', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.Disabled)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled))
|
||||
.then(() => testObject.getDisabledExtensions())
|
||||
.then(extensions => assert.deepEqual([{ id: 'pub.a' }], extensions));
|
||||
});
|
||||
|
||||
test('test disable an extension globally and then for workspace return a truthy promise', (done) => {
|
||||
testObject.setEnablement({ id: 'pub.a' }, false)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, false, true))
|
||||
.then(value => assert.ok(value))
|
||||
.then(done, done);
|
||||
test('test disable an extension globally and then for workspace return a truthy promise', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.Disabled)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled))
|
||||
.then(value => assert.ok(value));
|
||||
});
|
||||
|
||||
test('test disable an extension globally and then for workspace triggers the change event', (done) => {
|
||||
test('test disable an extension globally and then for workspace triggers the change event', () => {
|
||||
const target = sinon.spy();
|
||||
testObject.setEnablement({ id: 'pub.a' }, false)
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.Disabled)
|
||||
.then(() => testObject.onEnablementChanged(target))
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, false, true))
|
||||
.then(() => assert.ok(target.calledWithExactly({ id: 'pub.a' })))
|
||||
.then(done, done);
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled))
|
||||
.then(() => assert.ok(target.calledWithExactly({ id: 'pub.a' })));
|
||||
});
|
||||
|
||||
test('test disable an extension for workspace when there is no workspace throws error', (done) => {
|
||||
instantiationService.stub(IWorkspaceContextService, 'getWorkbenchState', WorkbenchState.EMPTY);
|
||||
testObject.setEnablement({ id: 'pub.a' }, false, true)
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled)
|
||||
.then(() => assert.fail('should throw an error'), error => assert.ok(error))
|
||||
.then(done, done);
|
||||
});
|
||||
|
||||
test('test enable an extension globally', (done) => {
|
||||
testObject.setEnablement({ id: 'pub.a' }, false)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, true))
|
||||
.then(() => assert.deepEqual([], testObject.getGloballyDisabledExtensions()))
|
||||
.then(done, done);
|
||||
test('test enable an extension globally', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.Disabled)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.Enabled))
|
||||
.then(() => testObject.getDisabledExtensions())
|
||||
.then(extensions => assert.deepEqual([], extensions));
|
||||
});
|
||||
|
||||
test('test enable an extension globally return truthy promise', (done) => {
|
||||
testObject.setEnablement({ id: 'pub.a' }, false)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, true))
|
||||
testObject.setEnablement({ id: 'pub.a' }, EnablementState.Disabled)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.Enabled))
|
||||
.then(value => assert.ok(value))
|
||||
.then(done, done);
|
||||
});
|
||||
|
||||
test('test enable an extension globally triggers change event', (done) => {
|
||||
const target = sinon.spy();
|
||||
testObject.setEnablement({ id: 'pub.a' }, false)
|
||||
testObject.setEnablement({ id: 'pub.a' }, EnablementState.Disabled)
|
||||
.then(() => testObject.onEnablementChanged(target))
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, true))
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.Enabled))
|
||||
.then(() => assert.ok(target.calledWithExactly({ id: 'pub.a' })))
|
||||
.then(done, done);
|
||||
});
|
||||
|
||||
test('test enable an extension globally when already enabled return falsy promise', (done) => {
|
||||
testObject.setEnablement({ id: 'pub.a' }, true)
|
||||
testObject.setEnablement({ id: 'pub.a' }, EnablementState.Enabled)
|
||||
.then(value => assert.ok(!value))
|
||||
.then(done, done);
|
||||
});
|
||||
|
||||
test('test enable an extension for workspace', (done) => {
|
||||
testObject.setEnablement({ id: 'pub.a' }, false, true)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, true, true))
|
||||
.then(() => assert.deepEqual([], testObject.getWorkspaceDisabledExtensions()))
|
||||
.then(done, done);
|
||||
test('test enable an extension for workspace', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceEnabled))
|
||||
.then(() => testObject.getDisabledExtensions())
|
||||
.then(extensions => assert.deepEqual([], extensions));
|
||||
});
|
||||
|
||||
test('test enable an extension for workspace return truthy promise', (done) => {
|
||||
testObject.setEnablement({ id: 'pub.a' }, false, true)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, true, true))
|
||||
.then(value => assert.ok(value))
|
||||
.then(done, done);
|
||||
test('test enable an extension for workspace return truthy promise', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceEnabled))
|
||||
.then(value => assert.ok(value));
|
||||
});
|
||||
|
||||
test('test enable an extension for workspace triggers change event', (done) => {
|
||||
test('test enable an extension for workspace triggers change event', () => {
|
||||
const target = sinon.spy();
|
||||
testObject.setEnablement({ id: 'pub.b' }, false, true)
|
||||
return testObject.setEnablement({ id: 'pub.b' }, EnablementState.WorkspaceDisabled)
|
||||
.then(() => testObject.onEnablementChanged(target))
|
||||
.then(() => testObject.setEnablement({ id: 'pub.b' }, true, true))
|
||||
.then(() => assert.ok(target.calledWithExactly({ id: 'pub.b' })))
|
||||
.then(done, done);
|
||||
.then(() => testObject.setEnablement({ id: 'pub.b' }, EnablementState.WorkspaceEnabled))
|
||||
.then(() => assert.ok(target.calledWithExactly({ id: 'pub.b' })));
|
||||
});
|
||||
|
||||
test('test enable an extension for workspace when already enabled return falsy promise', (done) => {
|
||||
testObject.setEnablement({ id: 'pub.a' }, true, true)
|
||||
.then(value => assert.ok(!value))
|
||||
.then(done, done);
|
||||
test('test enable an extension for workspace when already enabled return truthy promise', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceEnabled)
|
||||
.then(value => assert.ok(value));
|
||||
});
|
||||
|
||||
test('test enable an extension for workspace when disabled in workspace and gloablly', (done) => {
|
||||
testObject.setEnablement({ id: 'pub.a' }, false, true)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, false))
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, true, true))
|
||||
.then(() => {
|
||||
assert.deepEqual([{ id: 'pub.a' }], testObject.getGloballyDisabledExtensions());
|
||||
assert.deepEqual([], testObject.getWorkspaceDisabledExtensions());
|
||||
})
|
||||
.then(done, done);
|
||||
test('test enable an extension for workspace when disabled in workspace and gloablly', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.Disabled))
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceEnabled))
|
||||
.then(() => testObject.getDisabledExtensions())
|
||||
.then(extensions => assert.deepEqual([], extensions));
|
||||
});
|
||||
|
||||
test('test enable an extension globally when disabled in workspace and gloablly', (done) => {
|
||||
testObject.setEnablement({ id: 'pub.a' }, false, true)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, false))
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, true))
|
||||
.then(() => {
|
||||
assert.deepEqual([{ id: 'pub.a' }], testObject.getWorkspaceDisabledExtensions());
|
||||
assert.deepEqual([], testObject.getGloballyDisabledExtensions());
|
||||
})
|
||||
.then(done, done);
|
||||
test('test enable an extension globally when disabled in workspace and gloablly', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.Disabled))
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.Enabled))
|
||||
.then(() => testObject.getDisabledExtensions())
|
||||
.then(extensions => assert.deepEqual([], extensions));
|
||||
});
|
||||
|
||||
test('test remove an extension from disablement list when uninstalled', (done) => {
|
||||
testObject.setEnablement({ id: 'pub.a' }, false, true)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, false))
|
||||
test('test remove an extension from disablement list when uninstalled', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.a' }, EnablementState.Disabled))
|
||||
.then(() => didUninstallEvent.fire({ identifier: { id: 'pub.a-1.0.0' } }))
|
||||
.then(() => {
|
||||
assert.deepEqual([], testObject.getWorkspaceDisabledExtensions());
|
||||
assert.deepEqual([], testObject.getGloballyDisabledExtensions());
|
||||
})
|
||||
.then(done, done);
|
||||
.then(() => testObject.getDisabledExtensions())
|
||||
.then(extensions => assert.deepEqual([], extensions));
|
||||
});
|
||||
|
||||
test('test isEnabled return false extension is disabled globally', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.Disabled)
|
||||
.then(() => assert.ok(!testObject.isEnabled({ id: 'pub.a' })));
|
||||
});
|
||||
|
||||
test('test isEnabled return false extension is disabled in workspace', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled)
|
||||
.then(() => assert.ok(!testObject.isEnabled({ id: 'pub.a' })));
|
||||
});
|
||||
|
||||
test('test isEnabled return true extension is not disabled', () => {
|
||||
return testObject.setEnablement({ id: 'pub.a' }, EnablementState.WorkspaceDisabled)
|
||||
.then(() => testObject.setEnablement({ id: 'pub.c' }, EnablementState.Disabled))
|
||||
.then(() => assert.ok(testObject.isEnabled({ id: 'pub.b' })));
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,51 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import * as os from 'os';
|
||||
import extfs = require('vs/base/node/extfs');
|
||||
import { EnvironmentService } from 'vs/platform/environment/node/environmentService';
|
||||
import { parseArgs } from 'vs/platform/environment/node/argv';
|
||||
import { getRandomTestPath } from 'vs/workbench/test/workbenchTestServices';
|
||||
import { join } from 'path';
|
||||
import { mkdirp } from 'vs/base/node/pfs';
|
||||
import { resolveMarketplaceHeaders } from 'vs/platform/extensionManagement/node/extensionGalleryService';
|
||||
import { isUUID } from 'vs/base/common/uuid';
|
||||
|
||||
suite('Extension Gallery Service', () => {
|
||||
const parentDir = getRandomTestPath(os.tmpdir(), 'vsctests', 'extensiongalleryservice');
|
||||
const marketplaceHome = join(parentDir, 'Marketplace');
|
||||
|
||||
setup(done => {
|
||||
|
||||
// Delete any existing backups completely and then re-create it.
|
||||
extfs.del(marketplaceHome, os.tmpdir(), () => {
|
||||
mkdirp(marketplaceHome).then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
teardown(done => {
|
||||
extfs.del(marketplaceHome, os.tmpdir(), done);
|
||||
});
|
||||
|
||||
test('marketplace machine id', done => {
|
||||
const args = ['--user-data-dir', marketplaceHome];
|
||||
const environmentService = new EnvironmentService(parseArgs(args), process.execPath);
|
||||
|
||||
return resolveMarketplaceHeaders(environmentService).then(headers => {
|
||||
assert.ok(isUUID(headers['X-Market-User-Id']));
|
||||
|
||||
return resolveMarketplaceHeaders(environmentService).then(headers2 => {
|
||||
assert.equal(headers['X-Market-User-Id'], headers2['X-Market-User-Id']);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user