Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: pkg/scheduled_test/lib/scheduled_process.dart

Issue 22872012: Remove Encoding-enum from dart:io and add interface in dart:convert. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix ddbg. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library scheduled_test.scheduled_process; 5 library scheduled_test.scheduled_process;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:io'; 9 import 'dart:io';
10 10
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 /// [Process.start]. [description] is a string description of this process; it 75 /// [Process.start]. [description] is a string description of this process; it
76 /// defaults to the command-line invocation. [encoding] is the [Encoding] that 76 /// defaults to the command-line invocation. [encoding] is the [Encoding] that
77 /// will be used for the process's input and output. 77 /// will be used for the process's input and output.
78 /// 78 ///
79 /// [executable], [arguments], [workingDirectory], and [environment] may be 79 /// [executable], [arguments], [workingDirectory], and [environment] may be
80 /// either a [Future] or a concrete value. If any are [Future]s, the process 80 /// either a [Future] or a concrete value. If any are [Future]s, the process
81 /// won't start until the [Future]s have completed. In addition, [arguments] 81 /// won't start until the [Future]s have completed. In addition, [arguments]
82 /// may be a [List] containing a mix of strings and [Future]s. 82 /// may be a [List] containing a mix of strings and [Future]s.
83 ScheduledProcess.start(executable, arguments, 83 ScheduledProcess.start(executable, arguments,
84 {workingDirectory, environment, String description, 84 {workingDirectory, environment, String description,
85 Encoding encoding: Encoding.UTF_8}) 85 Encoding encoding: UTF8})
86 : _encoding = encoding, 86 : _encoding = encoding,
87 _explicitDescription = description != null, 87 _explicitDescription = description != null,
88 _description = description { 88 _description = description {
89 assert(currentSchedule.state == ScheduleState.SET_UP); 89 assert(currentSchedule.state == ScheduleState.SET_UP);
90 90
91 _updateDescription(executable, arguments); 91 _updateDescription(executable, arguments);
92 92
93 _scheduleStartProcess(executable, arguments, workingDirectory, environment); 93 _scheduleStartProcess(executable, arguments, workingDirectory, environment);
94 94
95 _scheduleExceptionCleanup(); 95 _scheduleExceptionCleanup();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 ]).then((results) { 145 ]).then((results) {
146 executable = results[0]; 146 executable = results[0];
147 arguments = results[1]; 147 arguments = results[1];
148 workingDirectory = results[2]; 148 workingDirectory = results[2];
149 environment = results[3]; 149 environment = results[3];
150 _updateDescription(executable, arguments); 150 _updateDescription(executable, arguments);
151 return Process.start(executable, 151 return Process.start(executable,
152 arguments, 152 arguments,
153 workingDirectory: workingDirectory, 153 workingDirectory: workingDirectory,
154 environment: environment).then((process) { 154 environment: environment).then((process) {
155 process.stdin.encoding = Encoding.UTF_8; 155 process.stdin.encoding = UTF8;
156 return process; 156 return process;
157 }); 157 });
158 }); 158 });
159 }, "starting process '$description'")); 159 }, "starting process '$description'"));
160 } 160 }
161 161
162 /// Listens for [_process] to exit and passes the exit code to 162 /// Listens for [_process] to exit and passes the exit code to
163 /// [exitCodeCompleter]. If the process completes earlier than expected, an 163 /// [exitCodeCompleter]. If the process completes earlier than expected, an
164 /// exception will be signaled to the schedule. 164 /// exception will be signaled to the schedule.
165 void _handleExit(Completer exitCodeCompleter) { 165 void _handleExit(Completer exitCodeCompleter) {
(...skipping 30 matching lines...) Expand all
196 Pair<Stream<String>, StreamCanceller> _lineStreamWithCanceller( 196 Pair<Stream<String>, StreamCanceller> _lineStreamWithCanceller(
197 Future<Stream<List<int>>> streamFuture) { 197 Future<Stream<List<int>>> streamFuture) {
198 return streamWithCanceller(futureStream(streamFuture) 198 return streamWithCanceller(futureStream(streamFuture)
199 .handleError((e) => currentSchedule.signalError(e)) 199 .handleError((e) => currentSchedule.signalError(e))
200 .map((chunk) { 200 .map((chunk) {
201 // Whenever the process produces any sort of output, reset the schedule's 201 // Whenever the process produces any sort of output, reset the schedule's
202 // timer. 202 // timer.
203 currentSchedule.heartbeat(); 203 currentSchedule.heartbeat();
204 return chunk; 204 return chunk;
205 }) 205 })
206 .transform(new StringDecoder(_encoding)) 206 .transform(_encoding.decoder)
207 .transform(new LineSplitter())); 207 .transform(new LineSplitter()));
208 } 208 }
209 209
210 /// Schedule an exception handler that will clean up the process and provide 210 /// Schedule an exception handler that will clean up the process and provide
211 /// debug information if an error occurs. 211 /// debug information if an error occurs.
212 void _scheduleExceptionCleanup() { 212 void _scheduleExceptionCleanup() {
213 currentSchedule.onException.schedule(() { 213 currentSchedule.onException.schedule(() {
214 _stdoutCanceller(); 214 _stdoutCanceller();
215 _stderrCanceller(); 215 _stderrCanceller();
216 216
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 schedule(() { 344 schedule(() {
345 _endExpected = true; 345 _endExpected = true;
346 return _exitCode.then((exitCode) { 346 return _exitCode.then((exitCode) {
347 if (expectedExitCode != null) { 347 if (expectedExitCode != null) {
348 expect(exitCode, equals(expectedExitCode)); 348 expect(exitCode, equals(expectedExitCode));
349 } 349 }
350 }); 350 });
351 }, "waiting for process '$description' to exit"); 351 }, "waiting for process '$description' to exit");
352 } 352 }
353 } 353 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698