taskConfiguration.ts 57.2 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';

17
import { ValidationStatus, IProblemReporter as IProblemReporterBase, NullProblemReporter as NullProblemReporterBase } from 'vs/base/common/parsers';
18 19
import {
	NamedProblemMatcher, ProblemMatcher, ProblemMatcherParser, Config as ProblemMatcherConfig,
20
	isNamedProblemMatcher, ProblemMatcherRegistry
21 22
} from 'vs/platform/markers/common/problemMatcher';

23
import * as Tasks from '../common/tasks';
D
Dirk Baeumer 已提交
24
import { TaskDefinitionRegistry } from '../common/taskDefinitionRegistry';
E
Erich Gamma 已提交
25 26 27 28 29 30 31 32 33 34 35 36

/**
 * Defines the problem handling strategy
 */
export class ProblemHandling {
	/**
	 * Cleans all problems for the owner defined in the
	 * error pattern.
	 */
	public static clean: string = 'cleanMatcherMatchers';
}

D
Dirk Baeumer 已提交
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
export interface ShellConfiguration {
	executable: string;
	args?: string[];
}

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;
}

61 62 63 64 65 66
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 已提交
67 68

	/**
69 70 71 72 73 74 75 76 77 78 79
	 * 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 已提交
80
	 */
81 82 83 84
	panel?: string;
}

export interface TaskIdentifier {
D
Dirk Baeumer 已提交
85
	type?: string;
86
}
D
Dirk Baeumer 已提交
87

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

128 129 130 131 132
	/**
	 * @deprecated Use presentation instead
	 */
	terminal?: PresentationOptions;

133 134 135 136 137 138 139 140 141 142 143 144
	/**
	 * @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;
145 146

	/**
D
Dirk Baeumer 已提交
147
	 * @deprecated use the task type instead.
148 149 150 151 152
	 * 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 已提交
153
	isShellCommand?: boolean | ShellConfiguration;
154 155 156 157 158 159 160 161 162 163 164 165 166 167
}

export interface BaseCommandProperties {

	/**
	 * Whether the task is a shell task or a process task.
	 */
	runtime?: string;

	/**
	 * The command to be executed. Can be an external program or a shell
	 * command.
	 */
	command?: string;
168 169 170 171

	/**
	 * The command options used when the command is executed. Can be omitted.
	 */
D
Dirk Baeumer 已提交
172
	options?: CommandOptions;
173 174 175 176

	/**
	 * The arguments passed to the command or additional arguments passed to the
	 * command when using a global command.
E
Erich Gamma 已提交
177 178
	 */
	args?: string[];
179 180 181
}


182
export interface CommandProperties extends BaseCommandProperties {
D
Dirk Baeumer 已提交
183

184
	/**
185
	 * Windows specific command properties
186
	 */
187
	windows?: BaseCommandProperties;
188

189
	/**
190
	 * OSX specific command properties
191
	 */
192
	osx?: BaseCommandProperties;
193 194

	/**
195
	 * linux specific command properties
196
	 */
197 198
	linux?: BaseCommandProperties;
}
199

D
Dirk Baeumer 已提交
200 201 202 203 204
export interface GroupKind {
	kind?: string;
	isPrimary?: boolean;
}

205
export interface ConfigurationProperties {
206
	/**
207
	 * The task's name
208
	 */
209
	taskName?: string;
E
Erich Gamma 已提交
210

211 212 213 214 215
	/**
	 * The UI label used for the task.
	 */
	label?: string;

E
Erich Gamma 已提交
216
	/**
217 218
	 * An optional indentifier which can be used to reference a task
	 * in a dependsOn or other attributes.
E
Erich Gamma 已提交
219
	 */
220
	identifier?: string;
E
Erich Gamma 已提交
221

222 223 224 225 226
	/**
	 * Whether the executed command is kept alive and runs in the background.
	 */
	isBackground?: boolean;

D
Dirk Baeumer 已提交
227 228 229 230 231
	/**
	 * Whether the task should prompt on close for confirmation if running.
	 */
	promptOnClose?: boolean;

E
Erich Gamma 已提交
232
	/**
233 234
	 * Defines the group the task belongs too.
	 */
D
Dirk Baeumer 已提交
235
	group?: string | GroupKind;
236 237

	/**
238
	 * The other tasks the task depend on
E
Erich Gamma 已提交
239
	 */
240
	dependsOn?: string | string[];
E
Erich Gamma 已提交
241 242

	/**
243
	 * Controls the behavior of the used terminal
E
Erich Gamma 已提交
244
	 */
245
	presentation?: PresentationOptions;
E
Erich Gamma 已提交
246 247

	/**
248 249
	 * The problem matcher(s) to use to capture problems in the tasks
	 * output.
E
Erich Gamma 已提交
250
	 */
251 252
	problemMatcher?: ProblemMatcherConfig.ProblemMatcherType;
}
E
Erich Gamma 已提交
253

254
export interface CustomTask extends CommandProperties, ConfigurationProperties {
E
Erich Gamma 已提交
255
	/**
256
	 * Custom tasks have the type 'custom'
E
Erich Gamma 已提交
257
	 */
258
	type?: string;
E
Erich Gamma 已提交
259

260
}
261

262
export interface ConfiguringTask extends ConfigurationProperties {
E
Erich Gamma 已提交
263
	/**
264
	 * The contributed type of the task
E
Erich Gamma 已提交
265
	 */
266
	type?: string;
E
Erich Gamma 已提交
267 268 269 270 271
}

/**
 * The base task runner configuration
 */
272
export interface BaseTaskRunnerConfiguration {
E
Erich Gamma 已提交
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290

