Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Move theia remote extension there and align it with new theia 0.3.19 #42

Merged
merged 4 commits into from
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions extensions/eclipse-che-theia-remote/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
.browser_modules
lib
*.log
*-app/*
!*-app/package.json
.idea
27 changes: 27 additions & 0 deletions extensions/eclipse-che-theia-remote/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) 2019 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation

FROM node:8.12-alpine as builder
RUN apk add --no-cache make gcc g++ python

# Grab dependencies
COPY /package.json /home/theia-endpoint/
RUN cd /home/theia-endpoint/ && yarn install --ignore-scripts

# Compile
COPY *.json /home/theia-endpoint/
COPY /src /home/theia-endpoint/src
RUN cd /home/theia-endpoint/ && yarn install

FROM node:8.12-alpine
# Grab runtime
COPY --from=builder /home/theia-endpoint/node_modules /home/theia/node_modules
COPY --from=builder /home/theia-endpoint/lib /home/theia/lib
CMD node /home/theia/lib/node/plugin-remote.js
36 changes: 36 additions & 0 deletions extensions/eclipse-che-theia-remote/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "@eclipse-che/theia-remote",
"author": "Florent Benoit",
"version": "0.0.1",
"license" : "EPL-2.0",
"files": [
"lib",
"src"
],
"dependencies": {
"@theia/plugin-ext": "0.3.19",
"@theia/plugin-ext-vscode": "0.3.19",
"@theia/core": "0.3.19"
},
"devDependencies": {
"tslint": "5.10.0",
"rimraf": "2.6.2",
"typescript": "3.1.3",
"typescript-formatter": "7.2.2"
},
"scripts": {
"prepare": "yarn run clean && yarn run tslint && yarn run build",
"tslint-fix": "tslint --fix --project .",
"tslint": "tslint --project .",
"clean": "rimraf lib",
"format-code": "tsfmt -r",
"compile": "tsc",
"build": "yarn run compile && yarn run format-code && yarn run tslint-fix",
"watch": "tsc -w"
},
"theiaExtensions": [
{
"backend": "lib/node/plugin-remote-backend-module"
}
]
}
96 changes: 96 additions & 0 deletions extensions/eclipse-che-theia-remote/src/node/dummy-trace-logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*********************************************************************
* Copyright (c) 2018-2019 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/

import { ILogger } from '@theia/core/lib/common';
import { Loggable } from '@theia/core';
import { injectable } from 'inversify';

/**
* Dummty trace logger used to provide a logger with inversify.
*/
@injectable()
export class DummyTraceLogger implements ILogger {

async log(logLevel: number, loggable: Loggable): Promise<void> {
// do nothing
}

async setLogLevel(logLevel: number): Promise<void> {

}
async getLogLevel(): Promise<number> {
return 0;
}
async isEnabled(logLevel: number): Promise<boolean> {
return true;
}
async ifEnabled(logLevel: number): Promise<void> {
}
async isTrace(): Promise<boolean> {
return true;
}
async ifTrace(): Promise<void> {
}
async isDebug(): Promise<boolean> {
return true;
}
async ifDebug(): Promise<void> {
}
async isInfo(): Promise<boolean> {
return true;
}
async ifInfo(): Promise<void> {
}
async isWarn(): Promise<boolean> {
return true;
}
async ifWarn(): Promise<void> {
}
async isError(): Promise<boolean> {
return true;
}
async ifError(): Promise<void> {
}
async isFatal(): Promise<boolean> {
return true;
}
async ifFatal(): Promise<void> {
}
child(name: string): ILogger {
return this;
}

// tslint:disable-next-line:no-any
async trace(message: any, ...params: any[]): Promise<void> {
console.trace(message, ...params);
}

// tslint:disable-next-line:no-any
async debug(message: any, ...params: any[]): Promise<void> {
console.debug(message, ...params);
}
// tslint:disable-next-line:no-any
async info(message: any, ...params: any[]): Promise<void> {
console.info(message, ...params);
}
// tslint:disable-next-line:no-any
async warn(message: any, ...params: any[]): Promise<void> {
console.warn(message, ...params);
}
// tslint:disable-next-line:no-any
async error(message: any, ...params: any[]): Promise<void> {
console.error(message, ...params);
}
// tslint:disable-next-line:no-any
async fatal(message: any, ...params: any[]): Promise<void> {
console.error(message, ...params);
}

}
141 changes: 141 additions & 0 deletions extensions/eclipse-che-theia-remote/src/node/hosted-plugin-remote.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*********************************************************************
* Copyright (c) 2018-2019 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/

