environment - depend on product service

This commit is contained in:
Benjamin Pasero 2021-03-15 11:56:03 +01:00
parent eb90b1c59c
commit 68a252ea77
No known key found for this signature in database
GPG key ID: E6380CC4C8219E65
17 changed files with 55 additions and 42 deletions

View file

@ -49,7 +49,7 @@ export class LanguagePackCachedDataCleaner extends Disposable {
let handle: any = setTimeout(async () => {
handle = undefined;
this._logService.info('Starting to clean up unused language packs.');
const maxAge = this._productService.nameLong.indexOf('Insiders') >= 0
const maxAge = this._productService.quality !== 'stable'
? 1000 * 60 * 60 * 24 * 7 // roughly 1 week
: 1000 * 60 * 60 * 24 * 30 * 3; // roughly 3 months
try {

View file

@ -144,8 +144,12 @@ class SharedProcessMain extends Disposable {
private async initServices(): Promise<IInstantiationService> {
const services = new ServiceCollection();
// Product
const productService = { _serviceBrand: undefined, ...product };
services.set(IProductService, productService);
// Environment
const environmentService = new NativeEnvironmentService(this.configuration.args);
const environmentService = new NativeEnvironmentService(this.configuration.args, productService);
services.set(INativeEnvironmentService, environmentService);
// Log
@ -183,10 +187,6 @@ class SharedProcessMain extends Disposable {
await storageService.initialize();
this._register(toDisposable(() => storageService.flush()));
// Product
const productService = { _serviceBrand: undefined, ...product };
services.set(IProductService, productService);
// Request
services.set(IRequestService, new SyncDescriptor(RequestService));

View file

@ -129,8 +129,12 @@ class CodeMain {
private createServices(args: NativeParsedArgs): [IInstantiationService, IProcessEnvironment, IEnvironmentMainService, ConfigurationService, StateService, BufferLogService, IProductService] {
const services = new ServiceCollection();
// Product
const productService = { _serviceBrand: undefined, ...product };
services.set(IProductService, productService);
// Environment
const environmentMainService = new EnvironmentMainService(args);
const environmentMainService = new EnvironmentMainService(args, productService);
const instanceEnvironment = this.patchEnvironment(environmentMainService); // Patch `process.env` with the instance's environment
services.set(IEnvironmentMainService, environmentMainService);
@ -171,10 +175,6 @@ class CodeMain {
// Signing
services.set(ISignService, new SyncDescriptor(SignService));
// Product
const productService = { _serviceBrand: undefined, ...product };
services.set(IProductService, productService);
// Tunnel
services.set(ITunnelService, new SyncDescriptor(TunnelService));

View file

@ -95,8 +95,12 @@ class CliMain extends Disposable {
private async initServices(): Promise<[IInstantiationService, AppInsightsAppender[]]> {
const services = new ServiceCollection();
// Product
const productService = { _serviceBrand: undefined, ...product };
services.set(IProductService, productService);
// Environment
const environmentService = new NativeEnvironmentService(this.argv);
const environmentService = new NativeEnvironmentService(this.argv, productService);
services.set(INativeEnvironmentService, environmentService);
// Init folders
@ -131,10 +135,6 @@ class CliMain extends Disposable {
const stateService = new StateService(environmentService, logService);
services.set(IStateService, stateService);
// Product
const productService = { _serviceBrand: undefined, ...product };
services.set(IProductService, productService);
const { appRoot, extensionsPath, extensionDevelopmentLocationURI, isBuilt, installSourcePath } = environmentService;
// Request

View file

@ -23,6 +23,7 @@ import { createHash } from 'crypto';
import { flakySuite, getRandomTestPath } from 'vs/base/test/node/testUtils';
import { Schemas } from 'vs/base/common/network';
import { isEqual } from 'vs/base/common/resources';
import product from 'vs/platform/product/common/product';
flakySuite('BackupMainService', () => {
@ -104,7 +105,7 @@ flakySuite('BackupMainService', () => {
backupWorkspacesPath = path.join(backupHome, 'workspaces.json');
existingTestFolder1 = URI.file(path.join(testDir, 'folder1'));
environmentService = new EnvironmentMainService(parseArgs(process.argv, OPTIONS));
environmentService = new EnvironmentMainService(parseArgs(process.argv, OPTIONS), { _serviceBrand: undefined, ...product });
await fs.promises.mkdir(backupHome, { recursive: true });

View file

@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import product from 'vs/platform/product/common/product';
import { IProductService } from 'vs/platform/product/common/productService';
import { IDebugParams, IExtensionHostDebugParams, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
import { dirname, join, normalize, resolve } from 'vs/base/common/path';
@ -103,7 +103,7 @@ export abstract class AbstractNativeEnvironmentService implements INativeEnviron
return URI.file(join(vscodePortable, 'argv.json'));
}
return joinPath(this.userHome, product.dataFolderName, 'argv.json');
return joinPath(this.userHome, this.productService.dataFolderName, 'argv.json');
}
@memoize
@ -154,7 +154,7 @@ export abstract class AbstractNativeEnvironmentService implements INativeEnviron
return join(vscodePortable, 'extensions');
}
return joinPath(this.userHome, product.dataFolderName, 'extensions').fsPath;
return joinPath(this.userHome, this.productService.dataFolderName, 'extensions').fsPath;
}
@memoize
@ -233,7 +233,11 @@ export abstract class AbstractNativeEnvironmentService implements INativeEnviron
get args(): NativeParsedArgs { return this._args; }
constructor(private readonly _args: NativeParsedArgs, private paths: INativeEnvironmentPaths) { }
constructor(
private readonly _args: NativeParsedArgs,
private readonly paths: INativeEnvironmentPaths,
protected readonly productService: IProductService
) { }
}
export function parseExtensionHostPort(args: NativeParsedArgs, isBuild: boolean): IExtensionHostDebugParams {

View file

@ -9,7 +9,6 @@ import { refineServiceDecorator } from 'vs/platform/instantiation/common/instant
import { IEnvironmentService, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { NativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import { createStaticIPCHandle } from 'vs/base/parts/ipc/node/ipc.net';
import product from 'vs/platform/product/common/product';
export const IEnvironmentMainService = refineServiceDecorator<IEnvironmentService, IEnvironmentMainService>(IEnvironmentService);
@ -51,7 +50,7 @@ export class EnvironmentMainService extends NativeEnvironmentService implements
get backupWorkspacesPath(): string { return join(this.backupHome, 'workspaces.json'); }
@memoize
get mainIPCHandle(): string { return createStaticIPCHandle(this.userDataPath, 'main', product.version); }
get mainIPCHandle(): string { return createStaticIPCHandle(this.userDataPath, 'main', this.productService.version); }
@memoize
get sandbox(): boolean { return !!this.args['__sandbox']; }

View file

@ -7,14 +7,15 @@ import { homedir, tmpdir } from 'os';
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
import { getUserDataPath } from 'vs/platform/environment/node/userDataPath';
import { AbstractNativeEnvironmentService } from 'vs/platform/environment/common/environmentService';
import { IProductService } from 'vs/platform/product/common/productService';
export class NativeEnvironmentService extends AbstractNativeEnvironmentService {
constructor(args: NativeParsedArgs) {
constructor(args: NativeParsedArgs, productService: IProductService) {
super(args, {
homeDir: homedir(),
tmpDir: tmpdir(),
userDataDir: getUserDataPath(args)
});
}, productService);
}
}

View file

@ -7,6 +7,7 @@ import * as assert from 'assert';
import { parseArgs, OPTIONS } from 'vs/platform/environment/node/argv';
import { parseExtensionHostPort } from 'vs/platform/environment/common/environmentService';
import { NativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import product from 'vs/platform/product/common/product';
suite('EnvironmentService', () => {
@ -56,13 +57,13 @@ suite('EnvironmentService', () => {
});
test('userDataDir', () => {
const service1 = new NativeEnvironmentService(parseArgs(process.argv, OPTIONS));
const service1 = new NativeEnvironmentService(parseArgs(process.argv, OPTIONS), { _serviceBrand: undefined, ...product });
assert.ok(service1.userDataPath.length > 0);
const args = parseArgs(process.argv, OPTIONS);
args['user-data-dir'] = '/userDataDir/folder';
const service2 = new NativeEnvironmentService(args);
const service2 = new NativeEnvironmentService(args, { _serviceBrand: undefined, ...product });
assert.notStrictEqual(service1.userDataPath, service2.userDataPath);
});
});

View file

@ -17,9 +17,13 @@ import { Emitter, Event } from 'vs/base/common/event';
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
import { ICodeWindow } from 'vs/platform/windows/electron-main/windows';
import { Promises } from 'vs/base/common/async';
import product from 'vs/platform/product/common/product';
import { IProductService } from 'vs/platform/product/common/productService';
suite('StorageMainService', function () {
const productService: IProductService = { _serviceBrand: undefined, ...product };
class TestStorageMainService extends StorageMainService {
protected getStorageOptions(): IStorageMainOptions {
@ -122,14 +126,14 @@ suite('StorageMainService', function () {
}
test('basics (global)', function () {
const storageMainService = new TestStorageMainService(new NullLogService(), new NativeEnvironmentService(parseArgs(process.argv, OPTIONS)), new StorageTestLifecycleMainService());
const storageMainService = new TestStorageMainService(new NullLogService(), new NativeEnvironmentService(parseArgs(process.argv, OPTIONS), productService), new StorageTestLifecycleMainService());
return testStorage(storageMainService.globalStorage, true);
});
test('basics (workspace)', function () {
const workspace = { id: generateUuid() };
const storageMainService = new TestStorageMainService(new NullLogService(), new NativeEnvironmentService(parseArgs(process.argv, OPTIONS)), new StorageTestLifecycleMainService());
const storageMainService = new TestStorageMainService(new NullLogService(), new NativeEnvironmentService(parseArgs(process.argv, OPTIONS), productService), new StorageTestLifecycleMainService());
return testStorage(storageMainService.workspaceStorage(workspace), false);
});
@ -137,7 +141,7 @@ suite('StorageMainService', function () {
test('storage closed onWillShutdown', async function () {
const lifecycleMainService = new StorageTestLifecycleMainService();
const workspace = { id: generateUuid() };
const storageMainService = new TestStorageMainService(new NullLogService(), new NativeEnvironmentService(parseArgs(process.argv, OPTIONS)), lifecycleMainService);
const storageMainService = new TestStorageMainService(new NullLogService(), new NativeEnvironmentService(parseArgs(process.argv, OPTIONS), productService), lifecycleMainService);
let workspaceStorage = storageMainService.workspaceStorage(workspace);
let didCloseWorkspaceStorage = false;
@ -168,7 +172,7 @@ suite('StorageMainService', function () {
});
test('storage closed before init works', async function () {
const storageMainService = new TestStorageMainService(new NullLogService(), new NativeEnvironmentService(parseArgs(process.argv, OPTIONS)), new StorageTestLifecycleMainService());
const storageMainService = new TestStorageMainService(new NullLogService(), new NativeEnvironmentService(parseArgs(process.argv, OPTIONS), productService), new StorageTestLifecycleMainService());
const workspace = { id: generateUuid() };
let workspaceStorage = storageMainService.workspaceStorage(workspace);
@ -191,7 +195,7 @@ suite('StorageMainService', function () {
});
test('storage closed before init awaits works', async function () {
const storageMainService = new TestStorageMainService(new NullLogService(), new NativeEnvironmentService(parseArgs(process.argv, OPTIONS)), new StorageTestLifecycleMainService());
const storageMainService = new TestStorageMainService(new NullLogService(), new NativeEnvironmentService(parseArgs(process.argv, OPTIONS), productService), new StorageTestLifecycleMainService());
const workspace = { id: generateUuid() };
let workspaceStorage = storageMainService.workspaceStorage(workspace);

View file

@ -23,6 +23,7 @@ import { INativeOpenDialogOptions } from 'vs/platform/dialogs/common/dialogs';
import { IBackupMainService, IWorkspaceBackupInfo } from 'vs/platform/backup/electron-main/backup';
import { IEmptyWindowBackupInfo } from 'vs/platform/backup/node/backup';
import product from 'vs/platform/product/common/product';
import { IProductService } from 'vs/platform/product/common/productService';
suite('WorkspacesManagementMainService', () => {
@ -93,10 +94,12 @@ suite('WorkspacesManagementMainService', () => {
testDir = getRandomTestPath(tmpDir, 'vsctests', 'workspacesmanagementmainservice');
untitledWorkspacesHomePath = path.join(testDir, 'Workspaces');
const productService: IProductService = { _serviceBrand: undefined, ...product };
environmentMainService = new class TestEnvironmentService extends EnvironmentMainService {
constructor() {
super(parseArgs(process.argv, OPTIONS));
super(parseArgs(process.argv, OPTIONS), productService);
}
get untitledWorkspacesHome(): URI {
@ -104,7 +107,7 @@ suite('WorkspacesManagementMainService', () => {
}
};
service = new WorkspacesManagementMainService(environmentMainService, new NullLogService(), new TestBackupMainService(), new TestDialogMainService(), { _serviceBrand: undefined, ...product });
service = new WorkspacesManagementMainService(environmentMainService, new NullLogService(), new TestBackupMainService(), new TestDialogMainService(), productService);
return fs.promises.mkdir(untitledWorkspacesHomePath, { recursive: true });
});

View file

@ -21,7 +21,7 @@ import { registerWindowDriver } from 'vs/platform/driver/electron-browser/driver
class DesktopMain extends SharedDesktopMain {
constructor(configuration: INativeWorkbenchConfiguration) {
super(configuration, new NativeWorkbenchEnvironmentService(configuration, productService, { homeDir: os.homedir(), tmpDir: os.tmpdir(), userDataDir: getUserDataPath(configuration) }));
super(configuration, new NativeWorkbenchEnvironmentService(configuration, { homeDir: os.homedir(), tmpDir: os.tmpdir(), userDataDir: getUserDataPath(configuration) }, productService));
// Enable gracefulFs
gracefulify(fs);

View file

@ -15,7 +15,7 @@ import { productService, SharedDesktopMain } from 'vs/workbench/electron-sandbox
class DesktopMain extends SharedDesktopMain {
constructor(configuration: INativeWorkbenchConfiguration) {
super({ ...configuration, workspace: { id: configuration.workspace?.id ?? '4064f6ec-cb38-4ad0-af64-ee6467e63c82', uri: simpleWorkspaceDir } }, new NativeWorkbenchEnvironmentService(configuration, productService, { homeDir: simpleHomeDir.fsPath, tmpDir: simpleTmpDir.fsPath, userDataDir: simpleUserDataDir.fsPath }));
super({ ...configuration, workspace: { id: configuration.workspace?.id ?? '4064f6ec-cb38-4ad0-af64-ee6467e63c82', uri: simpleWorkspaceDir } }, new NativeWorkbenchEnvironmentService(configuration, { homeDir: simpleHomeDir.fsPath, tmpDir: simpleTmpDir.fsPath, userDataDir: simpleUserDataDir.fsPath }, productService));
}
protected registerFileSystemProviders(fileService: IFileService, logService: ILogService, nativeHostService: INativeHostService): void {

View file

@ -35,7 +35,7 @@ import { isEqual } from 'vs/base/common/resources';
class TestWorkbenchEnvironmentService extends NativeWorkbenchEnvironmentService {
constructor(testDir: string, backupPath: string) {
super({ ...TestWorkbenchConfiguration, backupPath, 'user-data-dir': testDir }, TestProductService, TestEnvironmentPaths);
super({ ...TestWorkbenchConfiguration, backupPath, 'user-data-dir': testDir }, TestEnvironmentPaths, TestProductService);
}
}

View file

@ -712,6 +712,6 @@ class MockInputsConfigurationService extends TestConfigurationService {
class MockWorkbenchEnvironmentService extends NativeWorkbenchEnvironmentService {
constructor(public userEnv: platform.IProcessEnvironment) {
super({ ...TestWorkbenchConfiguration, userEnv }, TestProductService, TestEnvironmentPaths);
super({ ...TestWorkbenchConfiguration, userEnv }, TestEnvironmentPaths, TestProductService);
}
}

View file

@ -106,9 +106,9 @@ export class NativeWorkbenchEnvironmentService extends AbstractNativeEnvironment
constructor(
readonly configuration: INativeWorkbenchConfiguration,
private readonly productService: IProductService,
paths: INativeEnvironmentPaths
paths: INativeEnvironmentPaths,
productService: IProductService
) {
super(configuration, paths);
super(configuration, paths, productService);
}
}

View file

@ -63,7 +63,7 @@ export const TestWorkbenchConfiguration: INativeWorkbenchConfiguration = {
export const TestEnvironmentPaths: INativeEnvironmentPaths = { homeDir: homedir(), tmpDir: tmpdir(), userDataDir: getUserDataPath(TestWorkbenchConfiguration) };
export const TestEnvironmentService = new NativeWorkbenchEnvironmentService(TestWorkbenchConfiguration, TestProductService, TestEnvironmentPaths);
export const TestEnvironmentService = new NativeWorkbenchEnvironmentService(TestWorkbenchConfiguration, TestEnvironmentPaths, TestProductService);
export class TestTextFileService extends NativeTextFileService {
private resolveTextContentError!: FileOperationError | null;