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 /// Returns a list of packages in the default cache | |
Bob Nystrom
2013/03/12 22:12:03
Remove this comment.
keertip
2013/03/13 15:55:00
Done.
| |
122 Future<List<Package>> getCachedPackages() { | |
123 var url = _defaultUrl.replaceAll(new RegExp(r"^https?://"), ""); | |
Bob Nystrom
2013/03/12 22:12:03
Can you pull this out into a separate function and
keertip
2013/03/13 15:55:00
Done.
| |
124 return listDir(path.join(systemCacheRoot,url)).then((entries){ | |
Bob Nystrom
2013/03/12 22:12:03
Space after "," and between ")" and "{".
keertip
2013/03/13 15:55:00
Done.
| |
125 var list = new List(); | |
126 for (var entry in entries) { | |
127 var name = path.basename(entry).replaceAll(new RegExp(r"-(.*)"),""); | |
Bob Nystrom
2013/03/12 22:12:03
How about:
path.basename(entry).split('-')[0];
nweiz
2013/03/12 22:58:48
Both of these are dangerous if a package has a hyp
| |
128 var p = new Package.load(name, entry, systemCache.sources); | |
129 list.add(p); | |
130 } | |
131 return list; | |
Bob Nystrom
2013/03/12 22:12:03
return entries.map((entry) {
var name = ...
re
keertip
2013/03/13 15:55:00
Done.
| |
132 }).catchError((ex) { | |
133 throw 'Could not list packages in pub cache ${ex}'; | |
Bob Nystrom
2013/03/12 22:12:03
Don't bother catching this.
keertip
2013/03/13 15:55:00
Done.
| |
134 }); | |
135 } | |
136 | |
121 /// When an error occurs trying to read something about [package] from [url], | 137 /// 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 | 138 /// this tries to translate into a more user friendly error message. Always |
123 /// throws an error, either the original one or a better one. | 139 /// throws an error, either the original one or a better one. |
124 void _throwFriendlyError(AsyncError asyncError, package, url) { | 140 void _throwFriendlyError(AsyncError asyncError, package, url) { |
125 if (asyncError.error is PubHttpException && | 141 if (asyncError.error is PubHttpException && |
126 asyncError.error.response.statusCode == 404) { | 142 asyncError.error.response.statusCode == 404) { |
127 throw 'Could not find package "$package" at $url.'; | 143 throw 'Could not find package "$package" at $url.'; |
128 } | 144 } |
129 | 145 |
130 if (asyncError.error is TimeoutException) { | 146 if (asyncError.error is TimeoutException) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 } | 203 } |
188 | 204 |
189 var name = description["name"]; | 205 var name = description["name"]; |
190 if (name is! String) { | 206 if (name is! String) { |
191 throw new FormatException("The 'name' key must have a string value."); | 207 throw new FormatException("The 'name' key must have a string value."); |
192 } | 208 } |
193 | 209 |
194 var url = description.containsKey("url") ? description["url"] : _defaultUrl; | 210 var url = description.containsKey("url") ? description["url"] : _defaultUrl; |
195 return new Pair<String, String>(name, url); | 211 return new Pair<String, String>(name, url); |
196 } | 212 } |
OLD | NEW |