	/**
	 * The command to be executed. Can be an external program or a shell
	 * command.
	 */
	command?: string;

	/**
	 * 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 command options used when the command is executed. Can be omitted.
	 */
D
Dirk Baeumer 已提交
291
	options?: CommandOptions;
E
Erich Gamma 已提交
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313

	/**
	 * The arguments passed to the command. Can be omitted.
	 */
	args?: string[];

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

D
Dirk Baeumer 已提交
314 315 316
	/**
	 * Controls the behavior of the used terminal
	 */
317
	presentation?: PresentationOptions;
D
Dirk Baeumer 已提交
318

E
Erich Gamma 已提交
319 320 321 322 323 324 325 326 327 328 329 330
	/**
	 * 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 已提交
331
	taskSelector?: string;
E
Erich Gamma 已提交
332 333 334 335 336 337 338 339 340

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

	/**
341 342
	 * @deprecated Use `isBackground` instead.
	 *
E
Erich Gamma 已提交
343
	 * Specifies whether a global command is a watching the filesystem. A task.json
344
	 * file can either contain a global isWatching property or a tasks property
E
Erich Gamma 已提交
345 346 347 348
	 * but not both.
	 */
	isWatching?: boolean;

349 350 351 352 353
	/**
	 * Specifies whether a global command is a background task.
	 */
	isBackground?: boolean;

D
Dirk Baeumer 已提交
354 355 356 357 358
	/**
	 * Whether the task should prompt on close for confirmation if running.
	 */
	promptOnClose?: boolean;

E
Erich Gamma 已提交
359 360 361 362
	/**
	 * The configuration of the available tasks. A tasks.json file can either
	 * contain a global problemMatcher property or a tasks property but not both.
	 */
363
	tasks?: (CustomTask | ConfiguringTask)[];
E
Erich Gamma 已提交
364 365 366 367 368 369 370 371 372 373 374 375 376

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

377 378
	_runner?: string;

379 380 381 382 383
	/**
	 * Determines the runner to use
	 */
	runner?: string;

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

412 413
const EMPTY_ARRAY: any[] = [];
Object.freeze(EMPTY_ARRAY);
E
Erich Gamma 已提交
414

415
function assignProperty<T, K extends keyof T>(target: T, source: Partial<T>, key: K) {
416 417 418
	if (source[key] !== void 0) {
		target[key] = source[key];
	}
E
Erich Gamma 已提交
419 420
}

421
function fillProperty<T, K extends keyof T>(target: T, source: Partial<T>, key: K) {
422 423 424 425 426 427
	if (target[key] === void 0 && source[key] !== void 0) {
		target[key] = source[key];
	}
}


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
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]);
493
		} else if (target[property] === void 0) {
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
			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) {
			return Objects.deepClone(defaults);
		} 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;
}

552
interface ParseContext {
553
	problemReporter: IProblemReporter;
554
	namedProblemMatchers: IStringDictionary<NamedProblemMatcher>;
555
	uuidMap: UUIDMap;
556 557
	engine: Tasks.ExecutionEngine;
	schemaVersion: Tasks.JsonSchemaVersion;
E
Erich Gamma 已提交
558 559
}

560

561
namespace ShellConfiguration {
562 563 564

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

565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580
	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();
		}
		return result;
	}

581 582
	export function isEmpty(this: void, value: Tasks.ShellConfiguration): boolean {
		return _isEmpty(value, properties);
583 584
	}

585 586
	export function assignProperties(this: void, target: Tasks.ShellConfiguration, source: Tasks.ShellConfiguration): Tasks.ShellConfiguration {
		return _assignProperties(target, source, properties);
587 588
	}

589 590
	export function fillProperties(this: void, target: Tasks.ShellConfiguration, source: Tasks.ShellConfiguration): Tasks.ShellConfiguration {
		return _fillProperties(target, source, properties);
591 592
	}

593 594
	export function fillDefaults(this: void, value: Tasks.ShellConfiguration, context: ParseContext): Tasks.ShellConfiguration {
		return value;
595 596
	}

597
	export function freeze(this: void, value: Tasks.ShellConfiguration): Readonly<Tasks.ShellConfiguration> {
598
		if (!value) {
599
			return undefined;
600
		}
601
		return Object.freeze(value);
602 603 604
	}
}

605
namespace CommandOptions {
606 607 608 609

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

D
Dirk Baeumer 已提交
610
	export function from(this: void, options: CommandOptions, context: ParseContext): Tasks.CommandOptions {
611
		let result: Tasks.CommandOptions = {};
612 613 614 615
		if (options.cwd !== void 0) {
			if (Types.isString(options.cwd)) {
				result.cwd = options.cwd;
			} else {
616
				context.problemReporter.warn(nls.localize('ConfigurationParser.invalidCWD', 'Warning: options.cwd must be of type string. Ignoring value {0}\n', options.cwd));
617 618 619 620 621
			}
		}
		if (options.env !== void 0) {
			result.env = Objects.clone(options.env);
		}
D
Dirk Baeumer 已提交
622
		result.shell = ShellConfiguration.from(options.shell, context);
623
		return isEmpty(result) ? undefined : result;
E
Erich Gamma 已提交
624 625
	}

626
	export function isEmpty(value: Tasks.CommandOptions): boolean {
627
		return _isEmpty(value, properties);
E
Erich Gamma 已提交
628 629
	}

630
	export function assignProperties(target: Tasks.CommandOptions, source: Tasks.CommandOptions): Tasks.CommandOptions {
631 632
		if (isEmpty(source)) {
			return target;
E
Erich Gamma 已提交
633
		}
634 635
		if (isEmpty(target)) {
			return source;
E
Erich Gamma 已提交
636
		}
637
		assignProperty(target, source, 'cwd');
638 639 640 641 642
		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]);
