taskConfiguration.ts 59.1 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5 6
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

7 8
import * as crypto from 'crypto';

E
Erich Gamma 已提交
9 10 11 12 13 14 15 16
import nls = require('vs/nls');

import * as Objects from 'vs/base/common/objects';
import { IStringDictionary } from 'vs/base/common/collections';
import * as Platform from 'vs/base/common/platform';
import * as Types from 'vs/base/common/types';
import * as UUID from 'vs/base/common/uuid';

M
Matt Bierner 已提交
17
import { ValidationStatus, IProblemReporter as IProblemReporterBase } from 'vs/base/common/parsers';
18 19
import {
	NamedProblemMatcher, ProblemMatcher, ProblemMatcherParser, Config as ProblemMatcherConfig,
20
	isNamedProblemMatcher, ProblemMatcherRegistry
21
} from 'vs/workbench/parts/tasks/common/problemMatcher';
22

S
Sandeep Somavarapu 已提交
23
import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
24

25
import * as Tasks from '../common/tasks';
D
Dirk Baeumer 已提交
26
import { TaskDefinitionRegistry } from '../common/taskDefinitionRegistry';
E
Erich Gamma 已提交
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
export 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;
}

D
Dirk Baeumer 已提交
65 66 67
export interface ShellConfiguration {
	executable: string;
	args?: string[];
68
	quoting?: ShellQuotingOptions;
D
Dirk Baeumer 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
}

export interface CommandOptions {
	/**
	 * 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;
}

90 91 92 93 94 95
export interface PresentationOptions {
	/**
	 * Controls whether the terminal executing a task is brought to front or not.
	 * Defaults to `RevealKind.Always`.
	 */
	reveal?: string;
D
Dirk Baeumer 已提交
96 97

	/**
98 99 100 101 102 103 104 105 106 107 108
	 * 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
D
Dirk Baeumer 已提交
109
	 */
110 111 112 113
	panel?: string;
}

export interface TaskIdentifier {
D
Dirk Baeumer 已提交
114
	type?: string;
115
}
D
Dirk Baeumer 已提交
116

117
export interface LegacyTaskProperties {
E
Erich Gamma 已提交
118
	/**
119 120
	 * @deprecated Use `isBackground` instead.
	 * Whether the executed command is kept alive and is watching the file system.
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
	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;

157 158 159 160 161
	/**
	 * @deprecated Use presentation instead
	 */
	terminal?: PresentationOptions;

162 163 164 165 166 167 168 169 170 171 172 173
	/**
	 * @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;
174 175

	/**
D
Dirk Baeumer 已提交
176
	 * @deprecated use the task type instead.
177 178 179 180 181
	 * 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.
	 */
D
Dirk Baeumer 已提交
182
	isShellCommand?: boolean | ShellConfiguration;
183 184
}

185
export type CommandString = string | { value: string, quoting: 'escape' | 'strong' | 'weak' };
186

187 188 189 190 191 192 193 194 195 196 197
export namespace CommandString {
	export function value(value: CommandString): string {
		if (Types.isString(value)) {
			return value;
		} else {
			return value.value;
		}
	}
}

export interface BaseCommandProperties {
198 199 200 201 202

	/**
	 * The command to be executed. Can be an external program or a shell
	 * command.
	 */
203
	command?: CommandString;
204 205 206 207

	/**
	 * The command options used when the command is executed. Can be omitted.
	 */
D
Dirk Baeumer 已提交
208
	options?: CommandOptions;
209 210 211 212

	/**
	 * The arguments passed to the command or additional arguments passed to the
	 * command when using a global command.
E
Erich Gamma 已提交
213
	 */
214
	args?: CommandString[];
215 216 217
}


218
export interface CommandProperties extends BaseCommandProperties {
D
Dirk Baeumer 已提交
219

220
	/**
221
	 * Windows specific command properties
222
	 */
223
	windows?: BaseCommandProperties;
224

225
	/**
226
	 * OSX specific command properties
227
	 */
228
	osx?: BaseCommandProperties;
229 230

	/**
231
	 * linux specific command properties
232
	 */
233 234
	linux?: BaseCommandProperties;
}
235

D
Dirk Baeumer 已提交
236 237
export interface GroupKind {
	kind?: string;
238
	isDefault?: boolean;
D
Dirk Baeumer 已提交
239 240
}

241
export interface ConfigurationProperties {
242
	/**
243
	 * The task's name
244
	 */
245
	taskName?: string;
E
Erich Gamma 已提交
246

247 248 249 250 251
	/**
	 * The UI label used for the task.
	 */
	label?: string;

E
Erich Gamma 已提交
252
	/**
253 254
	 * An optional indentifier which can be used to reference a task
	 * in a dependsOn or other attributes.
E
Erich Gamma 已提交
255
	 */
256
	identifier?: string;
E
Erich Gamma 已提交
257

258 259 260 261 262
	/**
	 * Whether the executed command is kept alive and runs in the background.
	 */
	isBackground?: boolean;

D
Dirk Baeumer 已提交
263 264 265 266 267
	/**
	 * Whether the task should prompt on close for confirmation if running.
	 */
	promptOnClose?: boolean;

E
Erich Gamma 已提交
268
	/**
269 270
	 * Defines the group the task belongs too.
	 */
D
Dirk Baeumer 已提交
271
	group?: string | GroupKind;
272 273

	/**
274
	 * The other tasks the task depend on
E
Erich Gamma 已提交
275
	 */
276
	dependsOn?: string | string[];
E
Erich Gamma 已提交
277 278

	/**
279
	 * Controls the behavior of the used terminal
E
Erich Gamma 已提交
280
	 */
281
	presentation?: PresentationOptions;
E
Erich Gamma 已提交
282 283

	/**
284 285
	 * The problem matcher(s) to use to capture problems in the tasks
	 * output.
E
Erich Gamma 已提交
286
	 */
287 288
	problemMatcher?: ProblemMatcherConfig.ProblemMatcherType;
}
E
Erich Gamma 已提交
289

290
export interface CustomTask extends CommandProperties, ConfigurationProperties {
E
Erich Gamma 已提交
291
	/**
292
	 * Custom tasks have the type 'custom'
E
Erich Gamma 已提交
293
	 */
294
	type?: string;
E
Erich Gamma 已提交
295

296
}
297

298
export interface ConfiguringTask extends ConfigurationProperties {
E
Erich Gamma 已提交
299
	/**
300
	 * The contributed type of the task
E
Erich Gamma 已提交
301
	 */
302
	type?: string;
E
Erich Gamma 已提交
303 304 305 306 307
}

/**
 * The base task runner configuration
 */
308
export interface BaseTaskRunnerConfiguration {
E
Erich Gamma 已提交
309 310 311 312 313

	/**
	 * The command to be executed. Can be an external program or a shell
	 * command.
	 */
314
	command?: CommandString;
E
Erich Gamma 已提交
315 316

	/**
317 318
	 * @deprecated Use type instead
	 *
E
Erich Gamma 已提交
319 320 321 322 323 324 325
	 * 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;

326 327 328 329 330
	/**
	 * The task type
	 */
	type?: string;

E
Erich Gamma 已提交
331 332 333
	/**
	 * The command options used when the command is executed. Can be omitted.
	 */
D
Dirk Baeumer 已提交
334
	options?: CommandOptions;
E
Erich Gamma 已提交
335 336 337 338

	/**
	 * The arguments passed to the command. Can be omitted.
	 */
339
	args?: CommandString[];
E
Erich Gamma 已提交
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356

	/**
	 * 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;

357 358 359 360
	/**
	 * The group
	 */
	group?: string | GroupKind;
D
Dirk Baeumer 已提交
361 362 363
	/**
	 * Controls the behavior of the used terminal
	 */
364
	presentation?: PresentationOptions;
D
Dirk Baeumer 已提交
365

E
Erich Gamma 已提交
366 367 368 369 370 371 372 373 374 375 376 377
	/**
	 * 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.
	 */
J
Johannes Rieken 已提交
378
	taskSelector?: string;
E
Erich Gamma 已提交
379 380 381 382 383 384 385 386 387

	/**
	 * 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;

	/**
388 389
	 * @deprecated Use `isBackground` instead.
	 *
E
Erich Gamma 已提交
390
	 * Specifies whether a global command is a watching the filesystem. A task.json
391
	 * file can either contain a global isWatching property or a tasks property
E
Erich Gamma 已提交
392 393 394 395
	 * but not both.
	 */
	isWatching?: boolean;

396 397 398 399 400
	/**
	 * Specifies whether a global command is a background task.
	 */
	isBackground?: boolean;

D
Dirk Baeumer 已提交
401 402 403 404 405
	/**
	 * Whether the task should prompt on close for confirmation if running.
	 */
	promptOnClose?: boolean;

E
Erich Gamma 已提交
406 407 408 409
	/**
	 * The configuration of the available tasks. A tasks.json file can either
	 * contain a global problemMatcher property or a tasks property but not both.
	 */
410
	tasks?: (CustomTask | ConfiguringTask)[];
E
Erich Gamma 已提交
411 412 413 414 415 416 417 418 419 420 421 422 423

