| 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:json'); | 7 #import('dart:json'); |
| 8 #import('dart:uri'); | 8 #import('dart:uri'); |
| 9 #import('io.dart'); | 9 #import('io.dart'); |
| 10 #import('package.dart'); | 10 #import('package.dart'); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 } | 49 } |
| 50 | 50 |
| 51 /** | 51 /** |
| 52 * Downloads and parses the pubspec for a specific version of a package that | 52 * Downloads and parses the pubspec for a specific version of a package that |
| 53 * is available from the site. | 53 * is available from the site. |
| 54 */ | 54 */ |
| 55 Future<Pubspec> describe(PackageId id) { | 55 Future<Pubspec> describe(PackageId id) { |
| 56 var parsed = _parseDescription(id.description); | 56 var parsed = _parseDescription(id.description); |
| 57 var fullUrl = "${parsed.last}/packages/${parsed.first}/versions/" | 57 var fullUrl = "${parsed.last}/packages/${parsed.first}/versions/" |
| 58 "${id.version}.yaml"; | 58 "${id.version}.yaml"; |
| 59 return consumeInputStream(httpGet(fullUrl)).transform((data) { | 59 return httpGetString(fullUrl).transform((yaml) { |
| 60 return new Pubspec.parse( | 60 return new Pubspec.parse(yaml, systemCache.sources); |
| 61 new String.fromCharCodes(data), systemCache.sources); | |
| 62 }); | 61 }); |
| 63 } | 62 } |
| 64 | 63 |
| 65 /** | 64 /** |
| 66 * Downloads a package from the site and unpacks it. | 65 * Downloads a package from the site and unpacks it. |
| 67 */ | 66 */ |
| 68 Future<bool> install(PackageId id, String destPath) { | 67 Future<bool> install(PackageId id, String destPath) { |
| 69 var parsedDescription = _parseDescription(id.description); | 68 var parsedDescription = _parseDescription(id.description); |
| 70 var name = parsedDescription.first; | 69 var name = parsedDescription.first; |
| 71 var url = parsedDescription.last; | 70 var url = parsedDescription.last; |
| 72 | 71 |
| 73 return ensureDir(destPath).chain((destDir) { | 72 var fullUrl = "$url/packages/$name/versions/${id.version}.tar.gz"; |
| 74 var fullUrl = "$url/packages/$name/versions/${id.version}.tar.gz"; | 73 return Futures.wait([httpGet(fullUrl), ensureDir(destPath)]).chain((args) { |
| 75 return extractTarGz(httpGet(fullUrl), destDir); | 74 return future(extractTarGz(args[0], args[1]), HTTP_TIMEOUT, |
| 75 'Timed out while fetching URL "$fullUrl".'); |
| 76 }); | 76 }); |
| 77 } | 77 } |
| 78 | 78 |
| 79 /** | 79 /** |
| 80 * The system cache directory for the hosted source contains subdirectories | 80 * The system cache directory for the hosted source contains subdirectories |
| 81 * for each separate repository URL that's used on the system. Each of these | 81 * for each separate repository URL that's used on the system. Each of these |
| 82 * subdirectories then contains a subdirectory for each package installed | 82 * subdirectories then contains a subdirectory for each package installed |
| 83 * from that site. | 83 * from that site. |
| 84 */ | 84 */ |
| 85 String systemCacheDirectory(PackageId id) { | 85 String systemCacheDirectory(PackageId id) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 130 |
| 131 var name = description["name"]; | 131 var name = description["name"]; |
| 132 if (name is! String) { | 132 if (name is! String) { |
| 133 throw new FormatException("The 'name' key must have a string value."); | 133 throw new FormatException("The 'name' key must have a string value."); |
| 134 } | 134 } |
| 135 | 135 |
| 136 var url = description.containsKey("url") ? description["url"] : defaultUrl; | 136 var url = description.containsKey("url") ? description["url"] : defaultUrl; |
| 137 return new Pair<String, String>(name, url); | 137 return new Pair<String, String>(name, url); |
| 138 } | 138 } |
| 139 } | 139 } |
| OLD | NEW |