Chromium Code Reviews| Index: sdk/lib/_internal/pub/lib/src/source.dart |
| diff --git a/sdk/lib/_internal/pub/lib/src/source.dart b/sdk/lib/_internal/pub/lib/src/source.dart |
| index 2486e786ad9d4dd67838acb19193d3055f05f532..6a0712eae2566f02890b84651e04e54d5cbd1b96 100644 |
| --- a/sdk/lib/_internal/pub/lib/src/source.dart |
| +++ b/sdk/lib/_internal/pub/lib/src/source.dart |
| @@ -68,20 +68,48 @@ abstract class Source { |
| /// By default, this assumes that each description has a single version and |
| /// uses [describe] to get that version. |
| Future<List<Version>> getVersions(String name, description) { |
| - return describe(new PackageId(name, this, Version.none, description)) |
| - .then((pubspec) => [pubspec.version]); |
| + var id = new PackageId(name, this.name, Version.none, description); |
| + return describeUncached(id).then((pubspec) => [pubspec.version]); |
| } |
| /// Loads the (possibly remote) pubspec for the package version identified by |
| /// [id]. This may be called for packages that have not yet been installed |
| /// during the version resolution process. |
| /// |
| + /// If the package has been installed to the system cache, the cached pubspec |
| + /// will be used. Otherwise, it delegates to host-specific lookup behavior. |
| + /// |
| /// For cached sources, by default this uses [installToSystemCache] to get the |
| /// pubspec. There is no default implementation for non-cached sources; they |
| /// must implement it manually. |
| Future<Pubspec> describe(PackageId id) { |
|
nweiz
2013/05/17 23:55:55
I don't understand why the describe/describeUncach
Bob Nystrom
2013/05/20 20:06:00
This moves the cache checking into Source from Sys
nweiz
2013/05/20 23:54:05
It would be nice if this sort of change were separ
|
| + if (id.isRoot) throw new ArgumentError("Cannot describe the root package."); |
| + if (id.source != name) throw new ArgumentError( |
|
nweiz
2013/05/17 23:55:55
Use {} if the value is smaller than a single line.
Bob Nystrom
2013/05/20 20:06:00
Done.
|
| + "Package $id does not use this source."); |
|
nweiz
2013/05/17 23:55:55
Include the name of this source.
Bob Nystrom
2013/05/20 20:06:00
Done.
|
| + |
| + // Try to get it from the system cache first. |
| + if (shouldCache) { |
| + return systemCacheDirectory(id).then((packageDir) { |
| + if (!fileExists(path.join(packageDir, "pubspec.yaml"))) { |
| + return describeUncached(id); |
| + } |
| + |
| + return new Pubspec.load(id.name, packageDir, _systemCache.sources); |
| + }); |
| + } |
| + |
| + // Not cached, so get it from the source. |
| + return describeUncached(id); |
| + } |
| + |
| + /// Loads the pubspec for the package version identified by [id] which is not |
| + /// already in the system cache. For cached sources, by default this uses |
|
nweiz
2013/05/17 23:55:55
I learned recently that docstrings are supposed to
Bob Nystrom
2013/05/20 20:06:00
Done.
|
| + /// [installToSystemCache] to get the pubspec. There is no default |
| + /// implementation for non-cached sources; they must implement it manually. |
|
nweiz
2013/05/17 23:55:55
Mention that this is intended to be a protected me
Bob Nystrom
2013/05/20 20:06:00
Done.
|
| + Future<Pubspec> describeUncached(PackageId id) { |
| if (!shouldCache) { |
| - throw new UnimplementedError("Source $name must implement describe(id)."); |
| + throw new UnimplementedError( |
| + "Source $name must implement describeUncached(id)."); |
| } |
| return installToSystemCache(id).then((package) => package.pubspec); |
| } |