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

Plugin management #162

Merged
merged 4 commits into from
May 31, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions che-plugins/che-editor-theia/etc/che-plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@ containers:
env:
- name: THEIA_PLUGINS
value: local-dir:///plugins
- name: VSCODE_PLUGINS
value: local-dir:///vscode-plugins
- name: HOSTED_PLUGIN_HOSTNAME
value: 0.0.0.0
- name: HOSTED_PLUGIN_PORT
value: 3130
volumes:
- mountPath: "/plugins"
name: plugins
- mountPath: "/vscode-plugins"
name: vscode-plugins
- mountPath: "/home/theia/.theia"
name: theia-data
- mountPath: "/projects"
Expand Down
7 changes: 5 additions & 2 deletions extensions/eclipse-che-theia-plugin-ext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@
"@eclipse-che/plugin": "0.0.1",
"@eclipse-che/workspace-client": "latest",
"@theia/core": "next",
"@theia/plugin-ext": "next"
"@theia/plugin-ext": "next",
"axios": "0.18.0",
"js-yaml": "3.12.0"
},
"devDependencies": {
"clean-webpack-plugin": "^0.1.19",
"ts-loader": "^4.1.0",
"ts-node": "5.0.1",
"webpack": "^4.20.2",
"webpack-cli": "^3.1.1",
"typescript-formatter": "7.2.2"
"typescript-formatter": "7.2.2",
"@types/js-yaml": "3.11.2"
},
"scripts": {
"prepare": "yarn clean && yarn build",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,30 @@
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/

import '../../src/browser/style/che-plugins.css';

import { ContainerModule } from 'inversify';
import { MainPluginApiProvider } from '@theia/plugin-ext/lib/common/plugin-ext-api-contribution';
import { CheApiProvider } from './che-api-provider';
import {
CHE_API_SERVICE_PATH,
CHE_TASK_SERVICE_PATH,
CHE_PLUGIN_SERVICE_PATH,
CheApiService,
CheTaskClient,
CheTaskService
CheTaskService,
ChePluginService
} from '../common/che-protocol';
import { WebSocketConnectionProvider } from '@theia/core/lib/browser';
import { WebSocketConnectionProvider, bindViewContribution, WidgetFactory } from '@theia/core/lib/browser';
import { CommandContribution } from '@theia/core/lib/common';
import { CheTaskClientImpl } from './che-task-client';
import { ChePluginViewContribution } from './plugin/che-plugin-view-contribution';
import { ChePluginWidget } from './plugin/che-plugin-widget';
import { ChePluginFrontentService } from './plugin/che-plugin-frontend-service';
import { ChePluginManager } from './plugin/che-plugin-manager';
import { ChePluginMenu } from './plugin/che-plugin-menu';
import { ChePluginCommandContribution } from './plugin/che-plugin-command-contribution';
import { bindChePluginPreferences } from './plugin/che-plugin-preferences';

export default new ContainerModule(bind => {
bind(CheApiProvider).toSelf().inSingletonScope();
Expand All @@ -36,4 +48,26 @@ export default new ContainerModule(bind => {
const client: CheTaskClient = ctx.container.get(CheTaskClient);
return provider.createProxy<CheTaskService>(CHE_TASK_SERVICE_PATH, client);
}).inSingletonScope();

bindChePluginPreferences(bind);

bind(ChePluginService).toDynamicValue(ctx => {
const provider = ctx.container.get(WebSocketConnectionProvider);
return provider.createProxy<CheApiService>(CHE_PLUGIN_SERVICE_PATH);
}).inSingletonScope();

bind(ChePluginFrontentService).toSelf().inSingletonScope();
bind(ChePluginManager).toSelf().inSingletonScope();

bindViewContribution(bind, ChePluginViewContribution);

bind(ChePluginMenu).toSelf().inSingletonScope();
bind(ChePluginWidget).toSelf().inSingletonScope();
bind(WidgetFactory).toDynamicValue(ctx => ({
id: ChePluginViewContribution.PLUGINS_WIDGET_ID,
createWidget: () => ctx.container.get(ChePluginWidget)
}));

bind(ChePluginCommandContribution).toSelf().inSingletonScope();
bind(CommandContribution).toService(ChePluginCommandContribution);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
/********************************************************************************
* Copyright (C) 2018 Red Hat, Inc. and others.
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix year, please, for all files...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

*
* 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 { MessageService, Command } from '@theia/core/lib/common';
import { ChePluginRegistry } from '../../common/che-protocol';
import { ChePluginManager } from './che-plugin-manager';
import { QuickInputService } from '@theia/core/lib/browser';
import { MonacoQuickOpenService } from '@theia/monaco/lib/browser/monaco-quick-open-service';
import { QuickOpenModel, QuickOpenItem, QuickOpenMode } from '@theia/core/lib/browser/quick-open/quick-open-model';

function cmd(id: string, label: string): Command {
return {
id: `${ChePluginManagerCommands.PLUGIN_MANAGER_ID}:${id}`,
category: ChePluginManagerCommands.PLUGIN_MANAGER_CATEGORY,
label: label
};
}

export namespace ChePluginManagerCommands {

export const PLUGIN_MANAGER_ID = 'plugin-manager';
export const PLUGIN_MANAGER_CATEGORY = 'Plugin Manager';

export const SHOW_AVAILABLE_PLUGINS = cmd('show-available-plugins', 'Show Available Plugins');
export const SHOW_INSTALLED_PLUGINS = cmd('show-installed-plugins', 'Show Installed Plugins');
export const SHOW_BUILT_IN_PLUGINS = cmd('show-built-in-plugins', 'Show Built-in Plugins');

export const CHANGE_REGISTRY = cmd('change-registry', 'Change Registry');
export const ADD_REGISTRY = cmd('add-registry', 'Add Registry');
}

@injectable()
export class ChePluginCommandContribution implements CommandContribution {

@inject(MessageService)
protected readonly messageService: MessageService;

@inject(QuickInputService)
protected readonly quickInputService: QuickInputService;

@inject(MonacoQuickOpenService)
protected readonly monacoQuickOpenService: MonacoQuickOpenService;

@inject(ChePluginManager)
protected readonly chePluginManager: ChePluginManager;

registerCommands(commands: CommandRegistry): void {
commands.registerCommand(ChePluginManagerCommands.CHANGE_REGISTRY, {
execute: () => this.changePluginRegistry()
});

commands.registerCommand(ChePluginManagerCommands.ADD_REGISTRY, {
execute: () => this.addPluginRegistry()
});
}

//
async showAvailablePlugins() {
this.chePluginManager.changeFilter('', true);
}

// @installed
async showInstalledPlugins() {
this.chePluginManager.changeFilter('@installed', true);
}

// @builtin
async showBuiltInPlugins() {
mmorhun marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Displays prompt to add new plugin registry
mmorhun marked this conversation as resolved.
Show resolved Hide resolved
*/
async addPluginRegistry(): Promise<void> {
const name = await this.quickInputService.open({
prompt: 'Name of your registry'
});

if (!name) {
return;
}

const uri = await this.quickInputService.open({
prompt: 'Registry URI'
});

if (!uri) {
return;
}

const registry = {
name,
uri
};

this.chePluginManager.addRegistry(registry);
this.chePluginManager.changeRegistry(registry);
}

private async pickPluginRegistry(): Promise<ChePluginRegistry | undefined> {
const registryList = this.chePluginManager.getRegistryList();

return new Promise<ChePluginRegistry | undefined>((resolve, reject) => {
// Return undefined if registry list is empty
if (!registryList || registryList.length === 0) {
resolve(undefined);
return;
}

// Active before appearing the pick menu
const activeElement: HTMLElement | undefined = window.document.activeElement as HTMLElement;

// ChePluginRegistry to be returned
let returnValue: ChePluginRegistry | undefined;

const items = registryList.map(registry =>
new QuickOpenItem({
label: registry.name,
detail: registry.uri,
run: mode => {
if (mode === QuickOpenMode.OPEN) {
returnValue = {
name: registry.name,
uri: registry.uri
} as ChePluginRegistry;
}
return true;
}
})
);

// Create quick open model
const model = {
onType(lookFor: string, acceptor: (items: QuickOpenItem[]) => void): void {
acceptor(items);
}
} as QuickOpenModel;

// Show pick menu
this.monacoQuickOpenService.open(model, {
fuzzyMatchLabel: true,
fuzzyMatchDetail: true,
fuzzyMatchDescription: true,
onClose: () => {
if (activeElement) {
activeElement.focus();
}

resolve(returnValue);
}
});
});
}

async changePluginRegistry(): Promise<void> {
const registry = await this.pickPluginRegistry();
if (registry) {
this.chePluginManager.changeRegistry(registry);
}
}

}
Loading