import * as WebSocket from 'ws';

import { injectable, inject, postConstruct } from 'inversify';
import { ILogger } from '@theia/core/lib/common';
import { HostedPluginClient, PluginMetadata } from '@theia/plugin-ext';
import { HostedPluginMapping } from './plugin-remote-mapping';

/**
* Class handling remote connection for executing plug-ins.
* @author Florent Benoit
*/
@injectable()
export class HostedPluginRemote {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it for hosted plugin only?


private client: HostedPluginClient;

@inject(ILogger)
protected readonly logger: ILogger;

@inject(HostedPluginMapping)
protected hostedPluginMapping: HostedPluginMapping;

/**
* mapping between endpoint name and the websockets
*/
private endpointsSockets = new Map<string, WebSocket>();

/**
* mapping between endpoint's name and the websocket endpoint
*/
private pluginsMetadata: Map<string, PluginMetadata[]> = new Map<string, PluginMetadata[]>();

@postConstruct()
protected postConstruct(): void {
this.setupWebsocket();
}

/**
* Called when a client is connecting to this endpoint
*/
public setClient(client: HostedPluginClient): void {
this.client = client;
}

/**
* Handle the creation of connection to remote endpoints.
*/
setupWebsocket(): void {
this.hostedPluginMapping.getEndPoints().forEach(endpointAdress => {
if (endpointAdress) {
const websocket = new WebSocket(endpointAdress);
this.endpointsSockets.set(endpointAdress, websocket);
websocket.on('message', (messageRaw: string) => {
const parsed = JSON.parse(messageRaw);
if (parsed.internal) {
this.handleLocalMessage(parsed.internal);
return;
}
this.sendToClient(messageRaw);
});

// when websocket is opened, send the order
websocket.onopen = event => {
websocket.send(JSON.stringify({
'internal': {
'endpointName': endpointAdress,
'metadata': 'request'
}
}));
};
}
});
}

/**
* Checks if the given pluginID has a remote endpoint
*/
hasEndpoint(pluginID: string): boolean {
return this.hostedPluginMapping.hasEndpoint(pluginID);
}

/**
* Handle the mesage to remotely send to a ws endpoint
* @param jsonMessage the given message
*/
// tslint:disable-next-line:no-any
onMessage(jsonMessage: any): void {
// do the routing depending on the plugin's endpoint
const pluginId = jsonMessage.pluginID;

// socket ?
const endpoint = this.hostedPluginMapping.getPluginsEndPoints().get(pluginId);
if (!endpoint) {
this.logger.error('no endpoint configured for the given plugin', pluginId, 'skipping message');
return;
}
const websocket = this.endpointsSockets.get(endpoint);
websocket!.send(JSON.stringify(jsonMessage.content));
}

/**
* Handle a local message
* @param message the message to analyze locally and not sending back to client
*/
// tslint:disable-next-line:no-any
handleLocalMessage(jsonMessage: any): void {
if (jsonMessage.metadata && jsonMessage.metadata.result) {
this.pluginsMetadata.set(jsonMessage.endpointName, jsonMessage.metadata.result);
}
}

/**
* Send the given message back to the client
* @param message the message to send
*/
// tslint:disable-next-line:no-any
sendToClient(message: any) {
if (this.client) {
this.client.postMessage(message);
}

}

/**
* Return plugin metadata found remotely
*/
async getExtraPluginMetadata(): Promise<PluginMetadata[]> {
return [].concat.apply([], [...this.pluginsMetadata.values()]);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*********************************************************************
* Copyright (c) 2018-2019 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/

import { ContainerModule } from 'inversify';
import { HostedPluginRemote } from './hosted-plugin-remote';
import { ServerPluginProxyRunner } from './server-plugin-proxy-runner';
import { MetadataProcessor, ServerPluginRunner } from '@theia/plugin-ext/lib/common';
import { RemoteMetadataProcessor } from './remote-metadata-processor';
import { HostedPluginMapping } from './plugin-remote-mapping';

export default new ContainerModule(bind => {
bind(HostedPluginMapping).toSelf().inSingletonScope();
bind(HostedPluginRemote).toSelf().inSingletonScope();
bind(ServerPluginRunner).to(ServerPluginProxyRunner).inSingletonScope();
bind(MetadataProcessor).to(RemoteMetadataProcessor).inSingletonScope();
}
);
Loading