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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 } | 49 } |
50 | 50 |
51 /// Downloads and parses the pubspec for a specific version of a package that | 51 /// Downloads and parses the pubspec for a specific version of a package that |
52 /// is available from the site. | 52 /// is available from the site. |
53 Future<Pubspec> describe(PackageId id) { | 53 Future<Pubspec> describe(PackageId id) { |
54 var parsed = _parseDescription(id.description); | 54 var parsed = _parseDescription(id.description); |
55 var fullUrl = "${parsed.last}/packages/${parsed.first}/versions/" | 55 var fullUrl = "${parsed.last}/packages/${parsed.first}/versions/" |
56 "${id.version}.yaml"; | 56 "${id.version}.yaml"; |
57 | 57 |
58 return httpClient.read(fullUrl).then((yaml) { | 58 return httpClient.read(fullUrl).then((yaml) { |
59 return new Pubspec.parse(yaml, systemCache.sources); | 59 return new Pubspec.parse(null, yaml, systemCache.sources); |
60 }).catchError((ex) { | 60 }).catchError((ex) { |
61 _throwFriendlyError(ex, id, parsed.last); | 61 _throwFriendlyError(ex, id, parsed.last); |
62 }); | 62 }); |
63 } | 63 } |
64 | 64 |
65 /// Downloads a package from the site and unpacks it. | 65 /// Downloads a package from the site and unpacks it. |
66 Future<bool> install(PackageId id, String destPath) { | 66 Future<bool> install(PackageId id, String destPath) { |
67 return defer(() { | 67 return defer(() { |
68 var parsedDescription = _parseDescription(id.description); | 68 var parsedDescription = _parseDescription(id.description); |
69 var name = parsedDescription.first; | 69 var name = parsedDescription.first; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 String packageName(description) => _parseDescription(description).first; | 107 String packageName(description) => _parseDescription(description).first; |
108 | 108 |
109 bool descriptionsEqual(description1, description2) => | 109 bool descriptionsEqual(description1, description2) => |
110 _parseDescription(description1) == _parseDescription(description2); | 110 _parseDescription(description1) == _parseDescription(description2); |
111 | 111 |
112 /// Ensures that [description] is a valid hosted package description. | 112 /// Ensures that [description] is a valid hosted package description. |
113 /// | 113 /// |
114 /// There are two valid formats. A plain string refers to a package with the | 114 /// There are two valid formats. A plain string refers to a package with the |
115 /// given name from the default host, while a map with keys "name" and "url" | 115 /// given name from the default host, while a map with keys "name" and "url" |
116 /// refers to a package with the given name from the host at the given URL. | 116 /// refers to a package with the given name from the host at the given URL. |
117 void validateDescription(description, {bool fromLockFile: false}) { | 117 dynamic parseDescription(String containingPath, description, |
| 118 {bool fromLockFile: false}) { |
118 _parseDescription(description); | 119 _parseDescription(description); |
| 120 return description; |
119 } | 121 } |
120 | 122 |
121 /// When an error occurs trying to read something about [package] from [url], | 123 /// When an error occurs trying to read something about [package] from [url], |
122 /// this tries to translate into a more user friendly error message. Always | 124 /// this tries to translate into a more user friendly error message. Always |
123 /// throws an error, either the original one or a better one. | 125 /// throws an error, either the original one or a better one. |
124 void _throwFriendlyError(AsyncError asyncError, package, url) { | 126 void _throwFriendlyError(AsyncError asyncError, package, url) { |
125 if (asyncError.error is PubHttpException && | 127 if (asyncError.error is PubHttpException && |
126 asyncError.error.response.statusCode == 404) { | 128 asyncError.error.response.statusCode == 404) { |
127 throw 'Could not find package "$package" at $url.'; | 129 throw 'Could not find package "$package" at $url.'; |
128 } | 130 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 | 163 |
162 var name = description["name"]; | 164 var name = description["name"]; |
163 if (name is! String) { | 165 if (name is! String) { |
164 throw new FormatException("The 'name' key must have a string value."); | 166 throw new FormatException("The 'name' key must have a string value."); |
165 } | 167 } |
166 | 168 |
167 var url = description.containsKey("url") ? description["url"] : defaultUrl; | 169 var url = description.containsKey("url") ? description["url"] : defaultUrl; |
168 return new Pair<String, String>(name, url); | 170 return new Pair<String, String>(name, url); |
169 } | 171 } |
170 } | 172 } |
OLD | NEW |