643
			Object.keys(source.env).forEach(key => env[key] = source.env[key]);
644 645
			target.env = env;
		}
646 647 648 649 650
		target.shell = ShellConfiguration.assignProperties(target.shell, source.shell);
		return target;
	}

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

654 655
	export function fillDefaults(value: Tasks.CommandOptions, context: ParseContext): Tasks.CommandOptions {
		return _fillDefaults(value, defaults, properties, context);
656 657
	}

658 659
	export function freeze(value: Tasks.CommandOptions): Readonly<Tasks.CommandOptions> {
		return _freeze(value, properties);
E
Erich Gamma 已提交
660
	}
661
}
E
Erich Gamma 已提交
662

663
namespace CommandConfiguration {
664

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

668 669 670 671 672
		interface PresentationOptionsShape extends LegacyCommandProperties {
			presentation?: PresentationOptions;
		}

		export function from(this: void, config: PresentationOptionsShape, context: ParseContext): Tasks.PresentationOptions {
673 674 675
			let echo: boolean;
			let reveal: Tasks.RevealKind;
			let focus: boolean;
676
			let panel: Tasks.PanelKind;
D
Dirk Baeumer 已提交
677 678 679 680 681 682
			if (Types.isBoolean(config.echoCommand)) {
				echo = config.echoCommand;
			}
			if (Types.isString(config.showOutput)) {
				reveal = Tasks.RevealKind.fromString(config.showOutput);
			}
683 684 685 686
			let presentation = config.presentation || config.terminal;
			if (presentation) {
				if (Types.isBoolean(presentation.echo)) {
					echo = presentation.echo;
D
Dirk Baeumer 已提交
687
				}
688 689
				if (Types.isString(presentation.reveal)) {
					reveal = Tasks.RevealKind.fromString(presentation.reveal);
D
Dirk Baeumer 已提交
690
				}
691 692
				if (Types.isBoolean(presentation.focus)) {
					focus = presentation.focus;
693
				}
694 695
				if (Types.isString(presentation.panel)) {
					panel = Tasks.PanelKind.fromString(presentation.panel);
696
				}
D
Dirk Baeumer 已提交
697
			}
698
			if (echo === void 0 && reveal === void 0 && focus === void 0 && panel === void 0) {
D
Dirk Baeumer 已提交
699 700
				return undefined;
			}
701
			return { echo, reveal, focus, panel };
D
Dirk Baeumer 已提交
702 703
		}

704
		export function assignProperties(target: Tasks.PresentationOptions, source: Tasks.PresentationOptions): Tasks.PresentationOptions {
705
			return _assignProperties(target, source, properties);
706 707
		}

708
		export function fillProperties(target: Tasks.PresentationOptions, source: Tasks.PresentationOptions): Tasks.PresentationOptions {
709
			return _fillProperties(target, source, properties);
D
Dirk Baeumer 已提交
710 711
		}

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

717
		export function freeze(value: Tasks.PresentationOptions): Readonly<Tasks.PresentationOptions> {
718
			return _freeze(value, properties);
D
Dirk Baeumer 已提交
719 720
		}

721
		export function isEmpty(this: void, value: Tasks.PresentationOptions): boolean {
722
			return _isEmpty(value, properties);
D
Dirk Baeumer 已提交
723 724 725
		}
	}

726 727 728 729 730 731 732 733 734 735 736
	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 },
737
		{ property: 'args' }, { property: 'taskSelector' }, { property: 'suppressTaskName' },
738
		{ property: 'presentation', type: PresentationOptions }
739 740
	];

741 742
	export function from(this: void, config: CommandConfiguationShape, context: ParseContext): Tasks.CommandConfiguration {
		let result: Tasks.CommandConfiguration = fromBase(config, context);
743

744
		let osConfig: Tasks.CommandConfiguration = undefined;
745 746 747 748 749 750 751 752
		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) {
753
			result = assignProperties(result, osConfig);
754 755 756 757
		}
		return isEmpty(result) ? undefined : result;
	}

