| 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'); |
| 11 #import('dart:uri'); | 11 #import('dart:uri'); |
| 12 | 12 |
| 13 /** Gets the current working directory. */ | 13 /** Gets the current working directory. */ |
| 14 String get workingDir() => new File('.').fullPathSync(); | 14 String get workingDir => new File('.').fullPathSync(); |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * Prints the given string to `stderr` on its own line. | 17 * Prints the given string to `stderr` on its own line. |
| 18 */ | 18 */ |
| 19 void printError(value) { | 19 void printError(value) { |
| 20 stderr.writeString(value.toString()); | 20 stderr.writeString(value.toString()); |
| 21 stderr.writeString('\n'); | 21 stderr.writeString('\n'); |
| 22 } | 22 } |
| 23 | 23 |
| 24 /** | 24 /** |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 }; | 398 }; |
| 399 | 399 |
| 400 process.onError = (error) => completer.completeException(error); | 400 process.onError = (error) => completer.completeException(error); |
| 401 | 401 |
| 402 return completer.future; | 402 return completer.future; |
| 403 } | 403 } |
| 404 | 404 |
| 405 /** | 405 /** |
| 406 * Tests whether or not the git command-line app is available for use. | 406 * Tests whether or not the git command-line app is available for use. |
| 407 */ | 407 */ |
| 408 Future<bool> get isGitInstalled() { | 408 Future<bool> get isGitInstalled { |
| 409 // TODO(rnystrom): We could cache this after the first check. We aren't right | 409 // TODO(rnystrom): We could cache this after the first check. We aren't right |
| 410 // now because Future.immediate() will invoke its callback synchronously. | 410 // now because Future.immediate() will invoke its callback synchronously. |
| 411 // That does bad things in cases where the caller expects futures to always | 411 // That does bad things in cases where the caller expects futures to always |
| 412 // be async. In particular, withGit() in the pub tests which calls | 412 // be async. In particular, withGit() in the pub tests which calls |
| 413 // expectAsync() will fail horribly if the test isn't actually async. | 413 // expectAsync() will fail horribly if the test isn't actually async. |
| 414 | 414 |
| 415 var completer = new Completer<bool>(); | 415 var completer = new Completer<bool>(); |
| 416 | 416 |
| 417 // If "git --version" prints something familiar, git is working. | 417 // If "git --version" prints something familiar, git is working. |
| 418 var future = runProcess("git", ["--version"]); | 418 var future = runProcess("git", ["--version"]); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 /** | 453 /** |
| 454 * Contains the results of invoking a [Process] and waiting for it to complete. | 454 * Contains the results of invoking a [Process] and waiting for it to complete. |
| 455 */ | 455 */ |
| 456 class PubProcessResult { | 456 class PubProcessResult { |
| 457 final List<String> stdout; | 457 final List<String> stdout; |
| 458 final List<String> stderr; | 458 final List<String> stderr; |
| 459 final int exitCode; | 459 final int exitCode; |
| 460 | 460 |
| 461 const PubProcessResult(this.stdout, this.stderr, this.exitCode); | 461 const PubProcessResult(this.stdout, this.stderr, this.exitCode); |
| 462 | 462 |
| 463 bool get success() => exitCode == 0; | 463 bool get success => exitCode == 0; |
| 464 } | 464 } |
| 465 | 465 |
| 466 /** | 466 /** |
| 467 * Gets the path string for [entry], which can either already be a path string, | 467 * Gets the path string for [entry], which can either already be a path string, |
| 468 * or be a [File] or [Directory]. Allows working generically with "file-like" | 468 * or be a [File] or [Directory]. Allows working generically with "file-like" |
| 469 * objects. | 469 * objects. |
| 470 */ | 470 */ |
| 471 String _getPath(entry) { | 471 String _getPath(entry) { |
| 472 if (entry is String) return entry; | 472 if (entry is String) return entry; |
| 473 if (entry is File) return entry.name; | 473 if (entry is File) return entry.name; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 484 return new Directory(entry); | 484 return new Directory(entry); |
| 485 } | 485 } |
| 486 | 486 |
| 487 /** | 487 /** |
| 488 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 488 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
| 489 */ | 489 */ |
| 490 Uri _getUri(uri) { | 490 Uri _getUri(uri) { |
| 491 if (uri is Uri) return uri; | 491 if (uri is Uri) return uri; |
| 492 return new Uri.fromString(uri); | 492 return new Uri.fromString(uri); |
| 493 } | 493 } |
| OLD | NEW |