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

Unified Diff: utils/pub/cache.dart

Issue 10214006: Refactor command code and add support for --help and --version. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | utils/pub/command_list.dart » ('j') | utils/pub/command_list.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/cache.dart
diff --git a/utils/pub/cache.dart b/utils/pub/cache.dart
index 4c599e02c5800976b444b3d4778bcbed9576e42a..d14097aa4add7ff7a25a27347aecc292e06bce38 100644
--- a/utils/pub/cache.dart
+++ b/utils/pub/cache.dart
@@ -45,26 +45,14 @@ class PackageCache {
Future<Package> find(String name) {
// Use the previously loaded one.
final package = _loadedPackages[name];
- if (package != null) {
- return new Future.immediate(package);
- }
+ if (package != null) return new Future.immediate(package);
// If we are already in-progress loading it, re-use that one.
final pending = _pendingPackages[name];
- if (pending != null) {
- return pending;
- }
-
- return _loadPackage(name);
- }
-
- /**
- * Start loading the package.
- */
- Future<Package> _loadPackage(String name) {
- final future = _parsePubspec(name).transform((dependencies) {
- final package = new Package._(this, name, dependencies);
+ if (pending != null) return pending;
+ // Actually load it from the cache.
+ final future = Package.load(join(rootDir, name)).transform((package) {
_pendingPackages.remove(name);
_loadedPackages[name] = package;
return package;
@@ -73,32 +61,4 @@ class PackageCache {
_pendingPackages[name] = future;
return future;
}
-
- Future<List<String>> _parsePubspec(String name) {
- final completer = new Completer<List<String>>();
- final pubspecPath = join(rootDir, name, 'pubspec');
-
- // TODO(rnystrom): Handle the directory not existing.
- // TODO(rnystrom): Error-handling.
- final readFuture = readTextFile(pubspecPath);
- readFuture.handleException((error) {
- // If there is no pubspec, we implicitly treat that as a package with no
- // dependencies.
- // TODO(rnystrom): Distinguish file not found from other real errors.
- completer.complete(<String>[]);
- return true;
- });
-
- readFuture.then((pubspec) {
- // TODO(rnystrom): Use YAML parser when ready. For now, it's just a flat
- // list of newline-separated strings.
- final dependencyNames = pubspec.split('\n').
- map((name) => name.trim()).
- filter((name) => (name != null) && (name != ''));
-
- completer.complete(dependencyNames);
- });
-
- return completer.future;
- }
}
« no previous file with comments | « no previous file | utils/pub/command_list.dart » ('j') | utils/pub/command_list.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698