758 759 760
	function fromBase(this: void, config: BaseCommandConfiguationShape, context: ParseContext): Tasks.CommandConfiguration {
		let result: Tasks.CommandConfiguration = {
			name: undefined,
761
			runtime: undefined,
762
			presentation: undefined
763
		};
764 765
		if (Types.isString(config.command)) {
			result.name = config.command;
E
Erich Gamma 已提交
766
		}
D
Dirk Baeumer 已提交
767
		if (Types.isString(config.type)) {
768 769 770
			if (config.type === 'shell' || config.type === 'process') {
				result.runtime = Tasks.RuntimeType.fromString(config.type);
			}
D
Dirk Baeumer 已提交
771 772 773
		}
		let isShellConfiguration = ShellConfiguration.is(config.isShellCommand);
		if (Types.isBoolean(config.isShellCommand) || isShellConfiguration) {
774
			result.runtime = Tasks.RuntimeType.Shell;
775
		} else if (config.isShellCommand !== void 0) {
776 777 778 779
			result.runtime = !!config.isShellCommand ? Tasks.RuntimeType.Shell : Tasks.RuntimeType.Process;
		}
		if (Types.isString(config.runtime)) {
			result.runtime = Tasks.RuntimeType.fromString(config.runtime);
E
Erich Gamma 已提交
780
		}
781 782 783 784
		if (config.args !== void 0) {
			if (Types.isStringArray(config.args)) {
				result.args = config.args.slice(0);
			} else {
785
				context.problemReporter.fatal(nls.localize('ConfigurationParser.noargs', 'Error: command arguments must be an array of strings. Provided value is:\n{0}', config.args ? JSON.stringify(config.args, undefined, 4) : 'undefined'));
786
			}
E
Erich Gamma 已提交
787
		}
788 789
		if (config.options !== void 0) {
			result.options = CommandOptions.from(config.options, context);
D
Dirk Baeumer 已提交
790 791
			if (result.options && result.options.shell === void 0 && isShellConfiguration) {
				result.options.shell = ShellConfiguration.from(config.isShellCommand as ShellConfiguration, context);
792
				if (context.engine !== Tasks.ExecutionEngine.Terminal) {
D
Dirk Baeumer 已提交
793 794 795
					context.problemReporter.warn(nls.localize('ConfigurationParser.noShell', 'Warning: shell configuration is only supported when executing tasks in the terminal.'));
				}
			}
E
Erich Gamma 已提交
796
		}
797 798 799
		let panel = PresentationOptions.from(config, context);
		if (panel) {
			result.presentation = panel;
E
Erich Gamma 已提交
800
		}
801 802
		if (Types.isString(config.taskSelector)) {
			result.taskSelector = config.taskSelector;
E
Erich Gamma 已提交
803
		}
804 805 806
		if (Types.isBoolean(config.suppressTaskName)) {
			result.suppressTaskName = config.suppressTaskName;
		}
807
		return isEmpty(result) ? undefined : result;
E
Erich Gamma 已提交
808 809
	}

810
	export function isEmpty(value: Tasks.CommandConfiguration): boolean {
811
		return _isEmpty(value, properties);
812 813
	}

D
Dirk Baeumer 已提交
814 815
	export function onlyTerminalBehaviour(value: Tasks.CommandConfiguration): boolean {
		return value &&
816
			value.presentation && (value.presentation.echo !== void 0 || value.presentation.reveal !== void 0) &&
817
			value.name === void 0 && value.runtime === void 0 && value.args === void 0 && CommandOptions.isEmpty(value.options);
818 819
	}

820
	export function assignProperties(target: Tasks.CommandConfiguration, source: Tasks.CommandConfiguration): Tasks.CommandConfiguration {
821 822
		if (isEmpty(source)) {
			return target;
E
Erich Gamma 已提交
823
		}
824 825
		if (isEmpty(target)) {
			return source;
E
Erich Gamma 已提交
826
		}
827
		assignProperty(target, source, 'name');
828
		assignProperty(target, source, 'runtime');
829 830
		assignProperty(target, source, 'taskSelector');
		assignProperty(target, source, 'suppressTaskName');
831 832 833 834 835
		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 已提交
836 837
			}
		}
838
		target.presentation = PresentationOptions.assignProperties(target.presentation, source.presentation);
839 840 841 842
		target.options = CommandOptions.assignProperties(target.options, source.options);
		return target;
	}

843 844 845 846
	export function fillProperties(target: Tasks.CommandConfiguration, source: Tasks.CommandConfiguration): Tasks.CommandConfiguration {
		return _fillProperties(target, source, properties);
	}

847 848 849 850 851 852
	export function fillGlobals(target: Tasks.CommandConfiguration, source: Tasks.CommandConfiguration, taskName: string): Tasks.CommandConfiguration {
		if (isEmpty(source)) {
			return target;
		}
		target = target || {
			name: undefined,
853
			runtime: undefined,
854
			presentation: undefined
855
		};
856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872
		if (target.name === void 0) {
			fillProperty(target, source, 'name');
			fillProperty(target, source, 'taskSelector');
			fillProperty(target, source, 'suppressTaskName');
			let args: string[] = source.args ? source.args.slice() : [];
			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;
		}
873
		fillProperty(target, source, 'runtime');
874

875
		target.presentation = PresentationOptions.fillProperties(target.presentation, source.presentation);
876 877
		target.options = CommandOptions.fillProperties(target.options, source.options);

878
		return target;
E
Erich Gamma 已提交
879 880
	}

881
	export function fillDefaults(value: Tasks.CommandConfiguration, context: ParseContext): void {
882 883 884
		if (!value || Object.isFrozen(value)) {
			return;
		}
885 886
		if (value.name !== void 0 && value.runtime === void 0) {
			value.runtime = Tasks.RuntimeType.Process;
887
		}
888
		value.presentation = PresentationOptions.fillDefaults(value.presentation, context);
889
		if (!isEmpty(value)) {
890
			value.options = CommandOptions.fillDefaults(value.options, context);
891
		}
892 893 894
		if (value.args === void 0) {
			value.args = EMPTY_ARRAY;
		}
895 896
		if (value.suppressTaskName === void 0) {
			value.suppressTaskName = false;
E
Erich Gamma 已提交
897 898 899
		}
	}

900 901
	export function freeze(value: Tasks.CommandConfiguration): Readonly<Tasks.CommandConfiguration> {
		return _freeze(value, properties);
E
Erich Gamma 已提交
902
	}
903
}
E
Erich Gamma 已提交
904

905 906 907
namespace ProblemMatcherConverter {

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

		if (!Types.isArray(declares)) {
E
Erich Gamma 已提交
911 912
			return result;
		}
913
		(<ProblemMatcherConfig.NamedProblemMatcher[]>declares).forEach((value) => {
914
			let namedProblemMatcher = (new ProblemMatcherParser(context.problemReporter)).parse(value);
915
			if (isNamedProblemMatcher(namedProblemMatcher)) {
E
Erich Gamma 已提交
916
				result[namedProblemMatcher.name] = namedProblemMatcher;
917
			} else {
918
				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 已提交
919 920 921 922 923
			}
		});
		return result;
	}

