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

15540 user level tasks #739

Merged
merged 2 commits into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 5 additions & 12 deletions plugins/containers-plugin/src/containers-tree-data-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import * as theia from '@theia/plugin';
import { IContainer } from './containers-service';
import { TaskScope } from '@eclipse-che/plugin';

interface ITreeNodeItem {
id: string;
Expand Down Expand Up @@ -120,7 +121,7 @@ export class ContainersTreeDataProvider implements theia.TreeDataProvider<ITreeN
iconPath: 'fa-cogs medium-yellow',
command: {
id: CONTAINERS_PLUGIN_RUN_TASK_COMMAND_ID,
arguments: [this.getRootUri().toString(), command.commandName, container.name]
arguments: [command.commandName, container.name]
}
});
});
Expand Down Expand Up @@ -235,14 +236,6 @@ export class ContainersTreeDataProvider implements theia.TreeDataProvider<ITreeN
this.onDidChangeTreeDataEmitter.fire();
}

private getRootUri(): theia.Uri {
const workspaceFolders = theia.workspace.workspaceFolders;
if (!workspaceFolders || workspaceFolders.length < 1) {
return theia.Uri.file('/projects');
}
return workspaceFolders[0].uri;
}

private getRandId(): string {
let uniqueId = '';
for (let counter = 0; counter < 1000; counter++) {
Expand Down Expand Up @@ -295,10 +288,10 @@ export const CONTAINERS_PLUGIN_RUN_TASK_COMMAND_ID = 'containers-plugin-run-task
* This is needed if a command doesn't have container to be run in specified.
* In such case we run the command in the container under which this command was clicked.
*/
export async function containersTreeTaskLauncherCommandHandler(source: string, label: string, containerName: string): Promise<void> {
export async function containersTreeTaskLauncherCommandHandler(label: string, containerName: string): Promise<void> {
const tasks: theia.Task[] = await theia.tasks.fetchTasks({ type: 'che' });
for (const task of tasks) {
if (task.name === label && task.source === source) {
if (task.name === label) { // task labels are unique in the workspace
if (!task.definition.target) {
task.definition.target = {};
}
Expand All @@ -310,5 +303,5 @@ export async function containersTreeTaskLauncherCommandHandler(source: string, l
}

// Shouldn't happen. Fallback to default behaviour.
theia.commands.executeCommand('task:run', source, label);
theia.commands.executeCommand('task:run', 'che', label, TaskScope.Global);
}
18 changes: 4 additions & 14 deletions plugins/task-plugin/src/export/export-configs-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import { injectable, inject, multiInject } from 'inversify';
import { CheWorkspaceClient } from '../che-workspace-client';
import * as theia from '@theia/plugin';
import { che as cheApi } from '@eclipse-che/api';

export const ConfigurationsExporter = Symbol('ConfigurationsExporter');
Expand All @@ -23,7 +22,7 @@ export interface ConfigurationsExporter {
* @param workspaceFolder workspace folder for exporting configs in the config file
* @param commands commands with configurations for export
*/
export(workspaceFolder: theia.WorkspaceFolder, commands: cheApi.workspace.Command[]): Promise<void>;
export(commands: cheApi.workspace.Command[]): Promise<void>;
}
/** Contains configurations as array of object and as raw content and is used at getting configurations from config file for example */
export interface Configurations<T> {
Expand All @@ -46,25 +45,16 @@ export class ExportConfigurationsManager {
protected readonly exporters: ConfigurationsExporter[];

async export(): Promise<void> {
const workspaceFolders = theia.workspace.workspaceFolders;
if (!workspaceFolders || workspaceFolders.length < 1) {
return;
}

const exportPromises = [];
const cheCommands = await this.cheWorkspaceClient.getCommands();
for (const exporter of this.exporters) {
exportPromises.push(this.doExport(workspaceFolders, cheCommands, exporter));
exportPromises.push(this.doExport(cheCommands, exporter));
}

await Promise.all(exportPromises);
}

private async doExport(workspaceFolders: theia.WorkspaceFolder[], cheCommands: cheApi.workspace.Command[], exporter: ConfigurationsExporter): Promise<void> {
const exportConfigsPromises = [];
for (const workspaceFolder of workspaceFolders) {
exportConfigsPromises.push(exporter.export(workspaceFolder, cheCommands));
}
await Promise.all(exportConfigsPromises);
private async doExport(cheCommands: cheApi.workspace.Command[], exporter: ConfigurationsExporter): Promise<void> {
return exporter.export(cheCommands);
}
}
16 changes: 14 additions & 2 deletions plugins/task-plugin/src/export/launch-configs-exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,20 @@ export class LaunchConfigurationsExporter implements ConfigurationsExporter {
@inject(VsCodeLaunchConfigsExtractor)
protected readonly vsCodeLaunchConfigsExtractor: VsCodeLaunchConfigsExtractor;

async export(workspaceFolder: theia.WorkspaceFolder, commands: cheApi.workspace.Command[]): Promise<void> {
async export(commands: cheApi.workspace.Command[]): Promise<void> {
if (!theia.workspace.workspaceFolders) {
return;
}

const exportConfigsPromises: Promise<void>[] = [];

for (const workspaceFolder of theia.workspace.workspaceFolders) {
exportConfigsPromises.push(this.doExport(workspaceFolder, commands));
}
await Promise.all(exportConfigsPromises);
}

async doExport(workspaceFolder: theia.WorkspaceFolder, commands: cheApi.workspace.Command[]): Promise<void> {
const launchConfigFileUri = this.getConfigFileUri(workspaceFolder.uri.path);
const configFileConfigs = this.configFileLaunchConfigsExtractor.extract(launchConfigFileUri);
const vsCodeConfigs = this.vsCodeLaunchConfigsExtractor.extract(commands);
Expand Down Expand Up @@ -67,7 +80,6 @@ export class LaunchConfigurationsExporter implements ConfigurationsExporter {

conflictHandler(conflict, config2);
}

return result;
}

Expand Down
21 changes: 10 additions & 11 deletions plugins/task-plugin/src/export/task-configs-exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
**********************************************************************/

import { injectable, inject } from 'inversify';
import * as theia from '@theia/plugin';
import * as startPoint from '../task-plugin-backend';
import { che as cheApi } from '@eclipse-che/api';
import { TaskConfiguration } from '@eclipse-che/plugin';
Expand All @@ -20,13 +19,18 @@ import { VsCodeTaskConfigsExtractor } from '../extract/vscode-task-configs-extra
import { ConfigurationsExporter } from './export-configs-manager';
import { ConfigFileTasksExtractor } from '../extract/config-file-task-configs-extractor';
import { BackwardCompatibilityResolver } from '../task/backward-compatibility';
import { homedir } from 'os';

const CONFIG_DIR = '.theia';
const TASK_CONFIG_FILE = 'tasks.json';
const formattingOptions = { tabSize: 4, insertSpaces: true, eol: '' };

export const VSCODE_TASK_TYPE = 'vscode-task';

// this really should be handled through some theia API, but there is none available in plugins
// it only works on linux and only if this plugin runs in the theia container
export const THEIA_USER_TASKS_PATH = resolve(homedir(), CONFIG_DIR, TASK_CONFIG_FILE);

/** Exports configurations of tasks in the config file. */
@injectable()
export class TaskConfigurationsExporter implements ConfigurationsExporter {
Expand All @@ -43,9 +47,8 @@ export class TaskConfigurationsExporter implements ConfigurationsExporter {
@inject(BackwardCompatibilityResolver)
protected readonly backwardCompatibilityResolver: BackwardCompatibilityResolver;

async export(workspaceFolder: theia.WorkspaceFolder, commands: cheApi.workspace.Command[]): Promise<void> {
const tasksConfigFileUri = this.getConfigFileUri(workspaceFolder.uri.path);
const configFileTasks = this.configFileTasksExtractor.extract(tasksConfigFileUri);
async export(commands: cheApi.workspace.Command[]): Promise<void> {
const configFileTasks = this.configFileTasksExtractor.extract(THEIA_USER_TASKS_PATH);

const cheTasks = this.cheTaskConfigsExtractor.extract(commands);
const vsCodeTasks = this.vsCodeTaskConfigsExtractor.extract(commands);
Expand All @@ -54,18 +57,18 @@ export class TaskConfigurationsExporter implements ConfigurationsExporter {

const configFileContent = configFileTasks.content;
if (configFileContent) {
this.saveConfigs(tasksConfigFileUri, configFileContent, this.merge(configFileConfigs, devfileConfigs, this.getConsoleConflictLogger()));
this.saveConfigs(THEIA_USER_TASKS_PATH, configFileContent, this.merge(configFileConfigs, devfileConfigs, this.getConsoleConflictLogger()));
return;
}

const vsCodeTasksContent = vsCodeTasks.content;
if (vsCodeTasksContent) {
this.saveConfigs(tasksConfigFileUri, vsCodeTasksContent, devfileConfigs);
this.saveConfigs(THEIA_USER_TASKS_PATH, vsCodeTasksContent, devfileConfigs);
return;
}

if (cheTasks) {
this.saveConfigs(tasksConfigFileUri, '', cheTasks);
this.saveConfigs(THEIA_USER_TASKS_PATH, '', cheTasks);
}
}

Expand Down Expand Up @@ -103,10 +106,6 @@ export class TaskConfigurationsExporter implements ConfigurationsExporter {
return JSON.stringify(properties1) === JSON.stringify(properties2);
}

private getConfigFileUri(rootDir: string): string {
return resolve(rootDir.toString(), CONFIG_DIR, TASK_CONFIG_FILE);
}

private saveConfigs(tasksConfigFileUri: string, content: string, configurations: TaskConfiguration[]): void {
const result = modify(content, ['tasks'], configurations.map(config => Object.assign(config, { _scope: undefined })), formattingOptions);
writeFileSync(tasksConfigFileUri, result);
Expand Down
3 changes: 2 additions & 1 deletion plugins/workspace-plugin/src/theia-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { che as cheApi } from '@eclipse-che/api';
import * as fileuri from './file-uri';
import { execute } from './exec';
import * as git from './git';
import { TaskScope } from '@eclipse-che/plugin';

const SS_CRT_PATH = '/tmp/che/secret/ca.crt';
const CHE_TASK_TYPE = 'che';
Expand Down Expand Up @@ -265,7 +266,7 @@ export class TheiaCommand {

if (this.id === ActionId.RUN_COMMAND) {
if (this.properties) {
return theia.commands.executeCommand('task:run', CHE_TASK_TYPE, this.properties.name)
return theia.commands.executeCommand('task:run', CHE_TASK_TYPE, this.properties.name, TaskScope.Global)
.then(() => {
theia.window.showInformationMessage('Executed che command succesfully');
}, e => {
Expand Down