From 2097d7bc6603bc63669d15bfc32400645a517cd9 Mon Sep 17 00:00:00 2001 From: Alvaro Sanchez-Leon Date: Sat, 17 Apr 2021 19:48:38 -0400 Subject: [PATCH 1/3] Revert "Consider taskConfig.type when running tasks." This reverts commit 8b9fb43c763f2f1d179f9839ef993d7218d99073. --- packages/task/src/browser/process/process-task-resolver.ts | 3 +-- packages/task/src/node/process/process-task-runner.ts | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/task/src/browser/process/process-task-resolver.ts b/packages/task/src/browser/process/process-task-resolver.ts index 1be9e053bb232..649d16a1be02c 100644 --- a/packages/task/src/browser/process/process-task-resolver.ts +++ b/packages/task/src/browser/process/process-task-resolver.ts @@ -42,8 +42,7 @@ export class ProcessTaskResolver implements TaskResolver { * sane default values. Also, resolve all known variables, e.g. `${workspaceFolder}`. */ async resolveTask(taskConfig: TaskConfiguration): Promise { - const type = taskConfig.taskType || taskConfig.type; - if (type !== 'process' && type !== 'shell') { + if (taskConfig.taskType !== 'process' && taskConfig.taskType !== 'shell') { throw new Error('Unsupported task configuration type.'); } const context = typeof taskConfig._scope === 'string' ? new URI(taskConfig._scope) : undefined; diff --git a/packages/task/src/node/process/process-task-runner.ts b/packages/task/src/node/process/process-task-runner.ts index 8bf1b23d29d3b..43779a4b8b1b2 100644 --- a/packages/task/src/node/process/process-task-runner.ts +++ b/packages/task/src/node/process/process-task-runner.ts @@ -141,7 +141,7 @@ export class ProcessTaskRunner implements TaskRunner { */ let commandLine: string | undefined; - if ((taskConfig.taskType || taskConfig.type) === 'shell') { + if (taskConfig.type === 'shell') { // When running a shell task, we have to spawn a shell process somehow, // and tell it to run the command the user wants to run inside of it. // From be9b00868e168fe98e48df367058b04a6aa98a8f Mon Sep 17 00:00:00 2001 From: Alvaro Sanchez-Leon Date: Sat, 17 Apr 2021 19:48:57 -0400 Subject: [PATCH 2/3] Revert "Use task.type first to look up task runner" This reverts commit c1841b3ba9671f24bf9b2c603adb278ef3623abd. --- packages/task/src/node/task-runner.ts | 18 ++++++------------ packages/task/src/node/task-server.ts | 2 +- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/packages/task/src/node/task-runner.ts b/packages/task/src/node/task-runner.ts index aa53a768b8a48..e33767eff75f4 100644 --- a/packages/task/src/node/task-runner.ts +++ b/packages/task/src/node/task-runner.ts @@ -84,20 +84,14 @@ export class TaskRunnerRegistry { } /** - * Looks for a registered {@link TaskRunner} for each of the task types in sequence and returns the first that is found - * If no task runner is registered for any of the types, the default runner is returned. - * @param types the task types. + * Retrieves the {@link TaskRunner} registered for the specified Task type. + * @param type the task type. * - * @returns the registered {@link TaskRunner} or a default runner if none is registered for the specified types. + * @returns the registered {@link TaskRunner} or a default runner if none is registered for the specified type. */ - getRunner(...types: string[]): TaskRunner { - for (const type of types) { - const runner = this.runners.get(type); - if (runner) { - return runner; - } - } - return this.defaultRunner; + getRunner(type: string): TaskRunner { + const runner = this.runners.get(type); + return runner ? runner : this.defaultRunner; } /** diff --git a/packages/task/src/node/task-server.ts b/packages/task/src/node/task-server.ts index 798aad5bd3068..40385c56ceb05 100644 --- a/packages/task/src/node/task-server.ts +++ b/packages/task/src/node/task-server.ts @@ -90,7 +90,7 @@ export class TaskServerImpl implements TaskServer, Disposable { } async run(taskConfiguration: TaskConfiguration, ctx?: string, option?: RunTaskOption): Promise { - const runner = this.runnerRegistry.getRunner(taskConfiguration.type, taskConfiguration.taskType); + const runner = this.runnerRegistry.getRunner(taskConfiguration.taskType); const task = await runner.run(taskConfiguration, ctx); if (!this.toDispose.has(task.id)) { From 77babff47aef37b6d3c7cc41ca319f2b8b4892f8 Mon Sep 17 00:00:00 2001 From: Alvaro Sanchez-Leon Date: Sat, 17 Apr 2021 19:49:12 -0400 Subject: [PATCH 3/3] Revert "Fix task type is modified." This reverts commit 2184352a4f2adc9e222e8a037800ed4dc10de47e. --- packages/plugin-ext/src/plugin/tasks/tasks.ts | 4 ++-- packages/plugin-ext/src/plugin/type-converters.ts | 11 ++++++----- packages/plugin-ext/src/plugin/types-impl.ts | 11 +++++++---- .../task/src/browser/process/process-task-resolver.ts | 2 +- packages/task/src/node/task-server.ts | 2 +- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/packages/plugin-ext/src/plugin/tasks/tasks.ts b/packages/plugin-ext/src/plugin/tasks/tasks.ts index 98e46bf3334a8..14d339e831e29 100644 --- a/packages/plugin-ext/src/plugin/tasks/tasks.ts +++ b/packages/plugin-ext/src/plugin/tasks/tasks.ts @@ -158,7 +158,7 @@ export class TasksExtImpl implements TasksExt { // If this task is a custom execution, then we need to save it away // in the provided custom execution map that is cleaned up after the // task is executed. - if (CustomExecution.is(task.execution!)) { + if (taskDto.type === 'customExecution') { this.addCustomExecution(taskDto, false); } const executionDto = await this.proxy.$executeTask(taskDto); @@ -177,7 +177,7 @@ export class TasksExtImpl implements TasksExt { return adapter.provideTasks(token).then(tasks => { if (tasks) { for (const task of tasks) { - if (task.type === 'customExecution' || task.taskType === 'customExecution') { + if (task.type === 'customExecution') { this.addCustomExecution(task, true); } } diff --git a/packages/plugin-ext/src/plugin/type-converters.ts b/packages/plugin-ext/src/plugin/type-converters.ts index f89ad40443d73..2270455cd921b 100644 --- a/packages/plugin-ext/src/plugin/type-converters.ts +++ b/packages/plugin-ext/src/plugin/type-converters.ts @@ -750,15 +750,15 @@ export function fromTask(task: theia.Task): TaskDto | undefined { return taskDto; } - if (taskDefinition.taskType === 'shell' || types.ShellExecution.is(execution)) { + if (taskDefinition.type === 'shell' || types.ShellExecution.is(execution)) { return fromShellExecution(execution, taskDto); } - if (taskDefinition.taskType === 'process' || types.ProcessExecution.is(execution)) { + if (taskDefinition.type === 'process' || types.ProcessExecution.is(execution)) { return fromProcessExecution(execution, taskDto); } - if (taskDefinition.taskType === 'customExecution' || types.CustomExecution.is(execution)) { + if (taskDefinition.type === 'customExecution' || types.CustomExecution.is(execution)) { return fromCustomExecution(execution, taskDto); } @@ -770,7 +770,7 @@ export function toTask(taskDto: TaskDto): theia.Task { throw new Error('Task should be provided for converting'); } - const { type, taskType, label, source, scope, problemMatcher, detail, command, args, options, group, presentation, ...properties } = taskDto; + const { type, label, source, scope, problemMatcher, detail, command, args, options, group, presentation, ...properties } = taskDto; const result = {} as theia.Task; result.name = label; result.source = source; @@ -788,8 +788,9 @@ export function toTask(taskDto: TaskDto): theia.Task { result.scope = scope; } + const taskType = type; const taskDefinition: theia.TaskDefinition = { - type: type + type: taskType }; result.definition = taskDefinition; diff --git a/packages/plugin-ext/src/plugin/types-impl.ts b/packages/plugin-ext/src/plugin/types-impl.ts index 5b039ddca5652..76f54d87b5ce2 100644 --- a/packages/plugin-ext/src/plugin/types-impl.ts +++ b/packages/plugin-ext/src/plugin/types-impl.ts @@ -1911,18 +1911,21 @@ export class Task { private updateDefinitionBasedOnExecution(): void { if (this.taskExecution instanceof ProcessExecution) { Object.assign(this.taskDefinition, { + type: 'process', id: this.taskExecution.computeId(), - taskType: 'process' + taskType: this.taskDefinition!.type }); } else if (this.taskExecution instanceof ShellExecution) { Object.assign(this.taskDefinition, { + type: 'shell', id: this.taskExecution.computeId(), - taskType: 'shell' + taskType: this.taskDefinition!.type }); } else if (this.taskExecution instanceof CustomExecution) { Object.assign(this.taskDefinition, { - id: this.taskDefinition.id ? this.taskDefinition.id : this.taskExecution.computeId(), - taskType: 'customExecution' + type: 'customExecution', + id: this.taskExecution.computeId(), + taskType: this.taskDefinition!.type }); } else { Object.assign(this.taskDefinition, { diff --git a/packages/task/src/browser/process/process-task-resolver.ts b/packages/task/src/browser/process/process-task-resolver.ts index 649d16a1be02c..76b647c83b2d4 100644 --- a/packages/task/src/browser/process/process-task-resolver.ts +++ b/packages/task/src/browser/process/process-task-resolver.ts @@ -42,7 +42,7 @@ export class ProcessTaskResolver implements TaskResolver { * sane default values. Also, resolve all known variables, e.g. `${workspaceFolder}`. */ async resolveTask(taskConfig: TaskConfiguration): Promise { - if (taskConfig.taskType !== 'process' && taskConfig.taskType !== 'shell') { + if (taskConfig.type !== 'process' && taskConfig.type !== 'shell') { throw new Error('Unsupported task configuration type.'); } const context = typeof taskConfig._scope === 'string' ? new URI(taskConfig._scope) : undefined; diff --git a/packages/task/src/node/task-server.ts b/packages/task/src/node/task-server.ts index 40385c56ceb05..d7ca9d6610b8e 100644 --- a/packages/task/src/node/task-server.ts +++ b/packages/task/src/node/task-server.ts @@ -90,7 +90,7 @@ export class TaskServerImpl implements TaskServer, Disposable { } async run(taskConfiguration: TaskConfiguration, ctx?: string, option?: RunTaskOption): Promise { - const runner = this.runnerRegistry.getRunner(taskConfiguration.taskType); + const runner = this.runnerRegistry.getRunner(taskConfiguration.type); const task = await runner.run(taskConfiguration, ctx); if (!this.toDispose.has(task.id)) {