| 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 RunProcessTask(this._commandTemplate, this._argumentTemplates, this._timeout); |
| 12 this._commandTemplate = commandTemplate; | |
| 13 this._argumentTemplates = argumentTemplates; | |
| 14 this._timeout = timeout; | |
| 15 } | |
| 16 | 12 |
| 17 RunProcessTask(); | 13 execute(Path testfile, List stdout, List stderr, bool logging, |
| 18 | |
| 19 void execute(Path testfile, List stdout, List stderr, bool logging, | |
| 20 Function exitHandler) { | 14 Function exitHandler) { |
| 21 var cmd = expandMacros(_commandTemplate, testfile); | 15 var cmd = expandMacros(_commandTemplate, testfile); |
| 22 List args = new List(); | 16 List args = new List(); |
| 23 for (var i = 0; i < _argumentTemplates.length; i++) { | 17 for (var i = 0; i < _argumentTemplates.length; i++) { |
| 24 args.add(expandMacros(_argumentTemplates[i], testfile)); | 18 args.add(expandMacros(_argumentTemplates[i], testfile)); |
| 25 } | 19 } |
| 26 | 20 |
| 27 if (logging) { | 21 if (logging) { |
| 28 stdout.add('Running $cmd ${Strings.join(args, " ")}'); | 22 stdout.add('Running $cmd ${Strings.join(args, " ")}'); |
| 29 } | 23 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 48 print(" Error: $e"); | 42 print(" Error: $e"); |
| 49 exitHandler(-1); | 43 exitHandler(-1); |
| 50 }; | 44 }; |
| 51 | 45 |
| 52 StringInputStream stdoutStringStream = | 46 StringInputStream stdoutStringStream = |
| 53 new StringInputStream(process.stdout); | 47 new StringInputStream(process.stdout); |
| 54 StringInputStream stderrStringStream = | 48 StringInputStream stderrStringStream = |
| 55 new StringInputStream(process.stderr); | 49 new StringInputStream(process.stderr); |
| 56 stdoutStringStream.onLine = makeReadHandler(stdoutStringStream, stdout); | 50 stdoutStringStream.onLine = makeReadHandler(stdoutStringStream, stdout); |
| 57 stderrStringStream.onLine = makeReadHandler(stderrStringStream, stderr); | 51 stderrStringStream.onLine = makeReadHandler(stderrStringStream, stderr); |
| 52 return process; |
| 58 } | 53 } |
| 59 | 54 |
| 60 Function makeReadHandler(StringInputStream source, List<String> destination) { | 55 Function makeReadHandler(StringInputStream source, List<String> destination) { |
| 61 return () { | 56 return () { |
| 62 if (source.closed) return; | 57 if (source.closed) return; |
| 63 var line = source.readLine(); | 58 var line = source.readLine(); |
| 64 while (null != line) { | 59 while (null != line) { |
| 65 if (config.immediateOutput && line.startsWith('###')) { | 60 if (config.immediateOutput && line.startsWith('###')) { |
| 66 _outStream.writeString(line.substring(3)); | 61 _outStream.writeString(line.substring(3)); |
| 67 _outStream.writeString('\n'); | 62 _outStream.writeString('\n'); |
| 68 } else { | 63 } else { |
| 69 destination.add(line); | 64 destination.add(line); |
| 70 } | 65 } |
| 71 line = source.readLine(); | 66 line = source.readLine(); |
| 72 } | 67 } |
| 73 }; | 68 }; |
| 74 } | 69 } |
| 75 } | 70 } |
| OLD | NEW |