Skip to content

Commit

Permalink
handles invalid task configurations
Browse files Browse the repository at this point in the history
- not display the invalid task configurations in the list of tasks.
- displays a warning message to inform users if Theia finds invalid task
configuration(s) in tasks.json.
- fixes #6482

Signed-off-by: Liang Huang <liang.huang@ericsson.com>
  • Loading branch information
Liang Huang committed Nov 8, 2019
1 parent c26f35d commit 0912e85
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
7 changes: 5 additions & 2 deletions packages/task/src/browser/task-schema-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class TaskSchemaUpdater {
});
customizedDetectedTask.properties!.problemMatcher = problemMatcher;
customizedDetectedTask.properties!.options = commandOptionsSchema;
customizedDetectedTask.additionalProperties = true;
customizedDetectedTasks.push(customizedDetectedTask);
});

Expand All @@ -118,7 +119,8 @@ export class TaskSchemaUpdater {
}
},
inputs: inputsSchema.definitions!.inputs
}
},
additionalProperties: false
};
}

Expand Down Expand Up @@ -251,7 +253,8 @@ const processTaskConfigurationSchema: IJSONSchema = {
properties: commandAndArgs
},
problemMatcher
}
},
additionalProperties: true
};

const customizedDetectedTasks: IJSONSchema[] = [];
Expand Down
24 changes: 20 additions & 4 deletions packages/task/src/browser/task-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export interface QuickPickProblemMatcherItem {

@injectable()
export class TaskService implements TaskConfigurationClient {

/**
* The last executed task.
*/
Expand Down Expand Up @@ -233,9 +232,26 @@ export class TaskService implements TaskConfigurationClient {
return [...configuredTasks, ...notCustomizedProvidedTasks];
}

/** Returns an array of the task configurations which are configured in tasks.json files */
getConfiguredTasks(): Promise<TaskConfiguration[]> {
return this.taskConfigurations.getTasks();
/** Returns an array of the valid task configurations which are configured in tasks.json files */
async getConfiguredTasks(): Promise<TaskConfiguration[]> {
const taskConfigs = await this.taskConfigurations.getTasks();
const validTaskConfigs = taskConfigs.filter(t => this.isTaskConfigValid(t));
if (validTaskConfigs.length !== taskConfigs.length) {
this.messageService.warn('Invalid task configurations are found. Open tasks.json and find details in the Problems view.');
}
return validTaskConfigs;
}

/**
* Returns `true` if the given task configuration is valid as per the task schema defined in Theia
* or contributed by Theia extensions and plugins, `false` otherwise.
*/
isTaskConfigValid(task: TaskConfiguration): boolean {
const schema = this.taskSchemaUpdater.getTaskSchema();
const ajv = new Ajv();
const validateSchema = ajv.compile(schema);
const isValid = !!validateSchema({ tasks: [task] });
return isValid;
}

/** Returns an array of the task configurations which are provided by the extensions. */
Expand Down

0 comments on commit 0912e85

Please sign in to comment.