Skip to content

Commit

Permalink
#3871 Extract 'Hosted mode' in separate extension
Browse files Browse the repository at this point in the history
Signed-off-by: Yevhen Vydolob <[email protected]>
  • Loading branch information
evidolob committed Jun 3, 2019
1 parent 0b45619 commit dacb225
Show file tree
Hide file tree
Showing 37 changed files with 542 additions and 192 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
1 change: 1 addition & 0 deletions examples/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion examples/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 10 additions & 0 deletions packages/plugin-dev/README.md
Original file line number Diff line number Diff line change
@@ -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)
15 changes: 15 additions & 0 deletions packages/plugin-dev/compile.tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "../../configs/base.tsconfig",
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
"lib": [
"es6",
"dom"
]
},
"include": [
"src"
]
}

52 changes: 52 additions & 0 deletions packages/plugin-dev/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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}`);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
});

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
45 changes: 45 additions & 0 deletions packages/plugin-dev/src/browser/plugin-dev-frontend-module.ts
Original file line number Diff line number Diff line change
@@ -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<HostedPluginServer>(hostedServicePath, hostedWatcher.getHostedPluginClient());
}).inSingletonScope();
});
21 changes: 21 additions & 0 deletions packages/plugin-dev/src/common/index.ts
Original file line number Diff line number Diff line change
@@ -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';
44 changes: 44 additions & 0 deletions packages/plugin-dev/src/common/plugin-dev-protocol.ts
Original file line number Diff line number Diff line change
@@ -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<HostedPluginClient> {
getHostedPlugin(): Promise<PluginMetadata | undefined>;
runHostedPluginInstance(uri: string): Promise<string>;
runDebugHostedPluginInstance(uri: string, debugConfig: DebugConfiguration): Promise<string>;
terminateHostedPluginInstance(): Promise<void>;
isHostedPluginInstanceRunning(): Promise<boolean>;
getHostedPluginInstanceURI(): Promise<string>;
getHostedPluginURI(): Promise<string>;

runWatchCompilation(uri: string): Promise<void>;
stopWatchCompilation(uri: string): Promise<void>;
isWatchCompilationRunning(uri: string): Promise<boolean>;

isPluginValid(uri: string): Promise<boolean>;
}

export interface HostedPluginClient {
}

export interface DebugConfiguration {
port?: number;
debugMode?: string;
}
Original file line number Diff line number Diff line change
@@ -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);
});
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit dacb225

Please sign in to comment.