diff --git a/plugins/task-plugin/src/che-workspace-client.ts b/plugins/task-plugin/src/che-workspace-client.ts index 19824c2556..1d20ce9fbc 100644 --- a/plugins/task-plugin/src/che-workspace-client.ts +++ b/plugins/task-plugin/src/che-workspace-client.ts @@ -29,16 +29,9 @@ export class CheWorkspaceClient { return che.devfile.getComponentStatuses(); } - async getCommands(): Promise { - const workspace: cheApi.workspace.Workspace = await this.getCurrentWorkspace(); - - const runtime: cheApi.workspace.Runtime | undefined = workspace.runtime; - if (!runtime) { - return []; - } - - const commands = runtime.commands; - return commands ? commands : []; + async getCommands(): Promise { + const devfile = await che.devfile.get(); + return devfile.commands || []; } getCurrentWorkspace(): Promise { diff --git a/plugins/task-plugin/src/export/export-configs-manager.ts b/plugins/task-plugin/src/export/export-configs-manager.ts index 9021f6f413..a2de9e4f5c 100644 --- a/plugins/task-plugin/src/export/export-configs-manager.ts +++ b/plugins/task-plugin/src/export/export-configs-manager.ts @@ -8,11 +8,12 @@ * SPDX-License-Identifier: EPL-2.0 ***********************************************************************/ +import * as che from '@eclipse-che/plugin'; + import { inject, injectable, multiInject } from 'inversify'; import { CheWorkspaceClient } from '../che-workspace-client'; import { LaunchConfigurationsExporter } from './launch-configs-exporter'; -import { che as cheApi } from '@eclipse-che/api'; export const ConfigurationsExporter = Symbol('ConfigurationsExporter'); @@ -23,7 +24,7 @@ export interface ConfigurationsExporter { * @param workspaceFolder workspace folder for exporting configs in the config file * @param commands commands with configurations for export */ - export(commands: cheApi.workspace.Command[]): Promise; + export(commands: che.devfile.DevfileCommand[]): Promise; } /** Contains configurations as array of object and as raw content and is used at getting configurations from config file for example */ export interface Configurations { @@ -46,7 +47,7 @@ export class ExportConfigurationsManager { @inject(LaunchConfigurationsExporter) protected readonly launchConfigurationsExporter: LaunchConfigurationsExporter; - protected cheCommands: cheApi.workspace.Command[] = []; + protected cheCommands: che.devfile.DevfileCommand[] = []; async init(): Promise { this.cheCommands = await this.cheWorkspaceClient.getCommands(); @@ -63,7 +64,7 @@ export class ExportConfigurationsManager { await Promise.all(exportPromises); } - private async doExport(cheCommands: cheApi.workspace.Command[], exporter: ConfigurationsExporter): Promise { + private async doExport(cheCommands: che.devfile.DevfileCommand[], exporter: ConfigurationsExporter): Promise { return exporter.export(cheCommands); } } diff --git a/plugins/task-plugin/src/export/launch-configs-exporter.ts b/plugins/task-plugin/src/export/launch-configs-exporter.ts index 70b5abfcb8..6aeedfb50b 100644 --- a/plugins/task-plugin/src/export/launch-configs-exporter.ts +++ b/plugins/task-plugin/src/export/launch-configs-exporter.ts @@ -8,6 +8,7 @@ * SPDX-License-Identifier: EPL-2.0 ***********************************************************************/ +import * as che from '@eclipse-che/plugin'; import * as startPoint from '../task-plugin-backend'; import * as theia from '@theia/plugin'; @@ -17,7 +18,6 @@ import { inject, injectable } from 'inversify'; import { ConfigFileLaunchConfigsExtractor } from '../extract/config-file-launch-configs-extractor'; import { ConfigurationsExporter } from './export-configs-manager'; import { VsCodeLaunchConfigsExtractor } from '../extract/vscode-launch-configs-extractor'; -import { che as cheApi } from '@eclipse-che/api'; import { resolve } from 'path'; const CONFIG_DIR = '.theia'; @@ -33,7 +33,7 @@ export class LaunchConfigurationsExporter implements ConfigurationsExporter { @inject(VsCodeLaunchConfigsExtractor) protected readonly vsCodeLaunchConfigsExtractor: VsCodeLaunchConfigsExtractor; - async init(commands: cheApi.workspace.Command[]): Promise { + async init(commands: che.devfile.DevfileCommand[]): Promise { theia.workspace.onDidChangeWorkspaceFolders( event => { const workspaceFolders: theia.WorkspaceFolder[] | undefined = event.added; @@ -46,7 +46,7 @@ export class LaunchConfigurationsExporter implements ConfigurationsExporter { ); } - async export(commands: cheApi.workspace.Command[], workspaceFolders?: theia.WorkspaceFolder[]): Promise { + async export(commands: che.devfile.DevfileCommand[], workspaceFolders?: theia.WorkspaceFolder[]): Promise { workspaceFolders = workspaceFolders ? workspaceFolders : theia.workspace.workspaceFolders; if (!workspaceFolders) { return; @@ -60,7 +60,7 @@ export class LaunchConfigurationsExporter implements ConfigurationsExporter { await Promise.all(exportConfigsPromises); } - async doExport(workspaceFolder: theia.WorkspaceFolder, commands: cheApi.workspace.Command[]): Promise { + async doExport(workspaceFolder: theia.WorkspaceFolder, commands: che.devfile.DevfileCommand[]): Promise { const workspaceFolderPath = workspaceFolder.uri.path; const launchConfigFilePath = resolve(workspaceFolderPath, CONFIG_DIR, LAUNCH_CONFIG_FILE); const configFileConfigs = await this.configFileLaunchConfigsExtractor.extract(launchConfigFilePath); diff --git a/plugins/task-plugin/src/export/task-configs-exporter.ts b/plugins/task-plugin/src/export/task-configs-exporter.ts index 1048202128..1e54f71c4b 100644 --- a/plugins/task-plugin/src/export/task-configs-exporter.ts +++ b/plugins/task-plugin/src/export/task-configs-exporter.ts @@ -1,5 +1,5 @@ /********************************************************************** - * Copyright (c) 2019-2020 Red Hat, Inc. + * Copyright (c) 2019-2021 Red Hat, Inc. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -8,6 +8,7 @@ * SPDX-License-Identifier: EPL-2.0 ***********************************************************************/ +import * as che from '@eclipse-che/plugin'; import * as startPoint from '../task-plugin-backend'; import { inject, injectable } from 'inversify'; @@ -19,7 +20,6 @@ import { ConfigFileTasksExtractor } from '../extract/config-file-task-configs-ex import { ConfigurationsExporter } from './export-configs-manager'; import { TaskConfiguration } from '@eclipse-che/plugin'; import { VsCodeTaskConfigsExtractor } from '../extract/vscode-task-configs-extractor'; -import { che as cheApi } from '@eclipse-che/api'; import { homedir } from 'os'; import { resolve } from 'path'; @@ -48,7 +48,7 @@ export class TaskConfigurationsExporter implements ConfigurationsExporter { @inject(BackwardCompatibilityResolver) protected readonly backwardCompatibilityResolver: BackwardCompatibilityResolver; - async export(commands: cheApi.workspace.Command[]): Promise { + async export(commands: che.devfile.DevfileCommand[]): Promise { const configFileTasks = await this.configFileTasksExtractor.extract(THEIA_USER_TASKS_PATH); const cheTasks = this.cheTaskConfigsExtractor.extract(commands); diff --git a/plugins/task-plugin/src/extract/che-task-configs-extractor.ts b/plugins/task-plugin/src/extract/che-task-configs-extractor.ts index 411e3f5a09..47ad1f4cf5 100644 --- a/plugins/task-plugin/src/extract/che-task-configs-extractor.ts +++ b/plugins/task-plugin/src/extract/che-task-configs-extractor.ts @@ -1,5 +1,5 @@ /********************************************************************** - * Copyright (c) 2019-2020 Red Hat, Inc. + * Copyright (c) 2019-2021 Red Hat, Inc. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -8,21 +8,18 @@ * SPDX-License-Identifier: EPL-2.0 ***********************************************************************/ +import * as che from '@eclipse-che/plugin'; + import { TaskConfiguration } from '@eclipse-che/plugin'; -import { VSCODE_LAUNCH_TYPE } from './vscode-launch-configs-extractor'; -import { VSCODE_TASK_TYPE } from './vscode-task-configs-extractor'; -import { che as cheApi } from '@eclipse-che/api'; import { injectable } from 'inversify'; import { toTaskConfiguration } from '../task/converter'; /** Extracts CHE configurations of tasks. */ @injectable() export class CheTaskConfigsExtractor { - extract(commands: cheApi.workspace.Command[]): TaskConfiguration[] { + extract(commands: che.devfile.DevfileCommand[]): TaskConfiguration[] { // TODO filter should be changed according to task type after resolving https://github.com/eclipse/che/issues/12710 - const filteredCommands = commands.filter( - command => command.type !== VSCODE_TASK_TYPE && command.type !== VSCODE_LAUNCH_TYPE - ); + const filteredCommands = commands.filter(command => command.exec); if (filteredCommands.length === 0) { return []; diff --git a/plugins/task-plugin/src/extract/vscode-launch-configs-extractor.ts b/plugins/task-plugin/src/extract/vscode-launch-configs-extractor.ts index 43b364d1ad..e9e49d78e8 100644 --- a/plugins/task-plugin/src/extract/vscode-launch-configs-extractor.ts +++ b/plugins/task-plugin/src/extract/vscode-launch-configs-extractor.ts @@ -1,5 +1,5 @@ /********************************************************************** - * Copyright (c) 2019-2020 Red Hat, Inc. + * Copyright (c) 2019-2021 Red Hat, Inc. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -8,28 +8,26 @@ * SPDX-License-Identifier: EPL-2.0 ***********************************************************************/ +import * as che from '@eclipse-che/plugin'; import * as theia from '@theia/plugin'; import { Configurations } from '../export/export-configs-manager'; -import { che as cheApi } from '@eclipse-che/api'; import { injectable } from 'inversify'; import { parse } from '../utils'; -export const VSCODE_LAUNCH_TYPE = 'vscode-launch'; - /** Extracts vscode launch configurations. */ @injectable() export class VsCodeLaunchConfigsExtractor { - extract(commands: cheApi.workspace.Command[]): Configurations { + extract(commands: che.devfile.DevfileCommand[]): Configurations { const emptyContent: Configurations = { content: '', configs: [] }; - const configCommands = commands.filter(command => command.type === VSCODE_LAUNCH_TYPE); + const configCommands = commands.filter(command => command.vscodeLaunch); if (configCommands.length === 0) { return emptyContent; } if (configCommands.length > 1) { - console.warn(`Found duplicate entry with configurations for type ${VSCODE_LAUNCH_TYPE}`); + console.warn(`Found duplicate entry with configurations for type vscodeLaunch`); } const configCommand = configCommands[0]; diff --git a/plugins/task-plugin/src/extract/vscode-task-configs-extractor.ts b/plugins/task-plugin/src/extract/vscode-task-configs-extractor.ts index beb01bb40c..9075620c0e 100644 --- a/plugins/task-plugin/src/extract/vscode-task-configs-extractor.ts +++ b/plugins/task-plugin/src/extract/vscode-task-configs-extractor.ts @@ -1,5 +1,5 @@ /********************************************************************** - * Copyright (c) 2019-2020 Red Hat, Inc. + * Copyright (c) 2019-2021 Red Hat, Inc. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -8,27 +8,26 @@ * SPDX-License-Identifier: EPL-2.0 ***********************************************************************/ +import * as che from '@eclipse-che/plugin'; + import { Configurations } from '../export/export-configs-manager'; import { TaskConfiguration } from '@eclipse-che/plugin'; -import { che as cheApi } from '@eclipse-che/api'; import { injectable } from 'inversify'; import { parse } from '../utils'; -export const VSCODE_TASK_TYPE = 'vscode-task'; - /** Extracts vscode configurations of tasks. */ @injectable() export class VsCodeTaskConfigsExtractor { - extract(commands: cheApi.workspace.Command[]): Configurations { + extract(commands: che.devfile.DevfileCommand[]): Configurations { const emptyContent = { content: '', configs: [] } as Configurations; - const configCommands = commands.filter(command => command.type === VSCODE_TASK_TYPE); + const configCommands = commands.filter(command => command.vscodeTask); if (configCommands.length === 0) { return emptyContent; } if (configCommands.length > 1) { - console.warn(`Found duplicate entry with configurations for type ${VSCODE_TASK_TYPE}`); + console.warn(`Found duplicate entry with configurations for type vscodeTask`); } const configCommand = configCommands[0]; diff --git a/plugins/task-plugin/src/task/converter.ts b/plugins/task-plugin/src/task/converter.ts index 300353a97c..a0ed5b3dd7 100644 --- a/plugins/task-plugin/src/task/converter.ts +++ b/plugins/task-plugin/src/task/converter.ts @@ -1,5 +1,5 @@ /********************************************************************** - * Copyright (c) 2019-2020 Red Hat, Inc. + * Copyright (c) 2019-2021 Red Hat, Inc. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -8,28 +8,23 @@ * SPDX-License-Identifier: EPL-2.0 ***********************************************************************/ -import { - CHE_TASK_TYPE, - COMPONENT_ALIAS_ATTRIBUTE, - PREVIEW_URL_ATTRIBUTE, - WORKING_DIR_ATTRIBUTE, -} from './task-protocol'; +import * as che from '@eclipse-che/plugin'; + +import { CHE_TASK_TYPE, PREVIEW_URL_ATTRIBUTE } from './task-protocol'; -import { Task } from '@theia/plugin'; import { TaskConfiguration } from '@eclipse-che/plugin'; -import { che as cheApi } from '@eclipse-che/api'; import { getAttribute } from '../utils'; /** Converts the Che command to Theia Task Configuration */ -export function toTaskConfiguration(command: cheApi.workspace.Command): TaskConfiguration { +export function toTaskConfiguration(command: che.devfile.DevfileCommand): TaskConfiguration { const taskConfig: TaskConfiguration = { type: CHE_TASK_TYPE, - label: command.name!, - command: command.commandLine, + label: command.id, + command: command.exec?.commandLine, _scope: '', // not to put into tasks.json target: { - workingDir: getAttribute(WORKING_DIR_ATTRIBUTE, command.attributes), - component: getAttribute(COMPONENT_ALIAS_ATTRIBUTE, command.attributes), + workingDir: command.exec?.workingDir, + component: command.exec?.component, }, previewUrl: getAttribute(PREVIEW_URL_ATTRIBUTE, command.attributes), problemMatcher: [], @@ -38,24 +33,7 @@ export function toTaskConfiguration(command: cheApi.workspace.Command): TaskConf return taskConfig; } -/** Converts the Che command to Task API object */ -export function toTask(command: cheApi.workspace.Command): Task { - return { - definition: { - type: CHE_TASK_TYPE, - command: command.commandLine, - target: { - workingDir: getAttribute(WORKING_DIR_ATTRIBUTE, command.attributes), - component: getAttribute(COMPONENT_ALIAS_ATTRIBUTE, command.attributes), - }, - previewUrl: getAttribute(PREVIEW_URL_ATTRIBUTE, command.attributes), - }, - name: `${command.name}`, - source: CHE_TASK_TYPE, - }; -} - -export function getCommandAttribute(command: cheApi.workspace.Command, attrName: string): string | undefined { +export function getCommandAttribute(command: che.devfile.DevfileCommand, attrName: string): string | undefined { if (!command.attributes) { return undefined; } diff --git a/plugins/task-plugin/src/task/task-protocol.ts b/plugins/task-plugin/src/task/task-protocol.ts index 5d37d43c21..17ddef8f42 100644 --- a/plugins/task-plugin/src/task/task-protocol.ts +++ b/plugins/task-plugin/src/task/task-protocol.ts @@ -13,8 +13,6 @@ import { TaskDefinition } from '@theia/plugin'; export const CHE_TASK_TYPE: string = 'che'; export const MACHINE_NAME_ATTRIBUTE: string = 'machineName'; export const PREVIEW_URL_ATTRIBUTE: string = 'previewUrl'; -export const WORKING_DIR_ATTRIBUTE: string = 'workingDir'; -export const COMPONENT_ALIAS_ATTRIBUTE: string = 'componentAlias'; export interface CheTaskDefinition extends TaskDefinition { readonly target?: Target;