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

Side by Side Diff: utils/pub/source.dart

Issue 14253005: Migrate pub away from throwing strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 7 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 | « utils/pub/pubspec.dart ('k') | utils/pub/source_registry.dart » ('j') | no next file with comments »
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 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 /// For cached sources, by default this uses [installToSystemCache] to get the 79 /// For cached sources, by default this uses [installToSystemCache] to get the
80 /// pubspec. There is no default implementation for non-cached sources; they 80 /// pubspec. There is no default implementation for non-cached sources; they
81 /// must implement it manually. 81 /// must implement it manually.
82 Future<Pubspec> describe(PackageId id) { 82 Future<Pubspec> describe(PackageId id) {
83 if (!shouldCache) throw "Source $name must implement describe(id)."; 83 if (!shouldCache) {
84 throw new UnimplementedError("Source $name must implement describe(id).");
85 }
84 return installToSystemCache(id).then((package) => package.pubspec); 86 return installToSystemCache(id).then((package) => package.pubspec);
85 } 87 }
86 88
87 /// Installs the package identified by [id] to [path]. Returns a [Future] that 89 /// Installs the package identified by [id] to [path]. Returns a [Future] that
88 /// completes when the installation was finished. The [Future] should resolve 90 /// completes when the installation was finished. The [Future] should resolve
89 /// to true if the package was found in the source and false if it wasn't. For 91 /// to true if the package was found in the source and false if it wasn't. For
90 /// all other error conditions, it should complete with an exception. 92 /// all other error conditions, it should complete with an exception.
91 /// 93 ///
92 /// [path] is guaranteed not to exist, and its parent directory is guaranteed 94 /// [path] is guaranteed not to exist, and its parent directory is guaranteed
93 /// to exist. 95 /// to exist.
94 /// 96 ///
95 /// Note that [path] may be deleted. If re-installing a package that has 97 /// Note that [path] may be deleted. If re-installing a package that has
96 /// already been installed would be costly or impossible, 98 /// already been installed would be costly or impossible,
97 /// [installToSystemCache] should be implemented instead of [install]. 99 /// [installToSystemCache] should be implemented instead of [install].
98 /// 100 ///
99 /// This doesn't need to be implemented if [installToSystemCache] is 101 /// This doesn't need to be implemented if [installToSystemCache] is
100 /// implemented. 102 /// implemented.
101 Future<bool> install(PackageId id, String path) { 103 Future<bool> install(PackageId id, String path) {
102 throw "Either install or installToSystemCache must be implemented for " 104 throw new UnimplementedError("Either install or installToSystemCache must "
103 "source $name."; 105 "be implemented for source $name.");
104 } 106 }
105 107
106 /// Installs the package identified by [id] to the system cache. This is only 108 /// Installs the package identified by [id] to the system cache. This is only
107 /// called for sources with [shouldCache] set to true. 109 /// called for sources with [shouldCache] set to true.
108 /// 110 ///
109 /// By default, this uses [systemCacheDirectory] and [install]. 111 /// By default, this uses [systemCacheDirectory] and [install].
110 Future<Package> installToSystemCache(PackageId id) { 112 Future<Package> installToSystemCache(PackageId id) {
111 var packageDir; 113 var packageDir;
112 return systemCacheDirectory(id).then((p) { 114 return systemCacheDirectory(id).then((p) {
113 packageDir = p; 115 packageDir = p;
114 116
115 // See if it's already cached. 117 // See if it's already cached.
116 if (dirExists(packageDir)) { 118 if (dirExists(packageDir)) {
117 if (!_isCachedPackageCorrupted(packageDir)) return true; 119 if (!_isCachedPackageCorrupted(packageDir)) return true;
118 // Busted, so wipe out the package and reinstall. 120 // Busted, so wipe out the package and reinstall.
119 deleteEntry(packageDir); 121 deleteEntry(packageDir);
120 } 122 }
121 123
122 ensureDir(path.dirname(packageDir)); 124 ensureDir(path.dirname(packageDir));
123 return install(id, packageDir); 125 return install(id, packageDir);
124 }).then((found) { 126 }).then((found) {
125 if (!found) throw 'Package $id not found.'; 127 if (!found) fail('Package $id not found.');
126 return new Package.load(id.name, packageDir, systemCache.sources); 128 return new Package.load(id.name, packageDir, systemCache.sources);
127 }); 129 });
128 } 130 }
129 131
130 /// Since pub generates symlinks that point into the system cache (in 132 /// Since pub generates symlinks that point into the system cache (in
131 /// particular, targeting the "lib" directories of cached packages), it's 133 /// particular, targeting the "lib" directories of cached packages), it's
132 /// possible to accidentally break cached packages if something traverses 134 /// possible to accidentally break cached packages if something traverses
133 /// that symlink. 135 /// that symlink.
134 /// 136 ///
135 /// This tries to determine if the cached package at [packageDir] has been 137 /// This tries to determine if the cached package at [packageDir] has been
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 /// The returned [PackageId] may have a description field that's invalid 205 /// The returned [PackageId] may have a description field that's invalid
204 /// according to [parseDescription], although it must still be serializable 206 /// according to [parseDescription], although it must still be serializable
205 /// to JSON and YAML. It must also be equal to [id] according to 207 /// to JSON and YAML. It must also be equal to [id] according to
206 /// [descriptionsEqual]. 208 /// [descriptionsEqual].
207 /// 209 ///
208 /// By default, this just returns [id]. 210 /// By default, this just returns [id].
209 Future<PackageId> resolveId(PackageId id) => new Future.value(id); 211 Future<PackageId> resolveId(PackageId id) => new Future.value(id);
210 212
211 /// Returns the [Package]s that have been installed in the system cache. 213 /// Returns the [Package]s that have been installed in the system cache.
212 List<Package> getCachedPackages() { 214 List<Package> getCachedPackages() {
213 if (shouldCache) throw "Source $name must implement this."; 215 if (shouldCache) {
216 throw new UnimplementedError("Source $name must implement this.");
217 }
214 } 218 }
215 219
216 /// Returns the source's name. 220 /// Returns the source's name.
217 String toString() => name; 221 String toString() => name;
218 } 222 }
OLDNEW
« no previous file with comments | « utils/pub/pubspec.dart ('k') | utils/pub/source_registry.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698