| 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 hosted_source; | 5 library hosted_source; |
| 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:json' as json; | 9 import 'dart:json' as json; |
| 10 import 'dart:uri'; | 10 import 'dart:uri'; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 .map((version) => new Version.parse(version)) | 41 .map((version) => new Version.parse(version)) |
| 42 .toList(); | 42 .toList(); |
| 43 }).catchError((ex) { | 43 }).catchError((ex) { |
| 44 var parsed = _parseDescription(description); | 44 var parsed = _parseDescription(description); |
| 45 _throwFriendlyError(ex, parsed.first, parsed.last); | 45 _throwFriendlyError(ex, parsed.first, parsed.last); |
| 46 }); | 46 }); |
| 47 } | 47 } |
| 48 | 48 |
| 49 /// Downloads and parses the pubspec for a specific version of a package that | 49 /// Downloads and parses the pubspec for a specific version of a package that |
| 50 /// is available from the site. | 50 /// is available from the site. |
| 51 Future<Pubspec> describe(PackageId id) { | 51 Future<Pubspec> describeUncached(PackageId id) { |
| 52 // Request it from the server. | 52 // Request it from the server. |
| 53 var url = _makeVersionUrl(id, (server, package, version) => | 53 var url = _makeVersionUrl(id, (server, package, version) => |
| 54 "$server/packages/$package/versions/$version.yaml"); | 54 "$server/packages/$package/versions/$version.yaml"); |
| 55 | 55 |
| 56 log.io("Describe package at $url."); | 56 log.io("Describe package at $url."); |
| 57 return httpClient.read(url).then((yaml) { | 57 return httpClient.read(url).then((yaml) { |
| 58 // TODO(rnystrom): After this is pulled down, we could place it in | 58 // TODO(rnystrom): After this is pulled down, we could place it in |
| 59 // a secondary cache of just pubspecs. This would let us have a | 59 // a secondary cache of just pubspecs. This would let us have a |
| 60 // persistent cache for pubspecs for packages that haven't actually | 60 // persistent cache for pubspecs for packages that haven't actually |
| 61 // been installed. | 61 // been installed. |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 return versions; | 184 return versions; |
| 185 }); | 185 }); |
| 186 } | 186 } |
| 187 | 187 |
| 188 Future<bool> install(PackageId id, String destPath) { | 188 Future<bool> install(PackageId id, String destPath) { |
| 189 // Since HostedSource returns `true` for [shouldCache], install will only | 189 // Since HostedSource returns `true` for [shouldCache], install will only |
| 190 // be called for uncached packages. | 190 // be called for uncached packages. |
| 191 throw new UnsupportedError("Cannot install packages when offline."); | 191 throw new UnsupportedError("Cannot install packages when offline."); |
| 192 } | 192 } |
| 193 | 193 |
| 194 Future<Pubspec> describe(PackageId id) { | 194 Future<Pubspec> describeUncached(PackageId id) { |
| 195 // [getVersions()] will only return packages that are already cached. | 195 // [getVersions()] will only return packages that are already cached. |
| 196 // SystemCache should only call [describe()] on a package after it has | 196 // Source should only call [describeUncached()] on a package after it has |
| 197 // failed to find it in the cache, so this code should not be reached. | 197 // failed to find it in the cache, so this code should not be reached. |
| 198 throw new UnsupportedError("Cannot describe packages when offline."); | 198 throw new UnsupportedError("Cannot describe packages when offline."); |
| 199 } | 199 } |
| 200 } | 200 } |
| 201 | 201 |
| 202 /// The URL of the default package repository. | 202 /// The URL of the default package repository. |
| 203 final _defaultUrl = "https://pub.dartlang.org"; | 203 final _defaultUrl = "https://pub.dartlang.org"; |
| 204 | 204 |
| 205 String _getSourceDirectory(String url) { | 205 String _getSourceDirectory(String url) { |
| 206 url = url.replaceAll(new RegExp(r"^https?://"), ""); | 206 url = url.replaceAll(new RegExp(r"^https?://"), ""); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 } | 250 } |
| 251 | 251 |
| 252 var name = description["name"]; | 252 var name = description["name"]; |
| 253 if (name is! String) { | 253 if (name is! String) { |
| 254 throw new FormatException("The 'name' key must have a string value."); | 254 throw new FormatException("The 'name' key must have a string value."); |
| 255 } | 255 } |
| 256 | 256 |
| 257 var url = description.containsKey("url") ? description["url"] : _defaultUrl; | 257 var url = description.containsKey("url") ? description["url"] : _defaultUrl; |
| 258 return new Pair<String, String>(name, url); | 258 return new Pair<String, String>(name, url); |
| 259 } | 259 } |
| OLD | NEW |