This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 111
Move theia remote extension there and align it with new theia 0.3.19 #42
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d909a6f
Move theia remote extension there and align it with new theia 0.3.19 …
benoitf d8272a7
fixup! Move theia remote extension there and align it with new theia …
benoitf 13c4e24
fixup! Move theia remote extension there and align it with new theia …
benoitf 0af6fe6
fixup! Move theia remote extension there and align it with new theia …
benoitf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
96
extensions/eclipse-che-theia-remote/src/node/dummy-trace-logger.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
141
extensions/eclipse-che-theia-remote/src/node/hosted-plugin-remote.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
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()]); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
extensions/eclipse-che-theia-remote/src/node/plugin-remote-backend-module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?