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

Unified Diff: sdk/lib/_internal/pub/lib/src/source.dart

Issue 15347004: Gracefully handle pubspecs with dependencies using unknown sources. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add tests for unknown sources in lockfiles. Created 7 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 side-by-side diff with in-line comments
Download patch
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..f72f173477200a9a2b61b4a8d445d89fdff203f9 100644
--- a/sdk/lib/_internal/pub/lib/src/source.dart
+++ b/sdk/lib/_internal/pub/lib/src/source.dart
@@ -68,20 +68,54 @@ 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) {
+ if (id.isRoot) throw new ArgumentError("Cannot describe the root package.");
+ if (id.source != name) {
+ throw new ArgumentError("Package $id does not use source $name.");
+ }
+
+ // 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 [installToSystemCache] to get
+ /// the pubspec. There is no default implementation for non-cached sources;
+ /// they must implement it manually.
+ ///
+ /// This method is effectively protected. Derived classes may override it,
+ /// but external code should not call it. Call [describe()] instead.
+ 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);
}
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/solver/version_solver.dart ('k') | sdk/lib/_internal/pub/lib/src/system_cache.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698