Skip to content

Commit eae1b66

Browse files
committed
tasks: adopt configurationResolverService
1 parent 724c4ce commit eae1b66

4 files changed

Lines changed: 51 additions & 52 deletions

File tree

src/vs/base/common/processes.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import * as Platform from 'vs/base/common/platform';
1111
import { IStringDictionary } from 'vs/base/common/collections';
1212
import * as Types from 'vs/base/common/types';
1313

14-
import { ValidationStatus, ValidationState, ILogger, Parser, ISystemVariables } from 'vs/base/common/parsers';
15-
14+
import { ValidationStatus, ValidationState, ILogger, Parser } from 'vs/base/common/parsers';
1615

1716
/**
1817
* Options to be passed to the external program or shell.
@@ -252,24 +251,3 @@ export class ExecutableParser extends Parser {
252251
return executable;
253252
}
254253
}
255-
256-
export function resolveCommandOptions(options: CommandOptions, variables: ISystemVariables): CommandOptions {
257-
let result = Objects.clone(options);
258-
if (result.cwd) {
259-
result.cwd = variables.resolve(result.cwd);
260-
}
261-
if (result.env) {
262-
result.env = variables.resolve(result.env);
263-
}
264-
return result;
265-
}
266-
267-
export function resolveExecutable(executable: Executable, variables: ISystemVariables): Executable {
268-
let result = Objects.clone(executable);
269-
result.command = variables.resolve(result.command);
270-
result.args = variables.resolve(result.args);
271-
if (result.options) {
272-
result.options = resolveCommandOptions(result.options, variables);
273-
}
274-
return result;
275-
}

src/vs/workbench/parts/tasks/electron-browser/task.contribution.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
5454
import Constants from 'vs/workbench/parts/markers/common/constants';
5555
import { IPartService } from 'vs/workbench/services/part/common/partService';
5656
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
57+
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
5758
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
5859

59-
import { ConfigVariables } from 'vs/workbench/parts/lib/node/configVariables';
6060
import { ITextFileService } from 'vs/workbench/parts/files/common/files';
6161
import { IOutputService, IOutputChannelRegistry, Extensions as OutputExt, IOutputChannel } from 'vs/workbench/parts/output/common/output';
6262

@@ -184,7 +184,8 @@ abstract class OpenTaskConfigurationAction extends Action {
184184
@IWorkbenchEditorService editorService: IWorkbenchEditorService, @IFileService fileService: IFileService,
185185
@IWorkspaceContextService contextService: IWorkspaceContextService, @IOutputService outputService: IOutputService,
186186
@IMessageService messageService: IMessageService, @IQuickOpenService quickOpenService: IQuickOpenService,
187-
@IEnvironmentService private environmentService: IEnvironmentService) {
187+
@IEnvironmentService private environmentService: IEnvironmentService,
188+
@IConfigurationResolverService private configurationResolverService: IConfigurationResolverService) {
188189

189190
super(id, label);
190191
this.configurationService = configurationService;
@@ -216,7 +217,7 @@ abstract class OpenTaskConfigurationAction extends Action {
216217
const outputChannel = this.outputService.getChannel(TaskService.OutputChannelId);
217218
outputChannel.show();
218219
outputChannel.append(nls.localize('ConfigureTaskRunnerAction.autoDetecting', 'Auto detecting tasks for {0}', selection.id) + '\n');
219-
let detector = new ProcessRunnerDetector(this.fileService, this.contextService, new ConfigVariables(this.configurationService, this.editorService, this.contextService, this.environmentService));
220+
let detector = new ProcessRunnerDetector(this.fileService, this.contextService, this.configurationResolverService);
220221
contentPromise = detector.detect(false, selection.id).then((value) => {
221222
let config = value.config;
222223
if (value.stderr && value.stderr.length > 0) {
@@ -278,9 +279,10 @@ class ConfigureTaskRunnerAction extends OpenTaskConfigurationAction {
278279
@IWorkbenchEditorService editorService: IWorkbenchEditorService, @IFileService fileService: IFileService,
279280
@IWorkspaceContextService contextService: IWorkspaceContextService, @IOutputService outputService: IOutputService,
280281
@IMessageService messageService: IMessageService, @IQuickOpenService quickOpenService: IQuickOpenService,
281-
@IEnvironmentService environmentService: IEnvironmentService) {
282+
@IEnvironmentService environmentService: IEnvironmentService,
283+
@IConfigurationResolverService configurationResolverService: IConfigurationResolverService) {
282284
super(id, label, configurationService, editorService, fileService, contextService,
283-
outputService, messageService, quickOpenService, environmentService);
285+
outputService, messageService, quickOpenService, environmentService, configurationResolverService);
284286
}
285287

286288
}
@@ -293,9 +295,10 @@ class ConfigureBuildTaskAction extends OpenTaskConfigurationAction {
293295
@IWorkbenchEditorService editorService: IWorkbenchEditorService, @IFileService fileService: IFileService,
294296
@IWorkspaceContextService contextService: IWorkspaceContextService, @IOutputService outputService: IOutputService,
295297
@IMessageService messageService: IMessageService, @IQuickOpenService quickOpenService: IQuickOpenService,
296-
@IEnvironmentService environmentService: IEnvironmentService) {
298+
@IEnvironmentService environmentService: IEnvironmentService,
299+
@IConfigurationResolverService configurationResolverService: IConfigurationResolverService) {
297300
super(id, label, configurationService, editorService, fileService, contextService,
298-
outputService, messageService, quickOpenService, environmentService);
301+
outputService, messageService, quickOpenService, environmentService, configurationResolverService);
299302
}
300303
}
301304

@@ -628,7 +631,8 @@ class TaskService extends EventEmitter implements ITaskService {
628631
@ILifecycleService lifecycleService: ILifecycleService, @IEventService eventService: IEventService,
629632
@IModelService modelService: IModelService, @IExtensionService extensionService: IExtensionService,
630633
@IQuickOpenService quickOpenService: IQuickOpenService,
631-
@IEnvironmentService private environmentService: IEnvironmentService) {
634+
@IEnvironmentService private environmentService: IEnvironmentService,
635+
@IConfigurationResolverService private configurationResolverService: IConfigurationResolverService) {
632636

633637
super();
634638
this.modeService = modeService;
@@ -680,7 +684,6 @@ class TaskService extends EventEmitter implements ITaskService {
680684
this._taskSystem = new NullTaskSystem();
681685
this._taskSystemPromise = TPromise.as(this._taskSystem);
682686
} else {
683-
let variables = new ConfigVariables(this.configurationService, this.editorService, this.contextService, this.environmentService);
684687
let clearOutput = true;
685688
this._taskSystemPromise = TPromise.as(this.configurationService.getConfiguration<TaskConfiguration>('tasks')).then((config: TaskConfiguration) => {
686689
let parseErrors: string[] = config ? (<any>config).$parseErrors : null;
@@ -702,7 +705,7 @@ class TaskService extends EventEmitter implements ITaskService {
702705
if (config) {
703706
if (this.isRunnerConfig(config) && this.hasDetectorSupport(<FileConfig.ExternalTaskRunnerConfiguration>config)) {
704707
let fileConfig = <FileConfig.ExternalTaskRunnerConfiguration>config;
705-
configPromise = new ProcessRunnerDetector(this.fileService, this.contextService, variables, fileConfig).detect(true).then((value) => {
708+
configPromise = new ProcessRunnerDetector(this.fileService, this.contextService, this.configurationResolverService, fileConfig).detect(true).then((value) => {
706709
clearOutput = this.printStderr(value.stderr);
707710
let detectedConfig = value.config;
708711
if (!detectedConfig) {
@@ -728,7 +731,7 @@ class TaskService extends EventEmitter implements ITaskService {
728731
configPromise = TPromise.as<TaskConfiguration>(config);
729732
}
730733
} else {
731-
configPromise = new ProcessRunnerDetector(this.fileService, this.contextService, variables).detect(true).then((value) => {
734+
configPromise = new ProcessRunnerDetector(this.fileService, this.contextService, this.configurationResolverService).detect(true).then((value) => {
732735
clearOutput = this.printStderr(value.stderr);
733736
return value.config;
734737
});
@@ -742,7 +745,7 @@ class TaskService extends EventEmitter implements ITaskService {
742745
if (config.buildSystem === 'service') {
743746
result = new LanguageServiceTaskSystem(<LanguageServiceTaskConfiguration>config, this.telemetryService, this.modeService);
744747
} else if (this.isRunnerConfig(config)) {
745-
result = new ProcessRunnerSystem(<FileConfig.ExternalTaskRunnerConfiguration>config, variables, this.markerService, this.modelService, this.telemetryService, this.outputService, TaskService.OutputChannelId, clearOutput);
748+
result = new ProcessRunnerSystem(<FileConfig.ExternalTaskRunnerConfiguration>config, this.markerService, this.modelService, this.telemetryService, this.outputService, this.configurationResolverService, TaskService.OutputChannelId, clearOutput);
746749
}
747750
if (result === null) {
748751
this._taskSystemPromise = null;
@@ -788,13 +791,13 @@ class TaskService extends EventEmitter implements ITaskService {
788791
public configureAction(): Action {
789792
return new ConfigureTaskRunnerAction(ConfigureTaskRunnerAction.ID, ConfigureTaskRunnerAction.TEXT,
790793
this.configurationService, this.editorService, this.fileService, this.contextService,
791-
this.outputService, this.messageService, this.quickOpenService, this.environmentService);
794+
this.outputService, this.messageService, this.quickOpenService, this.environmentService, this.configurationResolverService);
792795
}
793796

794797
private configureBuildTask(): Action {
795798
return new ConfigureBuildTaskAction(ConfigureBuildTaskAction.ID, ConfigureBuildTaskAction.TEXT,
796799
this.configurationService, this.editorService, this.fileService, this.contextService,
797-
this.outputService, this.messageService, this.quickOpenService, this.environmentService);
800+
this.outputService, this.messageService, this.quickOpenService, this.environmentService, this.configurationResolverService);
798801
}
799802

800803
public build(): TPromise<ITaskSummary> {

src/vs/workbench/parts/tasks/node/processRunnerDetector.ts

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@
55
'use strict';
66

77
import nls = require('vs/nls');
8+
import * as Objects from 'vs/base/common/objects';
9+
import * as Paths from 'vs/base/common/paths';
810
import { TPromise } from 'vs/base/common/winjs.base';
911
import Strings = require('vs/base/common/strings');
1012
import Collections = require('vs/base/common/collections');
1113

12-
import { CommandOptions, resolveCommandOptions, Source, ErrorData } from 'vs/base/common/processes';
14+
import { CommandOptions, Source, ErrorData } from 'vs/base/common/processes';
1315
import { LineProcess } from 'vs/base/node/processes';
1416

1517
import { IFileService } from 'vs/platform/files/common/files';
1618

17-
import { SystemVariables } from 'vs/workbench/parts/lib/node/systemVariables';
19+
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
20+
1821
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
1922

2023
import * as FileConfig from './processRunnerConfiguration';
@@ -139,18 +142,21 @@ export class ProcessRunnerDetector {
139142

140143
private fileService: IFileService;
141144
private contextService: IWorkspaceContextService;
142-
private variables: SystemVariables;
145+
private configurationResolverService: IConfigurationResolverService;
143146
private taskConfiguration: FileConfig.ExternalTaskRunnerConfiguration;
144147
private _stderr: string[];
145148
private _stdout: string[];
149+
private _cwd: string;
146150

147-
constructor(fileService: IFileService, contextService: IWorkspaceContextService, variables:SystemVariables, config: FileConfig.ExternalTaskRunnerConfiguration = null) {
151+
constructor(fileService: IFileService, contextService: IWorkspaceContextService, configurationResolverService: IConfigurationResolverService, config: FileConfig.ExternalTaskRunnerConfiguration = null) {
148152
this.fileService = fileService;
149153
this.contextService = contextService;
150-
this.variables = variables;
154+
this.configurationResolverService = configurationResolverService;
151155
this.taskConfiguration = config;
152156
this._stderr = [];
153157
this._stdout = [];
158+
const workspace = this.contextService.getWorkspace();
159+
this._cwd = workspace ? Paths.normalize(workspace.resource.fsPath, true) : '';
154160
}
155161

156162
public get stderr(): string[] {
@@ -165,10 +171,10 @@ export class ProcessRunnerDetector {
165171
if (this.taskConfiguration && this.taskConfiguration.command && ProcessRunnerDetector.supports(this.taskConfiguration.command)) {
166172
let config = ProcessRunnerDetector.detectorConfig(this.taskConfiguration.command);
167173
let args = (this.taskConfiguration.args || []).concat(config.arg);
168-
let options: CommandOptions = this.taskConfiguration.options ? resolveCommandOptions(this.taskConfiguration.options, this.variables) : { cwd: this.variables.workspaceRoot };
174+
let options: CommandOptions = this.taskConfiguration.options ? this.resolveCommandOptions(this.taskConfiguration.options) : { cwd: this._cwd };
169175
let isShellCommand = !!this.taskConfiguration.isShellCommand;
170176
return this.runDetection(
171-
new LineProcess(this.taskConfiguration.command, this.variables.resolve(args), isShellCommand, options),
177+
new LineProcess(this.taskConfiguration.command, this.configurationResolverService.resolve(args), isShellCommand, options),
172178
this.taskConfiguration.command, isShellCommand, config.matcher, ProcessRunnerDetector.DefaultProblemMatchers, list);
173179
} else {
174180
if (detectSpecific) {
@@ -208,10 +214,21 @@ export class ProcessRunnerDetector {
208214
}
209215
}
210216

217+
private resolveCommandOptions(options: CommandOptions): CommandOptions {
218+
let result = Objects.clone(options);
219+
if (result.cwd) {
220+
result.cwd = this.configurationResolverService.resolve(result.cwd);
221+
}
222+
if (result.env) {
223+
result.env = this.configurationResolverService.resolve(result.env);
224+
}
225+
return result;
226+
}
227+
211228
private tryDetectGulp(list:boolean): TPromise<{ config: FileConfig.ExternalTaskRunnerConfiguration; stderr: string[]; }> {
212229
return this.fileService.resolveFile(this.contextService.toResource('gulpfile.js')).then((stat) => {
213230
let config = ProcessRunnerDetector.detectorConfig('gulp');
214-
let process = new LineProcess('gulp', [config.arg, '--no-color'], true, {cwd: this.variables.workspaceRoot});
231+
let process = new LineProcess('gulp', [config.arg, '--no-color'], true, {cwd: this._cwd});
215232
return this.runDetection(process, 'gulp', true, config.matcher, ProcessRunnerDetector.DefaultProblemMatchers, list);
216233
}, (err: any): FileConfig.ExternalTaskRunnerConfiguration => {
217234
return null;
@@ -221,7 +238,7 @@ export class ProcessRunnerDetector {
221238
private tryDetectGrunt(list:boolean): TPromise<{ config: FileConfig.ExternalTaskRunnerConfiguration; stderr: string[]; }> {
222239
return this.fileService.resolveFile(this.contextService.toResource('Gruntfile.js')).then((stat) => {
223240
let config = ProcessRunnerDetector.detectorConfig('grunt');
224-
let process = new LineProcess('grunt', [config.arg, '--no-color'], true, {cwd: this.variables.workspaceRoot});
241+
let process = new LineProcess('grunt', [config.arg, '--no-color'], true, {cwd: this._cwd});
225242
return this.runDetection(process, 'grunt', true, config.matcher, ProcessRunnerDetector.DefaultProblemMatchers, list);
226243
}, (err: any): FileConfig.ExternalTaskRunnerConfiguration => {
227244
return null;
@@ -231,7 +248,7 @@ export class ProcessRunnerDetector {
231248
private tryDetectJake(list:boolean): TPromise<{ config: FileConfig.ExternalTaskRunnerConfiguration; stderr: string[]; }> {
232249
let run = () => {
233250
let config = ProcessRunnerDetector.detectorConfig('jake');
234-
let process = new LineProcess('jake', [config.arg], true, {cwd: this.variables.workspaceRoot});
251+
let process = new LineProcess('jake', [config.arg], true, {cwd: this._cwd});
235252
return this.runDetection(process, 'jake', true, config.matcher, ProcessRunnerDetector.DefaultProblemMatchers, list);
236253
};
237254
return this.fileService.resolveFile(this.contextService.toResource('Jakefile')).then((stat) => {

src/vs/workbench/parts/tasks/node/processRunnerSystem.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { TerminateResponse, SuccessData, ErrorData } from 'vs/base/common/proces
1818
import { LineProcess, LineData } from 'vs/base/node/processes';
1919

2020
import { IOutputService, IOutputChannel } from 'vs/workbench/parts/output/common/output';
21-
import { ISystemVariables } from 'vs/base/common/parsers';
21+
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
2222

2323
import { IMarkerService } from 'vs/platform/markers/common/markers';
2424
import { ValidationStatus } from 'vs/base/common/parsers';
@@ -37,11 +37,11 @@ export class ProcessRunnerSystem extends EventEmitter implements ITaskSystem {
3737
public static TelemetryEventName: string = 'taskService';
3838

3939
private fileConfig: FileConfig.ExternalTaskRunnerConfiguration;
40-
private variables: ISystemVariables;
4140
private markerService: IMarkerService;
4241
private modelService: IModelService;
4342
private outputService: IOutputService;
4443
private telemetryService: ITelemetryService;
44+
private configurationResolverService: IConfigurationResolverService;
4545

4646
private validationStatus: ValidationStatus;
4747
private defaultBuildTaskIdentifier: string;
@@ -54,14 +54,15 @@ export class ProcessRunnerSystem extends EventEmitter implements ITaskSystem {
5454
private activeTaskIdentifier: string;
5555
private activeTaskPromise: TPromise<ITaskSummary>;
5656

57-
constructor(fileConfig:FileConfig.ExternalTaskRunnerConfiguration, variables:ISystemVariables, markerService:IMarkerService, modelService: IModelService, telemetryService: ITelemetryService, outputService:IOutputService, outputChannelId:string, clearOutput: boolean = true) {
57+
constructor(fileConfig: FileConfig.ExternalTaskRunnerConfiguration, markerService: IMarkerService, modelService: IModelService, telemetryService: ITelemetryService,
58+
outputService: IOutputService, configurationResolverService: IConfigurationResolverService, outputChannelId: string, clearOutput: boolean = true) {
5859
super();
5960
this.fileConfig = fileConfig;
60-
this.variables = variables;
6161
this.markerService = markerService;
6262
this.modelService = modelService;
6363
this.outputService = outputService;
6464
this.telemetryService = telemetryService;
65+
this.configurationResolverService = configurationResolverService;
6566

6667
this.defaultBuildTaskIdentifier = null;
6768
this.defaultTestTaskIdentifier = null;
@@ -405,7 +406,7 @@ export class ProcessRunnerSystem extends EventEmitter implements ITaskSystem {
405406
}
406407

407408
private resolveVariable(value: string): string {
408-
return this.variables.resolve(value);
409+
return this.configurationResolverService.resolve(value);
409410
}
410411

411412
public log(value: string): void {

0 commit comments

Comments
 (0)