924 925 926 927 928 929 930
	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) {
931
			context.problemReporter.warn(nls.localize(
932 933 934
				'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 已提交
935
			return result;
936
		} else if (kind === ProblemMatcherKind.String || kind === ProblemMatcherKind.ProblemMatcher) {
937
			let matcher = resolveProblemMatcher(config as ProblemMatcherConfig.ProblemMatcher, context);
938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959
			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 已提交
960
		} else {
961
			return ProblemMatcherKind.Unknown;
E
Erich Gamma 已提交
962 963 964
		}
	}

965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981
	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) {
					return Objects.clone(global);
				}
				let localProblemMatcher = context.namedProblemMatchers[variableName];
				if (localProblemMatcher) {
					localProblemMatcher = Objects.clone(localProblemMatcher);
					// remove the name
					delete localProblemMatcher.name;
					return localProblemMatcher;
				}
			}
982
			context.problemReporter.error(nls.localize('ConfigurationParser.invalidVaraibleReference', 'Error: Invalid problemMatcher reference: {0}\n', value));
983 984 985
			return undefined;
		} else {
			let json = <ProblemMatcherConfig.ProblemMatcher>value;
986
			return new ProblemMatcherParser(context.problemReporter).parse(json);
987 988 989 990
		}
	}
}

991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005
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;
	}
1006 1007
}

1008 1009 1010 1011 1012
const source: Tasks.TaskSource = {
	kind: Tasks.TaskSourceKind.Workspace,
	label: 'Workspace',
	detail: '.settins\\tasks.json'
};
1013

1014 1015
namespace ConfigurationProperties {

D
Dirk Baeumer 已提交
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027
	namespace GroupKind {
		export function from(this: void, external: GroupKind): [string, boolean] {
			if (external === void 0 || !Types.isString(external.kind)) {
				return undefined;
			}
			let group: string = external.kind;
			let primary: boolean = !!external.isPrimary;

			return [group, primary];
		}
	}

1028 1029 1030 1031 1032
	const properties: MetaData<Tasks.ConfigurationProperties, any>[] = [
		{ property: 'name' }, { property: 'identifier' }, { property: 'group' }, { property: 'isBackground' },
		{ property: 'promptOnClose' }, { property: 'dependsOn' },
		{ property: 'presentation', type: CommandConfiguration.PresentationOptions }, { property: 'problemMatchers' }
	];
1033

1034 1035
	export function from(this: void, external: ConfigurationProperties, context: ParseContext, includePresentation): Tasks.ConfigurationProperties {
		if (!external) {
1036
			return undefined;
E
Erich Gamma 已提交
1037
		}
1038 1039 1040 1041
		let result: Tasks.ConfigurationProperties = {};
		if (Types.isString(external.taskName)) {
			result.name = external.taskName;
		}
1042 1043 1044
		if (Types.isString(external.label) && context.schemaVersion === Tasks.JsonSchemaVersion.V2_0_0) {
			result.name = external.label;
		}
1045 1046 1047 1048 1049 1050 1051 1052 1053
		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 已提交
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064
		if (external.group !== void 0) {
			if (Types.isString(external.group) && Tasks.TaskGroup.is(external.group)) {
				result.group = external.group;
				result.isPrimaryGroupEntry = false;
			} else {
				let values = GroupKind.from(external.group);
				if (values) {
					result.group = values[0];
					result.isPrimaryGroupEntry = values[1];
				}
			}
1065 1066 1067 1068 1069 1070
		}
		if (external.dependsOn !== void 0) {
			if (Types.isString(external.dependsOn)) {
				result.dependsOn = [external.dependsOn];
			} else if (Types.isStringArray(external.dependsOn)) {
				result.dependsOn = external.dependsOn.slice();
1071
			}
1072
		}
1073
		if (includePresentation && (external.presentation !== void 0 || (external as LegacyCommandProperties).terminal !== void 0)) {
1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088
			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 {

1089 1090 1091 1092 1093 1094 1095 1096 1097 1098
	const grunt = 'grunt.';
	const jake = 'jake.';
	const gulp = 'gulp.';
	const npm = 'vscode.npm.';
	const typescript = 'vscode.typescript.';

	interface CustomizeShape {
		customize: string;
	}

1099 1100 1101 1102 1103
	export function from(this: void, external: ConfiguringTask, context: ParseContext): Tasks.ConfiguringTask {
		if (!external) {
			return undefined;
		}
		let type = external.type;
1104 1105
		let customize = (external as CustomizeShape).customize;
		if (!type && !customize) {
1106 1107 1108
			context.problemReporter.fatal(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)));
			return undefined;
		}
D
Dirk Baeumer 已提交
1109
		let typeDeclaration = TaskDefinitionRegistry.get(type);
1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121
		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 已提交
1122
			}
1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133
		} else {
			identifier = {
				type
			};
			Object.keys(typeDeclaration.properties).forEach((property) => {
				let value = external[property];
				if (value !== void 0 && value !== null) {
					identifier[property] = value;
				}
			});
		}
1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156
		let taskIdentifier = TaskIdentifier.from(identifier);
		let result: Tasks.ConfiguringTask = {
			type: type,
			configures: taskIdentifier,
			_id: taskIdentifier._key,
			_source: source,
			_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 已提交
1157
				}
1158
				result._label = label;
1159
			}
