| 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:json' as json; | 9 import 'dart:json' as json; |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 /// A package source that installs packages from a package hosting site that | 24 /// A package source that installs packages from a package hosting site that |
| 25 /// uses the same API as pub.dartlang.org. | 25 /// uses the same API as pub.dartlang.org. |
| 26 class HostedSource extends Source { | 26 class HostedSource extends Source { |
| 27 | 27 |
| 28 final name = "hosted"; | 28 final name = "hosted"; |
| 29 final shouldCache = true; | 29 final shouldCache = true; |
| 30 | 30 |
| 31 /// Gets the default URL for the package server for hosted dependencies. | 31 /// Gets the default URL for the package server for hosted dependencies. |
| 32 static String get defaultUrl { | 32 static String get defaultUrl { |
| 33 var url = io.Platform.environment["PUB_HOSTED_URL"]; | 33 var url = io.Platform.environment["PUB_HOSTED_URL"]; |
| 34 if (url != null) return url; | 34 if (url != null) { |
| 35 log.fine("Got server $url from PUB_HOSTED_URL."); |
| 36 return url; |
| 37 } |
| 38 |
| 35 return "https://pub.dartlang.org"; | 39 return "https://pub.dartlang.org"; |
| 36 } | 40 } |
| 37 | 41 |
| 38 /// Downloads a list of all versions of a package that are available from the | 42 /// Downloads a list of all versions of a package that are available from the |
| 39 /// site. | 43 /// site. |
| 40 Future<List<Version>> getVersions(String name, description) { | 44 Future<List<Version>> getVersions(String name, description) { |
| 41 var url = _makeUrl(description, | 45 var url = _makeUrl(description, |
| 42 (server, package) => "$server/api/packages/$package"); | 46 (server, package) => "$server/api/packages/$package"); |
| 43 | 47 |
| 44 log.io("Get versions from $url."); | 48 log.io("Get versions from $url."); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 var name = description["name"]; | 262 var name = description["name"]; |
| 259 if (name is! String) { | 263 if (name is! String) { |
| 260 throw new FormatException("The 'name' key must have a string value."); | 264 throw new FormatException("The 'name' key must have a string value."); |
| 261 } | 265 } |
| 262 | 266 |
| 263 var url = description["url"]; | 267 var url = description["url"]; |
| 264 if (url == null) url = HostedSource.defaultUrl; | 268 if (url == null) url = HostedSource.defaultUrl; |
| 265 | 269 |
| 266 return new Pair<String, String>(name, url); | 270 return new Pair<String, String>(name, url); |
| 267 } | 271 } |
| OLD | NEW |