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

Commit

Permalink
feat(plugins): allow to install che-plugins in devworkspace
Browse files Browse the repository at this point in the history
Signed-off-by: Vitaliy Gulyy <[email protected]>
  • Loading branch information
vitaliy-guliy committed Dec 21, 2021
1 parent 6538c23 commit a6fda6a
Show file tree
Hide file tree
Showing 28 changed files with 2,192 additions and 313 deletions.
1 change: 0 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ set -e
set -o pipefail

parse "$@"
yarn ${YARN_OPTS}

#Added to handle experimental Travis tag
if [[ -n "${TAG:-}" ]]; then
Expand Down
3 changes: 2 additions & 1 deletion extensions/eclipse-che-theia-about/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"inversify": "^5.0.1",
"@theia/core": "next",
"@theia/mini-browser": "next",
"@eclipse-che/theia-plugin-ext": "^0.0.1"
"@eclipse-che/theia-plugin-ext": "^0.0.1",
"react": "^16.8.0"
},
"devDependencies": {
"ts-jest": "27.0.7",
Expand Down
4 changes: 3 additions & 1 deletion extensions/eclipse-che-theia-plugin-ext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
"drivelist": "9.0.2",
"@eclipse-che/theia-remote-api": "^0.0.1",
"@eclipse-che/workspace-telemetry-client": "latest",
"mime": "2.5.2"
"mime": "2.5.2",
"react": "^16.8.0",
"@phosphor/messaging": "1"
},
"devDependencies": {
"clean-webpack-plugin": "^3.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import '../../src/browser/style/che-plugins.css';
import '../../src/browser/style/tasks.css';

import { CHE_PLUGIN_SERVICE_PATH, ChePluginService, ChePluginServiceClient } from '../common/che-plugin-protocol';
import {
CHE_PRODUCT_SERVICE_PATH,
CHE_TASK_SERVICE_PATH,
Expand All @@ -33,6 +32,7 @@ import { ChePluginFrontentService } from './plugin/che-plugin-frontend-service';
import { ChePluginHandleRegistry } from './che-plugin-handle-registry';
import { ChePluginManager } from './plugin/che-plugin-manager';
import { ChePluginMenu } from './plugin/che-plugin-menu';
import { ChePluginServiceClient } from '@eclipse-che/theia-remote-api/lib/common/plugin-service';
import { ChePluginServiceClientImpl } from './plugin/che-plugin-service-client';
import { ChePluginView } from './plugin/che-plugin-view';
import { ChePluginViewContribution } from './plugin/che-plugin-view-contribution';
Expand Down Expand Up @@ -70,13 +70,6 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {

bind(ChePluginServiceClientImpl).toSelf().inSingletonScope();
bind(ChePluginServiceClient).toService(ChePluginServiceClientImpl);
bind(ChePluginService)
.toDynamicValue(ctx => {
const provider = ctx.container.get(WebSocketConnectionProvider);
const client: ChePluginServiceClient = ctx.container.get(ChePluginServiceClient);
return provider.createProxy<ChePluginService>(CHE_PLUGIN_SERVICE_PATH, client);
})
.inSingletonScope();

rebind(WebviewEnvironment).to(CheWebviewEnvironment).inSingletonScope();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Command, CommandContribution, CommandRegistry, MessageService } from '@
import { inject, injectable } from 'inversify';

import { ChePluginManager } from './che-plugin-manager';
import { ChePluginRegistry } from '../../common/che-plugin-protocol';
import { ChePluginRegistry } from '@eclipse-che/theia-remote-api/lib/common/plugin-service';
import { QuickInputService } from '@theia/core/lib/browser';

function cmd(id: string, label: string): Command {
Expand Down Expand Up @@ -75,8 +75,8 @@ export class ChePluginCommandContribution implements CommandContribution {

const registry: ChePluginRegistry = {
name,
uri,
publicUri: uri,
internalURI: uri,
publicURI: uri,
};

this.chePluginManager.addRegistry(registry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import { DeployedPlugin, HostedPluginServer, PluginMetadata } from '@theia/plugin-ext/lib/common/plugin-protocol';
import { inject, injectable } from 'inversify';

import { ChePluginMetadata } from '../../common/che-plugin-protocol';
import { PluginFilter } from '../../common/plugin/plugin-filter';
import { ChePluginMetadata } from '@eclipse-che/theia-remote-api/lib/common/plugin-service';
import { PluginFilter } from './plugin-filter';

@injectable()
export class ChePluginFrontentService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
ChePluginRegistries,
ChePluginRegistry,
ChePluginService,
} from '../../common/che-plugin-protocol';
} from '@eclipse-che/theia-remote-api/lib/common/plugin-service';
import { ConfirmDialog, OpenerService } from '@theia/core/lib/browser';
import { Emitter, Event, MessageService } from '@theia/core/lib/common';
import { PreferenceChange, PreferenceScope, PreferenceService } from '@theia/core/lib/browser/preferences';
Expand All @@ -25,7 +25,7 @@ import { ChePluginPreferences } from './che-plugin-preferences';
import { ChePluginServiceClientImpl } from './che-plugin-service-client';
import { DevfileService } from '@eclipse-che/theia-remote-api/lib/common/devfile-service';
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
import { PluginFilter } from '../../common/plugin/plugin-filter';
import { PluginFilter } from './plugin-filter';
import { PluginServer } from '@theia/plugin-ext/lib/common/plugin-protocol';
import URI from '@theia/core/lib/common/uri';
import { WorkspaceService } from '@eclipse-che/theia-remote-api/lib/common/workspace-service';
Expand Down Expand Up @@ -87,31 +87,35 @@ export class ChePluginManager {
async onStart(): Promise<void> {
await this.initDefaults();
const fireChanged = debounce(() => this.pluginRegistryListChangedEvent.fire(), 5000);

this.preferenceService.onPreferenceChanged(async (event: PreferenceChange) => {
if (event.preferenceName !== 'chePlugins.repositories') {
return;
}

const oldPrefs = event.oldValue;
if (oldPrefs) {
for (const repoName of Object.keys(oldPrefs)) {
const registry = this.registryList.find(r => r.name === repoName && r.uri === oldPrefs[repoName]);
const registry = this.registryList.find(r => r.name === repoName && r.internalURI === oldPrefs[repoName]);
if (registry) {
this.registryList.splice(this.registryList.indexOf(registry), 1);
}
}
}

const newPrefs = event.newValue;
if (newPrefs) {
for (const repoName of Object.keys(newPrefs)) {
this.registryList.push({ name: repoName, uri: newPrefs[repoName], publicUri: newPrefs[repoName] });
this.registryList.push({ name: repoName, internalURI: newPrefs[repoName], publicURI: newPrefs[repoName] });
}
}
// notify that plugin registry list has been changed
fireChanged();
});

this.chePluginServiceClient.onInvalidRegistryFound(async registry => {
const result = await this.messageService.warn(
`Invalid plugin registry URL: "${registry.uri}" is detected`,
`Invalid plugin registry URL: "${registry.internalURI}" is detected`,
'Open settings.json'
);
if (result) {
Expand Down Expand Up @@ -154,12 +158,12 @@ export class ChePluginManager {
Object.keys(prefs).forEach(repoName => {
const uri = prefs[repoName];

const registry = this.registryList.find(r => r.uri === uri);
const registry = this.registryList.find(r => r.internalURI === uri);
if (registry === undefined) {
this.registryList.push({
name: repoName,
uri: uri,
publicUri: uri,
internalURI: uri,
publicURI: uri,
});
}
});
Expand All @@ -178,7 +182,7 @@ export class ChePluginManager {

if (!this.installedPlugins) {
// Get list of plugins from workspace config
this.installedPlugins = await this.chePluginService.getWorkspacePlugins();
this.installedPlugins = await this.chePluginService.getInstalledPlugins();
}
}

Expand All @@ -189,7 +193,7 @@ export class ChePluginManager {
const prefs: { [index: string]: string } = {};
this.registryList.forEach(r => {
if (r.name !== 'Default') {
prefs[r.name] = r.uri;
prefs[r.name] = r.internalURI;
}
});

Expand All @@ -200,7 +204,7 @@ export class ChePluginManager {
}

removeRegistry(registry: ChePluginRegistry): void {
this.registryList = this.registryList.filter(r => r.uri !== registry.uri);
this.registryList = this.registryList.filter(r => r.internalURI !== registry.internalURI);
}

getRegistryList(): ChePluginRegistry[] {
Expand Down Expand Up @@ -236,7 +240,7 @@ export class ChePluginManager {
.forEach(component => {
const registryUrl = component.plugin?.registryUrl!;
const name = component.plugin?.id!;
registries[name] = { name, uri: registryUrl, publicUri: registryUrl };
registries[name] = { name, internalURI: registryUrl, publicURI: registryUrl };
});
}

Expand All @@ -260,10 +264,10 @@ export class ChePluginManager {

// Filter plugins if user requested the list of installed plugins
if (PluginFilter.hasType(filter, '@installed')) {
return await this.getInstalledPlugins(filter);
return this.getInstalledPlugins(filter);
}

return await this.getAllPlugins(filter);
return this.getAllPlugins(filter);
}

private async getBuiltInPlugins(filter: string): Promise<ChePlugin[]> {
Expand All @@ -276,10 +280,11 @@ export class ChePluginManager {
*/
private async getAllPlugins(filter: string): Promise<ChePlugin[]> {
// get list of all plugins
const rawPlugins = await this.chePluginService.getPlugins(filter);
const rawPlugins = await this.chePluginService.getPlugins();
const filteredPlugins = PluginFilter.filterPlugins(rawPlugins, filter);

// group the plugins
const grouppedPlugins = this.groupPlugins(rawPlugins);
const grouppedPlugins = this.groupPlugins(filteredPlugins);

// prepare list of installed plugins without versions and repository URI
const installedPluginsInfo = this.getInstalledPluginsInfo();
Expand All @@ -305,10 +310,11 @@ export class ChePluginManager {
* Returns the list of installed plugins
*/
private async getInstalledPlugins(filter: string): Promise<ChePlugin[]> {
const rawPlugins: ChePluginMetadata[] = await this.chePluginService.getPlugins(filter);
const rawPlugins: ChePluginMetadata[] = await this.chePluginService.getPlugins();
const filteredPlugins = PluginFilter.filterPlugins(rawPlugins, filter);

// group the plugins
const grouppedPlugins = this.groupPlugins(rawPlugins);
const grouppedPlugins = this.groupPlugins(filteredPlugins);

// prepare list of installed plugins without versions and repository URI
const installedPluginsInfo = this.getInstalledPluginsInfo();
Expand Down Expand Up @@ -354,8 +360,8 @@ export class ChePluginManager {
// we need to remove the registry URI from the start of the plugin
const registries: string[] = [];
this.registryList.forEach(registry => {
let uri = registry.uri;
if (uri === this.defaultRegistry.uri) {
let uri = registry.internalURI;
if (uri === this.defaultRegistry.internalURI) {
return;
}

Expand Down Expand Up @@ -441,7 +447,7 @@ export class ChePluginManager {

try {
// add the plugin to workspace configuration
await this.chePluginService.addPlugin(metadata.key);
await this.chePluginService.installPlugin(metadata.key);
this.messageService.info(
`Plugin '${metadata.publisher}/${metadata.name}/${metadata.version}' has been successfully installed`
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* SPDX-License-Identifier: EPL-2.0
***********************************************************************/

import { ChePluginRegistry, ChePluginServiceClient } from '../../common/che-plugin-protocol';
import { ChePluginRegistry, ChePluginServiceClient } from '@eclipse-che/theia-remote-api/lib/common/plugin-service';
import { Emitter, Event } from '@theia/core/lib/common';

import { injectable } from 'inversify';
Expand Down Expand Up @@ -75,7 +75,7 @@ export class ChePluginServiceClientImpl implements ChePluginServiceClient {

async invalidRegistryFound(registry: ChePluginRegistry): Promise<void> {
this.onInvalidRegistryFoundEmitter.fire(registry);
console.log('Unable to read plugin registry', registry.uri);
console.log('Unable to read plugin registry', registry.internalURI);
}

async invalidPluginFound(pluginYaml: string): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import * as React from 'react';
import { ChePluginManager } from './che-plugin-manager';
import { ChePlugin, ChePluginMetadata } from '../../common/che-plugin-protocol';
import { ChePlugin, ChePluginMetadata } from '@eclipse-che/theia-remote-api/lib/common/plugin-service';

interface ListProps {
pluginManager: ChePluginManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { injectable, inject, postConstruct } from 'inversify';
import { Message } from '@phosphor/messaging';
import { AlertMessage } from '@theia/core/lib/browser/widgets/alert-message';
import * as React from 'react';
import { ChePlugin } from '../../common/che-plugin-protocol';
import { ChePlugin } from '@eclipse-che/theia-remote-api/lib/common/plugin-service';
import { ChePluginServiceClientImpl } from './che-plugin-service-client';
import { ChePluginManager } from './che-plugin-manager';
import { ChePluginMenu } from './che-plugin-menu';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* SPDX-License-Identifier: EPL-2.0
***********************************************************************/

import { ChePluginMetadata } from '../che-plugin-protocol';
import { ChePluginMetadata } from '@eclipse-che/theia-remote-api/lib/common/plugin-service';

export namespace PluginFilter {
// @installed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* SPDX-License-Identifier: EPL-2.0
***********************************************************************/

import { CHE_PLUGIN_SERVICE_PATH, ChePluginService, ChePluginServiceClient } from '../common/che-plugin-protocol';
import {
CHE_PRODUCT_SERVICE_PATH,
CHE_TASK_SERVICE_PATH,
Expand All @@ -23,14 +22,13 @@ import { CheClientIpServiceContribution } from './che-client-ip-service';
import { CheEnvVariablesServerImpl } from './che-env-variables-server';
import { ChePluginApiContribution } from './che-plugin-script-service';
import { ChePluginApiProvider } from './che-plugin-api-provider';
import { ChePluginServiceImpl } from './che-plugin-service';
import { CheProductServiceImpl } from './che-product-service';
import { CheTaskServiceImpl } from './che-task-service';
import { ContainerModule } from 'inversify';
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
import { ExtPluginApiProvider } from '@theia/plugin-ext';
import { PluginApiContribution } from '@theia/plugin-ext/lib/main/node/plugin-service';
import { PluginApiContributionIntercepted } from './plugin-service';
import { PluginApiContribution as WsRequestValidatorContributionImpl } from '@theia/plugin-ext/lib/main/node/plugin-service';
import { WsRequestValidatorContributionIntercepted } from './ws-request-validator-contribution';

export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(CheEnvVariablesServerImpl).toSelf().inSingletonScope();
Expand All @@ -44,7 +42,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(BackendApplicationContribution).toService(ChePluginApiContribution);
bind(BackendApplicationContribution).toService(CheClientIpServiceContribution);

rebind(PluginApiContribution).to(PluginApiContributionIntercepted).inSingletonScope();
rebind(WsRequestValidatorContributionImpl).to(WsRequestValidatorContributionIntercepted).inSingletonScope();

bind(CheTaskService)
.toDynamicValue(ctx => new CheTaskServiceImpl(ctx.container))
Expand All @@ -61,21 +59,6 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
)
.inSingletonScope();

bind(ChePluginService)
.toDynamicValue(ctx => new ChePluginServiceImpl(ctx.container))
.inSingletonScope();
bind(ConnectionHandler)
.toDynamicValue(
ctx =>
new JsonRpcConnectionHandler<ChePluginServiceClient>(CHE_PLUGIN_SERVICE_PATH, client => {
const server: ChePluginService = ctx.container.get(ChePluginService);
server.setClient(client);
client.onDidCloseConnection(() => server.disconnectClient(client));
return server;
})
)
.inSingletonScope();

bind(CheProductService).to(CheProductServiceImpl).inSingletonScope();
bind(ConnectionHandler)
.toDynamicValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ import { inject, injectable } from 'inversify';
import { Deferred } from '@theia/core/lib/common/promise-util';
import { EndpointService } from '@eclipse-che/theia-remote-api/lib/common/endpoint-service';
import { ILogger } from '@theia/core/lib/common/logger';
import { PluginApiContribution } from '@theia/plugin-ext/lib/main/node/plugin-service';
import { SERVER_WEBVIEWS_ATTR_VALUE } from '../common/che-server-common';
import { WebviewExternalEndpoint } from '@theia/plugin-ext/lib/main/common/webview-protocol';
import { PluginApiContribution as WsRequestValidatorContributionImpl } from '@theia/plugin-ext/lib/main/node/plugin-service';

const vhost = require('vhost');

const pluginPath = (process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE) + './theia/plugins/';

@injectable()
export class PluginApiContributionIntercepted extends PluginApiContribution {
export class WsRequestValidatorContributionIntercepted extends WsRequestValidatorContributionImpl {
@inject(EndpointService)
private endpointService: EndpointService;

Expand Down
3 changes: 2 additions & 1 deletion extensions/eclipse-che-theia-plugin/src/che-proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ declare module '@eclipse-che/plugin' {
}

export interface Devfile {
apiVersion: string;
apiVersion?: string;
schemaVersion?: string;
attributes?: { [attributeName: string]: string };
metadata: DevfileMetadata;
projects?: DevfileProject[];
Expand Down
1 change: 1 addition & 0 deletions extensions/eclipse-che-theia-remote-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"dependencies": {
"@kubernetes/client-node": "^0.12.1",
"@theia/core": "next",
"js-yaml": "3.13.1",
"inversify": "^5.0.1"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit a6fda6a

Please sign in to comment.