Skip to content

Commit

Permalink
[tasks] Fix execution of Configured tasks
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Nikitenko <rnikiten@redhat.com>
  • Loading branch information
RomanNikitenko committed May 30, 2019
1 parent 6893c4c commit 774f02e
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 27 deletions.
57 changes: 52 additions & 5 deletions packages/plugin-ext/src/plugin/type-converters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ describe('Type converters:', () => {
});

describe('convert tasks:', () => {
const type = 'shell';
const customType = 'custom';
const shellType = 'shell';
const label = 'yarn build';
const source = 'source';
const command = 'yarn';
Expand All @@ -178,7 +179,7 @@ describe('Type converters:', () => {
const additionalProperty = 'some property';

const shellTaskDto: ProcessTaskDto = {
type,
type: shellType,
label,
source,
scope: undefined,
Expand All @@ -193,7 +194,7 @@ describe('Type converters:', () => {
name: label,
source,
definition: {
type,
type: shellType,
additionalProperty
},
execution: {
Expand All @@ -206,7 +207,7 @@ describe('Type converters:', () => {
};

const taskDtoWithCommandLine: ProcessTaskDto = {
type,
type: shellType,
label,
source,
scope: undefined,
Expand All @@ -220,7 +221,7 @@ describe('Type converters:', () => {
name: label,
source,
definition: {
type
type: shellType
},
execution: {
commandLine: 'yarn run build',
Expand All @@ -230,6 +231,34 @@ describe('Type converters:', () => {
}
};

const customTaskDto: ProcessTaskDto = {
type: customType,
label,
source,
scope: undefined,
command,
args,
cwd,
options: {},
additionalProperty
};

const customPluginTask: theia.Task = {
name: label,
source,
definition: {
type: customType,
additionalProperty
},
execution: {
command,
args,
options: {
cwd
}
}
};

it('should convert to task dto', () => {
// when
const result: TaskDto | undefined = Converter.fromTask(shellPluginTask);
Expand All @@ -256,6 +285,24 @@ describe('Type converters:', () => {
assert.notEqual(result, undefined);
assert.deepEqual(result, taskDtoWithCommandLine);
});

it('should convert task with custom type to dto', () => {
// when
const result: TaskDto | undefined = Converter.fromTask(customPluginTask);

// then
assert.notEqual(result, undefined);
assert.deepEqual(result, customTaskDto);
});

it('should convert task with custom type from dto', () => {
// when
const result: theia.Task = Converter.toTask(customTaskDto);

// then
assert.notEqual(result, undefined);
assert.deepEqual(result, customPluginTask);
});
});

describe('Webview Panel Show Options:', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-ext/src/plugin/type-converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,8 @@ export function toTask(taskDto: TaskDto): theia.Task {
result.execution = getProcessExecution(taskDto as ProcessTaskDto);
}

if (taskType === 'shell') {
const execution = { command, args, options };
if (taskType === 'shell' || types.ShellExecution.is(execution)) {
result.execution = getShellExecution(taskDto as ProcessTaskDto);
}

Expand Down
46 changes: 27 additions & 19 deletions packages/task/src/browser/quick-open-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler {
async init(): Promise<void> {
const recentTasks = this.taskService.recentTasks;
const configuredTasks = this.taskService.getConfiguredTasks();
const providedTasks = await this.taskService.getProvidedTasks();
const detectedTasks = await this.taskService.getProvidedTasks();

const { filteredRecentTasks, filteredConfiguredTasks, filteredProvidedTasks } = this.getFilteredTasks(recentTasks, configuredTasks, providedTasks);
const { filteredRecentTasks, filteredConfiguredTasks, filteredDetectedTasks } = this.getFilteredTasks(recentTasks, configuredTasks, detectedTasks);
const stat = this.workspaceService.workspace;
const isMulti = stat ? !stat.isDirectory : false;
this.items = [];
Expand All @@ -83,7 +83,7 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler {
: index === 0 ? true : false
)
})),
...filteredProvidedTasks.map((task, index) =>
...filteredDetectedTasks.map((task, index) =>
new TaskRunQuickOpenItem(task, this.taskService, isMulti, {
groupLabel: index === 0 ? 'detected tasks' : undefined,
showBorder: (
Expand Down Expand Up @@ -186,36 +186,44 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler {
return `Task id: ${task.taskId}, label: ${task.config.label}`;
}

private getFilteredTasks(recentTasks: TaskConfiguration[], configuredTasks: TaskConfiguration[], providedTasks: TaskConfiguration[])
: { filteredRecentTasks: TaskConfiguration[], filteredConfiguredTasks: TaskConfiguration[], filteredProvidedTasks: TaskConfiguration[] } {
private getFilteredTasks(recentTasks: TaskConfiguration[], configuredTasks: TaskConfiguration[], detectedTasks: TaskConfiguration[])
: { filteredRecentTasks: TaskConfiguration[], filteredConfiguredTasks: TaskConfiguration[], filteredDetectedTasks: TaskConfiguration[] } {

const filteredRecentTasks: TaskConfiguration[] = [];
recentTasks.forEach(recent => {
const exist = [...configuredTasks, ...providedTasks].some(t => TaskConfiguration.equals(recent, t));
if (exist) {
filteredRecentTasks.push(recent);
for (const recent of recentTasks) {
const taskConfig = this.findConfig(recent.label, configuredTasks) || this.findConfig(recent.label, detectedTasks);
if (!taskConfig) {
continue;
}
});

const filteredProvidedTasks: TaskConfiguration[] = [];
providedTasks.forEach(provided => {
const exist = [...filteredRecentTasks, ...configuredTasks].some(t => TaskConfiguration.equals(provided, t));
const exist = filteredRecentTasks.some(task => TaskConfiguration.equals(task, taskConfig));
if (!exist) {
filteredProvidedTasks.push(provided);
filteredRecentTasks.push(taskConfig);
}
});
}

const filteredConfiguredTasks: TaskConfiguration[] = [];
configuredTasks.forEach(configured => {
const exist = filteredRecentTasks.some(t => TaskConfiguration.equals(configured, t));
const exist = filteredRecentTasks.some(recent => TaskConfiguration.equals(configured, recent));
if (!exist) {
filteredConfiguredTasks.push(configured);
}
});

return {
filteredRecentTasks, filteredConfiguredTasks, filteredProvidedTasks
};
const filteredDetectedTasks: TaskConfiguration[] = [];
detectedTasks.forEach(detected => {
const exist = filteredRecentTasks.some(recent => TaskConfiguration.equals(detected, recent)) ||
configuredTasks.some(configured => configured.label === detected.label);
if (!exist) {
filteredDetectedTasks.push(detected);
}
});

return { filteredRecentTasks, filteredConfiguredTasks, filteredDetectedTasks };
}

private findConfig(label: string, configs: TaskConfiguration[]): TaskConfiguration | undefined {
return configs.find(task => label === task.label);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/task/src/browser/task-configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export class TaskConfigurations implements Disposable {
console.error(`Error parsing ${uri}: error: ${e.error}, length: ${e.length}, offset: ${e.offset}`);
}
} else {
return this.filterDuplicates(tasks['tasks']).map(t => Object.assign(t, { _source: t.source || this.getSourceFolderFromConfigUri(uri) }));
return this.filterDuplicates(tasks['tasks']).map(t => Object.assign(t, { _source: this.getSourceFolderFromConfigUri(uri) }));
}
} catch (err) {
console.error(`Error(s) reading config file: ${uri}`);
Expand Down Expand Up @@ -267,7 +267,7 @@ export class TaskConfigurations implements Disposable {
await this.fileSystem.createFile(configFileUri);
}

const { _source, $ident, ...preparedTask } = task;
const { source, _source, _scope, $ident, ...preparedTask } = task;
try {
const response = await this.fileSystem.resolveContent(configFileUri);
const content = response.content;
Expand Down

0 comments on commit 774f02e

Please sign in to comment.