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

Side by Side 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: Handle bad sources in dev deps. 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 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 library source; 5 library source;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:pathos/path.dart' as path; 9 import 'package:pathos/path.dart' as path;
10 10
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 /// Get the list of all versions that exist for the package described by 61 /// Get the list of all versions that exist for the package described by
62 /// [description]. [name] is the expected name of the package. 62 /// [description]. [name] is the expected name of the package.
63 /// 63 ///
64 /// Note that this does *not* require the packages to be installed, which is 64 /// Note that this does *not* require the packages to be installed, which is
65 /// the point. This is used during version resolution to determine which 65 /// the point. This is used during version resolution to determine which
66 /// package versions are available to be installed (or already installed). 66 /// package versions are available to be installed (or already installed).
67 /// 67 ///
68 /// By default, this assumes that each description has a single version and 68 /// By default, this assumes that each description has a single version and
69 /// uses [describe] to get that version. 69 /// uses [describe] to get that version.
70 Future<List<Version>> getVersions(String name, description) { 70 Future<List<Version>> getVersions(String name, description) {
71 return describe(new PackageId(name, this, Version.none, description)) 71 var id = new PackageId(name, this.name, Version.none, description);
72 .then((pubspec) => [pubspec.version]); 72 return describeUncached(id).then((pubspec) => [pubspec.version]);
73 } 73 }
74 74
75 /// Loads the (possibly remote) pubspec for the package version identified by 75 /// Loads the (possibly remote) pubspec for the package version identified by
76 /// [id]. This may be called for packages that have not yet been installed 76 /// [id]. This may be called for packages that have not yet been installed
77 /// during the version resolution process. 77 /// during the version resolution process.
78 /// 78 ///
79 /// If the package has been installed to the system cache, the cached pubspec
80 /// will be used. Otherwise, it delegates to host-specific lookup behavior.
81 ///
79 /// For cached sources, by default this uses [installToSystemCache] to get the 82 /// For cached sources, by default this uses [installToSystemCache] to get the
80 /// pubspec. There is no default implementation for non-cached sources; they 83 /// pubspec. There is no default implementation for non-cached sources; they
81 /// must implement it manually. 84 /// must implement it manually.
82 Future<Pubspec> describe(PackageId id) { 85 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
86 if (id.isRoot) throw new ArgumentError("Cannot describe the root package.");
87 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.
88 "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.
89
90 // Try to get it from the system cache first.
91 if (shouldCache) {
92 return systemCacheDirectory(id).then((packageDir) {
93 if (!fileExists(path.join(packageDir, "pubspec.yaml"))) {
94 return describeUncached(id);
95 }
96
97 return new Pubspec.load(id.name, packageDir, _systemCache.sources);
98 });
99 }
100
101 // Not cached, so get it from the source.
102 return describeUncached(id);
103 }
104
105 /// Loads the pubspec for the package version identified by [id] which is not
106 /// 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.
107 /// [installToSystemCache] to get the pubspec. There is no default
108 /// 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.
109 Future<Pubspec> describeUncached(PackageId id) {
83 if (!shouldCache) { 110 if (!shouldCache) {
84 throw new UnimplementedError("Source $name must implement describe(id)."); 111 throw new UnimplementedError(
112 "Source $name must implement describeUncached(id).");
85 } 113 }
86 return installToSystemCache(id).then((package) => package.pubspec); 114 return installToSystemCache(id).then((package) => package.pubspec);
87 } 115 }
88 116
89 /// Installs the package identified by [id] to [path]. Returns a [Future] that 117 /// Installs the package identified by [id] to [path]. Returns a [Future] that
90 /// completes when the installation was finished. The [Future] should resolve 118 /// completes when the installation was finished. The [Future] should resolve
91 /// to true if the package was found in the source and false if it wasn't. For 119 /// to true if the package was found in the source and false if it wasn't. For
92 /// all other error conditions, it should complete with an exception. 120 /// all other error conditions, it should complete with an exception.
93 /// 121 ///
94 /// [path] is guaranteed not to exist, and its parent directory is guaranteed 122 /// [path] is guaranteed not to exist, and its parent directory is guaranteed
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 /// Returns the [Package]s that have been installed in the system cache. 241 /// Returns the [Package]s that have been installed in the system cache.
214 List<Package> getCachedPackages() { 242 List<Package> getCachedPackages() {
215 if (shouldCache) { 243 if (shouldCache) {
216 throw new UnimplementedError("Source $name must implement this."); 244 throw new UnimplementedError("Source $name must implement this.");
217 } 245 }
218 } 246 }
219 247
220 /// Returns the source's name. 248 /// Returns the source's name.
221 String toString() => name; 249 String toString() => name;
222 } 250 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698