| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 /// | 111 /// |
| 112 /// There are two valid formats. A plain string refers to a package with the | 112 /// There are two valid formats. A plain string refers to a package with the |
| 113 /// given name from the default host, while a map with keys "name" and "url" | 113 /// given name from the default host, while a map with keys "name" and "url" |
| 114 /// refers to a package with the given name from the host at the given URL. | 114 /// refers to a package with the given name from the host at the given URL. |
| 115 dynamic parseDescription(String containingPath, description, | 115 dynamic parseDescription(String containingPath, description, |
| 116 {bool fromLockFile: false}) { | 116 {bool fromLockFile: false}) { |
| 117 _parseDescription(description); | 117 _parseDescription(description); |
| 118 return description; | 118 return description; |
| 119 } | 119 } |
| 120 | 120 |
| 121 Future<List<Package>> getCachedPackages() { | 121 List<Package> getCachedPackages() { |
| 122 return defer(() { | 122 var cacheDir = path.join(systemCacheRoot, |
| 123 var cacheDir = path.join(systemCacheRoot, | 123 _getSourceDirectory(_defaultUrl)); |
| 124 _getSourceDirectory(_defaultUrl)); | 124 if (!dirExists(cacheDir)) return []; |
| 125 if (!dirExists(cacheDir)) return []; | 125 |
| 126 | 126 return listDir(path.join(cacheDir)).map((entry) => |
| 127 return listDir(path.join(cacheDir)).then((entries) { | 127 new Package.load(null, entry, systemCache.sources)); |
| 128 return entries.map((entry) => | |
| 129 new Package.load(null, entry, systemCache.sources)); | |
| 130 }); | |
| 131 }); | |
| 132 } | 128 } |
| 133 | 129 |
| 134 /// When an error occurs trying to read something about [package] from [url], | 130 /// When an error occurs trying to read something about [package] from [url], |
| 135 /// this tries to translate into a more user friendly error message. Always | 131 /// this tries to translate into a more user friendly error message. Always |
| 136 /// throws an error, either the original one or a better one. | 132 /// throws an error, either the original one or a better one. |
| 137 void _throwFriendlyError(AsyncError asyncError, package, url) { | 133 void _throwFriendlyError(AsyncError asyncError, package, url) { |
| 138 if (asyncError.error is PubHttpException && | 134 if (asyncError.error is PubHttpException && |
| 139 asyncError.error.response.statusCode == 404) { | 135 asyncError.error.response.statusCode == 404) { |
| 140 throw 'Could not find package "$package" at $url.'; | 136 throw 'Could not find package "$package" at $url.'; |
| 141 } | 137 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 } | 200 } |
| 205 | 201 |
| 206 var name = description["name"]; | 202 var name = description["name"]; |
| 207 if (name is! String) { | 203 if (name is! String) { |
| 208 throw new FormatException("The 'name' key must have a string value."); | 204 throw new FormatException("The 'name' key must have a string value."); |
| 209 } | 205 } |
| 210 | 206 |
| 211 var url = description.containsKey("url") ? description["url"] : _defaultUrl; | 207 var url = description.containsKey("url") ? description["url"] : _defaultUrl; |
| 212 return new Pair<String, String>(name, url); | 208 return new Pair<String, String>(name, url); |
| 213 } | 209 } |
| OLD | NEW |