-
Notifications
You must be signed in to change notification settings - Fork 29.7k
/
taskConfiguration.ts
2057 lines (1828 loc) · 66.5 KB
/
taskConfiguration.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';
import * as Objects from 'vs/base/common/objects';
import { IStringDictionary } from 'vs/base/common/collections';
import { Platform } from 'vs/base/common/platform';
import * as Types from 'vs/base/common/types';
import * as UUID from 'vs/base/common/uuid';
import { ValidationStatus, IProblemReporter as IProblemReporterBase } from 'vs/base/common/parsers';
import {
NamedProblemMatcher, ProblemMatcher, ProblemMatcherParser, Config as ProblemMatcherConfig,
isNamedProblemMatcher, ProblemMatcherRegistry
} from 'vs/workbench/contrib/tasks/common/problemMatcher';
import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import * as Tasks from './tasks';
import { TaskDefinitionRegistry } from './taskDefinitionRegistry';
import { ConfiguredInput } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
export const enum ShellQuoting {
/**
* Default is character escaping.
*/
escape = 1,
/**
* Default is strong quoting
*/
strong = 2,
/**
* Default is weak quoting.
*/
weak = 3
}
export interface ShellQuotingOptions {
/**
* The character used to do character escaping.
*/
escape?: string | {
escapeChar: string;
charsToEscape: string;
};
/**
* The character used for string quoting.
*/
strong?: string;
/**
* The character used for weak quoting.
*/
weak?: string;
}
export interface ShellConfiguration {
executable?: string;
args?: string[];
quoting?: ShellQuotingOptions;
}
export interface CommandOptionsConfig {
/**
* The current working directory of the executed program or shell.
* If omitted VSCode's current workspace root is used.
*/
cwd?: string;
/**
* The additional environment of the executed program or shell. If omitted
* the parent process' environment is used.
*/
env?: IStringDictionary<string>;
/**
* The shell configuration;
*/
shell?: ShellConfiguration;
}
export interface PresentationOptionsConfig {
/**
* Controls whether the terminal executing a task is brought to front or not.
* Defaults to `RevealKind.Always`.
*/
reveal?: string;
/**
* Controls whether the problems panel is revealed when running this task or not.
* Defaults to `RevealKind.Never`.
*/
revealProblems?: string;
/**
* Controls whether the executed command is printed to the output window or terminal as well.
*/
echo?: boolean;
/**
* Controls whether the terminal is focus when this task is executed
*/
focus?: boolean;
/**
* Controls whether the task runs in a new terminal
*/
panel?: string;
/**
* Controls whether to show the "Terminal will be reused by tasks, press any key to close it" message.
*/
showReuseMessage?: boolean;
/**
* Controls whether the terminal should be cleared before running the task.
*/
clear?: boolean;
/**
* Controls whether the task is executed in a specific terminal group using split panes.
*/
group?: string;
}
export interface RunOptionsConfig {
reevaluateOnRerun?: boolean;
runOn?: string;
}
export interface TaskIdentifier {
type?: string;
[name: string]: any;
}
export namespace TaskIdentifier {
export function is(value: any): value is TaskIdentifier {
let candidate: TaskIdentifier = value;
return candidate !== undefined && Types.isString(value.type);
}
}
export interface LegacyTaskProperties {
/**
* @deprecated Use `isBackground` instead.
* Whether the executed command is kept alive and is watching the file system.
*/
isWatching?: boolean;
/**
* @deprecated Use `group` instead.
* Whether this task maps to the default build command.
*/
isBuildCommand?: boolean;
/**
* @deprecated Use `group` instead.
* Whether this task maps to the default test command.
*/
isTestCommand?: boolean;
}
export interface LegacyCommandProperties {
/**
* Whether this is a shell or process
*/
type?: string;
/**
* @deprecated Use presentation options
* Controls whether the output view of the running tasks is brought to front or not.
* See BaseTaskRunnerConfiguration#showOutput for details.
*/
showOutput?: string;
/**
* @deprecated Use presentation options
* Controls whether the executed command is printed to the output windows as well.
*/
echoCommand?: boolean;
/**
* @deprecated Use presentation instead
*/
terminal?: PresentationOptionsConfig;
/**
* @deprecated Use inline commands.
* See BaseTaskRunnerConfiguration#suppressTaskName for details.
*/
suppressTaskName?: boolean;
/**
* Some commands require that the task argument is highlighted with a special
* prefix (e.g. /t: for msbuild). This property can be used to control such
* a prefix.
*/
taskSelector?: string;
/**
* @deprecated use the task type instead.
* Specifies whether the command is a shell command and therefore must
* be executed in a shell interpreter (e.g. cmd.exe, bash, ...).
*
* Defaults to false if omitted.
*/
isShellCommand?: boolean | ShellConfiguration;
}
export type CommandString = string | string[] | { value: string | string[], quoting: 'escape' | 'strong' | 'weak' };
export namespace CommandString {
export function value(value: CommandString): string {
if (Types.isString(value)) {
return value;
} else if (Types.isStringArray(value)) {
return value.join(' ');
} else {
if (Types.isString(value.value)) {
return value.value;
} else {
return value.value.join(' ');
}
}
}
}
export interface BaseCommandProperties {
/**
* The command to be executed. Can be an external program or a shell
* command.
*/
command?: CommandString;
/**
* The command options used when the command is executed. Can be omitted.
*/
options?: CommandOptionsConfig;
/**
* The arguments passed to the command or additional arguments passed to the
* command when using a global command.
*/
args?: CommandString[];
}
export interface CommandProperties extends BaseCommandProperties {
/**
* Windows specific command properties
*/
windows?: BaseCommandProperties;
/**
* OSX specific command properties
*/
osx?: BaseCommandProperties;
/**
* linux specific command properties
*/
linux?: BaseCommandProperties;
}
export interface GroupKind {
kind?: string;
isDefault?: boolean;
}
export interface ConfigurationProperties {
/**
* The task's name
*/
taskName?: string;
/**
* The UI label used for the task.
*/
label?: string;
/**
* An optional indentifier which can be used to reference a task
* in a dependsOn or other attributes.
*/
identifier?: string;
/**
* Whether the executed command is kept alive and runs in the background.
*/
isBackground?: boolean;
/**
* Whether the task should prompt on close for confirmation if running.
*/
promptOnClose?: boolean;
/**
* Defines the group the task belongs too.
*/
group?: string | GroupKind;
/**
* The other tasks the task depend on
*/
dependsOn?: string | TaskIdentifier | Array<string | TaskIdentifier>;
/**
* Controls the behavior of the used terminal
*/
presentation?: PresentationOptionsConfig;
/**
* Controls shell options.
*/
options?: CommandOptionsConfig;
/**
* The problem matcher(s) to use to capture problems in the tasks
* output.
*/
problemMatcher?: ProblemMatcherConfig.ProblemMatcherType;
/**
* Task run options. Control run related properties.
*/
runOptions?: RunOptionsConfig;
}
export interface CustomTask extends CommandProperties, ConfigurationProperties {
/**
* Custom tasks have the type CUSTOMIZED_TASK_TYPE
*/
type?: string;
}
export interface ConfiguringTask extends ConfigurationProperties {
/**
* The contributed type of the task
*/
type?: string;
}
/**
* The base task runner configuration
*/
export interface BaseTaskRunnerConfiguration {
/**
* The command to be executed. Can be an external program or a shell
* command.
*/
command?: CommandString;
/**
* @deprecated Use type instead
*
* Specifies whether the command is a shell command and therefore must
* be executed in a shell interpreter (e.g. cmd.exe, bash, ...).
*
* Defaults to false if omitted.
*/
isShellCommand?: boolean;
/**
* The task type
*/
type?: string;
/**
* The command options used when the command is executed. Can be omitted.
*/
options?: CommandOptionsConfig;
/**
* The arguments passed to the command. Can be omitted.
*/
args?: CommandString[];
/**
* Controls whether the output view of the running tasks is brought to front or not.
* Valid values are:
* "always": bring the output window always to front when a task is executed.
* "silent": only bring it to front if no problem matcher is defined for the task executed.
* "never": never bring the output window to front.
*
* If omitted "always" is used.
*/
showOutput?: string;
/**
* Controls whether the executed command is printed to the output windows as well.
*/
echoCommand?: boolean;
/**
* The group
*/
group?: string | GroupKind;
/**
* Controls the behavior of the used terminal
*/
presentation?: PresentationOptionsConfig;
/**
* If set to false the task name is added as an additional argument to the
* command when executed. If set to true the task name is suppressed. If
* omitted false is used.
*/
suppressTaskName?: boolean;
/**
* Some commands require that the task argument is highlighted with a special
* prefix (e.g. /t: for msbuild). This property can be used to control such
* a prefix.
*/
taskSelector?: string;
/**
* The problem matcher(s) to used if a global command is exucuted (e.g. no tasks
* are defined). A tasks.json file can either contain a global problemMatcher
* property or a tasks property but not both.
*/
problemMatcher?: ProblemMatcherConfig.ProblemMatcherType;
/**
* @deprecated Use `isBackground` instead.
*
* Specifies whether a global command is a watching the filesystem. A task.json
* file can either contain a global isWatching property or a tasks property
* but not both.
*/
isWatching?: boolean;
/**
* Specifies whether a global command is a background task.
*/
isBackground?: boolean;
/**
* Whether the task should prompt on close for confirmation if running.
*/
promptOnClose?: boolean;
/**
* The configuration of the available tasks. A tasks.json file can either
* contain a global problemMatcher property or a tasks property but not both.
*/
tasks?: Array<CustomTask | ConfiguringTask>;
/**
* Problem matcher declarations.
*/
declares?: ProblemMatcherConfig.NamedProblemMatcher[];
/**
* Optional user input variables.
*/
inputs?: ConfiguredInput[];
}
/**
* A configuration of an external build system. BuildConfiguration.buildSystem
* must be set to 'program'
*/
export interface ExternalTaskRunnerConfiguration extends BaseTaskRunnerConfiguration {
_runner?: string;
/**
* Determines the runner to use
*/
runner?: string;
/**
* The config's version number
*/
version: string;
/**
* Windows specific task configuration
*/
windows?: BaseTaskRunnerConfiguration;
/**
* Mac specific task configuration
*/
osx?: BaseTaskRunnerConfiguration;
/**
* Linux speciif task configuration
*/
linux?: BaseTaskRunnerConfiguration;
}
enum ProblemMatcherKind {
Unknown,
String,
ProblemMatcher,
Array
}
const EMPTY_ARRAY: any[] = [];
Object.freeze(EMPTY_ARRAY);
function assignProperty<T, K extends keyof T>(target: T, source: Partial<T>, key: K) {
const sourceAtKey = source[key];
if (sourceAtKey !== undefined) {
target[key] = sourceAtKey!;
}
}
function fillProperty<T, K extends keyof T>(target: T, source: Partial<T>, key: K) {
const sourceAtKey = source[key];
if (target[key] === undefined && sourceAtKey !== undefined) {
target[key] = sourceAtKey!;
}
}
interface ParserType<T> {
isEmpty(value: T | undefined): boolean;
assignProperties(target: T | undefined, source: T | undefined): T | undefined;
fillProperties(target: T | undefined, source: T | undefined): T | undefined;
fillDefaults(value: T | undefined, context: ParseContext): T | undefined;
freeze(value: T): Readonly<T> | undefined;
}
interface MetaData<T, U> {
property: keyof T;
type?: ParserType<U>;
}
function _isEmpty<T>(this: void, value: T | undefined, properties: MetaData<T, any>[] | undefined): boolean {
if (value === undefined || value === null || properties === undefined) {
return true;
}
for (let meta of properties) {
let property = value[meta.property];
if (property !== undefined && property !== null) {
if (meta.type !== undefined && !meta.type.isEmpty(property)) {
return false;
} else if (!Array.isArray(property) || property.length > 0) {
return false;
}
}
}
return true;
}
function _assignProperties<T>(this: void, target: T | undefined, source: T | undefined, properties: MetaData<T, any>[]): T | undefined {
if (!source || _isEmpty(source, properties)) {
return target;
}
if (!target || _isEmpty(target, properties)) {
return source;
}
for (let meta of properties) {
let property = meta.property;
let value: any;
if (meta.type !== undefined) {
value = meta.type.assignProperties(target[property], source[property]);
} else {
value = source[property];
}
if (value !== undefined && value !== null) {
target[property] = value;
}
}
return target;
}
function _fillProperties<T>(this: void, target: T | undefined, source: T | undefined, properties: MetaData<T, any>[] | undefined): T | undefined {
if (!source || _isEmpty(source, properties)) {
return target;
}
if (!target || _isEmpty(target, properties)) {
return source;
}
for (let meta of properties!) {
let property = meta.property;
let value: any;
if (meta.type) {
value = meta.type.fillProperties(target[property], source[property]);
} else if (target[property] === undefined) {
value = source[property];
}
if (value !== undefined && value !== null) {
target[property] = value;
}
}
return target;
}
function _fillDefaults<T>(this: void, target: T | undefined, defaults: T | undefined, properties: MetaData<T, any>[], context: ParseContext): T | undefined {
if (target && Object.isFrozen(target)) {
return target;
}
if (target === undefined || target === null || defaults === undefined || defaults === null) {
if (defaults !== undefined && defaults !== null) {
return Objects.deepClone(defaults);
} else {
return undefined;
}
}
for (let meta of properties) {
let property = meta.property;
if (target[property] !== undefined) {
continue;
}
let value: any;
if (meta.type) {
value = meta.type.fillDefaults(target[property], context);
} else {
value = defaults[property];
}
if (value !== undefined && value !== null) {
target[property] = value;
}
}
return target;
}
function _freeze<T>(this: void, target: T, properties: MetaData<T, any>[]): Readonly<T> | undefined {
if (target === undefined || target === null) {
return undefined;
}
if (Object.isFrozen(target)) {
return target;
}
for (let meta of properties) {
if (meta.type) {
let value = target[meta.property];
if (value) {
meta.type.freeze(value);
}
}
}
Object.freeze(target);
return target;
}
export namespace RunOnOptions {
export function fromString(value: string | undefined): Tasks.RunOnOptions {
if (!value) {
return Tasks.RunOnOptions.default;
}
switch (value.toLowerCase()) {
case 'folderopen':
return Tasks.RunOnOptions.folderOpen;
case 'default':
default:
return Tasks.RunOnOptions.default;
}
}
}
export namespace RunOptions {
export function fromConfiguration(value: RunOptionsConfig | undefined): Tasks.RunOptions {
return {
reevaluateOnRerun: value ? value.reevaluateOnRerun : true,
runOn: value ? RunOnOptions.fromString(value.runOn) : Tasks.RunOnOptions.default
};
}
}
class ParseContext {
workspaceFolder: IWorkspaceFolder;
problemReporter: IProblemReporter;
namedProblemMatchers: IStringDictionary<NamedProblemMatcher>;
uuidMap: UUIDMap;
engine: Tasks.ExecutionEngine;
schemaVersion: Tasks.JsonSchemaVersion;
platform: Platform;
taskLoadIssues: string[];
}
namespace ShellConfiguration {
const properties: MetaData<Tasks.ShellConfiguration, void>[] = [{ property: 'executable' }, { property: 'args' }, { property: 'quoting' }];
export function is(value: any): value is ShellConfiguration {
let candidate: ShellConfiguration = value;
return candidate && (Types.isString(candidate.executable) || Types.isStringArray(candidate.args));
}
export function from(this: void, config: ShellConfiguration | undefined, context: ParseContext): Tasks.ShellConfiguration | undefined {
if (!is(config)) {
return undefined;
}
let result: ShellConfiguration = {};
if (config.executable !== undefined) {
result.executable = config.executable;
}
if (config.args !== undefined) {
result.args = config.args.slice();
}
if (config.quoting !== undefined) {
result.quoting = Objects.deepClone(config.quoting);
}
return result;
}
export function isEmpty(this: void, value: Tasks.ShellConfiguration): boolean {
return _isEmpty(value, properties);
}
export function assignProperties(this: void, target: Tasks.ShellConfiguration | undefined, source: Tasks.ShellConfiguration | undefined): Tasks.ShellConfiguration | undefined {
return _assignProperties(target, source, properties);
}
export function fillProperties(this: void, target: Tasks.ShellConfiguration, source: Tasks.ShellConfiguration): Tasks.ShellConfiguration | undefined {
return _fillProperties(target, source, properties);
}
export function fillDefaults(this: void, value: Tasks.ShellConfiguration, context: ParseContext): Tasks.ShellConfiguration {
return value;
}
export function freeze(this: void, value: Tasks.ShellConfiguration): Readonly<Tasks.ShellConfiguration> | undefined {
if (!value) {
return undefined;
}
return Object.freeze(value);
}
}
namespace CommandOptions {
const properties: MetaData<Tasks.CommandOptions, Tasks.ShellConfiguration>[] = [{ property: 'cwd' }, { property: 'env' }, { property: 'shell', type: ShellConfiguration }];
const defaults: CommandOptionsConfig = { cwd: '${workspaceFolder}' };
export function from(this: void, options: CommandOptionsConfig, context: ParseContext): Tasks.CommandOptions | undefined {
let result: Tasks.CommandOptions = {};
if (options.cwd !== undefined) {
if (Types.isString(options.cwd)) {
result.cwd = options.cwd;
} else {
context.taskLoadIssues.push(nls.localize('ConfigurationParser.invalidCWD', 'Warning: options.cwd must be of type string. Ignoring value {0}\n', options.cwd));
}
}
if (options.env !== undefined) {
result.env = Objects.deepClone(options.env);
}
result.shell = ShellConfiguration.from(options.shell, context);
return isEmpty(result) ? undefined : result;
}
export function isEmpty(value: Tasks.CommandOptions | undefined): boolean {
return _isEmpty(value, properties);
}
export function assignProperties(target: Tasks.CommandOptions | undefined, source: Tasks.CommandOptions | undefined): Tasks.CommandOptions | undefined {
if ((source === undefined) || isEmpty(source)) {
return target;
}
if ((target === undefined) || isEmpty(target)) {
return source;
}
assignProperty(target, source, 'cwd');
if (target.env === undefined) {
target.env = source.env;
} else if (source.env !== undefined) {
let env: { [key: string]: string; } = Object.create(null);
if (target.env !== undefined) {
Object.keys(target.env).forEach(key => env[key] = target.env![key]);
}
if (source.env !== undefined) {
Object.keys(source.env).forEach(key => env[key] = source.env![key]);
}
target.env = env;
}
target.shell = ShellConfiguration.assignProperties(target.shell, source.shell);
return target;
}
export function fillProperties(target: Tasks.CommandOptions | undefined, source: Tasks.CommandOptions | undefined): Tasks.CommandOptions | undefined {
return _fillProperties(target, source, properties);
}
export function fillDefaults(value: Tasks.CommandOptions | undefined, context: ParseContext): Tasks.CommandOptions | undefined {
return _fillDefaults(value, defaults, properties, context);
}
export function freeze(value: Tasks.CommandOptions): Readonly<Tasks.CommandOptions> | undefined {
return _freeze(value, properties);
}
}
namespace CommandConfiguration {
export namespace PresentationOptions {
const properties: MetaData<Tasks.PresentationOptions, void>[] = [{ property: 'echo' }, { property: 'reveal' }, { property: 'revealProblems' }, { property: 'focus' }, { property: 'panel' }, { property: 'showReuseMessage' }, { property: 'clear' }, { property: 'group' }];
interface PresentationOptionsShape extends LegacyCommandProperties {
presentation?: PresentationOptionsConfig;
}
export function from(this: void, config: PresentationOptionsShape, context: ParseContext): Tasks.PresentationOptions | undefined {
let echo: boolean;
let reveal: Tasks.RevealKind;
let revealProblems: Tasks.RevealProblemKind;
let focus: boolean;
let panel: Tasks.PanelKind;
let showReuseMessage: boolean;
let clear: boolean;
let group: string | undefined;
let hasProps = false;
if (Types.isBoolean(config.echoCommand)) {
echo = config.echoCommand;
hasProps = true;
}
if (Types.isString(config.showOutput)) {
reveal = Tasks.RevealKind.fromString(config.showOutput);
hasProps = true;
}
let presentation = config.presentation || config.terminal;
if (presentation) {
if (Types.isBoolean(presentation.echo)) {
echo = presentation.echo;
}
if (Types.isString(presentation.reveal)) {
reveal = Tasks.RevealKind.fromString(presentation.reveal);
}
if (Types.isString(presentation.revealProblems)) {
revealProblems = Tasks.RevealProblemKind.fromString(presentation.revealProblems);
}
if (Types.isBoolean(presentation.focus)) {
focus = presentation.focus;
}
if (Types.isString(presentation.panel)) {
panel = Tasks.PanelKind.fromString(presentation.panel);
}
if (Types.isBoolean(presentation.showReuseMessage)) {
showReuseMessage = presentation.showReuseMessage;
}
if (Types.isBoolean(presentation.clear)) {
clear = presentation.clear;
}
if (Types.isString(presentation.group)) {
group = presentation.group;
}
hasProps = true;
}
if (!hasProps) {
return undefined;
}
return { echo: echo!, reveal: reveal!, revealProblems: revealProblems!, focus: focus!, panel: panel!, showReuseMessage: showReuseMessage!, clear: clear!, group };
}
export function assignProperties(target: Tasks.PresentationOptions, source: Tasks.PresentationOptions | undefined): Tasks.PresentationOptions | undefined {
return _assignProperties(target, source, properties);
}
export function fillProperties(target: Tasks.PresentationOptions, source: Tasks.PresentationOptions | undefined): Tasks.PresentationOptions | undefined {
return _fillProperties(target, source, properties);
}
export function fillDefaults(value: Tasks.PresentationOptions, context: ParseContext): Tasks.PresentationOptions | undefined {
let defaultEcho = context.engine === Tasks.ExecutionEngine.Terminal ? true : false;
return _fillDefaults(value, { echo: defaultEcho, reveal: Tasks.RevealKind.Always, revealProblems: Tasks.RevealProblemKind.Never, focus: false, panel: Tasks.PanelKind.Shared, showReuseMessage: true, clear: false }, properties, context);
}
export function freeze(value: Tasks.PresentationOptions): Readonly<Tasks.PresentationOptions> | undefined {
return _freeze(value, properties);
}
export function isEmpty(this: void, value: Tasks.PresentationOptions): boolean {
return _isEmpty(value, properties);
}
}
namespace ShellString {
export function from(this: void, value: CommandString | undefined): Tasks.CommandString | undefined {
if (value === undefined || value === null) {
return undefined;
}
if (Types.isString(value)) {
return value;
} else if (Types.isStringArray(value)) {
return value.join(' ');
} else {
let quoting = Tasks.ShellQuoting.from(value.quoting);
let result = Types.isString(value.value) ? value.value : Types.isStringArray(value.value) ? value.value.join(' ') : undefined;
if (result) {
return {
value: result,
quoting: quoting
};
} else {
return undefined;
}
}
}
}
interface BaseCommandConfiguationShape extends BaseCommandProperties, LegacyCommandProperties {
}
interface CommandConfiguationShape extends BaseCommandConfiguationShape {
windows?: BaseCommandConfiguationShape;
osx?: BaseCommandConfiguationShape;
linux?: BaseCommandConfiguationShape;
}
const properties: MetaData<Tasks.CommandConfiguration, any>[] = [
{ property: 'runtime' }, { property: 'name' }, { property: 'options', type: CommandOptions },
{ property: 'args' }, { property: 'taskSelector' }, { property: 'suppressTaskName' },
{ property: 'presentation', type: PresentationOptions }
];
export function from(this: void, config: CommandConfiguationShape, context: ParseContext): Tasks.CommandConfiguration | undefined {
let result: Tasks.CommandConfiguration = fromBase(config, context)!;
let osConfig: Tasks.CommandConfiguration | undefined = undefined;
if (config.windows && context.platform === Platform.Windows) {
osConfig = fromBase(config.windows, context);
} else if (config.osx && context.platform === Platform.Mac) {
osConfig = fromBase(config.osx, context);
} else if (config.linux && context.platform === Platform.Linux) {
osConfig = fromBase(config.linux, context);
}
if (osConfig) {
result = assignProperties(result, osConfig, context.schemaVersion === Tasks.JsonSchemaVersion.V2_0_0);
}
return isEmpty(result) ? undefined : result;
}
function fromBase(this: void, config: BaseCommandConfiguationShape, context: ParseContext): Tasks.CommandConfiguration | undefined {
let name: Tasks.CommandString | undefined = ShellString.from(config.command);
let runtime: Tasks.RuntimeType;
if (Types.isString(config.type)) {
if (config.type === 'shell' || config.type === 'process') {
runtime = Tasks.RuntimeType.fromString(config.type);
}
}
let isShellConfiguration = ShellConfiguration.is(config.isShellCommand);
if (Types.isBoolean(config.isShellCommand) || isShellConfiguration) {
runtime = Tasks.RuntimeType.Shell;
} else if (config.isShellCommand !== undefined) {
runtime = !!config.isShellCommand ? Tasks.RuntimeType.Shell : Tasks.RuntimeType.Process;
}
let result: Tasks.CommandConfiguration = {
name: name,
runtime: runtime!,
presentation: PresentationOptions.from(config, context)!
};
if (config.args !== undefined) {
result.args = [];
for (let arg of config.args) {
let converted = ShellString.from(arg);
if (converted !== undefined) {
result.args.push(converted);
} else {
context.taskLoadIssues.push(
nls.localize(
'ConfigurationParser.inValidArg',
'Error: command argument must either be a string or a quoted string. Provided value is:\n{0}',
arg ? JSON.stringify(arg, undefined, 4) : 'undefined'
));
}
}
}
if (config.options !== undefined) {
result.options = CommandOptions.from(config.options, context);
if (result.options && result.options.shell === undefined && isShellConfiguration) {
result.options.shell = ShellConfiguration.from(config.isShellCommand as ShellConfiguration, context);
if (context.engine !== Tasks.ExecutionEngine.Terminal) {
context.taskLoadIssues.push(nls.localize('ConfigurationParser.noShell', 'Warning: shell configuration is only supported when executing tasks in the terminal.'));
}
}
}
if (Types.isString(config.taskSelector)) {
result.taskSelector = config.taskSelector;
}
if (Types.isBoolean(config.suppressTaskName)) {
result.suppressTaskName = config.suppressTaskName;
}
return isEmpty(result) ? undefined : result;
}
export function hasCommand(value: Tasks.CommandConfiguration): boolean {
return value && !!value.name;
}