| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** A pipeline task to run a process and capture the output. */ | 5 /** A pipeline task to run a process and capture the output. */ |
| 6 class RunProcessTask extends PipelineTask { | 6 class RunProcessTask extends PipelineTask { |
| 7 String _commandTemplate; | 7 String _commandTemplate; |
| 8 List _argumentTemplates; | 8 List _argumentTemplates; |
| 9 int _timeout; | 9 int _timeout; |
| 10 | 10 |
| 11 void init(String commandTemplate, List argumentTemplates, int timeout) { | 11 void init(String commandTemplate, List argumentTemplates, int timeout) { |
| 12 this._commandTemplate = commandTemplate; | 12 this._commandTemplate = commandTemplate; |
| 13 this._argumentTemplates = argumentTemplates; | 13 this._argumentTemplates = argumentTemplates; |
| 14 this._timeout = timeout; | 14 this._timeout = timeout; |
| 15 } | 15 } |
| 16 | 16 |
| 17 RunProcessTask(); | 17 RunProcessTask(); |
| 18 | 18 |
| 19 void execute(Path testfile, List stdout, List stderr, bool logging, | 19 void execute(Path testfile, List stdout, List stderr, bool logging, |
| 20 Function exitHandler) { | 20 Function exitHandler) { |
| 21 var cmd = expandMacros(_commandTemplate, testfile); | 21 var cmd = expandMacros(_commandTemplate, testfile); |
| 22 List args = new List(); | 22 List args = new List(); |
| 23 for (var i = 0; i < _argumentTemplates.length; i++) { | 23 for (var i = 0; i < _argumentTemplates.length; i++) { |
| 24 args.add(expandMacros(_argumentTemplates[i], testfile)); | 24 args.add(expandMacros(_argumentTemplates[i], testfile)); |
| 25 } | 25 } |
| 26 | |
| 27 if (logging) { | 26 if (logging) { |
| 28 stdout.add('Running $cmd ${Strings.join(args, " ")}'); | 27 stdout.add('Running $cmd ${Strings.join(args, " ")}'); |
| 29 } | 28 } |
| 30 var timer = null; | 29 var timer = null; |
| 31 var process = Process.start(cmd, args); | 30 var process = Process.start(cmd, args); |
| 32 process.onStart = () { | 31 process.onStart = () { |
| 33 timer = new Timer(1000 * _timeout, (t) { | 32 timer = new Timer(1000 * _timeout, (t) { |
| 34 timer = null; | 33 timer = null; |
| 35 process.kill(); | 34 process.kill(); |
| 36 }); | 35 }); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 66 _outStream.writeString(line.substring(3)); | 65 _outStream.writeString(line.substring(3)); |
| 67 _outStream.writeString('\n'); | 66 _outStream.writeString('\n'); |
| 68 } else { | 67 } else { |
| 69 destination.add(line); | 68 destination.add(line); |
| 70 } | 69 } |
| 71 line = source.readLine(); | 70 line = source.readLine(); |
| 72 } | 71 } |
| 73 }; | 72 }; |
| 74 } | 73 } |
| 75 } | 74 } |
| OLD | NEW |