From dacb22517d668c3b6ae1bfe41362f968302ffab7 Mon Sep 17 00:00:00 2001 From: Yevhen Vydolob Date: Mon, 3 Jun 2019 09:48:03 +0300 Subject: [PATCH] #3871 Extract 'Hosted mode' in separate extension Signed-off-by: Yevhen Vydolob --- .travis.yml | 1 + CHANGELOG.md | 1 + examples/browser/package.json | 1 + examples/electron/package.json | 3 +- packages/plugin-dev/README.md | 10 ++ packages/plugin-dev/compile.tsconfig.json | 15 +++ packages/plugin-dev/package.json | 52 +++++++++ .../src}/browser/hosted-plugin-controller.ts | 4 +- .../hosted-plugin-frontend-contribution.ts | 45 ++++++++ .../src}/browser/hosted-plugin-informer.ts | 2 +- .../src}/browser/hosted-plugin-log-viewer.ts | 4 +- .../browser/hosted-plugin-manager-client.ts | 4 +- .../src}/browser/hosted-plugin-preferences.ts | 0 .../src/browser/plugin-dev-frontend-module.ts | 45 ++++++++ packages/plugin-dev/src/common/index.ts | 21 ++++ .../src/common/plugin-dev-protocol.ts | 44 ++++++++ .../plugin-dev-electron-backend-module.ts | 29 +++++ .../src}/node/hosted-instance-manager.ts | 14 ++- .../src/node/hosted-plugin-reader.ts | 57 ++++++++++ .../src/node/hosted-plugin-service.ts | 104 ++++++++++++++++++ .../node/hosted-plugin-uri-postprocessor.ts | 0 .../src}/node/hosted-plugins-manager.ts | 4 +- .../src/node/plugin-dev-backend-module.ts | 54 +++++++++ packages/plugin-dev/src/package.spec.ts | 28 +++++ packages/plugin-ext/README.md | 3 - packages/plugin-ext/package.json | 1 - packages/plugin-ext/src/common/index.ts | 4 - .../plugin-ext/src/common/plugin-protocol.ts | 17 --- .../src/hosted/browser/hosted-plugin.ts | 19 +--- ...ugin-ext-hosted-electron-backend-module.ts | 7 -- .../node/plugin-ext-hosted-backend-module.ts | 12 -- .../src/hosted/node/plugin-reader.ts | 24 +--- .../src/hosted/node/plugin-service.ts | 68 +----------- .../browser/plugin-ext-frontend-module.ts | 12 -- .../browser/plugin-frontend-contribution.ts | 19 ---- .../plugin-ext/src/plugin/tree/tree-views.ts | 3 +- tsconfig.json | 3 + 37 files changed, 542 insertions(+), 192 deletions(-) create mode 100644 packages/plugin-dev/README.md create mode 100644 packages/plugin-dev/compile.tsconfig.json create mode 100644 packages/plugin-dev/package.json rename packages/{plugin-ext/src/hosted => plugin-dev/src}/browser/hosted-plugin-controller.ts (98%) create mode 100644 packages/plugin-dev/src/browser/hosted-plugin-frontend-contribution.ts rename packages/{plugin-ext/src/hosted => plugin-dev/src}/browser/hosted-plugin-informer.ts (98%) rename packages/{plugin-ext/src/hosted => plugin-dev/src}/browser/hosted-plugin-log-viewer.ts (92%) rename packages/{plugin-ext/src/hosted => plugin-dev/src}/browser/hosted-plugin-manager-client.ts (98%) rename packages/{plugin-ext/src/hosted => plugin-dev/src}/browser/hosted-plugin-preferences.ts (100%) create mode 100644 packages/plugin-dev/src/browser/plugin-dev-frontend-module.ts create mode 100644 packages/plugin-dev/src/common/index.ts create mode 100644 packages/plugin-dev/src/common/plugin-dev-protocol.ts create mode 100644 packages/plugin-dev/src/node-electron/plugin-dev-electron-backend-module.ts rename packages/{plugin-ext/src/hosted => plugin-dev/src}/node/hosted-instance-manager.ts (96%) create mode 100644 packages/plugin-dev/src/node/hosted-plugin-reader.ts create mode 100644 packages/plugin-dev/src/node/hosted-plugin-service.ts rename packages/{plugin-ext/src/hosted => plugin-dev/src}/node/hosted-plugin-uri-postprocessor.ts (100%) rename packages/{plugin-ext/src/hosted => plugin-dev/src}/node/hosted-plugins-manager.ts (97%) create mode 100644 packages/plugin-dev/src/node/plugin-dev-backend-module.ts create mode 100644 packages/plugin-dev/src/package.spec.ts diff --git a/.travis.yml b/.travis.yml index 8c0ad507a22a7..b70d3ddc5260a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,6 +44,7 @@ cache: - packages/navigator/node_modules - packages/outline-view/node_modules - packages/output/node_modules + - packages/plugin-dev/node_modules - packages/plugin-ext-vscode/node_modules - packages/plugin-ext/node_modules - packages/plugin/node_modules diff --git a/CHANGELOG.md b/CHANGELOG.md index fd0844288d8ba..c85a301cf6184 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Breaking changes: +- [plugin] 'Hosted mode' extracted in `plugin-dev` extension - [core] `scheme` is mandatory for URI - `URI.withoutScheme` is removed, in order to get a path use `URI.path` diff --git a/examples/browser/package.json b/examples/browser/package.json index 0cfc6de25f474..c44e0e0907fee 100644 --- a/examples/browser/package.json +++ b/examples/browser/package.json @@ -41,6 +41,7 @@ "@theia/navigator": "^0.7.0", "@theia/outline-view": "^0.7.0", "@theia/output": "^0.7.0", + "@theia/plugin-dev": "^0.7.0", "@theia/plugin-ext": "^0.7.0", "@theia/plugin-ext-vscode": "^0.7.0", "@theia/preferences": "^0.7.0", diff --git a/examples/electron/package.json b/examples/electron/package.json index 18b3fb785a657..cac68f0c3de25 100644 --- a/examples/electron/package.json +++ b/examples/electron/package.json @@ -39,7 +39,8 @@ "@theia/navigator": "^0.7.0", "@theia/outline-view": "^0.7.0", "@theia/output": "^0.7.0", - "@theia/plugin": "^0.7.0", + "@theia/plugin-dev": "^0.7.0", + "@theia/plugin-ext": "^0.7.0", "@theia/plugin-ext-vscode": "^0.7.0", "@theia/preferences": "^0.7.0", "@theia/preview": "^0.7.0", diff --git a/packages/plugin-dev/README.md b/packages/plugin-dev/README.md new file mode 100644 index 0000000000000..7fefac3f89968 --- /dev/null +++ b/packages/plugin-dev/README.md @@ -0,0 +1,10 @@ +# Theia - Plugin Development + +See [here](https://www.theia-ide.org/doc/index.html) for a detailed documentation. + +## Contribution points: + - Hosted Instance uri post processor + +## License +- [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/) +- [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp) diff --git a/packages/plugin-dev/compile.tsconfig.json b/packages/plugin-dev/compile.tsconfig.json new file mode 100644 index 0000000000000..b24000a9aca92 --- /dev/null +++ b/packages/plugin-dev/compile.tsconfig.json @@ -0,0 +1,15 @@ +{ + "extends": "../../configs/base.tsconfig", + "compilerOptions": { + "rootDir": "src", + "outDir": "lib", + "lib": [ + "es6", + "dom" + ] + }, + "include": [ + "src" + ] +} + diff --git a/packages/plugin-dev/package.json b/packages/plugin-dev/package.json new file mode 100644 index 0000000000000..a892c8031fd3a --- /dev/null +++ b/packages/plugin-dev/package.json @@ -0,0 +1,52 @@ +{ + "name": "@theia/plugin-dev", + "version": "0.7.0", + "description": "Theia - Plugin Development Extension", + "main": "lib/common/index.js", + "typings": "lib/common/index.d.ts", + "dependencies": { + "@theia/core": "^0.7.0", + "@theia/plugin-ext": "^0.7.0", + "@theia/preferences": "^0.7.0", + "ps-tree": "1.1.0" + }, + "publishConfig": { + "access": "public" + }, + "theiaExtensions": [ + { + "backend": "lib/node/plugin-dev-backend-module", + "backendElectron": "lib/node-electron/plugin-dev-electron-backend-module", + "frontend": "lib/browser/plugin-dev-frontend-module" + } + ], + "keywords": [ + "theia-extension" + ], + "license": "EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0", + "repository": { + "type": "git", + "url": "https://github.com/theia-ide/theia.git" + }, + "bugs": { + "url": "https://github.com/theia-ide/theia/issues" + }, + "homepage": "https://github.com/theia-ide/theia", + "files": [ + "lib", + "src" + ], + "scripts": { + "prepare": "yarn run clean && yarn run build", + "clean": "theiaext clean", + "build": "theiaext build", + "watch": "theiaext watch", + "test": "theiaext test" + }, + "devDependencies": { + "@theia/ext-scripts": "^0.7.0" + }, + "nyc": { + "extends": "../../configs/nyc.json" + } +} diff --git a/packages/plugin-ext/src/hosted/browser/hosted-plugin-controller.ts b/packages/plugin-dev/src/browser/hosted-plugin-controller.ts similarity index 98% rename from packages/plugin-ext/src/hosted/browser/hosted-plugin-controller.ts rename to packages/plugin-dev/src/browser/hosted-plugin-controller.ts index cefc219ee8735..a234a2bd0877c 100644 --- a/packages/plugin-ext/src/hosted/browser/hosted-plugin-controller.ts +++ b/packages/plugin-dev/src/browser/hosted-plugin-controller.ts @@ -23,7 +23,7 @@ import { CommandRegistry } from '@phosphor/commands'; import { Menu } from '@phosphor/widgets'; import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state'; import { ConnectionStatusService, ConnectionStatus } from '@theia/core/lib/browser/connection-status-service'; -import { HostedPluginServer } from '../../common/plugin-protocol'; +import { HostedPluginServer } from '../common/plugin-dev-protocol'; import { HostedPluginManagerClient, HostedInstanceState, HostedPluginCommands, HostedInstanceData } from './hosted-plugin-manager-client'; import { HostedPluginLogViewer } from './hosted-plugin-log-viewer'; import { HostedPluginPreferences } from './hosted-plugin-preferences'; @@ -102,6 +102,8 @@ export class HostedPluginController implements FrontendApplicationContribution { this.connectionStatusService.onStatusChange(() => this.onConnectionStatusChanged()); this.preferenceService.onPreferenceChanged(preference => this.onPreferencesChanged(preference)); + } else { + console.error(`Need to load plugin ${pluginMetadata.model.id}`); } }); } diff --git a/packages/plugin-dev/src/browser/hosted-plugin-frontend-contribution.ts b/packages/plugin-dev/src/browser/hosted-plugin-frontend-contribution.ts new file mode 100644 index 0000000000000..fa92c82281a34 --- /dev/null +++ b/packages/plugin-dev/src/browser/hosted-plugin-frontend-contribution.ts @@ -0,0 +1,45 @@ +/******************************************************************************** + * Copyright (C) 2019 Red Hat, Inc. and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ + +import { injectable, inject } from 'inversify'; +import { CommandRegistry, CommandContribution } from '@theia/core/lib/common'; +import { HostedPluginManagerClient, HostedPluginCommands } from './hosted-plugin-manager-client'; + +@injectable() +export class HostedPluginFrontendContribution implements CommandContribution { + + @inject(HostedPluginManagerClient) + protected readonly hostedPluginManagerClient: HostedPluginManagerClient; + + registerCommands(commands: CommandRegistry): void { + commands.registerCommand(HostedPluginCommands.START, { + execute: () => this.hostedPluginManagerClient.start() + }); + commands.registerCommand(HostedPluginCommands.DEBUG, { + execute: () => this.hostedPluginManagerClient.debug() + }); + commands.registerCommand(HostedPluginCommands.STOP, { + execute: () => this.hostedPluginManagerClient.stop() + }); + commands.registerCommand(HostedPluginCommands.RESTART, { + execute: () => this.hostedPluginManagerClient.restart() + }); + commands.registerCommand(HostedPluginCommands.SELECT_PATH, { + execute: () => this.hostedPluginManagerClient.selectPluginPath() + }); + + } +} diff --git a/packages/plugin-ext/src/hosted/browser/hosted-plugin-informer.ts b/packages/plugin-dev/src/browser/hosted-plugin-informer.ts similarity index 98% rename from packages/plugin-ext/src/hosted/browser/hosted-plugin-informer.ts rename to packages/plugin-dev/src/browser/hosted-plugin-informer.ts index 7a73eb78cde5a..d165aad5d19a8 100644 --- a/packages/plugin-ext/src/hosted/browser/hosted-plugin-informer.ts +++ b/packages/plugin-dev/src/browser/hosted-plugin-informer.ts @@ -18,7 +18,7 @@ import { injectable, inject } from 'inversify'; import { StatusBar } from '@theia/core/lib/browser/status-bar/status-bar'; import { StatusBarAlignment, StatusBarEntry, FrontendApplicationContribution } from '@theia/core/lib/browser'; import { WorkspaceService } from '@theia/workspace/lib/browser'; -import { HostedPluginServer } from '../../common/plugin-protocol'; +import { HostedPluginServer } from '../common/plugin-dev-protocol'; import { ConnectionStatusService, ConnectionStatus } from '@theia/core/lib/browser/connection-status-service'; import URI from '@theia/core/lib/common/uri'; import { FileStat } from '@theia/filesystem/lib/common'; diff --git a/packages/plugin-ext/src/hosted/browser/hosted-plugin-log-viewer.ts b/packages/plugin-dev/src/browser/hosted-plugin-log-viewer.ts similarity index 92% rename from packages/plugin-ext/src/hosted/browser/hosted-plugin-log-viewer.ts rename to packages/plugin-dev/src/browser/hosted-plugin-log-viewer.ts index c56bde6bf7514..c8c487fa59d39 100644 --- a/packages/plugin-ext/src/hosted/browser/hosted-plugin-log-viewer.ts +++ b/packages/plugin-dev/src/browser/hosted-plugin-log-viewer.ts @@ -17,8 +17,8 @@ import { injectable, inject, postConstruct } from 'inversify'; import { OutputChannel, OutputChannelManager } from '@theia/output/lib/common/output-channel'; import { OutputContribution } from '@theia/output/lib/browser/output-contribution'; -import { HostedPluginWatcher } from './hosted-plugin-watcher'; -import { LogPart } from '../../common/types'; +import { LogPart } from '@theia/plugin-ext/lib/common/types'; +import { HostedPluginWatcher } from '@theia/plugin-ext/lib/hosted/browser/hosted-plugin-watcher'; @injectable() export class HostedPluginLogViewer { diff --git a/packages/plugin-ext/src/hosted/browser/hosted-plugin-manager-client.ts b/packages/plugin-dev/src/browser/hosted-plugin-manager-client.ts similarity index 98% rename from packages/plugin-ext/src/hosted/browser/hosted-plugin-manager-client.ts rename to packages/plugin-dev/src/browser/hosted-plugin-manager-client.ts index 092feb4c473c3..8aaf1bbe3f372 100644 --- a/packages/plugin-ext/src/hosted/browser/hosted-plugin-manager-client.ts +++ b/packages/plugin-dev/src/browser/hosted-plugin-manager-client.ts @@ -23,8 +23,8 @@ import { WindowService } from '@theia/core/lib/browser/window/window-service'; import { WorkspaceService } from '@theia/workspace/lib/browser'; import { FileSystem } from '@theia/filesystem/lib/common'; import { OpenFileDialogFactory, DirNode } from '@theia/filesystem/lib/browser'; -import { HostedPluginServer } from '../../common/plugin-protocol'; -import { DebugConfiguration as HostedDebugConfig } from '../../common'; +import { HostedPluginServer } from '../common/plugin-dev-protocol'; +import { DebugConfiguration as HostedDebugConfig } from '../common'; import { DebugSessionManager } from '@theia/debug/lib/browser/debug-session-manager'; import { HostedPluginPreferences } from './hosted-plugin-preferences'; diff --git a/packages/plugin-ext/src/hosted/browser/hosted-plugin-preferences.ts b/packages/plugin-dev/src/browser/hosted-plugin-preferences.ts similarity index 100% rename from packages/plugin-ext/src/hosted/browser/hosted-plugin-preferences.ts rename to packages/plugin-dev/src/browser/hosted-plugin-preferences.ts diff --git a/packages/plugin-dev/src/browser/plugin-dev-frontend-module.ts b/packages/plugin-dev/src/browser/plugin-dev-frontend-module.ts new file mode 100644 index 0000000000000..c09f2f231183a --- /dev/null +++ b/packages/plugin-dev/src/browser/plugin-dev-frontend-module.ts @@ -0,0 +1,45 @@ +/******************************************************************************** + * Copyright (C) 2019 Red Hat, Inc. and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ + +import { HostedPluginLogViewer } from './hosted-plugin-log-viewer'; +import { HostedPluginManagerClient } from './hosted-plugin-manager-client'; +import { HostedPluginInformer } from './hosted-plugin-informer'; +import { bindHostedPluginPreferences } from './hosted-plugin-preferences'; +import { HostedPluginController } from './hosted-plugin-controller'; +import { ContainerModule } from 'inversify'; +import { FrontendApplicationContribution, WebSocketConnectionProvider } from '@theia/core/lib/browser'; +import { HostedPluginFrontendContribution } from './hosted-plugin-frontend-contribution'; +import { CommandContribution } from '@theia/core/lib/common/command'; +import { HostedPluginServer, hostedServicePath } from '../common/plugin-dev-protocol'; +import { HostedPluginWatcher } from '@theia/plugin-ext/lib/hosted/browser/hosted-plugin-watcher'; + +export default new ContainerModule((bind, unbind, isBound, rebind) => { + bindHostedPluginPreferences(bind); + bind(HostedPluginLogViewer).toSelf().inSingletonScope(); + bind(HostedPluginManagerClient).toSelf().inSingletonScope(); + + bind(FrontendApplicationContribution).to(HostedPluginInformer).inSingletonScope(); + bind(FrontendApplicationContribution).to(HostedPluginController).inSingletonScope(); + + bind(HostedPluginFrontendContribution).toSelf().inSingletonScope(); + bind(CommandContribution).toService(HostedPluginFrontendContribution); + + bind(HostedPluginServer).toDynamicValue(ctx => { + const connection = ctx.container.get(WebSocketConnectionProvider); + const hostedWatcher = ctx.container.get(HostedPluginWatcher); + return connection.createProxy(hostedServicePath, hostedWatcher.getHostedPluginClient()); + }).inSingletonScope(); +}); diff --git a/packages/plugin-dev/src/common/index.ts b/packages/plugin-dev/src/common/index.ts new file mode 100644 index 0000000000000..7e46d61c6eeda --- /dev/null +++ b/packages/plugin-dev/src/common/index.ts @@ -0,0 +1,21 @@ +/******************************************************************************** + * Copyright (C) 2019 Red Hat, Inc. and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ + +// Exports contribution point for uri postprocessor of hosted plugin manager. +// This could be used to alter hosted instance uri, for example, change port. +export * from '../node/hosted-plugin-uri-postprocessor'; + +export * from './plugin-dev-protocol'; diff --git a/packages/plugin-dev/src/common/plugin-dev-protocol.ts b/packages/plugin-dev/src/common/plugin-dev-protocol.ts new file mode 100644 index 0000000000000..677d2d67e1902 --- /dev/null +++ b/packages/plugin-dev/src/common/plugin-dev-protocol.ts @@ -0,0 +1,44 @@ +/******************************************************************************** + * Copyright (C) 2019 Red Hat, Inc. and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ + +import { JsonRpcServer } from '@theia/core/lib/common/messaging/proxy-factory'; +import { PluginMetadata } from '@theia/plugin-ext/lib/common/plugin-protocol'; + +export const hostedServicePath = '/services/plugin-dev'; +export const HostedPluginServer = Symbol('HostedPluginServer'); +export interface HostedPluginServer extends JsonRpcServer { + getHostedPlugin(): Promise; + runHostedPluginInstance(uri: string): Promise; + runDebugHostedPluginInstance(uri: string, debugConfig: DebugConfiguration): Promise; + terminateHostedPluginInstance(): Promise; + isHostedPluginInstanceRunning(): Promise; + getHostedPluginInstanceURI(): Promise; + getHostedPluginURI(): Promise; + + runWatchCompilation(uri: string): Promise; + stopWatchCompilation(uri: string): Promise; + isWatchCompilationRunning(uri: string): Promise; + + isPluginValid(uri: string): Promise; +} + +export interface HostedPluginClient { +} + +export interface DebugConfiguration { + port?: number; + debugMode?: string; +} diff --git a/packages/plugin-dev/src/node-electron/plugin-dev-electron-backend-module.ts b/packages/plugin-dev/src/node-electron/plugin-dev-electron-backend-module.ts new file mode 100644 index 0000000000000..494388d5846f8 --- /dev/null +++ b/packages/plugin-dev/src/node-electron/plugin-dev-electron-backend-module.ts @@ -0,0 +1,29 @@ +/******************************************************************************** + * Copyright (C) 2019 Red Hat, Inc. and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ + +import { HostedInstanceManager, ElectronNodeHostedPluginRunner } from '../node/hosted-instance-manager'; +import { ContainerModule } from 'inversify'; +import { ConnectionContainerModule } from '@theia/core/lib/node/messaging/connection-container-module'; +import { bindCommonHostedBackend } from '../node/plugin-dev-backend-module'; + +const hostedBackendConnectionModule = ConnectionContainerModule.create(({ bind }) => { + bind(HostedInstanceManager).to(ElectronNodeHostedPluginRunner); +}); + +export default new ContainerModule(bind => { + bindCommonHostedBackend(bind); + bind(ConnectionContainerModule).toConstantValue(hostedBackendConnectionModule); +}); diff --git a/packages/plugin-ext/src/hosted/node/hosted-instance-manager.ts b/packages/plugin-dev/src/node/hosted-instance-manager.ts similarity index 96% rename from packages/plugin-ext/src/hosted/node/hosted-instance-manager.ts rename to packages/plugin-dev/src/node/hosted-instance-manager.ts index e7eb7bcb2d5ed..53c859c99f567 100644 --- a/packages/plugin-ext/src/hosted/node/hosted-instance-manager.ts +++ b/packages/plugin-dev/src/node/hosted-instance-manager.ts @@ -23,13 +23,13 @@ import * as request from 'request'; import URI from '@theia/core/lib/common/uri'; import { ContributionProvider } from '@theia/core/lib/common/contribution-provider'; -import { LogType } from './../../common/types'; import { HostedPluginUriPostProcessor, HostedPluginUriPostProcessorSymbolName } from './hosted-plugin-uri-postprocessor'; -import { HostedPluginSupport } from './hosted-plugin'; -import { DebugConfiguration } from '../../common'; +import { DebugConfiguration } from '../common'; import { environment } from '@theia/core'; -import { MetadataScanner } from './metadata-scanner'; import { FileUri } from '@theia/core/lib/node/file-uri'; +import { LogType } from '@theia/plugin-ext/lib/common/types'; +import { HostedPluginSupport } from '@theia/plugin-ext/lib/hosted/node/hosted-plugin'; +import { MetadataScanner } from '@theia/plugin-ext/lib/hosted/node/metadata-scanner'; const processTree = require('ps-tree'); export const HostedInstanceManager = Symbol('HostedInstanceManager'); @@ -190,8 +190,8 @@ export abstract class AbstractHostedInstanceManager implements HostedInstanceMan /** * Start a loop to ping, if ping is OK return immediately, else start a new ping after 1second. We iterate for the given amount of loops provided in remainingCount - * @param remainingCount the number of occurence to check - * @param resolve resolvefunction if ok + * @param remainingCount the number of occurrence to check + * @param resolve resolve function if ok * @param reject reject function if error */ private async pingLoop(remainingCount: number, @@ -246,11 +246,13 @@ export abstract class AbstractHostedInstanceManager implements HostedInstanceMan } else { command = processArguments.filter((arg, index, args) => { // remove --port=X and --port X arguments if set + // remove --plugins arguments if (arg.startsWith('--port') || args[index - 1] === '--port') { return; } else { return arg; } + }); } if (process.env.HOSTED_PLUGIN_HOSTNAME) { diff --git a/packages/plugin-dev/src/node/hosted-plugin-reader.ts b/packages/plugin-dev/src/node/hosted-plugin-reader.ts new file mode 100644 index 0000000000000..995169fec0108 --- /dev/null +++ b/packages/plugin-dev/src/node/hosted-plugin-reader.ts @@ -0,0 +1,57 @@ +/******************************************************************************** + * Copyright (C) 2018 Red Hat, Inc. and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ + +import { inject, injectable } from 'inversify'; +import { BackendApplicationContribution } from '@theia/core/lib/node/backend-application'; +import { HostedPluginReader as PluginReaderHosted } from '@theia/plugin-ext/lib/hosted/node/plugin-reader'; +import { Deferred } from '@theia/core/lib/common/promise-util'; +import { PluginMetadata } from '@theia/plugin-ext/lib/common/plugin-protocol'; +import { PluginDeployerEntryImpl } from '@theia/plugin-ext/lib/main/node/plugin-deployer-entry-impl'; +import { HostedPluginDeployerHandler } from '@theia/plugin-ext/lib/hosted/node/hosted-plugin-deployer-handler'; + +@injectable() +export class HostedPluginReader implements BackendApplicationContribution { + + @inject(PluginReaderHosted) + protected pluginReader: PluginReaderHosted; + + private readonly hostedPlugin = new Deferred(); + + @inject(HostedPluginDeployerHandler) + protected deployerHandler: HostedPluginDeployerHandler; + + async initialize() { + this.pluginReader.doGetPluginMetadata(process.env.HOSTED_PLUGIN) + .then(this.hostedPlugin.resolve.bind(this.hostedPlugin)); + + const pluginPath = process.env.HOSTED_PLUGIN; + if (pluginPath) { + const hostedPlugin = new PluginDeployerEntryImpl('Hosted Plugin', pluginPath!, pluginPath); + const hostedMetadata = await this.hostedPlugin.promise; + if (hostedMetadata!.model.entryPoint && hostedMetadata!.model.entryPoint.backend) { + this.deployerHandler.deployBackendPlugins([hostedPlugin]); + } + + if (hostedMetadata!.model.entryPoint && hostedMetadata!.model.entryPoint.frontend) { + this.deployerHandler.deployFrontendPlugins([hostedPlugin]); + } + } + } + + async getPlugin(): Promise { + return this.hostedPlugin.promise; + } +} diff --git a/packages/plugin-dev/src/node/hosted-plugin-service.ts b/packages/plugin-dev/src/node/hosted-plugin-service.ts new file mode 100644 index 0000000000000..5cf230ccd16b4 --- /dev/null +++ b/packages/plugin-dev/src/node/hosted-plugin-service.ts @@ -0,0 +1,104 @@ +/******************************************************************************** + * Copyright (C) 2019 Red Hat, Inc. and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ + +import { HostedPluginServer, DebugConfiguration, HostedPluginClient } from '../common/plugin-dev-protocol'; +import { injectable, inject } from 'inversify'; +import { HostedInstanceManager } from './hosted-instance-manager'; +import { PluginMetadata } from '@theia/plugin-ext/lib/common/plugin-protocol'; +import URI from '@theia/core/lib/common/uri'; +import { HostedPluginReader } from './hosted-plugin-reader'; +import { HostedPluginsManager } from './hosted-plugins-manager'; +import { HostedPluginSupport } from '@theia/plugin-ext/lib/hosted/node/hosted-plugin'; + +@injectable() +export class HostedPluginServerImpl implements HostedPluginServer { + + @inject(HostedPluginsManager) + protected readonly hostedPluginsManager: HostedPluginsManager; + + @inject(HostedInstanceManager) + protected readonly hostedInstanceManager: HostedInstanceManager; + + @inject(HostedPluginReader) + private readonly reader: HostedPluginReader; + + @inject(HostedPluginSupport) + private readonly hostedPlugin: HostedPluginSupport; + + dispose(): void { + this.hostedInstanceManager.terminate(); + } + setClient(client: HostedPluginClient): void { + + } + + async getHostedPlugin(): Promise { + const pluginMetadata = await this.reader.getPlugin(); + if (pluginMetadata) { + this.hostedPlugin.runPlugin(pluginMetadata.model); + } + return Promise.resolve(this.reader.getPlugin()); + } + + isPluginValid(uri: string): Promise { + return Promise.resolve(this.hostedInstanceManager.isPluginValid(new URI(uri))); + } + + runHostedPluginInstance(uri: string): Promise { + return this.uriToStrPromise(this.hostedInstanceManager.run(new URI(uri))); + } + + runDebugHostedPluginInstance(uri: string, debugConfig: DebugConfiguration): Promise { + return this.uriToStrPromise(this.hostedInstanceManager.debug(new URI(uri), debugConfig)); + } + + terminateHostedPluginInstance(): Promise { + this.hostedInstanceManager.terminate(); + return Promise.resolve(); + } + + isHostedPluginInstanceRunning(): Promise { + return Promise.resolve(this.hostedInstanceManager.isRunning()); + } + + getHostedPluginInstanceURI(): Promise { + return Promise.resolve(this.hostedInstanceManager.getInstanceURI().toString()); + } + + getHostedPluginURI(): Promise { + return Promise.resolve(this.hostedInstanceManager.getPluginURI().toString()); + } + + protected uriToStrPromise(promise: Promise): Promise { + return new Promise((resolve, reject) => { + promise.then((uri: URI) => { + resolve(uri.toString()); + }).catch(error => reject(error)); + }); + } + + runWatchCompilation(path: string): Promise { + return this.hostedPluginsManager.runWatchCompilation(path); + } + + stopWatchCompilation(path: string): Promise { + return this.hostedPluginsManager.stopWatchCompilation(path); + } + + isWatchCompilationRunning(path: string): Promise { + return this.hostedPluginsManager.isWatchCompilationRunning(path); + } +} diff --git a/packages/plugin-ext/src/hosted/node/hosted-plugin-uri-postprocessor.ts b/packages/plugin-dev/src/node/hosted-plugin-uri-postprocessor.ts similarity index 100% rename from packages/plugin-ext/src/hosted/node/hosted-plugin-uri-postprocessor.ts rename to packages/plugin-dev/src/node/hosted-plugin-uri-postprocessor.ts diff --git a/packages/plugin-ext/src/hosted/node/hosted-plugins-manager.ts b/packages/plugin-dev/src/node/hosted-plugins-manager.ts similarity index 97% rename from packages/plugin-ext/src/hosted/node/hosted-plugins-manager.ts rename to packages/plugin-dev/src/node/hosted-plugins-manager.ts index 90d006bde1802..d041dff9acedd 100644 --- a/packages/plugin-ext/src/hosted/node/hosted-plugins-manager.ts +++ b/packages/plugin-dev/src/node/hosted-plugins-manager.ts @@ -18,8 +18,8 @@ import { inject, injectable } from 'inversify'; import * as cp from 'child_process'; import * as fs from 'fs'; import { sep as PATH_SEPARATOR } from 'path'; -import { HostedPluginSupport } from './hosted-plugin'; -import { LogType } from '../../common/types'; +import { HostedPluginSupport } from '@theia/plugin-ext/lib/hosted/node/hosted-plugin'; +import { LogType } from '@theia/plugin-ext/lib/common/types'; export const HostedPluginsManager = Symbol('HostedPluginsManager'); diff --git a/packages/plugin-dev/src/node/plugin-dev-backend-module.ts b/packages/plugin-dev/src/node/plugin-dev-backend-module.ts new file mode 100644 index 0000000000000..5f0a654cc2515 --- /dev/null +++ b/packages/plugin-dev/src/node/plugin-dev-backend-module.ts @@ -0,0 +1,54 @@ +/******************************************************************************** + * Copyright (C) 2019 Red Hat, Inc. and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ + +import { HostedInstanceManager, NodeHostedPluginRunner } from './hosted-instance-manager'; +import { HostedPluginUriPostProcessorSymbolName } from './hosted-plugin-uri-postprocessor'; +import { HostedPluginsManager, HostedPluginsManagerImpl } from './hosted-plugins-manager'; +import { ContainerModule, interfaces } from 'inversify'; +import { ConnectionContainerModule } from '@theia/core/lib/node/messaging/connection-container-module'; +import { bindContributionProvider } from '@theia/core/lib/common/contribution-provider'; +import { HostedPluginServerImpl } from './hosted-plugin-service'; +import { HostedPluginServer, HostedPluginClient, hostedServicePath } from '../common/plugin-dev-protocol'; +import { HostedPluginReader } from './hosted-plugin-reader'; +import { BackendApplicationContribution } from '@theia/core/lib/node/backend-application'; + +const commonHostedConnectionModule = ConnectionContainerModule.create(({ bind, bindBackendService }) => { + bind(HostedPluginsManagerImpl).toSelf().inSingletonScope(); + bind(HostedPluginsManager).toService(HostedPluginsManagerImpl); + bind(HostedPluginServerImpl).toSelf().inSingletonScope(); + bind(HostedPluginServer).toService(HostedPluginServerImpl); + bindBackendService(hostedServicePath, HostedPluginServer, (server, client) => { + server.setClient(client); + client.onDidCloseConnection(() => server.dispose()); + return server; + }); +}); + +export function bindCommonHostedBackend(bind: interfaces.Bind): void { + bind(HostedPluginReader).toSelf().inSingletonScope(); + bind(BackendApplicationContribution).toService(HostedPluginReader); + bind(ConnectionContainerModule).toConstantValue(commonHostedConnectionModule); +} + +const hostedBackendConnectionModule = ConnectionContainerModule.create(({ bind }) => { + bindContributionProvider(bind, Symbol.for(HostedPluginUriPostProcessorSymbolName)); + bind(HostedInstanceManager).to(NodeHostedPluginRunner).inSingletonScope(); +}); + +export default new ContainerModule(bind => { + bindCommonHostedBackend(bind); + bind(ConnectionContainerModule).toConstantValue(hostedBackendConnectionModule); +}); diff --git a/packages/plugin-dev/src/package.spec.ts b/packages/plugin-dev/src/package.spec.ts new file mode 100644 index 0000000000000..2ea50f7e76e39 --- /dev/null +++ b/packages/plugin-dev/src/package.spec.ts @@ -0,0 +1,28 @@ +/******************************************************************************** + * Copyright (C) 2019 Red Hat, Inc. and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ + +/* note: this bogus test file is required so that + we are able to run mocha unit tests on this + package, without having any actual unit tests in it. + This way a coverage report will be generated, + showing 0% coverage, instead of no report. + This file can be removed once we have real unit + tests in place. */ + +describe('plugin-dev package', () => { + + it('support code coverage statistics', () => true); +}); diff --git a/packages/plugin-ext/README.md b/packages/plugin-ext/README.md index d1342d272a889..cb769b514262c 100644 --- a/packages/plugin-ext/README.md +++ b/packages/plugin-ext/README.md @@ -2,9 +2,6 @@ See [here](https://www.theia-ide.org/doc/index.html) for a detailed documentation. -## Contribution points: - - Hosted Istance uri post processor - ## License - [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/) - [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp) diff --git a/packages/plugin-ext/package.json b/packages/plugin-ext/package.json index 17df623e743f8..a0cbc56674925 100644 --- a/packages/plugin-ext/package.json +++ b/packages/plugin-ext/package.json @@ -24,7 +24,6 @@ "getmac": "^1.4.6", "jsonc-parser": "^2.0.2", "lodash.clonedeep": "^4.5.0", - "ps-tree": "1.1.0", "uuid": "^3.2.1", "vscode-debugprotocol": "^1.32.0" }, diff --git a/packages/plugin-ext/src/common/index.ts b/packages/plugin-ext/src/common/index.ts index 26b030e441f16..e433357f0f950 100644 --- a/packages/plugin-ext/src/common/index.ts +++ b/packages/plugin-ext/src/common/index.ts @@ -14,10 +14,6 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ -// Exports contribution point for uri postprocessor of hosted plugin manager. -// This could be used to alter hosted instance uri, for example, change port. -export * from '../hosted/node/hosted-plugin-uri-postprocessor'; - // Here we expose types from @theia/plugin, so it becames a direct dependency export * from '../common/plugin-protocol'; export * from '../plugin/plugin-context'; diff --git a/packages/plugin-ext/src/common/plugin-protocol.ts b/packages/plugin-ext/src/common/plugin-protocol.ts index c1c6b5af1bc8b..71da6eb4ddaa7 100644 --- a/packages/plugin-ext/src/common/plugin-protocol.ts +++ b/packages/plugin-ext/src/common/plugin-protocol.ts @@ -558,11 +558,6 @@ export function buildFrontendModuleName(plugin: PluginPackage | PluginModel): st return `${plugin.publisher}_${plugin.name}`.replace(/\W/g, '_'); } -export interface DebugConfiguration { - port?: number; - debugMode?: string; -} - export const HostedPluginClient = Symbol('HostedPluginClient'); export interface HostedPluginClient { setClientId(clientId: number): Promise; @@ -584,7 +579,6 @@ export interface PluginDeployerHandler { export const HostedPluginServer = Symbol('HostedPluginServer'); export interface HostedPluginServer extends JsonRpcServer { - getHostedPlugin(): Promise; getDeployedMetadata(): Promise; getDeployedFrontendMetadata(): Promise; @@ -594,17 +588,6 @@ export interface HostedPluginServer extends JsonRpcServer { onMessage(message: string): Promise; - isPluginValid(uri: string): Promise; - runHostedPluginInstance(uri: string): Promise; - runDebugHostedPluginInstance(uri: string, debugConfig: DebugConfiguration): Promise; - terminateHostedPluginInstance(): Promise; - isHostedPluginInstanceRunning(): Promise; - getHostedPluginInstanceURI(): Promise; - getHostedPluginURI(): Promise; - - runWatchCompilation(uri: string): Promise; - stopWatchCompilation(uri: string): Promise; - isWatchCompilationRunning(uri: string): Promise; } /** diff --git a/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts b/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts index 5534dde4731ea..8beca2a39792e 100644 --- a/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts +++ b/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts @@ -92,7 +92,6 @@ export class HostedPluginSupport { public initPlugins(): void { Promise.all([ this.server.getDeployedMetadata(), - this.server.getHostedPlugin(), this.pluginPathsService.provideHostLogPath(), this.storagePathService.provideHostStoragePath(), this.server.getExtPluginAPI(), @@ -102,23 +101,18 @@ export class HostedPluginSupport { ]).then(metadata => { const pluginsInitData: PluginsInitializationData = { plugins: metadata['0'], - hostedPlugin: metadata['1'], - logPath: metadata['2'], - storagePath: metadata['3'], - pluginAPIs: metadata['4'], - globalStates: metadata['5'], - workspaceStates: metadata['6'], - roots: metadata['7'] + logPath: metadata['1'], + storagePath: metadata['2'], + pluginAPIs: metadata['3'], + globalStates: metadata['4'], + workspaceStates: metadata['5'], + roots: metadata['6'] }; this.loadPlugins(pluginsInitData, this.container); }).catch(e => console.error(e)); } loadPlugins(initData: PluginsInitializationData, container: interfaces.Container): void { - if (initData.hostedPlugin) { - initData.plugins.push(initData.hostedPlugin); - } - // don't load plugins twice initData.plugins = initData.plugins.filter(value => !this.loadedPlugins.has(value.model.id)); @@ -232,7 +226,6 @@ export class HostedPluginSupport { interface PluginsInitializationData { plugins: PluginMetadata[], - hostedPlugin: PluginMetadata | undefined, logPath: string, storagePath: string | undefined, pluginAPIs: ExtPluginApi[], diff --git a/packages/plugin-ext/src/hosted/node-electron/plugin-ext-hosted-electron-backend-module.ts b/packages/plugin-ext/src/hosted/node-electron/plugin-ext-hosted-electron-backend-module.ts index 5adc5fecd1664..0a96f818adc17 100644 --- a/packages/plugin-ext/src/hosted/node-electron/plugin-ext-hosted-electron-backend-module.ts +++ b/packages/plugin-ext/src/hosted/node-electron/plugin-ext-hosted-electron-backend-module.ts @@ -14,20 +14,13 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ -import { HostedInstanceManager, ElectronNodeHostedPluginRunner } from '../node/hosted-instance-manager'; import { interfaces } from 'inversify'; -import { ConnectionContainerModule } from '@theia/core/lib/node/messaging/connection-container-module'; import { bindCommonHostedBackend } from '../node/plugin-ext-hosted-backend-module'; import { PluginScanner } from '../../common/plugin-protocol'; import { TheiaPluginScannerElectron } from './scanner-theia-electron'; -const hostedBackendConnectionModule = ConnectionContainerModule.create(({ bind }) => { - bind(HostedInstanceManager).to(ElectronNodeHostedPluginRunner); -}); - export function bindElectronBackend(bind: interfaces.Bind): void { bindCommonHostedBackend(bind); - bind(ConnectionContainerModule).toConstantValue(hostedBackendConnectionModule); bind(PluginScanner).to(TheiaPluginScannerElectron).inSingletonScope(); } diff --git a/packages/plugin-ext/src/hosted/node/plugin-ext-hosted-backend-module.ts b/packages/plugin-ext/src/hosted/node/plugin-ext-hosted-backend-module.ts index 743ed10704ec9..f762cd5ca6769 100644 --- a/packages/plugin-ext/src/hosted/node/plugin-ext-hosted-backend-module.ts +++ b/packages/plugin-ext/src/hosted/node/plugin-ext-hosted-backend-module.ts @@ -18,15 +18,12 @@ import { interfaces } from 'inversify'; import { bindContributionProvider } from '@theia/core/lib/common/contribution-provider'; import { CliContribution } from '@theia/core/lib/node/cli'; import { ConnectionContainerModule } from '@theia/core/lib/node/messaging/connection-container-module'; -import { HostedInstanceManager, NodeHostedPluginRunner } from './hosted-instance-manager'; -import { HostedPluginUriPostProcessorSymbolName } from './hosted-plugin-uri-postprocessor'; import { BackendApplicationContribution } from '@theia/core/lib/node/backend-application'; import { MetadataScanner } from './metadata-scanner'; import { HostedPluginServerImpl } from './plugin-service'; import { HostedPluginReader } from './plugin-reader'; import { HostedPluginSupport } from './hosted-plugin'; import { TheiaPluginScanner } from './scanners/scanner-theia'; -import { HostedPluginsManager, HostedPluginsManagerImpl } from './hosted-plugins-manager'; import { HostedPluginServer, PluginScanner, HostedPluginClient, hostedServicePath, PluginDeployerHandler, PluginHostEnvironmentVariable } from '../../common/plugin-protocol'; import { GrammarsReader } from './scanners/grammars-reader'; import { HostedPluginProcess } from './hosted-plugin-process'; @@ -39,9 +36,6 @@ const commonHostedConnectionModule = ConnectionContainerModule.create(({ bind, b bind(HostedPluginProcess).toSelf().inSingletonScope(); bind(HostedPluginSupport).toSelf().inSingletonScope(); - bind(HostedPluginsManagerImpl).toSelf().inSingletonScope(); - bind(HostedPluginsManager).toService(HostedPluginsManagerImpl); - bindContributionProvider(bind, Symbol.for(ExtPluginApiProvider)); bindContributionProvider(bind, PluginHostEnvironmentVariable); @@ -71,14 +65,8 @@ export function bindCommonHostedBackend(bind: interfaces.Bind): void { bind(ConnectionContainerModule).toConstantValue(commonHostedConnectionModule); } -const hostedBackendConnectionModule = ConnectionContainerModule.create(({ bind }) => { - bindContributionProvider(bind, Symbol.for(HostedPluginUriPostProcessorSymbolName)); - bind(HostedInstanceManager).to(NodeHostedPluginRunner).inSingletonScope(); -}); - export function bindHostedBackend(bind: interfaces.Bind): void { bindCommonHostedBackend(bind); - bind(ConnectionContainerModule).toConstantValue(hostedBackendConnectionModule); bind(PluginScanner).to(TheiaPluginScanner).inSingletonScope(); } diff --git a/packages/plugin-ext/src/hosted/node/plugin-reader.ts b/packages/plugin-ext/src/hosted/node/plugin-reader.ts index fcc7bc444a543..4dc30dd0d86dd 100644 --- a/packages/plugin-ext/src/hosted/node/plugin-reader.ts +++ b/packages/plugin-ext/src/hosted/node/plugin-reader.ts @@ -21,7 +21,6 @@ import * as fs from 'fs-extra'; import * as express from 'express'; import { ILogger } from '@theia/core'; import { inject, injectable, optional, multiInject } from 'inversify'; -import { Deferred } from '@theia/core/lib/common/promise-util'; import { BackendApplicationContribution } from '@theia/core/lib/node/backend-application'; import { PluginMetadata, getPluginId, MetadataProcessor } from '../../common/plugin-protocol'; import { MetadataScanner } from './metadata-scanner'; @@ -35,8 +34,6 @@ export class HostedPluginReader implements BackendApplicationContribution { @inject(MetadataScanner) private readonly scanner: MetadataScanner; - private readonly hostedPlugin = new Deferred(); - @optional() @multiInject(MetadataProcessor) private readonly metadataProcessors: MetadataProcessor[]; @@ -45,11 +42,6 @@ export class HostedPluginReader implements BackendApplicationContribution { */ private pluginsIdsFiles: Map = new Map(); - initialize(): void { - this.doGetPluginMetadata(process.env.HOSTED_PLUGIN) - .then(this.hostedPlugin.resolve.bind(this.hostedPlugin)); - } - configure(app: express.Application): void { app.get('/hostedPlugin/:pluginId/:path(*)', (req, res) => { const pluginId = req.params.pluginId; @@ -66,21 +58,13 @@ export class HostedPluginReader implements BackendApplicationContribution { } async getPluginMetadata(pluginPath: string): Promise { - const plugin = await this.doGetPluginMetadata(pluginPath); - if (plugin) { - const hostedPlugin = await this.getPlugin(); - if (hostedPlugin && hostedPlugin.model.name === plugin.model.name) { - // prefer hosted plugin - return undefined; - } - } - return plugin; + return this.doGetPluginMetadata(pluginPath); } /** * MUST never throw to isolate plugin deployment */ - protected async doGetPluginMetadata(pluginPath: string | undefined) { + async doGetPluginMetadata(pluginPath: string | undefined) { try { if (!pluginPath) { return undefined; @@ -115,10 +99,6 @@ export class HostedPluginReader implements BackendApplicationContribution { return pluginMetadata; } - async getPlugin(): Promise { - return this.hostedPlugin.promise; - } - protected async loadManifest(pluginPath: string): Promise { const [manifest, translations] = await Promise.all([ fs.readJson(path.join(pluginPath, 'package.json')), diff --git a/packages/plugin-ext/src/hosted/node/plugin-service.ts b/packages/plugin-ext/src/hosted/node/plugin-service.ts index a516a0195b0a6..16645de07191c 100644 --- a/packages/plugin-ext/src/hosted/node/plugin-service.ts +++ b/packages/plugin-ext/src/hosted/node/plugin-service.ts @@ -14,12 +14,8 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ import { injectable, inject, named, postConstruct } from 'inversify'; -import { HostedPluginServer, HostedPluginClient, PluginMetadata, DebugConfiguration, PluginDeployer } from '../../common/plugin-protocol'; -import { HostedPluginReader } from './plugin-reader'; -import { HostedInstanceManager } from './hosted-instance-manager'; +import { HostedPluginServer, HostedPluginClient, PluginMetadata, PluginDeployer } from '../../common/plugin-protocol'; import { HostedPluginSupport } from './hosted-plugin'; -import { HostedPluginsManager } from './hosted-plugins-manager'; -import URI from '@theia/core/lib/common/uri'; import { ILogger } from '@theia/core'; import { ContributionProvider } from '@theia/core'; import { ExtPluginApiProvider, ExtPluginApi } from '../../common/plugin-ext-api-contribution'; @@ -30,8 +26,6 @@ import { PluginDeployerImpl } from '../../main/node/plugin-deployer-impl'; export class HostedPluginServerImpl implements HostedPluginServer { @inject(ILogger) protected readonly logger: ILogger; - @inject(HostedPluginsManager) - protected readonly hostedPluginsManager: HostedPluginsManager; @inject(HostedPluginDeployerHandler) protected readonly deployerHandler: HostedPluginDeployerHandler; @@ -46,9 +40,7 @@ export class HostedPluginServerImpl implements HostedPluginServer { protected client: HostedPluginClient | undefined; constructor( - @inject(HostedPluginReader) private readonly reader: HostedPluginReader, - @inject(HostedPluginSupport) private readonly hostedPlugin: HostedPluginSupport, - @inject(HostedInstanceManager) protected readonly hostedInstanceManager: HostedInstanceManager) { + @inject(HostedPluginSupport) private readonly hostedPlugin: HostedPluginSupport) { } @postConstruct() @@ -67,13 +59,6 @@ export class HostedPluginServerImpl implements HostedPluginServer { this.client = client; this.hostedPlugin.setClient(client); } - async getHostedPlugin(): Promise { - const pluginMetadata = await this.reader.getPlugin(); - if (pluginMetadata) { - this.hostedPlugin.runPlugin(pluginMetadata.model); - } - return Promise.resolve(this.reader.getPlugin()); - } getDeployedFrontendMetadata(): Promise { return this.deployerHandler.getDeployedFrontendMetadata(); @@ -104,55 +89,6 @@ export class HostedPluginServerImpl implements HostedPluginServer { return Promise.resolve(); } - isPluginValid(uri: string): Promise { - return Promise.resolve(this.hostedInstanceManager.isPluginValid(new URI(uri))); - } - - runHostedPluginInstance(uri: string): Promise { - return this.uriToStrPromise(this.hostedInstanceManager.run(new URI(uri))); - } - - runDebugHostedPluginInstance(uri: string, debugConfig: DebugConfiguration): Promise { - return this.uriToStrPromise(this.hostedInstanceManager.debug(new URI(uri), debugConfig)); - } - - terminateHostedPluginInstance(): Promise { - this.hostedInstanceManager.terminate(); - return Promise.resolve(); - } - - isHostedPluginInstanceRunning(): Promise { - return Promise.resolve(this.hostedInstanceManager.isRunning()); - } - - getHostedPluginInstanceURI(): Promise { - return Promise.resolve(this.hostedInstanceManager.getInstanceURI().toString()); - } - - getHostedPluginURI(): Promise { - return Promise.resolve(this.hostedInstanceManager.getPluginURI().toString()); - } - - protected uriToStrPromise(promise: Promise): Promise { - return new Promise((resolve, reject) => { - promise.then((uri: URI) => { - resolve(uri.toString()); - }).catch(error => reject(error)); - }); - } - - runWatchCompilation(path: string): Promise { - return this.hostedPluginsManager.runWatchCompilation(path); - } - - stopWatchCompilation(path: string): Promise { - return this.hostedPluginsManager.stopWatchCompilation(path); - } - - isWatchCompilationRunning(path: string): Promise { - return this.hostedPluginsManager.isWatchCompilationRunning(path); - } - getExtPluginAPI(): Promise { return Promise.resolve(this.extPluginAPIContributions.getContributions().map(p => p.provideApi())); } diff --git a/packages/plugin-ext/src/main/browser/plugin-ext-frontend-module.ts b/packages/plugin-ext/src/main/browser/plugin-ext-frontend-module.ts index f2bf0f81bfb63..5f8536cb43423 100644 --- a/packages/plugin-ext/src/main/browser/plugin-ext-frontend-module.ts +++ b/packages/plugin-ext/src/main/browser/plugin-ext-frontend-module.ts @@ -22,8 +22,6 @@ import { MaybePromise, CommandContribution, ResourceResolver, bindContributionPr import { WebSocketConnectionProvider } from '@theia/core/lib/browser/messaging'; import { HostedPluginSupport } from '../../hosted/browser/hosted-plugin'; import { HostedPluginWatcher } from '../../hosted/browser/hosted-plugin-watcher'; -import { HostedPluginLogViewer } from '../../hosted/browser/hosted-plugin-log-viewer'; -import { HostedPluginManagerClient } from '../../hosted/browser/hosted-plugin-manager-client'; import { OpenUriCommandHandler } from './commands'; import { PluginApiFrontendContribution } from './plugin-frontend-contribution'; import { HostedPluginServer, hostedServicePath, PluginServer, pluginServerJsonRpcPath } from '../../common/plugin-protocol'; @@ -31,10 +29,6 @@ import { ModalNotification } from './dialogs/modal-notification'; import { PluginWidget } from './plugin-ext-widget'; import { PluginFrontendViewContribution } from './plugin-frontend-view-contribution'; -import { HostedPluginInformer } from '../../hosted/browser/hosted-plugin-informer'; -import { bindHostedPluginPreferences } from '../../hosted/browser/hosted-plugin-preferences'; -import { HostedPluginController } from '../../hosted/browser/hosted-plugin-controller'; - import '../../../src/main/browser/style/index.css'; import { PluginExtDeployCommandService } from './plugin-ext-deploy-command'; import { TextEditorService, TextEditorServiceImpl } from './text-editor-service'; @@ -64,20 +58,14 @@ import { TreeViewActions } from './view/tree-view-actions'; import { TreeViewContextKeyService } from './view/tree-view-context-key-service'; export default new ContainerModule((bind, unbind, isBound, rebind) => { - bindHostedPluginPreferences(bind); bind(ModalNotification).toSelf().inSingletonScope(); bind(HostedPluginSupport).toSelf().inSingletonScope(); bind(HostedPluginWatcher).toSelf().inSingletonScope(); - bind(HostedPluginLogViewer).toSelf().inSingletonScope(); - bind(HostedPluginManagerClient).toSelf().inSingletonScope(); bind(SelectionProviderCommandContribution).toSelf().inSingletonScope(); bind(CommandContribution).toService(SelectionProviderCommandContribution); - bind(FrontendApplicationContribution).to(HostedPluginInformer).inSingletonScope(); - bind(FrontendApplicationContribution).to(HostedPluginController).inSingletonScope(); - bind(OpenUriCommandHandler).toSelf().inSingletonScope(); bind(PluginApiFrontendContribution).toSelf().inSingletonScope(); bind(CommandContribution).toService(PluginApiFrontendContribution); diff --git a/packages/plugin-ext/src/main/browser/plugin-frontend-contribution.ts b/packages/plugin-ext/src/main/browser/plugin-frontend-contribution.ts index c1b0171d18754..984b8b4b64201 100644 --- a/packages/plugin-ext/src/main/browser/plugin-frontend-contribution.ts +++ b/packages/plugin-ext/src/main/browser/plugin-frontend-contribution.ts @@ -16,7 +16,6 @@ import { injectable, inject } from 'inversify'; import { CommandRegistry, CommandContribution } from '@theia/core/lib/common'; -import { HostedPluginManagerClient, HostedPluginCommands } from '../../hosted/browser/hosted-plugin-manager-client'; import { PluginExtDeployCommandService } from './plugin-ext-deploy-command'; import { OpenUriCommandHandler } from './commands'; import URI from '@theia/core/lib/common/uri'; @@ -24,9 +23,6 @@ import URI from '@theia/core/lib/common/uri'; @injectable() export class PluginApiFrontendContribution implements CommandContribution { - @inject(HostedPluginManagerClient) - protected readonly hostedPluginManagerClient: HostedPluginManagerClient; - @inject(PluginExtDeployCommandService) protected readonly pluginExtDeployCommandService: PluginExtDeployCommandService; @@ -34,21 +30,6 @@ export class PluginApiFrontendContribution implements CommandContribution { protected readonly openUriCommandHandler: OpenUriCommandHandler; registerCommands(commands: CommandRegistry): void { - commands.registerCommand(HostedPluginCommands.START, { - execute: () => this.hostedPluginManagerClient.start() - }); - commands.registerCommand(HostedPluginCommands.DEBUG, { - execute: () => this.hostedPluginManagerClient.debug() - }); - commands.registerCommand(HostedPluginCommands.STOP, { - execute: () => this.hostedPluginManagerClient.stop() - }); - commands.registerCommand(HostedPluginCommands.RESTART, { - execute: () => this.hostedPluginManagerClient.restart() - }); - commands.registerCommand(HostedPluginCommands.SELECT_PATH, { - execute: () => this.hostedPluginManagerClient.selectPluginPath() - }); commands.registerCommand(PluginExtDeployCommandService.COMMAND, { execute: () => this.pluginExtDeployCommandService.deploy() diff --git a/packages/plugin-ext/src/plugin/tree/tree-views.ts b/packages/plugin-ext/src/plugin/tree/tree-views.ts index 084b60296a915..92c483ad454cf 100644 --- a/packages/plugin-ext/src/plugin/tree/tree-views.ts +++ b/packages/plugin-ext/src/plugin/tree/tree-views.ts @@ -24,8 +24,9 @@ import { Disposable, ThemeIcon } from '../types-impl'; import { Plugin, PLUGIN_RPC_CONTEXT, TreeViewsExt, TreeViewsMain, TreeViewItem } from '../../api/plugin-api'; import { RPCProtocol } from '../../api/rpc-protocol'; import { CommandRegistryImpl } from '../command-registry'; -import { PluginPackage, TreeViewSelection } from '../../common'; +import { TreeViewSelection } from '../../common'; import { SelectionServiceExt } from '../selection-provider-ext'; +import { PluginPackage } from '../../common/plugin-protocol'; export class TreeViewsExtImpl implements TreeViewsExt { diff --git a/tsconfig.json b/tsconfig.json index 6853ecf897756..89626631288c6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -115,6 +115,9 @@ "@theia/file-search/lib/*": [ "packages/file-search/src/*" ], + "@theia/plugin-dev/lib/*": [ + "packages/plugin-dev/src/*" + ], "@theia/plugin-ext/lib/*": [ "packages/plugin-ext/src/*" ],