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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | utils/pub/command_list.dart » ('j') | utils/pub/command_list.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 * The local cache of previously installed packages. 6 * The local cache of previously installed packages.
7 */ 7 */
8 class PackageCache { 8 class PackageCache {
9 /** 9 /**
10 * The root directory where this package cache is located. 10 * The root directory where this package cache is located.
(...skipping 27 matching lines...) Expand all
38 }); 38 });
39 } 39 }
40 40
41 /** 41 /**
42 * Loads the package named [name] from this cache, if present. 42 * Loads the package named [name] from this cache, if present.
43 */ 43 */
44 // TODO(rnystrom): What happens if the package isn't cached? 44 // TODO(rnystrom): What happens if the package isn't cached?
45 Future<Package> find(String name) { 45 Future<Package> find(String name) {
46 // Use the previously loaded one. 46 // Use the previously loaded one.
47 final package = _loadedPackages[name]; 47 final package = _loadedPackages[name];
48 if (package != null) { 48 if (package != null) return new Future.immediate(package);
49 return new Future.immediate(package);
50 }
51 49
52 // If we are already in-progress loading it, re-use that one. 50 // If we are already in-progress loading it, re-use that one.
53 final pending = _pendingPackages[name]; 51 final pending = _pendingPackages[name];
54 if (pending != null) { 52 if (pending != null) return pending;
55 return pending;
56 }
57 53
58 return _loadPackage(name); 54 // Actually load it from the cache.
59 } 55 final future = Package.load(join(rootDir, name)).transform((package) {
60
61 /**
62 * Start loading the package.
63 */
64 Future<Package> _loadPackage(String name) {
65 final future = _parsePubspec(name).transform((dependencies) {
66 final package = new Package._(this, name, dependencies);
67
68 _pendingPackages.remove(name); 56 _pendingPackages.remove(name);
69 _loadedPackages[name] = package; 57 _loadedPackages[name] = package;
70 return package; 58 return package;
71 }); 59 });
72 60
73 _pendingPackages[name] = future; 61 _pendingPackages[name] = future;
74 return future; 62 return future;
75 } 63 }
76
77 Future<List<String>> _parsePubspec(String name) {
78 final completer = new Completer<List<String>>();
79 final pubspecPath = join(rootDir, name, 'pubspec');
80
81 // TODO(rnystrom): Handle the directory not existing.
82 // TODO(rnystrom): Error-handling.
83 final readFuture = readTextFile(pubspecPath);
84 readFuture.handleException((error) {
85 // If there is no pubspec, we implicitly treat that as a package with no
86 // dependencies.
87 // TODO(rnystrom): Distinguish file not found from other real errors.
88 completer.complete(<String>[]);
89 return true;
90 });
91
92 readFuture.then((pubspec) {
93 // TODO(rnystrom): Use YAML parser when ready. For now, it's just a flat
94 // list of newline-separated strings.
95 final dependencyNames = pubspec.split('\n').
96 map((name) => name.trim()).
97 filter((name) => (name != null) && (name != ''));
98
99 completer.complete(dependencyNames);
100 });
101
102 return completer.future;
103 }
104 } 64 }
OLDNEW
« 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