1160 1161
			if (!result.identifier) {
				result.identifier = taskIdentifier._key;
E
Erich Gamma 已提交
1162
			}
1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205
		}
		return result;
	}
}

namespace CustomTask {

	export function from(this: void, external: CustomTask, context: ParseContext): Tasks.CustomTask {
		if (!external) {
			return undefined;
		}
		let type = external.type;
		if (type === void 0 || type === null) {
			type = 'custom';
		}
		if (type !== 'custom' && type !== 'shell' && type !== 'process') {
			context.problemReporter.fatal(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)));
			return undefined;
		}
		let taskName = external.taskName;
		if (!taskName) {
			context.problemReporter.fatal(nls.localize('ConfigurationParser.noTaskName', 'Error: tasks must provide a taskName property. The task will be ignored.\n{0}\n', JSON.stringify(external, null, 4)));
			return undefined;
		}

		let result: Tasks.CustomTask = {
			type: 'custom',
			_id: context.uuidMap.getUUID(taskName),
			_source: source,
			_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;
1206
			}
1207 1208 1209 1210 1211
			if (result.group === void 0) {
				if (legacy.isBuildCommand === true) {
					result.group = Tasks.TaskGroup.Build;
				} else if (legacy.isTestCommand === true) {
					result.group = Tasks.TaskGroup.Test;
1212
				}
1213
			}
1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250
		}
		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
		if (task.dependsOn === void 0) {
			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;
		}
	}

1251
	export function createCustomTask(contributedTask: Tasks.ContributedTask, configuredProps: Tasks.ConfigurationProperties & { _id: string }): Tasks.CustomTask {
1252
		let result: Tasks.CustomTask = {
1253
			_id: configuredProps._id,
1254 1255 1256 1257 1258 1259 1260 1261 1262 1263
			_source: source,
			_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');
D
Dirk Baeumer 已提交
1264
		assignProperty(resultConfigProps, configuredProps, 'isPrimaryGroupEntry');
1265 1266 1267 1268 1269 1270 1271 1272 1273
		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');
D
Dirk Baeumer 已提交
1274
		fillProperty(resultConfigProps, contributedConfigProps, 'isPrimaryGroupEntry');
1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294
		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;
1295 1296
		let customize = (value as any).customize;
		return customize === void 0 && (type === void 0 || type === null || type === 'custom' || type === 'shell' || type === 'process');
1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355
	}

	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;

		for (let external of externals) {
			if (isCustomTask(external)) {
				let customTask = CustomTask.from(external, context);
				if (customTask) {
					CustomTask.fillGlobals(customTask, globals);
					CustomTask.fillDefaults(customTask, context);
					if (context.engine === Tasks.ExecutionEngine.Terminal && customTask.command && customTask.command.name && customTask.command.runtime === Tasks.RuntimeType.Shell && customTask.command.args && customTask.command.args.length > 0) {
						if (hasUnescapedSpaces(customTask.command.name) || customTask.command.args.some(hasUnescapedSpaces)) {
							context.problemReporter.warn(
								nls.localize(
									'taskConfiguration.shellArgs',
									'Warning: the task \'{0}\' is a shell command and either the command name or one of its arguments has unescaped spaces. To ensure correct command line quoting please merge args into the command.',
									customTask.name
								)
							);
						}
					}
					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 已提交
1356 1357
				}
			} else {
1358 1359 1360
				let configuredTask = ConfiguringTask.from(external, context);
				if (configuredTask) {
					result.configured.push(configuredTask);
D
Dirk Baeumer 已提交
1361
				}
E
Erich Gamma 已提交
1362
			}
1363
		}
1364
		if (defaultBuildTask.rank > -1 && defaultBuildTask.rank < 2) {
1365
			defaultBuildTask.task.group = Tasks.TaskGroup.Build;
1366
		} else if (defaultTestTask.rank > -1 && defaultTestTask.rank < 2) {
1367
			defaultTestTask.task.group = Tasks.TaskGroup.Test;
E
Erich Gamma 已提交
1368
		}
1369 1370

		return result;
E
Erich Gamma 已提交
1371 1372
	}

1373
	export function assignTasks(target: Tasks.CustomTask[], source: Tasks.CustomTask[]): Tasks.CustomTask[] {
1374
		if (source === void 0 || source.length === 0) {
1375 1376
			return target;
		}
1377
		if (target === void 0 || target.length === 0) {
1378 1379 1380
			return source;
		}

1381
		if (source) {
1382
			// Tasks are keyed by ID but we need to merge by name
1383
			let map: IStringDictionary<Tasks.CustomTask> = Object.create(null);
1384 1385
			target.forEach((task) => {
				map[task.name] = task;
1386 1387
			});

1388 1389
			source.forEach((task) => {
				map[task.name] = task;
1390
			});
1391
			let newTarget: Tasks.CustomTask[] = [];
1392 1393 1394
			target.forEach(task => {
				newTarget.push(map[task.name]);
				delete map[task.name];
E
Erich Gamma 已提交
1395
			});
1396 1397
			Object.keys(map).forEach(key => newTarget.push(map[key]));
			target = newTarget;
E
Erich Gamma 已提交
1398
		}
1399 1400 1401
		return target;
	}

