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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 return httpClient.read(url).then((yaml) { | 56 return httpClient.read(url).then((yaml) { |
57 return new Pubspec.parse(null, yaml, systemCache.sources); | 57 return new Pubspec.parse(null, yaml, systemCache.sources); |
58 }).catchError((ex) { | 58 }).catchError((ex) { |
59 var parsed = _parseDescription(id.description); | 59 var parsed = _parseDescription(id.description); |
60 _throwFriendlyError(ex, id, parsed.last); | 60 _throwFriendlyError(ex, id, parsed.last); |
61 }); | 61 }); |
62 } | 62 } |
63 | 63 |
64 /// Downloads a package from the site and unpacks it. | 64 /// Downloads a package from the site and unpacks it. |
65 Future<bool> install(PackageId id, String destPath) { | 65 Future<bool> install(PackageId id, String destPath) { |
66 return new Future.of(() { | 66 return new Future.sync(() { |
67 var url = _makeVersionUrl(id, (server, package, version) => | 67 var url = _makeVersionUrl(id, (server, package, version) => |
68 "$server/packages/$package/versions/$version.tar.gz"); | 68 "$server/packages/$package/versions/$version.tar.gz"); |
69 log.io("Install package from $url."); | 69 log.io("Install package from $url."); |
70 | 70 |
71 log.message('Downloading $id...'); | 71 log.message('Downloading $id...'); |
72 | 72 |
73 // Download and extract the archive to a temp directory. | 73 // Download and extract the archive to a temp directory. |
74 var tempDir = systemCache.createTempDir(); | 74 var tempDir = systemCache.createTempDir(); |
75 return httpClient.send(new http.Request("GET", url)) | 75 return httpClient.send(new http.Request("GET", url)) |
76 .then((response) => response.stream) | 76 .then((response) => response.stream) |
(...skipping 14 matching lines...) Expand all Loading... |
91 /// for each separate repository URL that's used on the system. Each of these | 91 /// for each separate repository URL that's used on the system. Each of these |
92 /// subdirectories then contains a subdirectory for each package installed | 92 /// subdirectories then contains a subdirectory for each package installed |
93 /// from that site. | 93 /// from that site. |
94 Future<String> systemCacheDirectory(PackageId id) { | 94 Future<String> systemCacheDirectory(PackageId id) { |
95 var parsed = _parseDescription(id.description); | 95 var parsed = _parseDescription(id.description); |
96 var url = _getSourceDirectory(parsed.last); | 96 var url = _getSourceDirectory(parsed.last); |
97 var urlDir = replace(url, new RegExp(r'[<>:"\\/|?*%]'), (match) { | 97 var urlDir = replace(url, new RegExp(r'[<>:"\\/|?*%]'), (match) { |
98 return '%${match[0].codeUnitAt(0)}'; | 98 return '%${match[0].codeUnitAt(0)}'; |
99 }); | 99 }); |
100 | 100 |
101 return new Future.immediate( | 101 return new Future.value( |
102 path.join(systemCacheRoot, urlDir, "${parsed.first}-${id.version}")); | 102 path.join(systemCacheRoot, urlDir, "${parsed.first}-${id.version}")); |
103 } | 103 } |
104 | 104 |
105 String packageName(description) => _parseDescription(description).first; | 105 String packageName(description) => _parseDescription(description).first; |
106 | 106 |
107 bool descriptionsEqual(description1, description2) => | 107 bool descriptionsEqual(description1, description2) => |
108 _parseDescription(description1) == _parseDescription(description2); | 108 _parseDescription(description1) == _parseDescription(description2); |
109 | 109 |
110 /// Ensures that [description] is a valid hosted package description. | 110 /// Ensures that [description] is a valid hosted package description. |
111 /// | 111 /// |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 } | 200 } |
201 | 201 |
202 var name = description["name"]; | 202 var name = description["name"]; |
203 if (name is! String) { | 203 if (name is! String) { |
204 throw new FormatException("The 'name' key must have a string value."); | 204 throw new FormatException("The 'name' key must have a string value."); |
205 } | 205 } |
206 | 206 |
207 var url = description.containsKey("url") ? description["url"] : _defaultUrl; | 207 var url = description.containsKey("url") ? description["url"] : _defaultUrl; |
208 return new Pair<String, String>(name, url); | 208 return new Pair<String, String>(name, url); |
209 } | 209 } |
OLD | NEW |