提交 a3209b5e 编写于 作者: D Dirk Baeumer

Fixes #4177 ('Auto detecting the task system failed' can be more user...

Fixes #4177 ('Auto detecting the task system failed' can be more user friendly) and #3304 (Configure task runner should only open output if autodetection fails or provides output.)
上级 fcb8e57b
......@@ -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"]',
......
......@@ -182,6 +182,8 @@ 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;
......@@ -189,9 +191,12 @@ class ConfigureTaskRunnerAction extends Action {
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 = [
'{',
......
......@@ -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';
......@@ -135,6 +141,7 @@ 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;
......@@ -142,13 +149,18 @@ export class ProcessRunnerDetector {
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);
......@@ -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) {
......@@ -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 {
......@@ -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 };
});
});
});
......@@ -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) => {
......@@ -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,
......@@ -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') {
......@@ -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);
......@@ -304,8 +316,10 @@ 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,
......@@ -313,8 +327,10 @@ export class ProcessRunnerDetector {
});
}
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
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册