@theia/task 1.45.1 → 1.46.0-next.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +193 -193
- package/lib/browser/index.d.ts +6 -6
- package/lib/browser/index.js +33 -33
- package/lib/browser/process/process-task-contribution.d.ts +6 -6
- package/lib/browser/process/process-task-contribution.js +43 -43
- package/lib/browser/process/process-task-frontend-module.d.ts +2 -2
- package/lib/browser/process/process-task-frontend-module.js +27 -27
- package/lib/browser/process/process-task-resolver.d.ts +17 -17
- package/lib/browser/process/process-task-resolver.js +101 -101
- package/lib/browser/provided-task-configurations.d.ts +43 -43
- package/lib/browser/provided-task-configurations.js +213 -213
- package/lib/browser/provided-task-configurations.spec.d.ts +1 -1
- package/lib/browser/provided-task-configurations.spec.js +43 -43
- package/lib/browser/quick-open-task.d.ts +144 -144
- package/lib/browser/quick-open-task.d.ts.map +1 -1
- package/lib/browser/quick-open-task.js +752 -748
- package/lib/browser/quick-open-task.js.map +1 -1
- package/lib/browser/task-configuration-manager.d.ts +64 -64
- package/lib/browser/task-configuration-manager.js +261 -261
- package/lib/browser/task-configuration-model.d.ts +32 -32
- package/lib/browser/task-configuration-model.js +79 -79
- package/lib/browser/task-configurations.d.ts +127 -127
- package/lib/browser/task-configurations.js +486 -486
- package/lib/browser/task-contribution.d.ts +182 -182
- package/lib/browser/task-contribution.js +206 -206
- package/lib/browser/task-definition-registry.d.ts +38 -38
- package/lib/browser/task-definition-registry.js +134 -134
- package/lib/browser/task-definition-registry.spec.d.ts +1 -1
- package/lib/browser/task-definition-registry.spec.js +170 -170
- package/lib/browser/task-frontend-contribution.d.ts +56 -56
- package/lib/browser/task-frontend-contribution.js +358 -358
- package/lib/browser/task-frontend-module.d.ts +5 -5
- package/lib/browser/task-frontend-module.js +79 -79
- package/lib/browser/task-name-resolver.d.ts +13 -13
- package/lib/browser/task-name-resolver.js +67 -67
- package/lib/browser/task-node.d.ts +9 -9
- package/lib/browser/task-node.js +17 -17
- package/lib/browser/task-preferences.d.ts +4 -4
- package/lib/browser/task-preferences.js +40 -40
- package/lib/browser/task-problem-matcher-registry.d.ts +40 -40
- package/lib/browser/task-problem-matcher-registry.js +309 -309
- package/lib/browser/task-problem-pattern-registry.d.ts +23 -23
- package/lib/browser/task-problem-pattern-registry.js +210 -210
- package/lib/browser/task-schema-updater.d.ts +58 -58
- package/lib/browser/task-schema-updater.js +688 -688
- package/lib/browser/task-service.d.ts +279 -279
- package/lib/browser/task-service.js +1119 -1119
- package/lib/browser/task-source-resolver.d.ts +9 -9
- package/lib/browser/task-source-resolver.js +51 -51
- package/lib/browser/task-templates.d.ts +13 -13
- package/lib/browser/task-templates.js +161 -161
- package/lib/browser/task-terminal-widget-manager.d.ts +44 -44
- package/lib/browser/task-terminal-widget-manager.js +228 -228
- package/lib/browser/tasks-monaco-contribution.d.ts +1 -1
- package/lib/browser/tasks-monaco-contribution.js +27 -27
- package/lib/common/index.d.ts +4 -4
- package/lib/common/index.js +31 -31
- package/lib/common/problem-matcher-protocol.d.ts +124 -124
- package/lib/common/problem-matcher-protocol.js +132 -132
- package/lib/common/process/task-protocol.d.ts +68 -68
- package/lib/common/process/task-protocol.js +33 -33
- package/lib/common/task-common-module.d.ts +7 -7
- package/lib/common/task-common-module.js +33 -33
- package/lib/common/task-protocol.d.ts +192 -192
- package/lib/common/task-protocol.js +137 -137
- package/lib/common/task-util.d.ts +22 -22
- package/lib/common/task-util.js +46 -46
- package/lib/common/task-watcher.d.ts +17 -17
- package/lib/common/task-watcher.js +86 -86
- package/lib/node/custom/custom-task-runner-backend-module.d.ts +2 -2
- package/lib/node/custom/custom-task-runner-backend-module.js +36 -36
- package/lib/node/custom/custom-task-runner-contribution.d.ts +6 -6
- package/lib/node/custom/custom-task-runner-contribution.js +42 -42
- package/lib/node/custom/custom-task-runner.d.ts +15 -15
- package/lib/node/custom/custom-task-runner.js +69 -69
- package/lib/node/custom/custom-task.d.ts +20 -20
- package/lib/node/custom/custom-task.js +78 -78
- package/lib/node/index.d.ts +3 -3
- package/lib/node/index.js +30 -30
- package/lib/node/process/process-task-runner-backend-module.d.ts +2 -2
- package/lib/node/process/process-task-runner-backend-module.js +36 -36
- package/lib/node/process/process-task-runner-contribution.d.ts +6 -6
- package/lib/node/process/process-task-runner-contribution.js +43 -43
- package/lib/node/process/process-task-runner.d.ts +60 -60
- package/lib/node/process/process-task-runner.js +355 -355
- package/lib/node/process/process-task.d.ts +26 -26
- package/lib/node/process/process-task.js +135 -135
- package/lib/node/process/process-task.spec.d.ts +1 -1
- package/lib/node/process/process-task.spec.js +29 -29
- package/lib/node/task-abstract-line-matcher.d.ts +49 -49
- package/lib/node/task-abstract-line-matcher.js +273 -273
- package/lib/node/task-backend-application-contribution.d.ts +8 -8
- package/lib/node/task-backend-application-contribution.js +48 -48
- package/lib/node/task-backend-module.d.ts +3 -3
- package/lib/node/task-backend-module.js +50 -50
- package/lib/node/task-line-matchers.d.ts +27 -27
- package/lib/node/task-line-matchers.js +121 -121
- package/lib/node/task-manager.d.ts +55 -55
- package/lib/node/task-manager.js +135 -135
- package/lib/node/task-problem-collector.d.ts +10 -10
- package/lib/node/task-problem-collector.js +57 -57
- package/lib/node/task-problem-collector.spec.d.ts +1 -1
- package/lib/node/task-problem-collector.spec.js +310 -310
- package/lib/node/task-runner-protocol.d.ts +16 -16
- package/lib/node/task-runner-protocol.js +19 -19
- package/lib/node/task-runner.d.ts +50 -50
- package/lib/node/task-runner.js +97 -97
- package/lib/node/task-server.d.ts +39 -39
- package/lib/node/task-server.js +237 -237
- package/lib/node/task-server.slow-spec.d.ts +1 -1
- package/lib/node/task-server.slow-spec.js +395 -395
- package/lib/node/task.d.ts +50 -50
- package/lib/node/task.js +77 -77
- package/lib/node/test/task-test-container.d.ts +2 -2
- package/lib/node/test/task-test-container.js +58 -58
- package/package.json +14 -14
- package/src/browser/index.ts +22 -22
- package/src/browser/process/process-task-contribution.ts +31 -31
- package/src/browser/process/process-task-frontend-module.ts +27 -27
- package/src/browser/process/process-task-resolver.ts +89 -89
- package/src/browser/provided-task-configurations.spec.ts +46 -46
- package/src/browser/provided-task-configurations.ts +213 -213
- package/src/browser/quick-open-task.ts +831 -827
- package/src/browser/style/index.css +19 -19
- package/src/browser/task-configuration-manager.ts +256 -256
- package/src/browser/task-configuration-model.ts +101 -101
- package/src/browser/task-configurations.ts +508 -508
- package/src/browser/task-contribution.ts +266 -266
- package/src/browser/task-definition-registry.spec.ts +203 -203
- package/src/browser/task-definition-registry.ts +131 -131
- package/src/browser/task-frontend-contribution.ts +402 -402
- package/src/browser/task-frontend-module.ts +86 -86
- package/src/browser/task-name-resolver.ts +55 -55
- package/src/browser/task-node.ts +37 -37
- package/src/browser/task-preferences.ts +40 -40
- package/src/browser/task-problem-matcher-registry.ts +308 -308
- package/src/browser/task-problem-pattern-registry.ts +196 -196
- package/src/browser/task-schema-updater.ts +701 -701
- package/src/browser/task-service.ts +1164 -1164
- package/src/browser/task-source-resolver.ts +36 -36
- package/src/browser/task-templates.ts +168 -168
- package/src/browser/task-terminal-widget-manager.ts +224 -224
- package/src/browser/tasks-monaco-contribution.ts +27 -27
- package/src/common/index.ts +20 -20
- package/src/common/problem-matcher-protocol.ts +234 -234
- package/src/common/process/task-protocol.ts +97 -97
- package/src/common/task-common-module.ts +34 -34
- package/src/common/task-protocol.ts +317 -317
- package/src/common/task-util.ts +43 -43
- package/src/common/task-watcher.ts +78 -78
- package/src/node/custom/custom-task-runner-backend-module.ts +37 -37
- package/src/node/custom/custom-task-runner-contribution.ts +30 -30
- package/src/node/custom/custom-task-runner.ts +60 -60
- package/src/node/custom/custom-task.ts +73 -73
- package/src/node/index.ts +19 -19
- package/src/node/process/process-task-runner-backend-module.ts +37 -37
- package/src/node/process/process-task-runner-contribution.ts +31 -31
- package/src/node/process/process-task-runner.ts +371 -371
- package/src/node/process/process-task.spec.ts +30 -30
- package/src/node/process/process-task.ts +144 -144
- package/src/node/task-abstract-line-matcher.ts +312 -312
- package/src/node/task-backend-application-contribution.ts +36 -36
- package/src/node/task-backend-module.ts +57 -57
- package/src/node/task-line-matchers.ts +127 -127
- package/src/node/task-manager.ts +129 -129
- package/src/node/task-problem-collector.spec.ts +338 -338
- package/src/node/task-problem-collector.ts +62 -62
- package/src/node/task-runner-protocol.ts +33 -33
- package/src/node/task-runner.ts +96 -96
- package/src/node/task-server.slow-spec.ts +444 -444
- package/src/node/task-server.ts +263 -263
- package/src/node/task.ts +103 -103
- package/src/node/test/task-test-container.ts +63 -63
|
@@ -1,508 +1,508 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2017-2018 Ericsson and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
|
|
18
|
-
import {
|
|
19
|
-
TaskConfiguration,
|
|
20
|
-
TaskCustomization,
|
|
21
|
-
TaskDefinition,
|
|
22
|
-
TaskOutputPresentation,
|
|
23
|
-
TaskConfigurationScope,
|
|
24
|
-
TaskScope,
|
|
25
|
-
asVariableName
|
|
26
|
-
} from '../common';
|
|
27
|
-
import { TaskDefinitionRegistry } from './task-definition-registry';
|
|
28
|
-
import { ProvidedTaskConfigurations } from './provided-task-configurations';
|
|
29
|
-
import { TaskConfigurationManager, TasksChange } from './task-configuration-manager';
|
|
30
|
-
import { TaskSchemaUpdater } from './task-schema-updater';
|
|
31
|
-
import { TaskSourceResolver } from './task-source-resolver';
|
|
32
|
-
import { Disposable, DisposableCollection } from '@theia/core/lib/common';
|
|
33
|
-
import { FileChangeType } from '@theia/filesystem/lib/common/filesystem-watcher-protocol';
|
|
34
|
-
import { WorkspaceService } from '@theia/workspace/lib/browser';
|
|
35
|
-
|
|
36
|
-
export interface TaskConfigurationClient {
|
|
37
|
-
/**
|
|
38
|
-
* The task configuration file has changed, so a client might want to refresh its configurations
|
|
39
|
-
* @returns an array of strings, each one being a task label
|
|
40
|
-
*/
|
|
41
|
-
taskConfigurationChanged: (event: string[]) => void;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Watches a tasks.json configuration file and provides a parsed version of the contained task configurations
|
|
46
|
-
*/
|
|
47
|
-
@injectable()
|
|
48
|
-
export class TaskConfigurations implements Disposable {
|
|
49
|
-
protected readonly toDispose = new DisposableCollection();
|
|
50
|
-
/**
|
|
51
|
-
* Map of source (path of root folder that the task configs come from) and task config map.
|
|
52
|
-
* For the inner map (i.e., task config map), the key is task label and value TaskConfiguration
|
|
53
|
-
*/
|
|
54
|
-
protected tasksMap = new Map<string, Map<string, TaskConfiguration>>();
|
|
55
|
-
/**
|
|
56
|
-
* Map of source (path of root folder that the task configs come from) and task customizations map.
|
|
57
|
-
*/
|
|
58
|
-
protected taskCustomizationMap = new Map<string, TaskCustomization[]>();
|
|
59
|
-
|
|
60
|
-
protected client: TaskConfigurationClient | undefined = undefined;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Map of source (path of root folder that the task configs come from) and raw task configurations / customizations.
|
|
64
|
-
* This map is used to store the data from `tasks.json` files in workspace.
|
|
65
|
-
*/
|
|
66
|
-
private rawTaskConfigurations = new Map<string, TaskCustomization[]>();
|
|
67
|
-
|
|
68
|
-
@inject(WorkspaceService)
|
|
69
|
-
protected readonly workspaceService: WorkspaceService;
|
|
70
|
-
|
|
71
|
-
@inject(TaskDefinitionRegistry)
|
|
72
|
-
protected readonly taskDefinitionRegistry: TaskDefinitionRegistry;
|
|
73
|
-
|
|
74
|
-
@inject(ProvidedTaskConfigurations)
|
|
75
|
-
protected readonly providedTaskConfigurations: ProvidedTaskConfigurations;
|
|
76
|
-
|
|
77
|
-
@inject(TaskConfigurationManager)
|
|
78
|
-
protected readonly taskConfigurationManager: TaskConfigurationManager;
|
|
79
|
-
|
|
80
|
-
@inject(TaskSchemaUpdater)
|
|
81
|
-
protected readonly taskSchemaUpdater: TaskSchemaUpdater;
|
|
82
|
-
|
|
83
|
-
@inject(TaskSourceResolver)
|
|
84
|
-
protected readonly taskSourceResolver: TaskSourceResolver;
|
|
85
|
-
|
|
86
|
-
constructor() {
|
|
87
|
-
this.toDispose.push(Disposable.create(() => {
|
|
88
|
-
this.tasksMap.clear();
|
|
89
|
-
this.taskCustomizationMap.clear();
|
|
90
|
-
this.rawTaskConfigurations.clear();
|
|
91
|
-
this.client = undefined;
|
|
92
|
-
}));
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
@postConstruct()
|
|
96
|
-
protected init(): void {
|
|
97
|
-
this.toDispose.push(
|
|
98
|
-
this.taskConfigurationManager.onDidChangeTaskConfig(async change => {
|
|
99
|
-
try {
|
|
100
|
-
await this.onDidTaskFileChange([change]);
|
|
101
|
-
if (this.client) {
|
|
102
|
-
this.client.taskConfigurationChanged(this.getTaskLabels());
|
|
103
|
-
}
|
|
104
|
-
} catch (err) {
|
|
105
|
-
console.error(err);
|
|
106
|
-
}
|
|
107
|
-
})
|
|
108
|
-
);
|
|
109
|
-
this.reorganizeTasks();
|
|
110
|
-
this.toDispose.push(this.taskSchemaUpdater.onDidChangeTaskSchema(() => this.reorganizeTasks()));
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
setClient(client: TaskConfigurationClient): void {
|
|
114
|
-
this.client = client;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
dispose(): void {
|
|
118
|
-
this.toDispose.dispose();
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/** returns the list of known task labels */
|
|
122
|
-
getTaskLabels(): string[] {
|
|
123
|
-
return Array.from(this.tasksMap.values()).reduce((acc, labelConfigMap) => acc.concat(Array.from(labelConfigMap.keys())), [] as string[]);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* returns a collection of known tasks, which includes:
|
|
128
|
-
* - all the configured tasks in `tasks.json`, and
|
|
129
|
-
* - the customized detected tasks.
|
|
130
|
-
*
|
|
131
|
-
* The invalid task configs are not returned.
|
|
132
|
-
*/
|
|
133
|
-
async getTasks(token: number): Promise<TaskConfiguration[]> {
|
|
134
|
-
const configuredTasks = Array.from(this.tasksMap.values()).reduce((acc, labelConfigMap) => acc.concat(Array.from(labelConfigMap.values())), [] as TaskConfiguration[]);
|
|
135
|
-
const detectedTasksAsConfigured: TaskConfiguration[] = [];
|
|
136
|
-
for (const [rootFolder, customizations] of Array.from(this.taskCustomizationMap.entries())) {
|
|
137
|
-
for (const customization of customizations) {
|
|
138
|
-
// TODO: getTasksToCustomize() will ask all task providers to contribute tasks. Doing this in a loop is bad.
|
|
139
|
-
const detected = await this.providedTaskConfigurations.getTaskToCustomize(token, customization, rootFolder);
|
|
140
|
-
if (detected) {
|
|
141
|
-
// there might be a provided task that has a different scope from the task we're inspecting
|
|
142
|
-
detectedTasksAsConfigured.push({ ...detected, ...customization });
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return [...configuredTasks, ...detectedTasksAsConfigured];
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
getRawTaskConfigurations(scope?: TaskConfigurationScope): (TaskCustomization | TaskConfiguration)[] {
|
|
150
|
-
if (scope === undefined) {
|
|
151
|
-
const tasks: (TaskCustomization | TaskConfiguration)[] = [];
|
|
152
|
-
for (const configs of this.rawTaskConfigurations.values()) {
|
|
153
|
-
tasks.push(...configs);
|
|
154
|
-
}
|
|
155
|
-
return tasks;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const scopeKey = this.getKeyFromScope(scope);
|
|
159
|
-
if (this.rawTaskConfigurations.has(scopeKey)) {
|
|
160
|
-
return Array.from(this.rawTaskConfigurations.get(scopeKey)!.values());
|
|
161
|
-
}
|
|
162
|
-
return [];
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* returns a collection of invalid task configs as per the task schema defined in Theia.
|
|
167
|
-
*/
|
|
168
|
-
getInvalidTaskConfigurations(): (TaskCustomization | TaskConfiguration)[] {
|
|
169
|
-
const invalidTaskConfigs: (TaskCustomization | TaskConfiguration)[] = [];
|
|
170
|
-
for (const taskConfigs of this.rawTaskConfigurations.values()) {
|
|
171
|
-
for (const taskConfig of taskConfigs) {
|
|
172
|
-
const isValid = this.isTaskConfigValid(taskConfig);
|
|
173
|
-
if (!isValid) {
|
|
174
|
-
invalidTaskConfigs.push(taskConfig);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return invalidTaskConfigs;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/** returns the task configuration for a given label or undefined if none */
|
|
182
|
-
getTask(scope: TaskConfigurationScope, taskLabel: string): TaskConfiguration | undefined {
|
|
183
|
-
const labelConfigMap = this.tasksMap.get(this.getKeyFromScope(scope));
|
|
184
|
-
if (labelConfigMap) {
|
|
185
|
-
return labelConfigMap.get(taskLabel);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/** returns the customized task for a given label or undefined if none */
|
|
190
|
-
async getCustomizedTask(token: number, scope: TaskConfigurationScope, taskLabel: string): Promise<TaskConfiguration | undefined> {
|
|
191
|
-
const customizations = this.taskCustomizationMap.get(this.getKeyFromScope(scope));
|
|
192
|
-
if (customizations) {
|
|
193
|
-
const customization = customizations.find(cus => cus.label === taskLabel);
|
|
194
|
-
if (customization) {
|
|
195
|
-
const detected = await this.providedTaskConfigurations.getTaskToCustomize(token, customization, scope);
|
|
196
|
-
if (detected) {
|
|
197
|
-
return {
|
|
198
|
-
...detected,
|
|
199
|
-
...customization,
|
|
200
|
-
type: detected.type
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/** removes tasks configured in the given task config file */
|
|
208
|
-
private removeTasks(scope: TaskConfigurationScope): void {
|
|
209
|
-
const source = this.getKeyFromScope(scope);
|
|
210
|
-
this.tasksMap.delete(source);
|
|
211
|
-
this.taskCustomizationMap.delete(source);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Removes task customization objects found in the given task config file from the memory.
|
|
216
|
-
* Please note: this function does not modify the task config file.
|
|
217
|
-
*/
|
|
218
|
-
private removeTaskCustomizations(scope: TaskConfigurationScope): void {
|
|
219
|
-
const source = this.getKeyFromScope(scope);
|
|
220
|
-
this.taskCustomizationMap.delete(source);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Returns the task customizations by type from a given root folder in the workspace.
|
|
225
|
-
* @param type the type of task customizations
|
|
226
|
-
* @param rootFolder the root folder to find task customizations from. If `undefined`, this function returns an empty array.
|
|
227
|
-
*/
|
|
228
|
-
private getTaskCustomizations(type: string, scope: TaskConfigurationScope): TaskCustomization[] {
|
|
229
|
-
const customizationInRootFolder = this.taskCustomizationMap.get(this.getKeyFromScope(scope));
|
|
230
|
-
if (customizationInRootFolder) {
|
|
231
|
-
return customizationInRootFolder.filter(c => c.type === type);
|
|
232
|
-
} else {
|
|
233
|
-
return [];
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Returns the customization object in `tasks.json` for the given task. Please note, this function
|
|
239
|
-
* returns `undefined` if the given task is not a detected task, because configured tasks don't need
|
|
240
|
-
* customization objects - users can modify its config directly in `tasks.json`.
|
|
241
|
-
* @param taskConfig The task config, which could either be a configured task or a detected task.
|
|
242
|
-
*/
|
|
243
|
-
getCustomizationForTask(taskConfig: TaskConfiguration): TaskCustomization | undefined {
|
|
244
|
-
if (!this.isDetectedTask(taskConfig)) {
|
|
245
|
-
return undefined;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
const customizationByType = this.getTaskCustomizations(taskConfig.type, taskConfig._scope) || [];
|
|
249
|
-
const hasCustomization = customizationByType.length > 0;
|
|
250
|
-
if (hasCustomization) {
|
|
251
|
-
const taskDefinition = this.taskDefinitionRegistry.getDefinition(taskConfig);
|
|
252
|
-
if (taskDefinition) {
|
|
253
|
-
const required = taskDefinition.properties.required || [];
|
|
254
|
-
// Only support having one customization per task.
|
|
255
|
-
return customizationByType.find(customization => required.every(property => customization[property] === taskConfig[property]));
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
return undefined;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Called when a change, to a config file we watch, is detected.
|
|
263
|
-
*/
|
|
264
|
-
protected async onDidTaskFileChange(fileChanges: TasksChange[]): Promise<void> {
|
|
265
|
-
for (const change of fileChanges) {
|
|
266
|
-
if (change.type === FileChangeType.DELETED) {
|
|
267
|
-
this.removeTasks(change.scope);
|
|
268
|
-
} else {
|
|
269
|
-
// re-parse the config file
|
|
270
|
-
await this.refreshTasks(change.scope);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Read the task configs from the task configuration manager, and updates the list of available tasks.
|
|
277
|
-
*/
|
|
278
|
-
protected async refreshTasks(scope: TaskConfigurationScope): Promise<void> {
|
|
279
|
-
await this.readTasks(scope);
|
|
280
|
-
|
|
281
|
-
this.removeTasks(scope);
|
|
282
|
-
this.removeTaskCustomizations(scope);
|
|
283
|
-
|
|
284
|
-
this.reorganizeTasks();
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/** parses a config file and extracts the tasks launch configurations */
|
|
288
|
-
protected async readTasks(scope: TaskConfigurationScope): Promise<(TaskCustomization | TaskConfiguration)[] | undefined> {
|
|
289
|
-
const rawConfigArray = this.taskConfigurationManager.getTasks(scope);
|
|
290
|
-
const key = this.getKeyFromScope(scope);
|
|
291
|
-
if (this.rawTaskConfigurations.has(key)) {
|
|
292
|
-
this.rawTaskConfigurations.delete(key);
|
|
293
|
-
}
|
|
294
|
-
this.rawTaskConfigurations.set(key, rawConfigArray);
|
|
295
|
-
return rawConfigArray;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
async openUserTasks(): Promise<void> {
|
|
299
|
-
await this.taskConfigurationManager.openConfiguration(TaskScope.Global);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
/** Adds given task to a config file and opens the file to provide ability to edit task configuration. */
|
|
303
|
-
async configure(token: number, task: TaskConfiguration): Promise<void> {
|
|
304
|
-
const scope = task._scope;
|
|
305
|
-
if (scope === TaskScope.Global) {
|
|
306
|
-
return this.openUserTasks();
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
const workspace = this.workspaceService.workspace;
|
|
310
|
-
if (!workspace) {
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
const configuredAndCustomizedTasks = await this.getTasks(token);
|
|
315
|
-
if (!configuredAndCustomizedTasks.some(t => this.taskDefinitionRegistry.compareTasks(t, task))) {
|
|
316
|
-
await this.saveTask(scope, task);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
try {
|
|
320
|
-
await this.taskConfigurationManager.openConfiguration(scope);
|
|
321
|
-
} catch (e) {
|
|
322
|
-
console.error(`Error occurred while opening 'tasks.json' in ${this.taskSourceResolver.resolve(task)}.`, e);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
private getTaskCustomizationTemplate(task: TaskConfiguration): TaskCustomization | undefined {
|
|
327
|
-
const definition = this.getTaskDefinition(task);
|
|
328
|
-
if (!definition) {
|
|
329
|
-
console.error('Detected / Contributed tasks should have a task definition.');
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
const customization: TaskCustomization = { type: task.type, runOptions: task.runOptions };
|
|
333
|
-
definition.properties.all.forEach(p => {
|
|
334
|
-
if (task[p] !== undefined) {
|
|
335
|
-
customization[p] = task[p];
|
|
336
|
-
}
|
|
337
|
-
});
|
|
338
|
-
if ('problemMatcher' in task) {
|
|
339
|
-
const problemMatcher: string[] = [];
|
|
340
|
-
if (Array.isArray(task.problemMatcher)) {
|
|
341
|
-
problemMatcher.push(...task.problemMatcher.map(t => {
|
|
342
|
-
if (typeof t === 'string') {
|
|
343
|
-
return t;
|
|
344
|
-
} else {
|
|
345
|
-
return t.name!;
|
|
346
|
-
}
|
|
347
|
-
}));
|
|
348
|
-
} else if (typeof task.problemMatcher === 'string') {
|
|
349
|
-
problemMatcher.push(task.problemMatcher);
|
|
350
|
-
} else if (task.problemMatcher) {
|
|
351
|
-
problemMatcher.push(task.problemMatcher.name!);
|
|
352
|
-
}
|
|
353
|
-
customization.problemMatcher = problemMatcher.map(asVariableName);
|
|
354
|
-
}
|
|
355
|
-
if (task.group) {
|
|
356
|
-
customization.group = task.group;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
customization.label = task.label;
|
|
360
|
-
|
|
361
|
-
return { ...customization };
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/** Writes the task to a config file. Creates a config file if this one does not exist */
|
|
365
|
-
saveTask(scope: TaskConfigurationScope, task: TaskConfiguration): Promise<boolean> {
|
|
366
|
-
const { _source, $ident, ...preparedTask } = task;
|
|
367
|
-
const customizedTaskTemplate = this.getTaskCustomizationTemplate(task) || preparedTask;
|
|
368
|
-
return this.taskConfigurationManager.addTaskConfiguration(scope, customizedTaskTemplate);
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* This function is called after a change in TaskDefinitionRegistry happens.
|
|
373
|
-
* It checks all tasks that have been loaded, and re-organized them in `tasksMap` and `taskCustomizationMap`.
|
|
374
|
-
*/
|
|
375
|
-
protected reorganizeTasks(): void {
|
|
376
|
-
const newTaskMap = new Map<string, Map<string, TaskConfiguration>>();
|
|
377
|
-
const newTaskCustomizationMap = new Map<string, TaskCustomization[]>();
|
|
378
|
-
const addCustomization = (rootFolder: string, customization: TaskCustomization) => {
|
|
379
|
-
if (newTaskCustomizationMap.has(rootFolder)) {
|
|
380
|
-
newTaskCustomizationMap.get(rootFolder)!.push(customization);
|
|
381
|
-
} else {
|
|
382
|
-
newTaskCustomizationMap.set(rootFolder, [customization]);
|
|
383
|
-
}
|
|
384
|
-
};
|
|
385
|
-
const addConfiguredTask = (rootFolder: string, label: string, configuredTask: TaskCustomization) => {
|
|
386
|
-
if (newTaskMap.has(rootFolder)) {
|
|
387
|
-
newTaskMap.get(rootFolder)!.set(label, configuredTask as TaskConfiguration);
|
|
388
|
-
} else {
|
|
389
|
-
const newConfigMap = new Map();
|
|
390
|
-
newConfigMap.set(label, configuredTask);
|
|
391
|
-
newTaskMap.set(rootFolder, newConfigMap);
|
|
392
|
-
}
|
|
393
|
-
};
|
|
394
|
-
|
|
395
|
-
for (const [scopeKey, taskConfigs] of this.rawTaskConfigurations.entries()) {
|
|
396
|
-
for (const taskConfig of taskConfigs) {
|
|
397
|
-
const scope = this.getScopeFromKey(scopeKey);
|
|
398
|
-
const isValid = this.isTaskConfigValid(taskConfig);
|
|
399
|
-
if (!isValid) {
|
|
400
|
-
continue;
|
|
401
|
-
}
|
|
402
|
-
const transformedTask = this.getTransformedRawTask(taskConfig, scope);
|
|
403
|
-
if (this.isDetectedTask(transformedTask)) {
|
|
404
|
-
addCustomization(scopeKey, transformedTask);
|
|
405
|
-
} else {
|
|
406
|
-
addConfiguredTask(scopeKey, transformedTask['label'] as string, transformedTask);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
this.taskCustomizationMap = newTaskCustomizationMap;
|
|
412
|
-
this.tasksMap = newTaskMap;
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
private getTransformedRawTask(rawTask: TaskCustomization | TaskConfiguration, scope: TaskConfigurationScope): TaskCustomization | TaskConfiguration {
|
|
416
|
-
let taskConfig: TaskCustomization | TaskConfiguration;
|
|
417
|
-
if (this.isDetectedTask(rawTask)) {
|
|
418
|
-
const def = this.getTaskDefinition(rawTask);
|
|
419
|
-
taskConfig = {
|
|
420
|
-
...rawTask,
|
|
421
|
-
_source: def!.source,
|
|
422
|
-
_scope: scope
|
|
423
|
-
};
|
|
424
|
-
} else {
|
|
425
|
-
taskConfig = {
|
|
426
|
-
...rawTask,
|
|
427
|
-
_source: scope,
|
|
428
|
-
_scope: scope
|
|
429
|
-
};
|
|
430
|
-
}
|
|
431
|
-
return {
|
|
432
|
-
...taskConfig,
|
|
433
|
-
presentation: TaskOutputPresentation.fromJson(rawTask)
|
|
434
|
-
};
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
/**
|
|
438
|
-
* Returns `true` if the given task configuration is valid as per the task schema defined in Theia
|
|
439
|
-
* or contributed by Theia extensions and plugins, `false` otherwise.
|
|
440
|
-
*/
|
|
441
|
-
private isTaskConfigValid(task: TaskCustomization): boolean {
|
|
442
|
-
return this.taskSchemaUpdater.validate({ tasks: [task] });
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
/**
|
|
446
|
-
* Updates the task config in the `tasks.json`.
|
|
447
|
-
* The task config, together with updates, will be written into the `tasks.json` if it is not found in the file.
|
|
448
|
-
*
|
|
449
|
-
* @param task task that the updates will be applied to
|
|
450
|
-
* @param update the updates to be applied
|
|
451
|
-
*/
|
|
452
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
453
|
-
async updateTaskConfig(token: number, task: TaskConfiguration, update: { [name: string]: any }): Promise<void> {
|
|
454
|
-
const scope = task._scope;
|
|
455
|
-
const configuredAndCustomizedTasks = await this.getTasks(token);
|
|
456
|
-
if (configuredAndCustomizedTasks.some(t => this.taskDefinitionRegistry.compareTasks(t, task))) { // task is already in `tasks.json`
|
|
457
|
-
const jsonTasks = this.taskConfigurationManager.getTasks(scope);
|
|
458
|
-
if (jsonTasks) {
|
|
459
|
-
const ind = jsonTasks.findIndex((t: TaskCustomization | TaskConfiguration) => {
|
|
460
|
-
if (t.type !== (task.type)) {
|
|
461
|
-
return false;
|
|
462
|
-
}
|
|
463
|
-
const def = this.taskDefinitionRegistry.getDefinition(t);
|
|
464
|
-
if (def) {
|
|
465
|
-
return def.properties.all.every(p => t[p] === task[p]);
|
|
466
|
-
}
|
|
467
|
-
return t.label === task.label;
|
|
468
|
-
});
|
|
469
|
-
jsonTasks[ind] = {
|
|
470
|
-
...jsonTasks[ind],
|
|
471
|
-
...update
|
|
472
|
-
};
|
|
473
|
-
}
|
|
474
|
-
this.taskConfigurationManager.setTaskConfigurations(scope, jsonTasks);
|
|
475
|
-
} else { // task is not in `tasks.json`
|
|
476
|
-
Object.keys(update).forEach(taskProperty => {
|
|
477
|
-
task[taskProperty] = update[taskProperty];
|
|
478
|
-
});
|
|
479
|
-
this.saveTask(scope, task);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
private getKeyFromScope(scope: TaskConfigurationScope): string {
|
|
484
|
-
// Converting the enums to string will not yield a valid URI, so the keys will be distinct from any URI.
|
|
485
|
-
return scope.toString();
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
private getScopeFromKey(key: string): TaskConfigurationScope {
|
|
489
|
-
if (TaskScope.Global.toString() === key) {
|
|
490
|
-
return TaskScope.Global;
|
|
491
|
-
} else if (TaskScope.Workspace.toString() === key) {
|
|
492
|
-
return TaskScope.Workspace;
|
|
493
|
-
} else {
|
|
494
|
-
return key;
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
/** checks if the config is a detected / contributed task */
|
|
499
|
-
private isDetectedTask(task: TaskConfiguration | TaskCustomization): boolean {
|
|
500
|
-
const taskDefinition = this.getTaskDefinition(task);
|
|
501
|
-
// it is considered as a customization if the task definition registry finds a def for the task configuration
|
|
502
|
-
return !!taskDefinition;
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
private getTaskDefinition(task: TaskCustomization): TaskDefinition | undefined {
|
|
506
|
-
return this.taskDefinitionRegistry.getDefinition(task);
|
|
507
|
-
}
|
|
508
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2017-2018 Ericsson and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
|
|
18
|
+
import {
|
|
19
|
+
TaskConfiguration,
|
|
20
|
+
TaskCustomization,
|
|
21
|
+
TaskDefinition,
|
|
22
|
+
TaskOutputPresentation,
|
|
23
|
+
TaskConfigurationScope,
|
|
24
|
+
TaskScope,
|
|
25
|
+
asVariableName
|
|
26
|
+
} from '../common';
|
|
27
|
+
import { TaskDefinitionRegistry } from './task-definition-registry';
|
|
28
|
+
import { ProvidedTaskConfigurations } from './provided-task-configurations';
|
|
29
|
+
import { TaskConfigurationManager, TasksChange } from './task-configuration-manager';
|
|
30
|
+
import { TaskSchemaUpdater } from './task-schema-updater';
|
|
31
|
+
import { TaskSourceResolver } from './task-source-resolver';
|
|
32
|
+
import { Disposable, DisposableCollection } from '@theia/core/lib/common';
|
|
33
|
+
import { FileChangeType } from '@theia/filesystem/lib/common/filesystem-watcher-protocol';
|
|
34
|
+
import { WorkspaceService } from '@theia/workspace/lib/browser';
|
|
35
|
+
|
|
36
|
+
export interface TaskConfigurationClient {
|
|
37
|
+
/**
|
|
38
|
+
* The task configuration file has changed, so a client might want to refresh its configurations
|
|
39
|
+
* @returns an array of strings, each one being a task label
|
|
40
|
+
*/
|
|
41
|
+
taskConfigurationChanged: (event: string[]) => void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Watches a tasks.json configuration file and provides a parsed version of the contained task configurations
|
|
46
|
+
*/
|
|
47
|
+
@injectable()
|
|
48
|
+
export class TaskConfigurations implements Disposable {
|
|
49
|
+
protected readonly toDispose = new DisposableCollection();
|
|
50
|
+
/**
|
|
51
|
+
* Map of source (path of root folder that the task configs come from) and task config map.
|
|
52
|
+
* For the inner map (i.e., task config map), the key is task label and value TaskConfiguration
|
|
53
|
+
*/
|
|
54
|
+
protected tasksMap = new Map<string, Map<string, TaskConfiguration>>();
|
|
55
|
+
/**
|
|
56
|
+
* Map of source (path of root folder that the task configs come from) and task customizations map.
|
|
57
|
+
*/
|
|
58
|
+
protected taskCustomizationMap = new Map<string, TaskCustomization[]>();
|
|
59
|
+
|
|
60
|
+
protected client: TaskConfigurationClient | undefined = undefined;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Map of source (path of root folder that the task configs come from) and raw task configurations / customizations.
|
|
64
|
+
* This map is used to store the data from `tasks.json` files in workspace.
|
|
65
|
+
*/
|
|
66
|
+
private rawTaskConfigurations = new Map<string, TaskCustomization[]>();
|
|
67
|
+
|
|
68
|
+
@inject(WorkspaceService)
|
|
69
|
+
protected readonly workspaceService: WorkspaceService;
|
|
70
|
+
|
|
71
|
+
@inject(TaskDefinitionRegistry)
|
|
72
|
+
protected readonly taskDefinitionRegistry: TaskDefinitionRegistry;
|
|
73
|
+
|
|
74
|
+
@inject(ProvidedTaskConfigurations)
|
|
75
|
+
protected readonly providedTaskConfigurations: ProvidedTaskConfigurations;
|
|
76
|
+
|
|
77
|
+
@inject(TaskConfigurationManager)
|
|
78
|
+
protected readonly taskConfigurationManager: TaskConfigurationManager;
|
|
79
|
+
|
|
80
|
+
@inject(TaskSchemaUpdater)
|
|
81
|
+
protected readonly taskSchemaUpdater: TaskSchemaUpdater;
|
|
82
|
+
|
|
83
|
+
@inject(TaskSourceResolver)
|
|
84
|
+
protected readonly taskSourceResolver: TaskSourceResolver;
|
|
85
|
+
|
|
86
|
+
constructor() {
|
|
87
|
+
this.toDispose.push(Disposable.create(() => {
|
|
88
|
+
this.tasksMap.clear();
|
|
89
|
+
this.taskCustomizationMap.clear();
|
|
90
|
+
this.rawTaskConfigurations.clear();
|
|
91
|
+
this.client = undefined;
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@postConstruct()
|
|
96
|
+
protected init(): void {
|
|
97
|
+
this.toDispose.push(
|
|
98
|
+
this.taskConfigurationManager.onDidChangeTaskConfig(async change => {
|
|
99
|
+
try {
|
|
100
|
+
await this.onDidTaskFileChange([change]);
|
|
101
|
+
if (this.client) {
|
|
102
|
+
this.client.taskConfigurationChanged(this.getTaskLabels());
|
|
103
|
+
}
|
|
104
|
+
} catch (err) {
|
|
105
|
+
console.error(err);
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
);
|
|
109
|
+
this.reorganizeTasks();
|
|
110
|
+
this.toDispose.push(this.taskSchemaUpdater.onDidChangeTaskSchema(() => this.reorganizeTasks()));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
setClient(client: TaskConfigurationClient): void {
|
|
114
|
+
this.client = client;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
dispose(): void {
|
|
118
|
+
this.toDispose.dispose();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** returns the list of known task labels */
|
|
122
|
+
getTaskLabels(): string[] {
|
|
123
|
+
return Array.from(this.tasksMap.values()).reduce((acc, labelConfigMap) => acc.concat(Array.from(labelConfigMap.keys())), [] as string[]);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* returns a collection of known tasks, which includes:
|
|
128
|
+
* - all the configured tasks in `tasks.json`, and
|
|
129
|
+
* - the customized detected tasks.
|
|
130
|
+
*
|
|
131
|
+
* The invalid task configs are not returned.
|
|
132
|
+
*/
|
|
133
|
+
async getTasks(token: number): Promise<TaskConfiguration[]> {
|
|
134
|
+
const configuredTasks = Array.from(this.tasksMap.values()).reduce((acc, labelConfigMap) => acc.concat(Array.from(labelConfigMap.values())), [] as TaskConfiguration[]);
|
|
135
|
+
const detectedTasksAsConfigured: TaskConfiguration[] = [];
|
|
136
|
+
for (const [rootFolder, customizations] of Array.from(this.taskCustomizationMap.entries())) {
|
|
137
|
+
for (const customization of customizations) {
|
|
138
|
+
// TODO: getTasksToCustomize() will ask all task providers to contribute tasks. Doing this in a loop is bad.
|
|
139
|
+
const detected = await this.providedTaskConfigurations.getTaskToCustomize(token, customization, rootFolder);
|
|
140
|
+
if (detected) {
|
|
141
|
+
// there might be a provided task that has a different scope from the task we're inspecting
|
|
142
|
+
detectedTasksAsConfigured.push({ ...detected, ...customization });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return [...configuredTasks, ...detectedTasksAsConfigured];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
getRawTaskConfigurations(scope?: TaskConfigurationScope): (TaskCustomization | TaskConfiguration)[] {
|
|
150
|
+
if (scope === undefined) {
|
|
151
|
+
const tasks: (TaskCustomization | TaskConfiguration)[] = [];
|
|
152
|
+
for (const configs of this.rawTaskConfigurations.values()) {
|
|
153
|
+
tasks.push(...configs);
|
|
154
|
+
}
|
|
155
|
+
return tasks;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const scopeKey = this.getKeyFromScope(scope);
|
|
159
|
+
if (this.rawTaskConfigurations.has(scopeKey)) {
|
|
160
|
+
return Array.from(this.rawTaskConfigurations.get(scopeKey)!.values());
|
|
161
|
+
}
|
|
162
|
+
return [];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* returns a collection of invalid task configs as per the task schema defined in Theia.
|
|
167
|
+
*/
|
|
168
|
+
getInvalidTaskConfigurations(): (TaskCustomization | TaskConfiguration)[] {
|
|
169
|
+
const invalidTaskConfigs: (TaskCustomization | TaskConfiguration)[] = [];
|
|
170
|
+
for (const taskConfigs of this.rawTaskConfigurations.values()) {
|
|
171
|
+
for (const taskConfig of taskConfigs) {
|
|
172
|
+
const isValid = this.isTaskConfigValid(taskConfig);
|
|
173
|
+
if (!isValid) {
|
|
174
|
+
invalidTaskConfigs.push(taskConfig);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return invalidTaskConfigs;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** returns the task configuration for a given label or undefined if none */
|
|
182
|
+
getTask(scope: TaskConfigurationScope, taskLabel: string): TaskConfiguration | undefined {
|
|
183
|
+
const labelConfigMap = this.tasksMap.get(this.getKeyFromScope(scope));
|
|
184
|
+
if (labelConfigMap) {
|
|
185
|
+
return labelConfigMap.get(taskLabel);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** returns the customized task for a given label or undefined if none */
|
|
190
|
+
async getCustomizedTask(token: number, scope: TaskConfigurationScope, taskLabel: string): Promise<TaskConfiguration | undefined> {
|
|
191
|
+
const customizations = this.taskCustomizationMap.get(this.getKeyFromScope(scope));
|
|
192
|
+
if (customizations) {
|
|
193
|
+
const customization = customizations.find(cus => cus.label === taskLabel);
|
|
194
|
+
if (customization) {
|
|
195
|
+
const detected = await this.providedTaskConfigurations.getTaskToCustomize(token, customization, scope);
|
|
196
|
+
if (detected) {
|
|
197
|
+
return {
|
|
198
|
+
...detected,
|
|
199
|
+
...customization,
|
|
200
|
+
type: detected.type
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** removes tasks configured in the given task config file */
|
|
208
|
+
private removeTasks(scope: TaskConfigurationScope): void {
|
|
209
|
+
const source = this.getKeyFromScope(scope);
|
|
210
|
+
this.tasksMap.delete(source);
|
|
211
|
+
this.taskCustomizationMap.delete(source);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Removes task customization objects found in the given task config file from the memory.
|
|
216
|
+
* Please note: this function does not modify the task config file.
|
|
217
|
+
*/
|
|
218
|
+
private removeTaskCustomizations(scope: TaskConfigurationScope): void {
|
|
219
|
+
const source = this.getKeyFromScope(scope);
|
|
220
|
+
this.taskCustomizationMap.delete(source);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Returns the task customizations by type from a given root folder in the workspace.
|
|
225
|
+
* @param type the type of task customizations
|
|
226
|
+
* @param rootFolder the root folder to find task customizations from. If `undefined`, this function returns an empty array.
|
|
227
|
+
*/
|
|
228
|
+
private getTaskCustomizations(type: string, scope: TaskConfigurationScope): TaskCustomization[] {
|
|
229
|
+
const customizationInRootFolder = this.taskCustomizationMap.get(this.getKeyFromScope(scope));
|
|
230
|
+
if (customizationInRootFolder) {
|
|
231
|
+
return customizationInRootFolder.filter(c => c.type === type);
|
|
232
|
+
} else {
|
|
233
|
+
return [];
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Returns the customization object in `tasks.json` for the given task. Please note, this function
|
|
239
|
+
* returns `undefined` if the given task is not a detected task, because configured tasks don't need
|
|
240
|
+
* customization objects - users can modify its config directly in `tasks.json`.
|
|
241
|
+
* @param taskConfig The task config, which could either be a configured task or a detected task.
|
|
242
|
+
*/
|
|
243
|
+
getCustomizationForTask(taskConfig: TaskConfiguration): TaskCustomization | undefined {
|
|
244
|
+
if (!this.isDetectedTask(taskConfig)) {
|
|
245
|
+
return undefined;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const customizationByType = this.getTaskCustomizations(taskConfig.type, taskConfig._scope) || [];
|
|
249
|
+
const hasCustomization = customizationByType.length > 0;
|
|
250
|
+
if (hasCustomization) {
|
|
251
|
+
const taskDefinition = this.taskDefinitionRegistry.getDefinition(taskConfig);
|
|
252
|
+
if (taskDefinition) {
|
|
253
|
+
const required = taskDefinition.properties.required || [];
|
|
254
|
+
// Only support having one customization per task.
|
|
255
|
+
return customizationByType.find(customization => required.every(property => customization[property] === taskConfig[property]));
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return undefined;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Called when a change, to a config file we watch, is detected.
|
|
263
|
+
*/
|
|
264
|
+
protected async onDidTaskFileChange(fileChanges: TasksChange[]): Promise<void> {
|
|
265
|
+
for (const change of fileChanges) {
|
|
266
|
+
if (change.type === FileChangeType.DELETED) {
|
|
267
|
+
this.removeTasks(change.scope);
|
|
268
|
+
} else {
|
|
269
|
+
// re-parse the config file
|
|
270
|
+
await this.refreshTasks(change.scope);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Read the task configs from the task configuration manager, and updates the list of available tasks.
|
|
277
|
+
*/
|
|
278
|
+
protected async refreshTasks(scope: TaskConfigurationScope): Promise<void> {
|
|
279
|
+
await this.readTasks(scope);
|
|
280
|
+
|
|
281
|
+
this.removeTasks(scope);
|
|
282
|
+
this.removeTaskCustomizations(scope);
|
|
283
|
+
|
|
284
|
+
this.reorganizeTasks();
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** parses a config file and extracts the tasks launch configurations */
|
|
288
|
+
protected async readTasks(scope: TaskConfigurationScope): Promise<(TaskCustomization | TaskConfiguration)[] | undefined> {
|
|
289
|
+
const rawConfigArray = this.taskConfigurationManager.getTasks(scope);
|
|
290
|
+
const key = this.getKeyFromScope(scope);
|
|
291
|
+
if (this.rawTaskConfigurations.has(key)) {
|
|
292
|
+
this.rawTaskConfigurations.delete(key);
|
|
293
|
+
}
|
|
294
|
+
this.rawTaskConfigurations.set(key, rawConfigArray);
|
|
295
|
+
return rawConfigArray;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
async openUserTasks(): Promise<void> {
|
|
299
|
+
await this.taskConfigurationManager.openConfiguration(TaskScope.Global);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/** Adds given task to a config file and opens the file to provide ability to edit task configuration. */
|
|
303
|
+
async configure(token: number, task: TaskConfiguration): Promise<void> {
|
|
304
|
+
const scope = task._scope;
|
|
305
|
+
if (scope === TaskScope.Global) {
|
|
306
|
+
return this.openUserTasks();
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const workspace = this.workspaceService.workspace;
|
|
310
|
+
if (!workspace) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const configuredAndCustomizedTasks = await this.getTasks(token);
|
|
315
|
+
if (!configuredAndCustomizedTasks.some(t => this.taskDefinitionRegistry.compareTasks(t, task))) {
|
|
316
|
+
await this.saveTask(scope, task);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
try {
|
|
320
|
+
await this.taskConfigurationManager.openConfiguration(scope);
|
|
321
|
+
} catch (e) {
|
|
322
|
+
console.error(`Error occurred while opening 'tasks.json' in ${this.taskSourceResolver.resolve(task)}.`, e);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
private getTaskCustomizationTemplate(task: TaskConfiguration): TaskCustomization | undefined {
|
|
327
|
+
const definition = this.getTaskDefinition(task);
|
|
328
|
+
if (!definition) {
|
|
329
|
+
console.error('Detected / Contributed tasks should have a task definition.');
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
const customization: TaskCustomization = { type: task.type, runOptions: task.runOptions };
|
|
333
|
+
definition.properties.all.forEach(p => {
|
|
334
|
+
if (task[p] !== undefined) {
|
|
335
|
+
customization[p] = task[p];
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
if ('problemMatcher' in task) {
|
|
339
|
+
const problemMatcher: string[] = [];
|
|
340
|
+
if (Array.isArray(task.problemMatcher)) {
|
|
341
|
+
problemMatcher.push(...task.problemMatcher.map(t => {
|
|
342
|
+
if (typeof t === 'string') {
|
|
343
|
+
return t;
|
|
344
|
+
} else {
|
|
345
|
+
return t.name!;
|
|
346
|
+
}
|
|
347
|
+
}));
|
|
348
|
+
} else if (typeof task.problemMatcher === 'string') {
|
|
349
|
+
problemMatcher.push(task.problemMatcher);
|
|
350
|
+
} else if (task.problemMatcher) {
|
|
351
|
+
problemMatcher.push(task.problemMatcher.name!);
|
|
352
|
+
}
|
|
353
|
+
customization.problemMatcher = problemMatcher.map(asVariableName);
|
|
354
|
+
}
|
|
355
|
+
if (task.group) {
|
|
356
|
+
customization.group = task.group;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
customization.label = task.label;
|
|
360
|
+
|
|
361
|
+
return { ...customization };
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/** Writes the task to a config file. Creates a config file if this one does not exist */
|
|
365
|
+
saveTask(scope: TaskConfigurationScope, task: TaskConfiguration): Promise<boolean> {
|
|
366
|
+
const { _source, $ident, ...preparedTask } = task;
|
|
367
|
+
const customizedTaskTemplate = this.getTaskCustomizationTemplate(task) || preparedTask;
|
|
368
|
+
return this.taskConfigurationManager.addTaskConfiguration(scope, customizedTaskTemplate);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* This function is called after a change in TaskDefinitionRegistry happens.
|
|
373
|
+
* It checks all tasks that have been loaded, and re-organized them in `tasksMap` and `taskCustomizationMap`.
|
|
374
|
+
*/
|
|
375
|
+
protected reorganizeTasks(): void {
|
|
376
|
+
const newTaskMap = new Map<string, Map<string, TaskConfiguration>>();
|
|
377
|
+
const newTaskCustomizationMap = new Map<string, TaskCustomization[]>();
|
|
378
|
+
const addCustomization = (rootFolder: string, customization: TaskCustomization) => {
|
|
379
|
+
if (newTaskCustomizationMap.has(rootFolder)) {
|
|
380
|
+
newTaskCustomizationMap.get(rootFolder)!.push(customization);
|
|
381
|
+
} else {
|
|
382
|
+
newTaskCustomizationMap.set(rootFolder, [customization]);
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
const addConfiguredTask = (rootFolder: string, label: string, configuredTask: TaskCustomization) => {
|
|
386
|
+
if (newTaskMap.has(rootFolder)) {
|
|
387
|
+
newTaskMap.get(rootFolder)!.set(label, configuredTask as TaskConfiguration);
|
|
388
|
+
} else {
|
|
389
|
+
const newConfigMap = new Map();
|
|
390
|
+
newConfigMap.set(label, configuredTask);
|
|
391
|
+
newTaskMap.set(rootFolder, newConfigMap);
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
for (const [scopeKey, taskConfigs] of this.rawTaskConfigurations.entries()) {
|
|
396
|
+
for (const taskConfig of taskConfigs) {
|
|
397
|
+
const scope = this.getScopeFromKey(scopeKey);
|
|
398
|
+
const isValid = this.isTaskConfigValid(taskConfig);
|
|
399
|
+
if (!isValid) {
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
const transformedTask = this.getTransformedRawTask(taskConfig, scope);
|
|
403
|
+
if (this.isDetectedTask(transformedTask)) {
|
|
404
|
+
addCustomization(scopeKey, transformedTask);
|
|
405
|
+
} else {
|
|
406
|
+
addConfiguredTask(scopeKey, transformedTask['label'] as string, transformedTask);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
this.taskCustomizationMap = newTaskCustomizationMap;
|
|
412
|
+
this.tasksMap = newTaskMap;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
private getTransformedRawTask(rawTask: TaskCustomization | TaskConfiguration, scope: TaskConfigurationScope): TaskCustomization | TaskConfiguration {
|
|
416
|
+
let taskConfig: TaskCustomization | TaskConfiguration;
|
|
417
|
+
if (this.isDetectedTask(rawTask)) {
|
|
418
|
+
const def = this.getTaskDefinition(rawTask);
|
|
419
|
+
taskConfig = {
|
|
420
|
+
...rawTask,
|
|
421
|
+
_source: def!.source,
|
|
422
|
+
_scope: scope
|
|
423
|
+
};
|
|
424
|
+
} else {
|
|
425
|
+
taskConfig = {
|
|
426
|
+
...rawTask,
|
|
427
|
+
_source: scope,
|
|
428
|
+
_scope: scope
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
return {
|
|
432
|
+
...taskConfig,
|
|
433
|
+
presentation: TaskOutputPresentation.fromJson(rawTask)
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Returns `true` if the given task configuration is valid as per the task schema defined in Theia
|
|
439
|
+
* or contributed by Theia extensions and plugins, `false` otherwise.
|
|
440
|
+
*/
|
|
441
|
+
private isTaskConfigValid(task: TaskCustomization): boolean {
|
|
442
|
+
return this.taskSchemaUpdater.validate({ tasks: [task] });
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Updates the task config in the `tasks.json`.
|
|
447
|
+
* The task config, together with updates, will be written into the `tasks.json` if it is not found in the file.
|
|
448
|
+
*
|
|
449
|
+
* @param task task that the updates will be applied to
|
|
450
|
+
* @param update the updates to be applied
|
|
451
|
+
*/
|
|
452
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
453
|
+
async updateTaskConfig(token: number, task: TaskConfiguration, update: { [name: string]: any }): Promise<void> {
|
|
454
|
+
const scope = task._scope;
|
|
455
|
+
const configuredAndCustomizedTasks = await this.getTasks(token);
|
|
456
|
+
if (configuredAndCustomizedTasks.some(t => this.taskDefinitionRegistry.compareTasks(t, task))) { // task is already in `tasks.json`
|
|
457
|
+
const jsonTasks = this.taskConfigurationManager.getTasks(scope);
|
|
458
|
+
if (jsonTasks) {
|
|
459
|
+
const ind = jsonTasks.findIndex((t: TaskCustomization | TaskConfiguration) => {
|
|
460
|
+
if (t.type !== (task.type)) {
|
|
461
|
+
return false;
|
|
462
|
+
}
|
|
463
|
+
const def = this.taskDefinitionRegistry.getDefinition(t);
|
|
464
|
+
if (def) {
|
|
465
|
+
return def.properties.all.every(p => t[p] === task[p]);
|
|
466
|
+
}
|
|
467
|
+
return t.label === task.label;
|
|
468
|
+
});
|
|
469
|
+
jsonTasks[ind] = {
|
|
470
|
+
...jsonTasks[ind],
|
|
471
|
+
...update
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
this.taskConfigurationManager.setTaskConfigurations(scope, jsonTasks);
|
|
475
|
+
} else { // task is not in `tasks.json`
|
|
476
|
+
Object.keys(update).forEach(taskProperty => {
|
|
477
|
+
task[taskProperty] = update[taskProperty];
|
|
478
|
+
});
|
|
479
|
+
this.saveTask(scope, task);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
private getKeyFromScope(scope: TaskConfigurationScope): string {
|
|
484
|
+
// Converting the enums to string will not yield a valid URI, so the keys will be distinct from any URI.
|
|
485
|
+
return scope.toString();
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
private getScopeFromKey(key: string): TaskConfigurationScope {
|
|
489
|
+
if (TaskScope.Global.toString() === key) {
|
|
490
|
+
return TaskScope.Global;
|
|
491
|
+
} else if (TaskScope.Workspace.toString() === key) {
|
|
492
|
+
return TaskScope.Workspace;
|
|
493
|
+
} else {
|
|
494
|
+
return key;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/** checks if the config is a detected / contributed task */
|
|
499
|
+
private isDetectedTask(task: TaskConfiguration | TaskCustomization): boolean {
|
|
500
|
+
const taskDefinition = this.getTaskDefinition(task);
|
|
501
|
+
// it is considered as a customization if the task definition registry finds a def for the task configuration
|
|
502
|
+
return !!taskDefinition;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
private getTaskDefinition(task: TaskCustomization): TaskDefinition | undefined {
|
|
506
|
+
return this.taskDefinitionRegistry.getDefinition(task);
|
|
507
|
+
}
|
|
508
|
+
}
|