1402
	function hasUnescapedSpaces(this: void, value: string): boolean {
1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414
		if (Platform.isWindows) {
			if (value.length >= 2 && value.charAt(0) === '"' && value.charAt(value.length - 1) === '"') {
				return false;
			}
			return value.indexOf(' ') !== -1;
		} else {
			if (value.length >= 2 && ((value.charAt(0) === '"' && value.charAt(value.length - 1) === '"') || (value.charAt(0) === '\'' && value.charAt(value.length - 1) === '\''))) {
				return false;
			}
			for (let i = 0; i < value.length; i++) {
				let ch = value.charAt(i);
				if (ch === ' ') {
D
Dirk Baeumer 已提交
1415
					if (i === 0 || value.charAt(i - 1) !== '\\') {
1416 1417 1418 1419 1420 1421 1422
						return true;
					}
				}
			}
			return false;
		}
	}
1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437

	export function quickParse(this: void, externals: (CustomTask | ConfiguringTask)[], context: ParseContext): (Tasks.CustomTask | Tasks.ConfiguringTask)[] {
		if (!externals) {
			return undefined;
		}
		let result: (Tasks.CustomTask | Tasks.ConfiguringTask)[] = [];
		for (let external of externals) {
			if (isCustomTask(external)) {
				result.push(CustomTask.from(external, context));
			} else {
				result.push(ConfiguringTask.from(external, context));
			}
		}
		return result;
	}
1438 1439 1440
}

interface Globals {
1441
	command?: Tasks.CommandConfiguration;
1442 1443 1444 1445 1446
	promptOnClose?: boolean;
	suppressTaskName?: boolean;
}

namespace Globals {
1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458

	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) {
1459
			result = Globals.assignProperties(result, osGlobals);
1460 1461 1462 1463 1464
		}
		let command = CommandConfiguration.from(config, context);
		if (command) {
			result.command = command;
		}
1465
		Globals.fillDefaults(result, context);
1466 1467 1468 1469 1470
		Globals.freeze(result);
		return result;
	}

	export function fromBase(this: void, config: BaseTaskRunnerConfiguration, context: ParseContext): Globals {
1471 1472 1473 1474 1475 1476 1477
		let result: Globals = {};
		if (config.suppressTaskName !== void 0) {
			result.suppressTaskName = !!config.suppressTaskName;
		}
		if (config.promptOnClose !== void 0) {
			result.promptOnClose = !!config.promptOnClose;
		}
E
Erich Gamma 已提交
1478 1479 1480
		return result;
	}

1481
	export function isEmpty(value: Globals): boolean {
D
Dirk Baeumer 已提交
1482
		return !value || value.command === void 0 && value.promptOnClose === void 0 && value.suppressTaskName === void 0;
1483 1484
	}

1485
	export function assignProperties(target: Globals, source: Globals): Globals {
1486 1487
		if (isEmpty(source)) {
			return target;
E
Erich Gamma 已提交
1488
		}
1489 1490 1491
		if (isEmpty(target)) {
			return source;
		}
1492 1493
		assignProperty(target, source, 'promptOnClose');
		assignProperty(target, source, 'suppressTaskName');
1494
		return target;
E
Erich Gamma 已提交
1495 1496
	}

1497
	export function fillDefaults(value: Globals, context: ParseContext): void {
1498 1499 1500
		if (!value) {
			return;
		}
1501
		CommandConfiguration.fillDefaults(value.command, context);
1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517
		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);
		}
	}
}

1518 1519
export namespace ExecutionEngine {

1520
	export function from(config: ExternalTaskRunnerConfiguration): Tasks.ExecutionEngine {
1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540
		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.');
		}
1541
	}
1542
}
1543

1544 1545
export namespace JsonSchemaVersion {

1546
	const _default: Tasks.JsonSchemaVersion = Tasks.JsonSchemaVersion.V2_0_0;
1547

1548 1549 1550
	export function from(config: ExternalTaskRunnerConfiguration): Tasks.JsonSchemaVersion {
		let version = config.version;
		if (!version) {
1551
			return _default;
1552 1553 1554 1555
		}
		switch (version) {
			case '0.1.0':
				return Tasks.JsonSchemaVersion.V0_1_0;
1556
			case '2.0.0':
1557
				return Tasks.JsonSchemaVersion.V2_0_0;
1558 1559
			default:
				return _default;
1560
		}
1561 1562 1563
	}
}

1564 1565
export interface ParseResult {
	validationStatus: ValidationStatus;
1566 1567
	custom: Tasks.CustomTask[];
	configured: Tasks.ConfiguringTask[];
1568
	engine: Tasks.ExecutionEngine;
1569 1570
}

1571
export interface IProblemReporter extends IProblemReporterBase {
1572
	clearOutput(): void;
1573 1574
}

1575 1576 1577 1578
class NullProblemReporter extends NullProblemReporterBase implements IProblemReporter {
	clearOutput(): void { };
}

1579 1580 1581 1582 1583
class UUIDMap {

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

1584
	constructor(other?: UUIDMap) {
1585
		this.current = Object.create(null);
1586 1587 1588 1589 1590 1591 1592 1593 1594 1595
		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;
				}
			}
		}
1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639
	}

	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;
	}
}

1640 1641
class ConfigurationParser {

1642
	private problemReporter: IProblemReporter;
1643 1644 1645
	private uuidMap: UUIDMap;

	constructor(problemReporter: IProblemReporter, uuidMap: UUIDMap) {
1646
		this.problemReporter = problemReporter;
1647
		this.uuidMap = uuidMap;
1648 1649 1650
	}

