OLD | NEW |
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 pub.source.hosted; | 5 library pub.source.hosted; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io' as io; | 8 import 'dart:io' as io; |
9 import "dart:convert"; | 9 import "dart:convert"; |
10 | 10 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 var parsed = _parseDescription(description); | 245 var parsed = _parseDescription(description); |
246 var server = parsed.last; | 246 var server = parsed.last; |
247 log.io("Finding versions of $name in " | 247 log.io("Finding versions of $name in " |
248 "$systemCacheRoot/${_urlToDirectory(server)}"); | 248 "$systemCacheRoot/${_urlToDirectory(server)}"); |
249 var versions = await _getCachedPackagesInDirectory(_urlToDirectory(server)) | 249 var versions = await _getCachedPackagesInDirectory(_urlToDirectory(server)) |
250 .where((package) => package.name == name) | 250 .where((package) => package.name == name) |
251 .map((package) => package.pubspec) | 251 .map((package) => package.pubspec) |
252 .toList(); | 252 .toList(); |
253 | 253 |
254 // If there are no versions in the cache, report a clearer error. | 254 // If there are no versions in the cache, report a clearer error. |
255 if (versions.isEmpty) fail("Could not find package $name in cache."); | 255 if (versions.isEmpty) { |
| 256 throw new PackageNotFoundException( |
| 257 "Could not find package $name in cache."); |
| 258 } |
256 | 259 |
257 return versions; | 260 return versions; |
258 } | 261 } |
259 | 262 |
260 Future<bool> _download(String server, String package, Version version, | 263 Future<bool> _download(String server, String package, Version version, |
261 String destPath) { | 264 String destPath) { |
262 // Since HostedSource is cached, this will only be called for uncached | 265 // Since HostedSource is cached, this will only be called for uncached |
263 // packages. | 266 // packages. |
264 throw new UnsupportedError("Cannot download packages when offline."); | 267 throw new UnsupportedError("Cannot download packages when offline."); |
265 } | 268 } |
266 | 269 |
267 Future<Pubspec> doDescribeUncached(PackageId id) { | 270 Future<Pubspec> describeUncached(PackageId id) { |
268 // [getVersions()] will only return packages that are already cached. | 271 throw new PackageNotFoundException( |
269 // [CachedSource] will only call [doDescribeUncached()] on a package after | 272 "${id.name} ${id.version} is not available in your system cache."); |
270 // it has failed to find it in the cache, so this code should not be | |
271 // reached. | |
272 throw new UnsupportedError("Cannot describe packages when offline."); | |
273 } | 273 } |
274 } | 274 } |
275 | 275 |
276 /// Given a URL, returns a "normalized" string to be used as a directory name | 276 /// Given a URL, returns a "normalized" string to be used as a directory name |
277 /// for packages downloaded from the server at that URL. | 277 /// for packages downloaded from the server at that URL. |
278 /// | 278 /// |
279 /// This normalization strips off the scheme (which is presumed to be HTTP or | 279 /// This normalization strips off the scheme (which is presumed to be HTTP or |
280 /// HTTPS) and *sort of* URL-encodes it. I say "sort of" because it does it | 280 /// HTTPS) and *sort of* URL-encodes it. I say "sort of" because it does it |
281 /// incorrectly: it uses the character's *decimal* ASCII value instead of hex. | 281 /// incorrectly: it uses the character's *decimal* ASCII value instead of hex. |
282 /// | 282 /// |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 var name = description["name"]; | 363 var name = description["name"]; |
364 if (name is! String) { | 364 if (name is! String) { |
365 throw new FormatException("The 'name' key must have a string value."); | 365 throw new FormatException("The 'name' key must have a string value."); |
366 } | 366 } |
367 | 367 |
368 var url = description["url"]; | 368 var url = description["url"]; |
369 if (url == null) url = HostedSource.defaultUrl; | 369 if (url == null) url = HostedSource.defaultUrl; |
370 | 370 |
371 return new Pair<String, String>(name, url); | 371 return new Pair<String, String>(name, url); |
372 } | 372 } |
OLD | NEW |