Skip to content

Commit

Permalink
Fixes #4177 ('Auto detecting the task system failed' can be more user…
Browse files Browse the repository at this point in the history
… friendly) and #3304 (Configure task runner should only open output if autodetection fails or provides output.)
  • Loading branch information
dbaeumer committed Mar 17, 2016
1 parent fcb8e57 commit a3209b5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/vs/workbench/parts/tasks/common/taskTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const npm: TaskEntry = {
'\t\t{',
'\t\t\t"taskName": "update",',
'\t\t\t"args": ["update"]',
'\t\t}',
'\t\t},',
'\t\t{',
'\t\t\t"taskName": "test",',
'\t\t\t"args": ["run", "test"]',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,21 @@ class ConfigureTaskRunnerAction extends Action {
}
let contentPromise: TPromise<string>;
if (selection.autoDetect) {
this.outputService.showOutput(TaskService.OutputChannel);
this.outputService.append(TaskService.OutputChannel, nls.localize('ConfigureTaskRunnerAction.autoDetecting', 'Auto detecting tasks for {0}', selection.id) + '\n');
let detector = new ProcessRunnerDetector(this.fileService, this.contextService, new SystemVariables(this.editorService, this.contextService));
contentPromise = detector.detect(false, selection.id).then((value) => {
let config = value.config;
if (value.stderr && value.stderr.length > 0) {
value.stderr.forEach((line) => {
this.outputService.append(TaskService.OutputChannel, line + '\n');
});
this.messageService.show(Severity.Error, nls.localize('ConfigureTaskRunnerAction.autoDetect', 'Auto detecting the task system failed. Using default template. Consult the task output for details.'));
this.messageService.show(Severity.Warning, nls.localize('ConfigureTaskRunnerAction.autoDetect', 'Auto detecting the task system failed. Using default template. Consult the task output for details.'));
return selection.content;
} else if (config) {
if (value.stdout && value.stdout.length > 0) {
value.stdout.forEach(line => this.outputService.append(TaskService.OutputChannel, line + '\n'));
}
let content = JSON.stringify(config, null, '\t');
content = [
'{',
Expand Down
36 changes: 26 additions & 10 deletions src/vs/workbench/parts/tasks/node/processRunnerDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ class GruntTaskMatcher implements TaskDetectorMatcher {
}
}

export interface DetectorResult {
config: FileConfig.ExternalTaskRunnerConfiguration;
stdout: string[];
stderr: string[];
}

export class ProcessRunnerDetector {

private static Version: string = '0.1.0';
Expand Down Expand Up @@ -135,20 +141,26 @@ export class ProcessRunnerDetector {
private variables: SystemVariables;
private taskConfiguration: FileConfig.ExternalTaskRunnerConfiguration;
private _stderr: string[];
private _stdout: string[];

constructor(fileService: IFileService, contextService: IWorkspaceContextService, variables:SystemVariables, config: FileConfig.ExternalTaskRunnerConfiguration = null) {
this.fileService = fileService;
this.contextService = contextService;
this.variables = variables;
this.taskConfiguration = config;
this._stderr = [];
this._stdout = [];
}

public get stderr(): string[] {
return this._stderr;
}

public detect(list: boolean = false, detectSpecific?: string): TPromise<{ config: FileConfig.ExternalTaskRunnerConfiguration; stderr: string[]; }> {
public get stdout(): string[] {
return this._stdout;
}

public detect(list: boolean = false, detectSpecific?: string): TPromise<DetectorResult> {
if (this.taskConfiguration && this.taskConfiguration.command && ProcessRunnerDetector.supports(this.taskConfiguration.command)) {
let config = ProcessRunnerDetector.detectorConfig(this.taskConfiguration.command);
let args = (this.taskConfiguration.args || []).concat(config.arg);
Expand All @@ -159,7 +171,7 @@ export class ProcessRunnerDetector {
this.taskConfiguration.command, isShellCommand, config.matcher, ProcessRunnerDetector.DefaultProblemMatchers, list);
} else {
if (detectSpecific) {
let detectorPromise: TPromise<{ config: FileConfig.ExternalTaskRunnerConfiguration; stderr: string[]; }>;
let detectorPromise: TPromise<DetectorResult>;
if ('gulp' === detectSpecific) {
detectorPromise = this.tryDetectGulp(list);
} else if ('jake' === detectSpecific) {
Expand All @@ -171,7 +183,7 @@ export class ProcessRunnerDetector {
if (value) {
return value;
} else {
return { config: null, stderr: this.stderr };
return { config: null, stdout: this.stdout, stderr: this.stderr };
}
});
} else {
Expand All @@ -187,7 +199,7 @@ export class ProcessRunnerDetector {
if (value) {
return value;
}
return { config: null, stderr: this.stderr };
return { config: null, stdout: this.stdout, stderr: this.stderr };
});
});
});
Expand Down Expand Up @@ -232,7 +244,7 @@ export class ProcessRunnerDetector {
});
}

private runDetection(process: LineProcess, command: string, isShellCommand: boolean, matcher: TaskDetectorMatcher, problemMatchers: string[], list: boolean): TPromise<{ config: FileConfig.ExternalTaskRunnerConfiguration; stderr: string[]; }> {
private runDetection(process: LineProcess, command: string, isShellCommand: boolean, matcher: TaskDetectorMatcher, problemMatchers: string[], list: boolean): TPromise<DetectorResult> {
let tasks:string[] = [];
matcher.init();
return process.start().then((success) => {
Expand All @@ -244,7 +256,7 @@ export class ProcessRunnerDetector {
this._stderr.push(nls.localize('TaskSystemDetector.noJakeTasks', 'Running jake --tasks didn\'t list any tasks. Did you run npm install?'));
}
}
return { config: null, stderr: this._stderr };
return { config: null, stdout: this._stdout, stderr: this._stderr };
}
let result: FileConfig.ExternalTaskRunnerConfiguration = {
version: ProcessRunnerDetector.Version,
Expand All @@ -256,7 +268,7 @@ export class ProcessRunnerDetector {
result.args = ['--no-color'];
}
result.tasks = this.createTaskDescriptions(tasks, problemMatchers, list);
return { config: result, stderr: this._stderr };
return { config: result, stdout: this._stdout, stderr: this._stderr };
}, (err: ErrorData) => {
let error = err.error;
if ((<any>error).code === 'ENOENT') {
Expand All @@ -270,7 +282,7 @@ export class ProcessRunnerDetector {
} else {
this._stderr.push(nls.localize('TaskSystemDetector.noProgram', 'Program {0} was not found. Message is {1}', command, error.message));
}
return { config: null, stderr: this._stderr };
return { config: null, stdout: this._stdout, stderr: this._stderr };
}, (progress) => {
if (progress.source === Source.stderr) {
this._stderr.push(progress.line);
Expand Down Expand Up @@ -304,17 +316,21 @@ export class ProcessRunnerDetector {
this.testTest(taskInfos.test, task, index);
});
if (taskInfos.build.index !== -1) {
let name = tasks[taskInfos.build.index];
this._stdout.push(nls.localize('TaskSystemDetector.buildTaskDetected','Build task named \'{0}\' detected.', name));
taskConfigs.push({
taskName: tasks[taskInfos.build.index],
taskName: name,
args: [],
isBuildCommand: true,
isWatching: false,
problemMatcher: problemMatchers
});
}
if (taskInfos.test.index !== -1) {
let name = tasks[taskInfos.test.index];
this._stdout.push(nls.localize('TaskSystemDetector.testTaskDetected','Test task named \'{0}\' detected.', name));
taskConfigs.push({
taskName: tasks[taskInfos.test.index],
taskName: name,
args: [],
isTestCommand: true
});
Expand Down

0 comments on commit a3209b5

Please sign in to comment.