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

Side by Side Diff: utils/pub/io.dart

Issue 10421026: Make pub handle missing git more gracefully. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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) 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('pub_io'); 8 #library('pub_io');
9 9
10 #import('dart:io'); 10 #import('dart:io');
11 11
12 /** Gets the current working directory. */ 12 /** Gets the current working directory. */
13 String get workingDir() => new File('.').fullPathSync(); 13 String get workingDir() => new File('.').fullPathSync();
14 14
15 /** 15 /**
16 * Prints the given string to `stderr` on its own line.
17 */
18 void printError(value) {
19 stderr.writeString(value.toString());
20 stderr.writeString('\n');
21 }
22
23 /**
16 * Joins a number of path string parts into a single path. Handles 24 * Joins a number of path string parts into a single path. Handles
17 * platform-specific path separators. Parts can be [String], [Directory], or 25 * platform-specific path separators. Parts can be [String], [Directory], or
18 * [File] objects. 26 * [File] objects.
19 */ 27 */
20 String join(part1, [part2, part3, part4]) { 28 String join(part1, [part2, part3, part4]) {
21 final parts = _getPath(part1).split('/'); 29 final parts = _getPath(part1).split('/');
22 30
23 for (final part in [part2, part3, part4]) { 31 for (final part in [part2, part3, part4]) {
24 if (part == null) continue; 32 if (part == null) continue;
25 33
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 exitCode = actualExitCode; 320 exitCode = actualExitCode;
313 checkComplete(); 321 checkComplete();
314 }; 322 };
315 323
316 process.onError = (error) => completer.completeException(error); 324 process.onError = (error) => completer.completeException(error);
317 325
318 return completer.future; 326 return completer.future;
319 } 327 }
320 328
321 /** 329 /**
330 * Tests whether or not the git command-line app is available for use.
331 */
332 Future<bool> get isGitInstalled() {
333 // TODO(rnystrom): We could cache this after the first check. We aren't right
334 // now because Future.immediate() will invoke its callback synchronously.
335 // That does bad things in cases where the caller expects futures to always
336 // be async. In particular, withGit() in the pub tests which calls
337 // expectAsync() will fail horribly if the test isn't actually async.
338
339 var completer = new Completer<bool>();
340
341 // If "git --version" prints something familiar, git is working.
342 var future = runProcess("git", ["--version"]);
343
344 future.then((results) {
345 var regex = new RegExp("^git version");
346 completer.complete(results.stdout.length == 1 &&
347 regex.hasMatch(results.stdout[0]));
348 });
349
350 future.handleException((err) {
351 // If the process failed, they probably don't have it.
352 completer.complete(false);
353 return true;
354 });
355
356 return completer.future;
357 }
358
359 /**
322 * Contains the results of invoking a [Process] and waiting for it to complete. 360 * Contains the results of invoking a [Process] and waiting for it to complete.
323 */ 361 */
324 class PubProcessResult { 362 class PubProcessResult {
325 final List<String> stdout; 363 final List<String> stdout;
326 final List<String> stderr; 364 final List<String> stderr;
327 final int exitCode; 365 final int exitCode;
328 366
329 const PubProcessResult(this.stdout, this.stderr, this.exitCode); 367 const PubProcessResult(this.stdout, this.stderr, this.exitCode);
330 368
331 bool get success() => exitCode == 0; 369 bool get success() => exitCode == 0;
(...skipping 12 matching lines...) Expand all
344 } 382 }
345 383
346 /** 384 /**
347 * Gets a [Directory] for [entry], which can either already be one, or be a 385 * Gets a [Directory] for [entry], which can either already be one, or be a
348 * [String]. 386 * [String].
349 */ 387 */
350 Directory _getDirectory(entry) { 388 Directory _getDirectory(entry) {
351 if (entry is Directory) return entry; 389 if (entry is Directory) return entry;
352 return new Directory(entry); 390 return new Directory(entry);
353 } 391 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698