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 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 /** | 474 /** |
475 * Spawns and runs the process located at [executable], passing in [args]. | 475 * Spawns and runs the process located at [executable], passing in [args]. |
476 * Returns a [Future] that will complete the results of the process after it | 476 * Returns a [Future] that will complete the results of the process after it |
477 * has ended. | 477 * has ended. |
478 * | 478 * |
479 * If [pipeStdout] and/or [pipeStderr] are set, all output from the subprocess's | 479 * If [pipeStdout] and/or [pipeStderr] are set, all output from the subprocess's |
480 * output streams are sent to the parent process's output streams. Output from | 480 * output streams are sent to the parent process's output streams. Output from |
481 * piped streams won't be available in the result object. | 481 * piped streams won't be available in the result object. |
482 */ | 482 */ |
483 Future<PubProcessResult> runProcess(String executable, List<String> args, | 483 Future<PubProcessResult> runProcess(String executable, List<String> args, |
484 [workingDir, Map<String, String> environment, bool pipeStdout = false, | 484 {workingDir, Map<String, String> environment, bool pipeStdout: false, |
485 bool pipeStderr = false]) { | 485 bool pipeStderr: false}) { |
486 int exitCode; | 486 int exitCode; |
487 | 487 |
488 // TODO(rnystrom): Should dart:io just handle this? | 488 // TODO(rnystrom): Should dart:io just handle this? |
489 // Spawning a process on Windows will not look for the executable in the | 489 // Spawning a process on Windows will not look for the executable in the |
490 // system path. So, if executable looks like it needs that (i.e. it doesn't | 490 // system path. So, if executable looks like it needs that (i.e. it doesn't |
491 // have any path separators in it), then spawn it through a shell. | 491 // have any path separators in it), then spawn it through a shell. |
492 if ((Platform.operatingSystem == "windows") && | 492 if ((Platform.operatingSystem == "windows") && |
493 (executable.indexOf('\\') == -1)) { | 493 (executable.indexOf('\\') == -1)) { |
494 args = flatten(["/c", executable, args]); | 494 args = flatten(["/c", executable, args]); |
495 executable = "cmd"; | 495 executable = "cmd"; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 if (_isGitInstalledCache != null) { | 549 if (_isGitInstalledCache != null) { |
550 // TODO(rnystrom): The sleep is to pump the message queue. Can use | 550 // TODO(rnystrom): The sleep is to pump the message queue. Can use |
551 // Future.immediate() when #3356 is fixed. | 551 // Future.immediate() when #3356 is fixed. |
552 return sleep(0).transform((_) => _isGitInstalledCache); | 552 return sleep(0).transform((_) => _isGitInstalledCache); |
553 } | 553 } |
554 | 554 |
555 return _gitCommand.transform((git) => git != null); | 555 return _gitCommand.transform((git) => git != null); |
556 } | 556 } |
557 | 557 |
558 /// Run a git process with [args] from [workingDir]. | 558 /// Run a git process with [args] from [workingDir]. |
559 Future<PubProcessResult> runGit(List<String> args, [String workingDir]) => | 559 Future<PubProcessResult> runGit(List<String> args, {String workingDir}) => |
560 _gitCommand.chain((git) => runProcess(git, args, workingDir)); | 560 _gitCommand.chain((git) => runProcess(git, args, workingDir: workingDir)); |
561 | 561 |
562 /// Returns the name of the git command-line app, or null if Git could not be | 562 /// Returns the name of the git command-line app, or null if Git could not be |
563 /// found on the user's PATH. | 563 /// found on the user's PATH. |
564 Future<String> get _gitCommand { | 564 Future<String> get _gitCommand { |
565 // TODO(nweiz): Just use Future.immediate once issue 3356 is fixed. | 565 // TODO(nweiz): Just use Future.immediate once issue 3356 is fixed. |
566 if (_gitCommandCache != null) { | 566 if (_gitCommandCache != null) { |
567 return sleep(0).transform((_) => _gitCommandCache); | 567 return sleep(0).transform((_) => _gitCommandCache); |
568 } | 568 } |
569 | 569 |
570 return _tryGitCommand("git").chain((success) { | 570 return _tryGitCommand("git").chain((success) { |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 return new Directory(entry); | 755 return new Directory(entry); |
756 } | 756 } |
757 | 757 |
758 /** | 758 /** |
759 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 759 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
760 */ | 760 */ |
761 Uri _getUri(uri) { | 761 Uri _getUri(uri) { |
762 if (uri is Uri) return uri; | 762 if (uri is Uri) return uri; |
763 return new Uri.fromString(uri); | 763 return new Uri.fromString(uri); |
764 } | 764 } |
OLD | NEW |