	public run(fileConfig: ExternalTaskRunnerConfiguration): ParseResult {
1651
		let engine = ExecutionEngine.from(fileConfig);
1652
		let schemaVersion = JsonSchemaVersion.from(fileConfig);
1653
		if (engine === Tasks.ExecutionEngine.Terminal) {
1654
			this.problemReporter.clearOutput();
1655
		}
1656 1657
		let context: ParseContext = {
			problemReporter: this.problemReporter,
1658
			uuidMap: this.uuidMap,
1659
			namedProblemMatchers: undefined,
1660
			engine,
1661
			schemaVersion
1662 1663
		};
		let taskParseResult = this.createTaskRunnerConfiguration(fileConfig, context);
1664
		return {
1665
			validationStatus: this.problemReporter.status,
1666 1667
			custom: taskParseResult.custom,
			configured: taskParseResult.configured,
1668
			engine
1669 1670 1671
		};
	}

1672
	private createTaskRunnerConfiguration(fileConfig: ExternalTaskRunnerConfiguration, context: ParseContext): TaskParseResult {
1673
		let globals = Globals.from(fileConfig, context);
1674
		if (this.problemReporter.status.isFatal()) {
1675
			return { custom: [], configured: [] };
1676 1677
		}
		context.namedProblemMatchers = ProblemMatcherConverter.namedFrom(fileConfig.declares, context);
1678
		let globalTasks: Tasks.CustomTask[];
1679
		let externalGlobalTasks: (ConfiguringTask | CustomTask)[];
1680
		if (fileConfig.windows && Platform.platform === Platform.Platform.Windows) {
1681
			globalTasks = TaskParser.from(fileConfig.windows.tasks, globals, context).custom;
1682
			externalGlobalTasks = fileConfig.windows.tasks;
1683
		} else if (fileConfig.osx && Platform.platform === Platform.Platform.Mac) {
1684
			globalTasks = TaskParser.from(fileConfig.osx.tasks, globals, context).custom;
1685
			externalGlobalTasks = fileConfig.osx.tasks;
1686
		} else if (fileConfig.linux && Platform.platform === Platform.Platform.Linux) {
1687
			globalTasks = TaskParser.from(fileConfig.linux.tasks, globals, context).custom;
1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699
			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',
					'Task version 2.0.0 doesn\'t support gloabl OS specific tasks. Convert them to a task with a OS specific command. Affected tasks are:\n{0}', taskContent.join('\n'))
			);
1700 1701
		}

1702
		let result: TaskParseResult = { custom: undefined, configured: undefined };
1703
		if (fileConfig.tasks) {
1704
			result = TaskParser.from(fileConfig.tasks, globals, context);
1705
		}
1706
		if (globalTasks) {
1707
			result.custom = TaskParser.assignTasks(result.custom, globalTasks);
1708 1709
		}

1710
		if ((!result.custom || result.custom.length === 0) && (globals.command && globals.command.name)) {
1711
			let matchers: ProblemMatcher[] = ProblemMatcherConverter.from(fileConfig.problemMatcher, context);
1712
			let isBackground = fileConfig.isBackground ? !!fileConfig.isBackground : fileConfig.isWatching ? !!fileConfig.isWatching : undefined;
1713
			let task: Tasks.CustomTask = {
1714
				_id: context.uuidMap.getUUID(globals.command.name),
1715
				_source: source,
1716
				_label: globals.command.name,
1717
				type: 'custom',
1718 1719 1720
				name: globals.command.name,
				identifier: globals.command.name,
				group: Tasks.TaskGroup.Build,
1721 1722
				command: {
					name: undefined,
1723
					runtime: undefined,
1724
					presentation: undefined,
1725 1726
					suppressTaskName: true
				},
1727 1728 1729
				isBackground: isBackground,
				problemMatchers: matchers
			};
1730 1731 1732
			CustomTask.fillGlobals(task, globals);
			CustomTask.fillDefaults(task, context);
			result.custom = [task];
1733
		}
1734 1735
		result.custom = result.custom || [];
		result.configured = result.configured || [];
1736
		return result;
1737
	}
E
Erich Gamma 已提交
1738 1739
}

1740
let uuidMap: UUIDMap = new UUIDMap();
1741
export function parse(configuration: ExternalTaskRunnerConfiguration, logger: IProblemReporter): ParseResult {
1742 1743 1744 1745 1746 1747
	try {
		uuidMap.start();
		return (new ConfigurationParser(logger, uuidMap)).run(configuration);
	} finally {
		uuidMap.finish();
	}
1748 1749
}

1750
export function createCustomTask(contributedTask: Tasks.ContributedTask, configuredProps: Tasks.ConfigurationProperties & { _id: string }): Tasks.CustomTask {
1751 1752 1753 1754 1755
	return CustomTask.createCustomTask(contributedTask, configuredProps);
}

export function getTaskIdentifier(value: TaskIdentifier): Tasks.TaskIdentifier {
	return TaskIdentifier.from(value);
D
Dirk Baeumer 已提交
1756 1757
}

1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786
export function findTaskIndex(fileConfig: ExternalTaskRunnerConfiguration, task: Tasks.Task): number {
	if (!fileConfig || !fileConfig.tasks) {
		return undefined;
	}
	if (fileConfig.tasks.length === 0) {
		return -1;
	}
	let localMap = new UUIDMap(uuidMap);
	let context: ParseContext = {
		problemReporter: this.problemReporter,
		uuidMap: localMap,
		namedProblemMatchers: undefined,
		engine: ExecutionEngine.from(fileConfig),
		schemaVersion: JsonSchemaVersion.from(fileConfig)
	};
	try {
		localMap.start();
		let tasks = TaskParser.quickParse(fileConfig.tasks, context);
		for (let i = 0; i < tasks.length; i++) {
			if (task._id === tasks[i]._id) {
				return i;
			}
		}
		return -1;
	} finally {
		localMap.finish();
	}
}

D
Dirk Baeumer 已提交
1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863
/*
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(' ');
	}

}
*/