	/**
	 * Problem matcher declarations
	 */
	declares?: ProblemMatcherConfig.NamedProblemMatcher[];
}

/**
 * A configuration of an external build system. BuildConfiguration.buildSystem
 * must be set to 'program'
 */
export interface ExternalTaskRunnerConfiguration extends BaseTaskRunnerConfiguration {

424 425
	_runner?: string;

426 427 428 429 430
	/**
	 * Determines the runner to use
	 */
	runner?: string;

E
Erich Gamma 已提交
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
	/**
	 * 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
}

459 460
const EMPTY_ARRAY: any[] = [];
Object.freeze(EMPTY_ARRAY);
E
Erich Gamma 已提交
461

462
function assignProperty<T, K extends keyof T>(target: T, source: Partial<T>, key: K) {
463 464 465
	if (source[key] !== void 0) {
		target[key] = source[key];
	}
E
Erich Gamma 已提交
466 467
}

468
function fillProperty<T, K extends keyof T>(target: T, source: Partial<T>, key: K) {
469 470 471 472 473 474
	if (target[key] === void 0 && source[key] !== void 0) {
		target[key] = source[key];
	}
}


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
interface ParserType<T> {
	isEmpty(value: T): boolean;
	assignProperties(target: T, source: T): T;
	fillProperties(target: T, source: T): T;
	fillDefaults(value: T, context: ParseContext): T;
	freeze(value: T): Readonly<T>;
}

interface MetaData<T, U> {
	property: keyof T;
	type?: ParserType<U>;
}


function _isEmpty<T>(this: void, value: T, properties: MetaData<T, any>[]): boolean {
	if (value === void 0 || value === null) {
		return true;
	}
	for (let meta of properties) {
		let property = value[meta.property];
		if (property !== void 0 && property !== null) {
			if (meta.type !== void 0 && !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, source: T, properties: MetaData<T, any>[]): T {
	if (_isEmpty(source, properties)) {
		return target;
	}
	if (_isEmpty(target, properties)) {
		return source;
	}
	for (let meta of properties) {
		let property = meta.property;
		let value: any;
		if (meta.type !== void 0) {
			value = meta.type.assignProperties(target[property], source[property]);
		} else {
			value = source[property];
		}
		if (value !== void 0 && value !== null) {
			target[property] = value;
		}
	}
	return target;
}

function _fillProperties<T>(this: void, target: T, source: T, properties: MetaData<T, any>[]): T {
	if (_isEmpty(source, properties)) {
		return target;
	}
	if (_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]);
540
		} else if (target[property] === void 0) {
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
			value = source[property];
		}
		if (value !== void 0 && value !== null) {
			target[property] = value;
		}
	}
	return target;
}

function _fillDefaults<T>(this: void, target: T, defaults: T, properties: MetaData<T, any>[], context: ParseContext): T {
	if (target && Object.isFrozen(target)) {
		return target;
	}
	if (target === void 0 || target === null) {
		if (defaults !== void 0 && defaults !== null) {
J
Johannes Rieken 已提交
556
			return Objects.deepClone(defaults);
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
		} else {
			return undefined;
		}
	}
	for (let meta of properties) {
		let property = meta.property;
		if (target[property] !== void 0) {
			continue;
		}
		let value: any;
		if (meta.type) {
			value = meta.type.fillDefaults(target[property], context);
		} else {
			value = defaults[property];
		}

		if (value !== void 0 && value !== null) {
			target[property] = value;
		}
	}
	return target;
}

function _freeze<T>(this: void, target: T, properties: MetaData<T, any>[]): Readonly<T> {
	if (target === void 0 || 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;
}

599
interface ParseContext {
S
Sandeep Somavarapu 已提交
600
	workspaceFolder: IWorkspaceFolder;
601
	problemReporter: IProblemReporter;
602
	namedProblemMatchers: IStringDictionary<NamedProblemMatcher>;
603
	uuidMap: UUIDMap;
604 605
	engine: Tasks.ExecutionEngine;
	schemaVersion: Tasks.JsonSchemaVersion;
E
Erich Gamma 已提交
606 607
}

608

609
namespace ShellConfiguration {
610

611
	const properties: MetaData<Tasks.ShellConfiguration, void>[] = [{ property: 'executable' }, { property: 'args' }, { property: 'quoting' }];
612

613 614 615 616 617 618 619 620 621 622 623 624 625
	export function is(value: any): value is ShellConfiguration {
		let candidate: ShellConfiguration = value;
		return candidate && Types.isString(candidate.executable) && (candidate.args === void 0 || Types.isStringArray(candidate.args));
	}

	export function from(this: void, config: ShellConfiguration, context: ParseContext): Tasks.ShellConfiguration {
		if (!is(config)) {
			return undefined;
		}
		let result: ShellConfiguration = { executable: config.executable };
		if (config.args !== void 0) {
			result.args = config.args.slice();
		}
626 627 628 629
		if (config.quoting !== void 0) {
			result.quoting = Objects.deepClone(config.quoting);
		}

630 631 632
		return result;
	}

633 634
	export function isEmpty(this: void, value: Tasks.ShellConfiguration): boolean {
		return _isEmpty(value, properties);
635 636
	}

637 638
	export function assignProperties(this: void, target: Tasks.ShellConfiguration, source: Tasks.ShellConfiguration): Tasks.ShellConfiguration {
		return _assignProperties(target, source, properties);
639 640
	}

641 642
	export function fillProperties(this: void, target: Tasks.ShellConfiguration, source: Tasks.ShellConfiguration): Tasks.ShellConfiguration {
		return _fillProperties(target, source, properties);
643 644
	}

645 646
	export function fillDefaults(this: void, value: Tasks.ShellConfiguration, context: ParseContext): Tasks.ShellConfiguration {
		return value;
647 648
	}

649
	export function freeze(this: void, value: Tasks.ShellConfiguration): Readonly<Tasks.ShellConfiguration> {
650
		if (!value) {
651
			return undefined;
652
		}
653
		return Object.freeze(value);
654 655 656
	}
}

657
namespace CommandOptions {
658 659

	const properties: MetaData<Tasks.CommandOptions, Tasks.ShellConfiguration>[] = [{ property: 'cwd' }, { property: 'env' }, { property: 'shell', type: ShellConfiguration }];
660
	const defaults: CommandOptions = { cwd: '${workspaceFolder}' };
661

D
Dirk Baeumer 已提交
662
	export function from(this: void, options: CommandOptions, context: ParseContext): Tasks.CommandOptions {
663
		let result: Tasks.CommandOptions = {};
664 665 666 667
		if (options.cwd !== void 0) {
			if (Types.isString(options.cwd)) {
				result.cwd = options.cwd;
			} else {
668
				context.problemReporter.warn(nls.localize('ConfigurationParser.invalidCWD', 'Warning: options.cwd must be of type string. Ignoring value {0}\n', options.cwd));
669 670 671
			}
		}
		if (options.env !== void 0) {
J
Johannes Rieken 已提交
672
			result.env = Objects.deepClone(options.env);
673
		}
D
Dirk Baeumer 已提交
674
		result.shell = ShellConfiguration.from(options.shell, context);
675
		return isEmpty(result) ? undefined : result;
E
Erich Gamma 已提交
676 677
	}

678
	export function isEmpty(value: Tasks.CommandOptions): boolean {
679
		return _isEmpty(value, properties);
E
Erich Gamma 已提交
680 681
	}

682
	export function assignProperties(target: Tasks.CommandOptions, source: Tasks.CommandOptions): Tasks.CommandOptions {
683 684
		if (isEmpty(source)) {
			return target;
E
Erich Gamma 已提交
685
		}
686 687
		if (isEmpty(target)) {
			return source;
E
Erich Gamma 已提交
688
		}
689
		assignProperty(target, source, 'cwd');
690 691 692 693 694
		if (target.env === void 0) {
			target.env = source.env;
		} else if (source.env !== void 0) {
			let env: { [key: string]: string; } = Object.create(null);
			Object.keys(target.env).forEach(key => env[key] = target.env[key]);
695
			Object.keys(source.env).forEach(key => env[key] = source.env[key]);
696 697
			target.env = env;
		}
698 699 700 701 702
		target.shell = ShellConfiguration.assignProperties(target.shell, source.shell);
		return target;
	}

	export function fillProperties(target: Tasks.CommandOptions, source: Tasks.CommandOptions): Tasks.CommandOptions {
703
		return _fillProperties(target, source, properties);
E
Erich Gamma 已提交
704 705
	}

706 707
	export function fillDefaults(value: Tasks.CommandOptions, context: ParseContext): Tasks.CommandOptions {
		return _fillDefaults(value, defaults, properties, context);
708 709
	}

710 711
	export function freeze(value: Tasks.CommandOptions): Readonly<Tasks.CommandOptions> {
		return _freeze(value, properties);
E
Erich Gamma 已提交
712
	}
713
}
E
Erich Gamma 已提交
714

715
namespace CommandConfiguration {
716

717 718
	export namespace PresentationOptions {
		const properties: MetaData<Tasks.PresentationOptions, void>[] = [{ property: 'echo' }, { property: 'reveal' }, { property: 'focus' }, { property: 'panel' }];
719

720 721 722 723 724
		interface PresentationOptionsShape extends LegacyCommandProperties {
			presentation?: PresentationOptions;
		}

		export function from(this: void, config: PresentationOptionsShape, context: ParseContext): Tasks.PresentationOptions {
725 726 727
			let echo: boolean;
			let reveal: Tasks.RevealKind;
			let focus: boolean;
728
			let panel: Tasks.PanelKind;
D
Dirk Baeumer 已提交
729 730 731 732 733 734
			if (Types.isBoolean(config.echoCommand)) {
				echo = config.echoCommand;
			}
			if (Types.isString(config.showOutput)) {
				reveal = Tasks.RevealKind.fromString(config.showOutput);
			}
735 736 737 738
			let presentation = config.presentation || config.terminal;
			if (presentation) {
				if (Types.isBoolean(presentation.echo)) {
					echo = presentation.echo;
D
Dirk Baeumer 已提交
739
				}
740 741
				if (Types.isString(presentation.reveal)) {
					reveal = Tasks.RevealKind.fromString(presentation.reveal);
D
Dirk Baeumer 已提交
742
				}
743 744
				if (Types.isBoolean(presentation.focus)) {
					focus = presentation.focus;
745
				}
746 747
				if (Types.isString(presentation.panel)) {
					panel = Tasks.PanelKind.fromString(presentation.panel);
748
				}
D
Dirk Baeumer 已提交
749
			}
750
			if (echo === void 0 && reveal === void 0 && focus === void 0 && panel === void 0) {
D
Dirk Baeumer 已提交
751 752
				return undefined;
			}
753
			return { echo, reveal, focus, panel };
D
Dirk Baeumer 已提交
754 755
		}

756
		export function assignProperties(target: Tasks.PresentationOptions, source: Tasks.PresentationOptions): Tasks.PresentationOptions {
757
			return _assignProperties(target, source, properties);
758 759
		}

760
		export function fillProperties(target: Tasks.PresentationOptions, source: Tasks.PresentationOptions): Tasks.PresentationOptions {
761
			return _fillProperties(target, source, properties);
D
Dirk Baeumer 已提交
762 763
		}

764
		export function fillDefaults(value: Tasks.PresentationOptions, context: ParseContext): Tasks.PresentationOptions {
765
			let defaultEcho = context.engine === Tasks.ExecutionEngine.Terminal ? true : false;
766
			return _fillDefaults(value, { echo: defaultEcho, reveal: Tasks.RevealKind.Always, focus: false, panel: Tasks.PanelKind.Shared }, properties, context);
D
Dirk Baeumer 已提交
767 768
		}

769
		export function freeze(value: Tasks.PresentationOptions): Readonly<Tasks.PresentationOptions> {
770
			return _freeze(value, properties);
D
Dirk Baeumer 已提交
771 772
		}

773
		export function isEmpty(this: void, value: Tasks.PresentationOptions): boolean {
774
			return _isEmpty(value, properties);
D
Dirk Baeumer 已提交
775 776 777
		}
	}

778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795
	namespace ShellString {
		export function from(this: void, value: CommandString): Tasks.CommandString {
			if (value === void 0 || value === null) {
				return undefined;
			}
			if (Types.isString(value)) {
				return value;
			}
			if (Types.isString(value.value)) {
				return {
					value: value.value,
					quoting: Tasks.ShellQuoting.from(value.quoting)
				};
			}
			return undefined;
		}
	}

796 797 798 799 800 801 802 803 804 805 806
	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 },
807
		{ property: 'args' }, { property: 'taskSelector' }, { property: 'suppressTaskName' },
808
		{ property: 'presentation', type: PresentationOptions }
809 810
	];

811 812
	export function from(this: void, config: CommandConfiguationShape, context: ParseContext): Tasks.CommandConfiguration {
		let result: Tasks.CommandConfiguration = fromBase(config, context);
813

814
		let osConfig: Tasks.CommandConfiguration = undefined;
815 816 817 818 819 820 821 822
		if (config.windows && Platform.platform === Platform.Platform.Windows) {
			osConfig = fromBase(config.windows, context);
		} else if (config.osx && Platform.platform === Platform.Platform.Mac) {
			osConfig = fromBase(config.osx, context);
		} else if (config.linux && Platform.platform === Platform.Platform.Linux) {
			osConfig = fromBase(config.linux, context);
		}
		if (osConfig) {
823
			result = assignProperties(result, osConfig);
824 825 826 827
		}
		return isEmpty(result) ? undefined : result;
	}

828 829 830
	function fromBase(this: void, config: BaseCommandConfiguationShape, context: ParseContext): Tasks.CommandConfiguration {
		let result: Tasks.CommandConfiguration = {
			name: undefined,
831
			runtime: undefined,
832
			presentation: undefined
833
		};
834 835

		result.name = ShellString.from(config.command);
D
Dirk Baeumer 已提交
836
		if (Types.isString(config.type)) {
837 838 839
			if (config.type === 'shell' || config.type === 'process') {
				result.runtime = Tasks.RuntimeType.fromString(config.type);
			}
D
Dirk Baeumer 已提交
840 841 842
		}
		let isShellConfiguration = ShellConfiguration.is(config.isShellCommand);
		if (Types.isBoolean(config.isShellCommand) || isShellConfiguration) {
843
			result.runtime = Tasks.RuntimeType.Shell;
844
		} else if (config.isShellCommand !== void 0) {
845 846
			result.runtime = !!config.isShellCommand ? Tasks.RuntimeType.Shell : Tasks.RuntimeType.Process;
		}
847

848
		if (config.args !== void 0) {
849 850 851 852 853 854 855 856
			result.args = [];
			for (let arg of config.args) {
				let converted = ShellString.from(arg);
				if (converted) {
					result.args.push(converted);
				} else {
					context.problemReporter.error(nls.localize('ConfigurationParser.inValidArg', 'Error: command argument must either be a string or a quoted string. Provided value is:\n{0}', context.problemReporter.error(nls.localize('ConfigurationParser.noargs', 'Error: command arguments must be an array of strings. Provided value is:\n{0}', arg ? JSON.stringify(arg, undefined, 4) : 'undefined'))));
				}
857
			}
E
Erich Gamma 已提交
858
		}
859 860
		if (config.options !== void 0) {
			result.options = CommandOptions.from(config.options, context);
D
Dirk Baeumer 已提交
861 862
			if (result.options && result.options.shell === void 0 && isShellConfiguration) {
				result.options.shell = ShellConfiguration.from(config.isShellCommand as ShellConfiguration, context);
863
				if (context.engine !== Tasks.ExecutionEngine.Terminal) {
D
Dirk Baeumer 已提交
864 865 866
					context.problemReporter.warn(nls.localize('ConfigurationParser.noShell', 'Warning: shell configuration is only supported when executing tasks in the terminal.'));
				}
			}
E
Erich Gamma 已提交
867
		}
868 869 870
		let panel = PresentationOptions.from(config, context);
		if (panel) {
			result.presentation = panel;
E
Erich Gamma 已提交
871
		}
872 873
		if (Types.isString(config.taskSelector)) {
			result.taskSelector = config.taskSelector;
E
Erich Gamma 已提交
874
		}
875 876 877
		if (Types.isBoolean(config.suppressTaskName)) {
			result.suppressTaskName = config.suppressTaskName;
		}
878
		return isEmpty(result) ? undefined : result;
E
Erich Gamma 已提交
879 880
	}

881 882 883 884
	export function hasCommand(value: Tasks.CommandConfiguration): boolean {
		return value && !!value.name;
	}

885
	export function isEmpty(value: Tasks.CommandConfiguration): boolean {
886
		return _isEmpty(value, properties);
887 888
	}

889
	export function assignProperties(target: Tasks.CommandConfiguration, source: Tasks.CommandConfiguration): Tasks.CommandConfiguration {
890 891
		if (isEmpty(source)) {
			return target;
E
Erich Gamma 已提交
892
		}
893 894
		if (isEmpty(target)) {
			return source;
E
Erich Gamma 已提交
895
		}
896
		assignProperty(target, source, 'name');
897
		assignProperty(target, source, 'runtime');
898 899
		assignProperty(target, source, 'taskSelector');
		assignProperty(target, source, 'suppressTaskName');
900 901 902 903 904
		if (source.args !== void 0) {
			if (target.args === void 0) {
				target.args = source.args;
			} else {
				target.args = target.args.concat(source.args);
E
Erich Gamma 已提交
905 906
			}
		}
907
		target.presentation = PresentationOptions.assignProperties(target.presentation, source.presentation);
908 909 910 911
		target.options = CommandOptions.assignProperties(target.options, source.options);
		return target;
	}

912 913 914 915
	export function fillProperties(target: Tasks.CommandConfiguration, source: Tasks.CommandConfiguration): Tasks.CommandConfiguration {
		return _fillProperties(target, source, properties);
	}

916 917 918 919 920 921
	export function fillGlobals(target: Tasks.CommandConfiguration, source: Tasks.CommandConfiguration, taskName: string): Tasks.CommandConfiguration {
		if (isEmpty(source)) {
			return target;
		}
		target = target || {
			name: undefined,
922
			runtime: undefined,
923
			presentation: undefined
924
		};
925 926 927 928
		if (target.name === void 0) {
			fillProperty(target, source, 'name');
			fillProperty(target, source, 'taskSelector');
			fillProperty(target, source, 'suppressTaskName');
929
			let args: Tasks.CommandString[] = source.args ? source.args.slice() : [];
930 931 932 933 934 935 936 937 938 939 940 941
			if (!target.suppressTaskName) {
				if (target.taskSelector !== void 0) {
					args.push(target.taskSelector + taskName);
				} else {
					args.push(taskName);
				}
			}
			if (target.args) {
				args = args.concat(target.args);
			}
			target.args = args;
		}
942
		fillProperty(target, source, 'runtime');
943

944
		target.presentation = PresentationOptions.fillProperties(target.presentation, source.presentation);
945 946
		target.options = CommandOptions.fillProperties(target.options, source.options);

947
		return target;
E
Erich Gamma 已提交
948 949
	}

950
	export function fillDefaults(value: Tasks.CommandConfiguration, context: ParseContext): void {
951 952 953
		if (!value || Object.isFrozen(value)) {
			return;
		}
954 955
		if (value.name !== void 0 && value.runtime === void 0) {
			value.runtime = Tasks.RuntimeType.Process;
956
		}
957
		value.presentation = PresentationOptions.fillDefaults(value.presentation, context);
958
		if (!isEmpty(value)) {
959
			value.options = CommandOptions.fillDefaults(value.options, context);
960
		}
961 962 963
		if (value.args === void 0) {
			value.args = EMPTY_ARRAY;
		}
964 965
		if (value.suppressTaskName === void 0) {
			value.suppressTaskName = false;
E
Erich Gamma 已提交
966 967 968
		}
	}

969 970
	export function freeze(value: Tasks.CommandConfiguration): Readonly<Tasks.CommandConfiguration> {
		return _freeze(value, properties);
E
Erich Gamma 已提交
971
	}
972
}
E
Erich Gamma 已提交
973

974 975 976
namespace ProblemMatcherConverter {

	export function namedFrom(this: void, declares: ProblemMatcherConfig.NamedProblemMatcher[], context: ParseContext): IStringDictionary<NamedProblemMatcher> {
J
Johannes Rieken 已提交
977
		let result: IStringDictionary<NamedProblemMatcher> = Object.create(null);
978 979

		if (!Types.isArray(declares)) {
E
Erich Gamma 已提交
980 981
			return result;
		}
982
		(<ProblemMatcherConfig.NamedProblemMatcher[]>declares).forEach((value) => {
983
			let namedProblemMatcher = (new ProblemMatcherParser(context.problemReporter)).parse(value);
984
			if (isNamedProblemMatcher(namedProblemMatcher)) {
E
Erich Gamma 已提交
985
				result[namedProblemMatcher.name] = namedProblemMatcher;
986
			} else {
987
				context.problemReporter.error(nls.localize('ConfigurationParser.noName', 'Error: Problem Matcher in declare scope must have a name:\n{0}\n', JSON.stringify(value, undefined, 4)));
E
Erich Gamma 已提交
988 989 990 991 992
			}
		});
		return result;
	}

993 994 995 996 997 998 999
	export function from(this: void, config: ProblemMatcherConfig.ProblemMatcherType, context: ParseContext): ProblemMatcher[] {
		let result: ProblemMatcher[] = [];
		if (config === void 0) {
			return result;
		}
		let kind = getProblemMatcherKind(config);
		if (kind === ProblemMatcherKind.Unknown) {
1000
			context.problemReporter.warn(nls.localize(
1001 1002 1003
				'ConfigurationParser.unknownMatcherKind',
				'Warning: the defined problem matcher is unknown. Supported types are string | ProblemMatcher | (string | ProblemMatcher)[].\n{0}\n',
				JSON.stringify(config, null, 4)));
E
Erich Gamma 已提交
1004
			return result;
1005
		} else if (kind === ProblemMatcherKind.String || kind === ProblemMatcherKind.ProblemMatcher) {
1006
			let matcher = resolveProblemMatcher(config as ProblemMatcherConfig.ProblemMatcher, context);
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028
			if (matcher) {
				result.push(matcher);
			}
		} else if (kind === ProblemMatcherKind.Array) {
			let problemMatchers = <(string | ProblemMatcherConfig.ProblemMatcher)[]>config;
			problemMatchers.forEach(problemMatcher => {
				let matcher = resolveProblemMatcher(problemMatcher, context);
				if (matcher) {
					result.push(matcher);
				}
			});
		}
		return result;
	}

	function getProblemMatcherKind(this: void, value: ProblemMatcherConfig.ProblemMatcherType): ProblemMatcherKind {
		if (Types.isString(value)) {
			return ProblemMatcherKind.String;
		} else if (Types.isArray(value)) {
			return ProblemMatcherKind.Array;
		} else if (!Types.isUndefined(value)) {
			return ProblemMatcherKind.ProblemMatcher;
E
Erich Gamma 已提交
1029
		} else {
1030
			return ProblemMatcherKind.Unknown;
E
Erich Gamma 已提交
1031 1032 1033
		}
	}

1034 1035 1036 1037 1038 1039 1040
	function resolveProblemMatcher(this: void, value: string | ProblemMatcherConfig.ProblemMatcher, context: ParseContext): ProblemMatcher {
		if (Types.isString(value)) {
			let variableName = <string>value;
			if (variableName.length > 1 && variableName[0] === '$') {
				variableName = variableName.substring(1);
				let global = ProblemMatcherRegistry.get(variableName);
				if (global) {
J
Johannes Rieken 已提交
1041
					return Objects.deepClone(global);
1042 1043 1044
				}
				let localProblemMatcher = context.namedProblemMatchers[variableName];
				if (localProblemMatcher) {
J
Johannes Rieken 已提交
1045
					localProblemMatcher = Objects.deepClone(localProblemMatcher);
1046 1047 1048 1049 1050
					// remove the name
					delete localProblemMatcher.name;
					return localProblemMatcher;
				}
			}
1051
			context.problemReporter.error(nls.localize('ConfigurationParser.invalidVaraibleReference', 'Error: Invalid problemMatcher reference: {0}\n', value));
1052 1053 1054
			return undefined;
		} else {
			let json = <ProblemMatcherConfig.ProblemMatcher>value;
1055
			return new ProblemMatcherParser(context.problemReporter).parse(json);
1056 1057 1058 1059
		}
	}
}

1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074
namespace TaskIdentifier {
	export function from(this: void, value: TaskIdentifier): Tasks.TaskIdentifier {
		if (!value || !Types.isString(value.type)) {
			return undefined;
		}
		const hash = crypto.createHash('md5');
		hash.update(JSON.stringify(value));
		let key = hash.digest('hex');
		let result: Tasks.TaskIdentifier = {
			_key: key,
			type: value.type
		};
		result = Objects.assign(result, value);
		return result;
	}
1075 1076
}

1077 1078 1079
const source: Tasks.TaskSource = {
	kind: Tasks.TaskSourceKind.Workspace,
	label: 'Workspace',
1080
	config: undefined
1081
};
1082

1083
namespace GroupKind {
1084
	export function from(this: void, external: string | GroupKind): [string, Tasks.GroupType] {
1085 1086 1087 1088 1089
		if (external === void 0) {
			return undefined;
		}
		if (Types.isString(external)) {
			if (Tasks.TaskGroup.is(external)) {
1090
				return [external, Tasks.GroupType.user];
1091
			} else {
D
Dirk Baeumer 已提交
1092 1093 1094
				return undefined;
			}
		}
1095 1096 1097 1098
		if (!Types.isString(external.kind) || !Tasks.TaskGroup.is(external.kind)) {
			return undefined;
		}
		let group: string = external.kind;
1099
		let isDefault: boolean = !!external.isDefault;
1100

1101
		return [group, isDefault ? Tasks.GroupType.default : Tasks.GroupType.user];
D
Dirk Baeumer 已提交
1102
	}
1103 1104 1105
}

namespace ConfigurationProperties {
D
Dirk Baeumer 已提交
1106

1107
	const properties: MetaData<Tasks.ConfigurationProperties, any>[] = [
1108

1109 1110 1111 1112
		{ property: 'name' }, { property: 'identifier' }, { property: 'group' }, { property: 'isBackground' },
		{ property: 'promptOnClose' }, { property: 'dependsOn' },
		{ property: 'presentation', type: CommandConfiguration.PresentationOptions }, { property: 'problemMatchers' }
	];
1113

1114
	export function from(this: void, external: ConfigurationProperties, context: ParseContext, includePresentation: boolean): Tasks.ConfigurationProperties {
1115
		if (!external) {
1116
			return undefined;
E
Erich Gamma 已提交
1117
		}
1118 1119 1120 1121
		let result: Tasks.ConfigurationProperties = {};
		if (Types.isString(external.taskName)) {
			result.name = external.taskName;
		}
1122 1123 1124
		if (Types.isString(external.label) && context.schemaVersion === Tasks.JsonSchemaVersion.V2_0_0) {
			result.name = external.label;
		}
1125 1126 1127 1128 1129 1130 1131 1132 1133
		if (Types.isString(external.identifier)) {
			result.identifier = external.identifier;
		}
		if (external.isBackground !== void 0) {
			result.isBackground = !!external.isBackground;
		}
		if (external.promptOnClose !== void 0) {
			result.promptOnClose = !!external.promptOnClose;
		}
D
Dirk Baeumer 已提交
1134 1135 1136
		if (external.group !== void 0) {
			if (Types.isString(external.group) && Tasks.TaskGroup.is(external.group)) {
				result.group = external.group;
1137
				result.groupType = Tasks.GroupType.user;
D
Dirk Baeumer 已提交
1138 1139 1140 1141
			} else {
				let values = GroupKind.from(external.group);
				if (values) {
					result.group = values[0];
1142
					result.groupType = values[1];
D
Dirk Baeumer 已提交
1143 1144
				}
			}
1145 1146 1147
		}
		if (external.dependsOn !== void 0) {
			if (Types.isString(external.dependsOn)) {
1148
				result.dependsOn = [{ workspaceFolder: context.workspaceFolder, task: external.dependsOn }];
1149
			} else if (Types.isStringArray(external.dependsOn)) {
1150
				result.dependsOn = external.dependsOn.map((task) => { return { workspaceFolder: context.workspaceFolder, task: task }; });
1151
			}
1152
		}
1153
		if (includePresentation && (external.presentation !== void 0 || (external as LegacyCommandProperties).terminal !== void 0)) {
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168
			result.presentation = CommandConfiguration.PresentationOptions.from(external, context);
		}
		if (external.problemMatcher) {
			result.problemMatchers = ProblemMatcherConverter.from(external.problemMatcher, context);
		}
		return isEmpty(result) ? undefined : result;
	}

	export function isEmpty(this: void, value: Tasks.ConfigurationProperties): boolean {
		return _isEmpty(value, properties);
	}
}

namespace ConfiguringTask {

1169 1170 1171 1172 1173 1174 1175 1176 1177 1178
	const grunt = 'grunt.';
	const jake = 'jake.';
	const gulp = 'gulp.';
	const npm = 'vscode.npm.';
	const typescript = 'vscode.typescript.';

	interface CustomizeShape {
		customize: string;
	}

1179
	export function from(this: void, external: ConfiguringTask, context: ParseContext, index: number): Tasks.ConfiguringTask {
1180 1181 1182 1183
		if (!external) {
			return undefined;
		}
		let type = external.type;
1184 1185
		let customize = (external as CustomizeShape).customize;
		if (!type && !customize) {
1186
			context.problemReporter.error(nls.localize('ConfigurationParser.noTaskType', 'Error: tasks configuration must have a type property. The configuration will be ignored.\n{0}\n', JSON.stringify(external, null, 4)));
1187 1188
			return undefined;
		}
D
Dirk Baeumer 已提交
1189
		let typeDeclaration = TaskDefinitionRegistry.get(type);
1190
		if (!typeDeclaration) {
1191
			let message = nls.localize('ConfigurationParser.noTypeDefinition', 'Error: there is no registered task type \'{0}\'. Did you miss to install an extension that provides a corresponding task provider?', type);
1192 1193 1194
			context.problemReporter.error(message);
			return undefined;
		}
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206
		let identifier: TaskIdentifier;
		if (Types.isString(customize)) {
			if (customize.indexOf(grunt) === 0) {
				identifier = { type: 'grunt', task: customize.substring(grunt.length) } as TaskIdentifier;
			} else if (customize.indexOf(jake) === 0) {
				identifier = { type: 'jake', task: customize.substring(jake.length) } as TaskIdentifier;
			} else if (customize.indexOf(gulp) === 0) {
				identifier = { type: 'gulp', task: customize.substring(gulp.length) } as TaskIdentifier;
			} else if (customize.indexOf(npm) === 0) {
				identifier = { type: 'npm', script: customize.substring(npm.length + 4) } as TaskIdentifier;
			} else if (customize.indexOf(typescript) === 0) {
				identifier = { type: 'typescript', tsconfig: customize.substring(typescript.length + 6) } as TaskIdentifier;
E
Erich Gamma 已提交
1207
			}
1208 1209 1210 1211
		} else {
			identifier = {
				type
			};
1212 1213 1214 1215 1216 1217
			let properties = typeDeclaration.properties;
			let required: Set<string> = new Set();
			if (Array.isArray(typeDeclaration.required)) {
				typeDeclaration.required.forEach(element => Types.isString(element) ? required.add(element) : required);
			}
			for (let property of Object.keys(properties)) {
1218 1219 1220
				let value = external[property];
				if (value !== void 0 && value !== null) {
					identifier[property] = value;
1221 1222 1223
				} else if (required.has(property)) {
					let schema = properties[property];
					if (schema.default !== void 0) {
J
Johannes Rieken 已提交
1224
						identifier[property] = Objects.deepClone(schema.default);
1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245
					} else {
						switch (schema.type) {
							case 'boolean':
								identifier[property] = false;
								break;
							case 'number':
							case 'integer':
								identifier[property] = 0;
								break;
							case 'string':
								identifier[property] = '';
								break;
							default:
								let message = nls.localize(
									'ConfigurationParser.missingRequiredProperty',
									'Error: the task configuration \'{0}\' missed the required property \'{1}\'. The task configuration will be ignored.', JSON.stringify(external, undefined, 0), property
								);
								context.problemReporter.error(message);
								return undefined;
						}
					}
1246
				}
1247
			}
1248
		}
1249
		let taskIdentifier = TaskIdentifier.from(identifier);
1250
		let configElement: Tasks.TaskSourceConfigElement = {
1251
			workspaceFolder: context.workspaceFolder,
1252 1253 1254 1255
			file: '.vscode\\tasks.json',
			index,
			element: external
		};
1256 1257 1258
		let result: Tasks.ConfiguringTask = {
			type: type,
			configures: taskIdentifier,
1259
			_id: `${typeDeclaration.extensionId}.${taskIdentifier._key}`,
1260
			_source: Objects.assign({}, source, { config: configElement }),
1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277
			_label: undefined
		};
		let configuration = ConfigurationProperties.from(external, context, true);
		if (configuration) {
			result = Objects.assign(result, configuration);
			if (result.name) {
				result._label = result.name;
			} else {
				let label = result.configures.type;
				if (typeDeclaration.required && typeDeclaration.required.length > 0) {
					for (let required of typeDeclaration.required) {
						let value = result.configures[required];
						if (value) {
							label = label + ' ' + value;
							break;
						}
					}
D
Dirk Baeumer 已提交
1278
				}
1279
				result._label = label;
1280
			}
1281 1282
			if (!result.identifier) {
				result.identifier = taskIdentifier._key;
E
Erich Gamma 已提交
1283
			}
1284 1285 1286 1287 1288 1289 1290
		}
		return result;
	}
}

namespace CustomTask {

1291
	export function from(this: void, external: CustomTask, context: ParseContext, index: number): Tasks.CustomTask {
1292 1293 1294 1295 1296 1297 1298 1299
		if (!external) {
			return undefined;
		}
		let type = external.type;
		if (type === void 0 || type === null) {
			type = 'custom';
		}
		if (type !== 'custom' && type !== 'shell' && type !== 'process') {
1300
			context.problemReporter.error(nls.localize('ConfigurationParser.notCustom', 'Error: tasks is not declared as a custom task. The configuration will be ignored.\n{0}\n', JSON.stringify(external, null, 4)));
1301 1302 1303
			return undefined;
		}
		let taskName = external.taskName;
1304 1305 1306
		if (Types.isString(external.label) && context.schemaVersion === Tasks.JsonSchemaVersion.V2_0_0) {
			taskName = external.label;
		}
1307
		if (!taskName) {
D
Dirk Baeumer 已提交
1308
			context.problemReporter.error(nls.localize('ConfigurationParser.noTaskName', 'Error: a task must provide a label property. The task will be ignored.\n{0}\n', JSON.stringify(external, null, 4)));
1309 1310 1311 1312 1313 1314
			return undefined;
		}

		let result: Tasks.CustomTask = {
			type: 'custom',
			_id: context.uuidMap.getUUID(taskName),
D
Dirk Baeumer 已提交
1315
			_source: Objects.assign({}, source, { config: { index, element: external, file: '.vscode\\tasks.json', workspaceFolder: context.workspaceFolder } }),
1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329
			_label: taskName,
			name: taskName,
			identifier: taskName,
			command: undefined
		};
		let configuration = ConfigurationProperties.from(external, context, false);
		if (configuration) {
			result = Objects.assign(result, configuration);
		}
		let supportLegacy: boolean = true; //context.schemaVersion === Tasks.JsonSchemaVersion.V2_0_0;
		if (supportLegacy) {
			let legacy: LegacyTaskProperties = external as LegacyTaskProperties;
			if (result.isBackground === void 0 && legacy.isWatching !== void 0) {
				result.isBackground = !!legacy.isWatching;
1330
			}
1331 1332 1333 1334 1335
			if (result.group === void 0) {
				if (legacy.isBuildCommand === true) {
					result.group = Tasks.TaskGroup.Build;
				} else if (legacy.isTestCommand === true) {
					result.group = Tasks.TaskGroup.Test;
1336
				}
1337
			}
1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352
		}
		let command: Tasks.CommandConfiguration = CommandConfiguration.from(external, context);
		if (command) {
			result.command = command;
		}
		if (external.command !== void 0) {
			// if the task has its own command then we suppress the
			// task name by default.
			command.suppressTaskName = true;
		}
		return result;
	}

	export function fillGlobals(task: Tasks.CustomTask, globals: Globals): void {
		// We only merge a command from a global definition if there is no dependsOn
1353 1354
		// or there is a dependsOn and a defined command.
		if (CommandConfiguration.hasCommand(task.command) || task.dependsOn === void 0) {
1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373
			task.command = CommandConfiguration.fillGlobals(task.command, globals.command, task.name);
		}
		// promptOnClose is inferred from isBackground if available
		if (task.promptOnClose === void 0 && task.isBackground === void 0 && globals.promptOnClose !== void 0) {
			task.promptOnClose = globals.promptOnClose;
		}
	}

	export function fillDefaults(task: Tasks.CustomTask, context: ParseContext): void {
		CommandConfiguration.fillDefaults(task.command, context);
		if (task.promptOnClose === void 0) {
			task.promptOnClose = task.isBackground !== void 0 ? !task.isBackground : true;
		}
		if (task.isBackground === void 0) {
			task.isBackground = false;
		}
		if (task.problemMatchers === void 0) {
			task.problemMatchers = EMPTY_ARRAY;
		}
1374 1375
		if (task.group !== void 0 && task.groupType === void 0) {
			task.groupType = Tasks.GroupType.user;
1376
		}
1377 1378
	}

1379
	export function createCustomTask(contributedTask: Tasks.ContributedTask, configuredProps: Tasks.ConfigurationProperties & { _id: string, _source: Tasks.WorkspaceTaskSource }): Tasks.CustomTask {
1380
		let result: Tasks.CustomTask = {
1381
			_id: configuredProps._id,
1382
			_source: Objects.assign({}, configuredProps._source, { customizes: contributedTask.defines }),
1383 1384 1385 1386 1387 1388 1389 1390 1391
			_label: configuredProps.name || contributedTask._label,
			type: 'custom',
			command: contributedTask.command,
			name: configuredProps.name || contributedTask.name,
			identifier: configuredProps.identifier || contributedTask.identifier
		};
		let resultConfigProps: Tasks.ConfigurationProperties = result;

		assignProperty(resultConfigProps, configuredProps, 'group');
1392
		assignProperty(resultConfigProps, configuredProps, 'groupType');
1393 1394 1395 1396 1397 1398 1399 1400 1401
		assignProperty(resultConfigProps, configuredProps, 'isBackground');
		assignProperty(resultConfigProps, configuredProps, 'dependsOn');
		assignProperty(resultConfigProps, configuredProps, 'problemMatchers');
		assignProperty(resultConfigProps, configuredProps, 'promptOnClose');
		result.command.presentation = CommandConfiguration.PresentationOptions.assignProperties(
			result.command.presentation, configuredProps.presentation);

		let contributedConfigProps: Tasks.ConfigurationProperties = contributedTask;
		fillProperty(resultConfigProps, contributedConfigProps, 'group');
1402
		fillProperty(resultConfigProps, contributedConfigProps, 'groupType');
1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422
		fillProperty(resultConfigProps, contributedConfigProps, 'isBackground');
		fillProperty(resultConfigProps, contributedConfigProps, 'dependsOn');
		fillProperty(resultConfigProps, contributedConfigProps, 'problemMatchers');
		fillProperty(resultConfigProps, contributedConfigProps, 'promptOnClose');
		result.command.presentation = CommandConfiguration.PresentationOptions.fillProperties(
			result.command.presentation, contributedConfigProps.presentation);

		return result;
	}
}

interface TaskParseResult {
	custom: Tasks.CustomTask[];
	configured: Tasks.ConfiguringTask[];
}

namespace TaskParser {

	function isCustomTask(value: CustomTask | ConfiguringTask): value is CustomTask {
		let type = value.type;
1423 1424
		let customize = (value as any).customize;
		return customize === void 0 && (type === void 0 || type === null || type === 'custom' || type === 'shell' || type === 'process');
1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435
	}

	export function from(this: void, externals: (CustomTask | ConfiguringTask)[], globals: Globals, context: ParseContext): TaskParseResult {
		let result: TaskParseResult = { custom: [], configured: [] };
		if (!externals) {
			return result;
		}
		let defaultBuildTask: { task: Tasks.Task; rank: number; } = { task: undefined, rank: -1 };
		let defaultTestTask: { task: Tasks.Task; rank: number; } = { task: undefined, rank: -1 };
		let schema2_0_0: boolean = context.schemaVersion === Tasks.JsonSchemaVersion.V2_0_0;

1436 1437
		for (let index = 0; index < externals.length; index++) {
			let external = externals[index];
1438
			if (isCustomTask(external)) {
1439
				let customTask = CustomTask.from(external, context, index);
1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473
				if (customTask) {
					CustomTask.fillGlobals(customTask, globals);
					CustomTask.fillDefaults(customTask, context);
					if (schema2_0_0) {
						if ((customTask.command === void 0 || customTask.command.name === void 0) && (customTask.dependsOn === void 0 || customTask.dependsOn.length === 0)) {
							context.problemReporter.error(nls.localize(
								'taskConfiguration.noCommandOrDependsOn', 'Error: the task \'{0}\' neither specifies a command nor a dependsOn property. The task will be ignored. Its definition is:\n{1}',
								customTask.name, JSON.stringify(external, undefined, 4)
							));
							continue;
						}
					} else {
						if (customTask.command === void 0 || customTask.command.name === void 0) {
							context.problemReporter.warn(nls.localize(
								'taskConfiguration.noCommand', 'Error: the task \'{0}\' doesn\'t define a command. The task will be ignored. Its definition is:\n{1}',
								customTask.name, JSON.stringify(external, undefined, 4)
							));
							continue;
						}
					}
					if (customTask.group === Tasks.TaskGroup.Build && defaultBuildTask.rank < 2) {
						defaultBuildTask.task = customTask;
						defaultBuildTask.rank = 2;
					} else if (customTask.group === Tasks.TaskGroup.Test && defaultTestTask.rank < 2) {
						defaultTestTask.task = customTask;
						defaultTestTask.rank = 2;
					} else if (customTask.name === 'build' && defaultBuildTask.rank < 1) {
						defaultBuildTask.task = customTask;
						defaultBuildTask.rank = 1;
					} else if (customTask.name === 'test' && defaultTestTask.rank < 1) {
						defaultTestTask.task = customTask;
						defaultTestTask.rank = 1;
					}
					result.custom.push(customTask);
D
Dirk Baeumer 已提交
1474 1475
				}
			} else {
1476
				let configuredTask = ConfiguringTask.from(external, context, index);
1477 1478
				if (configuredTask) {
					result.configured.push(configuredTask);
D
Dirk Baeumer 已提交
1479
				}
E
Erich Gamma 已提交
1480
			}
1481
		}
1482
		if (defaultBuildTask.rank > -1 && defaultBuildTask.rank < 2) {
1483
			defaultBuildTask.task.group = Tasks.TaskGroup.Build;
1484
			defaultBuildTask.task.groupType = Tasks.GroupType.user;
1485
		} else if (defaultTestTask.rank > -1 && defaultTestTask.rank < 2) {
1486
			defaultTestTask.task.group = Tasks.TaskGroup.Test;
1487
			defaultTestTask.task.groupType = Tasks.GroupType.user;
E
Erich Gamma 已提交
1488
		}
1489 1490

		return result;
E
Erich Gamma 已提交
1491 1492
	}

1493
	export function assignTasks(target: Tasks.CustomTask[], source: Tasks.CustomTask[]): Tasks.CustomTask[] {
1494
		if (source === void 0 || source.length === 0) {
1495 1496
			return target;
		}
1497
		if (target === void 0 || target.length === 0) {
1498 1499 1500
			return source;
		}

1501
		if (source) {
1502
			// Tasks are keyed by ID but we need to merge by name
1503
			let map: IStringDictionary<Tasks.CustomTask> = Object.create(null);
1504 1505
			target.forEach((task) => {
				map[task.name] = task;
1506 1507
			});

1508 1509
			source.forEach((task) => {
				map[task.name] = task;
1510
			});
1511
			let newTarget: Tasks.CustomTask[] = [];
1512 1513 1514
			target.forEach(task => {
				newTarget.push(map[task.name]);
				delete map[task.name];
E
Erich Gamma 已提交
1515
			});
1516 1517
			Object.keys(map).forEach(key => newTarget.push(map[key]));
			target = newTarget;
E
Erich Gamma 已提交
1518
		}
1519 1520 1521 1522 1523
		return target;
	}
}

interface Globals {
1524
	command?: Tasks.CommandConfiguration;
1525 1526 1527 1528 1529
	promptOnClose?: boolean;
	suppressTaskName?: boolean;
}

namespace Globals {
1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541

	export function from(config: ExternalTaskRunnerConfiguration, context: ParseContext): Globals {
		let result = fromBase(config, context);
		let osGlobals: Globals = undefined;
		if (config.windows && Platform.platform === Platform.Platform.Windows) {
			osGlobals = fromBase(config.windows, context);
		} else if (config.osx && Platform.platform === Platform.Platform.Mac) {
			osGlobals = fromBase(config.osx, context);
		} else if (config.linux && Platform.platform === Platform.Platform.Linux) {
			osGlobals = fromBase(config.linux, context);
		}
		if (osGlobals) {
1542
			result = Globals.assignProperties(result, osGlobals);
1543 1544 1545 1546 1547
		}
		let command = CommandConfiguration.from(config, context);
		if (command) {
			result.command = command;
		}
1548
		Globals.fillDefaults(result, context);
1549 1550 1551 1552 1553
		Globals.freeze(result);
		return result;
	}

	export function fromBase(this: void, config: BaseTaskRunnerConfiguration, context: ParseContext): Globals {
1554 1555 1556 1557 1558 1559 1560
		let result: Globals = {};
		if (config.suppressTaskName !== void 0) {
			result.suppressTaskName = !!config.suppressTaskName;
		}
		if (config.promptOnClose !== void 0) {
			result.promptOnClose = !!config.promptOnClose;
		}
E
Erich Gamma 已提交
1561 1562 1563
		return result;
	}

1564
	export function isEmpty(value: Globals): boolean {
D
Dirk Baeumer 已提交
1565
		return !value || value.command === void 0 && value.promptOnClose === void 0 && value.suppressTaskName === void 0;
1566 1567
	}

1568
	export function assignProperties(target: Globals, source: Globals): Globals {
1569 1570
		if (isEmpty(source)) {
			return target;
E
Erich Gamma 已提交
1571
		}
1572 1573 1574
		if (isEmpty(target)) {
			return source;
		}
1575 1576
		assignProperty(target, source, 'promptOnClose');
		assignProperty(target, source, 'suppressTaskName');
1577
		return target;
E
Erich Gamma 已提交
1578 1579
	}

1580
	export function fillDefaults(value: Globals, context: ParseContext): void {
1581 1582 1583
		if (!value) {
			return;
		}
1584
		CommandConfiguration.fillDefaults(value.command, context);
1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600
		if (value.suppressTaskName === void 0) {
			value.suppressTaskName = false;
		}
		if (value.promptOnClose === void 0) {
			value.promptOnClose = true;
		}
	}

	export function freeze(value: Globals): void {
		Object.freeze(value);
		if (value.command) {
			CommandConfiguration.freeze(value.command);
		}
	}
}

1601 1602
export namespace ExecutionEngine {

1603
	export function from(config: ExternalTaskRunnerConfiguration): Tasks.ExecutionEngine {
1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623
		let runner = config.runner || config._runner;
		let result: Tasks.ExecutionEngine;
		if (runner) {
			switch (runner) {
				case 'terminal':
					result = Tasks.ExecutionEngine.Terminal;
					break;
				case 'process':
					result = Tasks.ExecutionEngine.Process;
					break;
			}
		}
		let schemaVersion = JsonSchemaVersion.from(config);
		if (schemaVersion === Tasks.JsonSchemaVersion.V0_1_0) {
			return result || Tasks.ExecutionEngine.Process;
		} else if (schemaVersion === Tasks.JsonSchemaVersion.V2_0_0) {
			return Tasks.ExecutionEngine.Terminal;
		} else {
			throw new Error('Shouldn\'t happen.');
		}
1624
	}
1625
}
1626

1627 1628
export namespace JsonSchemaVersion {

1629
	const _default: Tasks.JsonSchemaVersion = Tasks.JsonSchemaVersion.V2_0_0;
1630

1631 1632 1633
	export function from(config: ExternalTaskRunnerConfiguration): Tasks.JsonSchemaVersion {
		let version = config.version;
		if (!version) {
1634
			return _default;
1635 1636 1637 1638
		}
		switch (version) {
			case '0.1.0':
				return Tasks.JsonSchemaVersion.V0_1_0;
1639
			case '2.0.0':
1640
				return Tasks.JsonSchemaVersion.V2_0_0;
1641 1642
			default:
				return _default;
1643
		}
1644 1645 1646
	}
}

1647 1648
export interface ParseResult {
	validationStatus: ValidationStatus;
1649 1650
	custom: Tasks.CustomTask[];
	configured: Tasks.ConfiguringTask[];
1651
	engine: Tasks.ExecutionEngine;
1652 1653
}

1654
export interface IProblemReporter extends IProblemReporterBase {
1655 1656
}

1657 1658 1659 1660 1661
class UUIDMap {

	private last: IStringDictionary<string | string[]>;
	private current: IStringDictionary<string | string[]>;

1662
	constructor(other?: UUIDMap) {
1663
		this.current = Object.create(null);
1664 1665 1666 1667 1668 1669 1670 1671 1672 1673
		if (other) {
			for (let key of Object.keys(other.current)) {
				let value = other.current[key];
				if (Array.isArray(value)) {
					this.current[key] = value.slice();
				} else {
					this.current[key] = value;
				}
			}
		}
1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717
	}

	public start(): void {
		this.last = this.current;
		this.current = Object.create(null);
	}

	public getUUID(identifier: string): string {
		let lastValue = this.last[identifier];
		let result: string;
		if (lastValue !== void 0) {
			if (Array.isArray(lastValue)) {
				result = lastValue.shift();
				if (lastValue.length === 0) {
					delete this.last[identifier];
				}
			} else {
				result = lastValue;
				delete this.last[identifier];
			}
		}
		if (result === void 0) {
			result = UUID.generateUuid();
		}
		let currentValue = this.current[identifier];
		if (currentValue === void 0) {
			this.current[identifier] = result;
		} else {
			if (Array.isArray(currentValue)) {
				currentValue.push(result);
			} else {
				let arrayValue: string[] = [currentValue];
				arrayValue.push(result);
				this.current[identifier] = arrayValue;
			}
		}
		return result;
	}

	public finish(): void {
		this.last = undefined;
	}
}

1718 1719
class ConfigurationParser {

S
Sandeep Somavarapu 已提交
1720
	private workspaceFolder: IWorkspaceFolder;
1721
	private problemReporter: IProblemReporter;
1722 1723
	private uuidMap: UUIDMap;

S
Sandeep Somavarapu 已提交
1724
	constructor(workspaceFolder: IWorkspaceFolder, problemReporter: IProblemReporter, uuidMap: UUIDMap) {
1725
		this.workspaceFolder = workspaceFolder;
1726
		this.problemReporter = problemReporter;
1727
		this.uuidMap = uuidMap;
1728 1729 1730
	}

	public run(fileConfig: ExternalTaskRunnerConfiguration): ParseResult {
1731
		let engine = ExecutionEngine.from(fileConfig);
1732
		let schemaVersion = JsonSchemaVersion.from(fileConfig);
1733
		let context: ParseContext = {
1734
			workspaceFolder: this.workspaceFolder,
1735
			problemReporter: this.problemReporter,
1736
			uuidMap: this.uuidMap,
1737
			namedProblemMatchers: undefined,
1738
			engine,
1739
			schemaVersion
1740 1741
		};
		let taskParseResult = this.createTaskRunnerConfiguration(fileConfig, context);
1742
		return {
1743
			validationStatus: this.problemReporter.status,
1744 1745
			custom: taskParseResult.custom,
			configured: taskParseResult.configured,
1746
			engine
1747 1748 1749
		};
	}

1750
	private createTaskRunnerConfiguration(fileConfig: ExternalTaskRunnerConfiguration, context: ParseContext): TaskParseResult {
1751
		let globals = Globals.from(fileConfig, context);
1752
		if (this.problemReporter.status.isFatal()) {
1753
			return { custom: [], configured: [] };
1754 1755
		}
		context.namedProblemMatchers = ProblemMatcherConverter.namedFrom(fileConfig.declares, context);
1756
		let globalTasks: Tasks.CustomTask[];
1757
		let externalGlobalTasks: (ConfiguringTask | CustomTask)[];
1758
		if (fileConfig.windows && Platform.platform === Platform.Platform.Windows) {
1759
			globalTasks = TaskParser.from(fileConfig.windows.tasks, globals, context).custom;
1760
			externalGlobalTasks = fileConfig.windows.tasks;
1761
		} else if (fileConfig.osx && Platform.platform === Platform.Platform.Mac) {
1762
			globalTasks = TaskParser.from(fileConfig.osx.tasks, globals, context).custom;
1763
			externalGlobalTasks = fileConfig.osx.tasks;
1764
		} else if (fileConfig.linux && Platform.platform === Platform.Platform.Linux) {
1765
			globalTasks = TaskParser.from(fileConfig.linux.tasks, globals, context).custom;
1766 1767 1768 1769 1770 1771 1772 1773 1774 1775
			externalGlobalTasks = fileConfig.linux.tasks;
		}
		if (context.schemaVersion === Tasks.JsonSchemaVersion.V2_0_0 && globalTasks && globalTasks.length > 0 && externalGlobalTasks && externalGlobalTasks.length > 0) {
			let taskContent: string[] = [];
			for (let task of externalGlobalTasks) {
				taskContent.push(JSON.stringify(task, null, 4));
			}
			context.problemReporter.error(
				nls.localize(
					'TaskParse.noOsSpecificGlobalTasks',
1776
					'Task version 2.0.0 doesn\'t support global OS specific tasks. Convert them to a task with a OS specific command. Affected tasks are:\n{0}', taskContent.join('\n'))
1777
			);
1778 1779
		}

1780
		let result: TaskParseResult = { custom: undefined, configured: undefined };
1781
		if (fileConfig.tasks) {
1782
			result = TaskParser.from(fileConfig.tasks, globals, context);
1783
		}
1784
		if (globalTasks) {
1785
			result.custom = TaskParser.assignTasks(result.custom, globalTasks);
1786 1787
		}

1788
		if ((!result.custom || result.custom.length === 0) && (globals.command && globals.command.name)) {
1789
			let matchers: ProblemMatcher[] = ProblemMatcherConverter.from(fileConfig.problemMatcher, context);
1790
			let isBackground = fileConfig.isBackground ? !!fileConfig.isBackground : fileConfig.isWatching ? !!fileConfig.isWatching : undefined;
1791
			let name = Tasks.CommandString.value(globals.command.name);
1792
			let task: Tasks.CustomTask = {
1793
				_id: context.uuidMap.getUUID(name),
D
Dirk Baeumer 已提交
1794
				_source: Objects.assign({}, source, { config: { index: -1, element: fileConfig, workspaceFolder: context.workspaceFolder } }),
1795
				_label: name,
1796
				type: 'custom',
1797 1798
				name: name,
				identifier: name,
1799
				group: Tasks.TaskGroup.Build,
1800 1801
				command: {
					name: undefined,
1802
					runtime: undefined,
1803
					presentation: undefined,
1804 1805
					suppressTaskName: true
				},
1806 1807 1808
				isBackground: isBackground,
				problemMatchers: matchers
			};
1809 1810 1811
			let value = GroupKind.from(fileConfig.group);
			if (value) {
				task.group = value[0];
1812
				task.groupType = value[1];
1813 1814 1815
			} else if (fileConfig.group === 'none') {
				task.group = undefined;
			}
1816 1817 1818
			CustomTask.fillGlobals(task, globals);
			CustomTask.fillDefaults(task, context);
			result.custom = [task];
1819
		}
1820 1821
		result.custom = result.custom || [];
		result.configured = result.configured || [];
1822
		return result;
1823
	}
E
Erich Gamma 已提交
1824 1825
}

1826
let uuidMaps: Map<string, UUIDMap> = new Map();
S
Sandeep Somavarapu 已提交
1827
export function parse(workspaceFolder: IWorkspaceFolder, configuration: ExternalTaskRunnerConfiguration, logger: IProblemReporter): ParseResult {
1828 1829 1830 1831 1832
	let uuidMap = uuidMaps.get(workspaceFolder.uri.toString());
	if (!uuidMap) {
		uuidMap = new UUIDMap();
		uuidMaps.set(workspaceFolder.uri.toString(), uuidMap);
	}
1833 1834
	try {
		uuidMap.start();
1835
		return (new ConfigurationParser(workspaceFolder, logger, uuidMap)).run(configuration);
1836 1837 1838
	} finally {
		uuidMap.finish();
	}
1839 1840
}

1841
export function createCustomTask(contributedTask: Tasks.ContributedTask, configuredProps: Tasks.ConfigurationProperties & { _id: string; _source: Tasks.WorkspaceTaskSource }): Tasks.CustomTask {
1842 1843 1844 1845 1846
	return CustomTask.createCustomTask(contributedTask, configuredProps);
}

export function getTaskIdentifier(value: TaskIdentifier): Tasks.TaskIdentifier {
	return TaskIdentifier.from(value);
D
Dirk Baeumer 已提交
1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924
}

/*
class VersionConverter {
	constructor(private problemReporter: IProblemReporter) {
	}

	public convert(fromConfig: ExternalTaskRunnerConfiguration): ExternalTaskRunnerConfiguration {
		let result: ExternalTaskRunnerConfiguration;
		result.version = '2.0.0';
		if (Array.isArray(fromConfig.tasks)) {

		} else {
			result.tasks = [];
		}


		return result;
	}

	private convertGlobalTask(fromConfig: ExternalTaskRunnerConfiguration): TaskDescription {
		let command: string = this.getGlobalCommand(fromConfig);
		if (!command) {
			this.problemReporter.error(nls.localize('Converter.noGlobalName', 'No global command specified. Can\'t convert to 2.0.0 version.'));
			return undefined;
		}
		let result: TaskDescription = {
			taskName: command
		};
		if (fromConfig.isShellCommand) {
			result.type = 'shell';
		} else {
			result.type = 'process';
			result.args = fromConfig.args;
		}
		if (fromConfig.)

		return result;
	}

	private getGlobalCommand(fromConfig: ExternalTaskRunnerConfiguration): string {
		if (fromConfig.command) {
			return fromConfig.command;
		} else if (fromConfig.windows && fromConfig.windows.command) {
			return fromConfig.windows.command;
		} else if (fromConfig.osx && fromConfig.osx.command) {
			return fromConfig.osx.command;
		} else if (fromConfig.linux && fromConfig.linux.command) {
			return fromConfig.linux.command;
		} else {
			return undefined;
		}
	}

	private createCommandLine(command: string, args: string[], isWindows: boolean): string {
		let result: string[];
		let commandHasSpace = false;
		let argHasSpace = false;
		if (TaskDescription.hasUnescapedSpaces(command)) {
			result.push(`"${command}"`);
			commandHasSpace = true;
		} else {
			result.push(command);
		}
		if (args) {
			for (let arg of args) {
				if (TaskDescription.hasUnescapedSpaces(arg)) {
					result.push(`"${arg}"`);
					argHasSpace= true;
				} else {
					result.push(arg);
				}
			}
		}
		return result.join(' ');
	}

}
J
Johannes Rieken 已提交
1925
*/