| 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 /** | 5 /** |
| 6 * Helper functionality to make working with IO easier. | 6 * Helper functionality to make working with IO easier. |
| 7 */ | 7 */ |
| 8 library io; | 8 library io; |
| 9 | 9 |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 } | 494 } |
| 495 | 495 |
| 496 final options = new ProcessOptions(); | 496 final options = new ProcessOptions(); |
| 497 if (workingDir != null) { | 497 if (workingDir != null) { |
| 498 options.workingDirectory = _getDirectory(workingDir).path; | 498 options.workingDirectory = _getDirectory(workingDir).path; |
| 499 } | 499 } |
| 500 options.environment = environment; | 500 options.environment = environment; |
| 501 | 501 |
| 502 var future = Process.run(executable, args, options); | 502 var future = Process.run(executable, args, options); |
| 503 return future.transform((result) { | 503 return future.transform((result) { |
| 504 return new PubProcessResult(result.stdout, result.stderr, result.exitCode); | 504 // TODO(rnystrom): Remove this and change to returning one string. |
| 505 List<String> toLines(String output) { |
| 506 var lines = output.split("\n"); |
| 507 if (!lines.isEmpty() && lines.last() == "") lines.removeLast(); |
| 508 return lines; |
| 509 } |
| 510 return new PubProcessResult(toLines(result.stdout), |
| 511 toLines(result.stderr), |
| 512 result.exitCode); |
| 505 }); | 513 }); |
| 506 } | 514 } |
| 507 | 515 |
| 508 /** | 516 /** |
| 509 * Wraps [input] to provide a timeout. If [input] completes before | 517 * Wraps [input] to provide a timeout. If [input] completes before |
| 510 * [milliseconds] have passed, then the return value completes in the same way. | 518 * [milliseconds] have passed, then the return value completes in the same way. |
| 511 * However, if [milliseconds] pass before [input] has completed, it completes | 519 * However, if [milliseconds] pass before [input] has completed, it completes |
| 512 * with a [TimeoutException] with [message]. | 520 * with a [TimeoutException] with [message]. |
| 513 * | 521 * |
| 514 * Note that timing out will not cancel the asynchronous operation behind | 522 * Note that timing out will not cancel the asynchronous operation behind |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 return new Directory(entry); | 753 return new Directory(entry); |
| 746 } | 754 } |
| 747 | 755 |
| 748 /** | 756 /** |
| 749 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 757 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
| 750 */ | 758 */ |
| 751 Uri _getUri(uri) { | 759 Uri _getUri(uri) { |
| 752 if (uri is Uri) return uri; | 760 if (uri is Uri) return uri; |
| 753 return new Uri.fromString(uri); | 761 return new Uri.fromString(uri); |
| 754 } | 762 } |
| OLD | NEW |