From 2494b2a85e4731208dc5d97c0ea93b73ece92cf7 Mon Sep 17 00:00:00 2001 From: Mykola Morhun Date: Wed, 18 Sep 2019 09:33:05 +0000 Subject: [PATCH] Run Che command in selected container Signed-off-by: Mykola Morhun --- .../src/containers-plugin.ts | 13 +++++++-- .../src/containers-tree-data-provider.ts | 29 ++++++++++++++++++- yarn.lock | 4 +-- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/plugins/containers-plugin/src/containers-plugin.ts b/plugins/containers-plugin/src/containers-plugin.ts index 9410d53f3..5d5f7c8ce 100644 --- a/plugins/containers-plugin/src/containers-plugin.ts +++ b/plugins/containers-plugin/src/containers-plugin.ts @@ -8,9 +8,13 @@ * SPDX-License-Identifier: EPL-2.0 **********************************************************************/ -import { ContainersTreeDataProvider } from './containers-tree-data-provider'; -import { ContainersService } from './containers-service'; import * as theia from '@theia/plugin'; +import { ContainersService } from './containers-service'; +import { + ContainersTreeDataProvider, + CONTAINERS_PLUGIN_RUN_TASK_COMMAND_ID, + containersTreeTaskLauncherCommandHandler +} from './containers-tree-data-provider'; export function start(context: theia.PluginContext) { const treeDataProvider = new ContainersTreeDataProvider(); @@ -28,6 +32,11 @@ export function start(context: theia.PluginContext) { console.error(error); theia.window.showErrorMessage(error); }); + + const containersTreeTaskLauncherCommand = { id: CONTAINERS_PLUGIN_RUN_TASK_COMMAND_ID }; + context.subscriptions.push( + theia.commands.registerCommand(containersTreeTaskLauncherCommand, containersTreeTaskLauncherCommandHandler) + ); } export function stop() { diff --git a/plugins/containers-plugin/src/containers-tree-data-provider.ts b/plugins/containers-plugin/src/containers-tree-data-provider.ts index 4acb3c7f2..0918f6451 100644 --- a/plugins/containers-plugin/src/containers-tree-data-provider.ts +++ b/plugins/containers-plugin/src/containers-tree-data-provider.ts @@ -106,7 +106,10 @@ export class ContainersTreeDataProvider implements theia.TreeDataProvider { + const tasks: theia.Task[] = await theia.tasks.fetchTasks({ type: 'che' }); + for (const task of tasks) { + if (task.name === label && task.source === source) { + if (!task.definition.target) { + task.definition.target = {}; + } + task.definition.target.containerName = containerName; + + theia.tasks.executeTask(task); + return; + } + } + + // Shouldn't happen. Fallback to default behaviour. + theia.commands.executeCommand('task:run', source, label); +} diff --git a/yarn.lock b/yarn.lock index c14fc8852..dc5a8e7cf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8270,9 +8270,9 @@ move-concurrently@^1.0.1: rimraf "^2.5.4" run-queue "^1.0.3" -"moxios@git://github.com/stoplightio/moxios.git#v1.3.0": +"moxios@git://github.com/stoplightio/moxios#v1.3.0": version "1.3.0" - resolved "git://github.com/stoplightio/moxios.git#9d702c8eafee4b02917d6bc400ae15f1e835cf51" + resolved "git://github.com/stoplightio/moxios#9d702c8eafee4b02917d6bc400ae15f1e835cf51" dependencies: class-autobind "^0.1.4"