OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /// Pub-specific scheduled_test descriptors. | 5 /// Pub-specific scheduled_test descriptors. |
6 library descriptor; | 6 library descriptor; |
7 | 7 |
8 import "dart:io" show File; | |
9 | |
8 import 'package:oauth2/oauth2.dart' as oauth2; | 10 import 'package:oauth2/oauth2.dart' as oauth2; |
11 import 'package:path/path.dart' as p; | |
9 import 'package:pub/src/io.dart'; | 12 import 'package:pub/src/io.dart'; |
10 import 'package:pub/src/utils.dart'; | 13 import 'package:pub/src/utils.dart'; |
11 import 'package:scheduled_test/descriptor.dart'; | 14 import 'package:scheduled_test/descriptor.dart'; |
12 import 'package:scheduled_test/scheduled_server.dart'; | 15 import 'package:scheduled_test/scheduled_server.dart'; |
16 import 'package:package_config/packages_file.dart' as packages_file; | |
17 import 'package:stack_trace/stack_trace.dart'; | |
13 | 18 |
14 import 'descriptor/git.dart'; | 19 import 'descriptor/git.dart'; |
15 import 'descriptor/tar.dart'; | 20 import 'descriptor/tar.dart'; |
16 import 'test_pub.dart'; | 21 import 'test_pub.dart'; |
17 | 22 |
18 export 'package:scheduled_test/descriptor.dart'; | 23 export 'package:scheduled_test/descriptor.dart'; |
19 export 'descriptor/git.dart'; | 24 export 'descriptor/git.dart'; |
20 export 'descriptor/tar.dart'; | 25 export 'descriptor/tar.dart'; |
21 | 26 |
22 /// Creates a new [GitRepoDescriptor] with [name] and [contents]. | 27 /// Creates a new [GitRepoDescriptor] with [name] and [contents]. |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 ['https://www.googleapis.com/auth/userinfo.email'], | 180 ['https://www.googleapis.com/auth/userinfo.email'], |
176 expiration).toJson()) | 181 expiration).toJson()) |
177 ]); | 182 ]); |
178 })); | 183 })); |
179 } | 184 } |
180 | 185 |
181 /// Describes the application directory, containing only a pubspec specifying | 186 /// Describes the application directory, containing only a pubspec specifying |
182 /// the given [dependencies]. | 187 /// the given [dependencies]. |
183 DirectoryDescriptor appDir([Map dependencies]) => | 188 DirectoryDescriptor appDir([Map dependencies]) => |
184 dir(appPath, [appPubspec(dependencies)]); | 189 dir(appPath, [appPubspec(dependencies)]); |
190 | |
191 /// Describes a `.packages` file. | |
192 /// | |
193 /// The [dependencies] maps package names to version strings. | |
nweiz
2015/06/12 23:48:08
Remove "The"
Lasse Reichstein Nielsen
2015/06/23 14:54:33
Done.
| |
194 /// | |
195 /// Validation checks that the `.packages` file exists, has the expected | |
196 /// entries (one per key in []) with a path that contains the version string. | |
nweiz
2015/06/12 23:48:08
"[]" -> "[dependencies]"
Lasse Reichstein Nielsen
2015/06/23 14:54:34
Done.
| |
197 Descriptor packagesFile([Map dependencies]) => | |
198 new _PackagesFileDescriptor(dependencies); | |
199 | |
200 class _PackagesFileDescriptor extends Descriptor { | |
nweiz
2015/06/12 23:48:08
This is big enough now it probably warrants its ow
Lasse Reichstein Nielsen
2015/06/23 14:54:33
Done.
| |
201 final _dependencies; | |
202 | |
203 _PackagesFileDescriptor([Map<String, String> contents]) | |
204 : _dependencies = contents, super('.packages'); | |
205 | |
206 Future create([String parent]) => schedule(() { | |
207 if (parent == null) parent = defaultRoot; | |
208 var contents = const <int>[]; | |
209 if (_dependencies != null) { | |
210 var mapping = {}; | |
211 _dependencies.forEach((k, v) { | |
nweiz
2015/06/12 23:48:08
Nit: use full words for variables. Also, something
Lasse Reichstein Nielsen
2015/06/23 14:54:33
Done.
| |
212 mapping[k] = p.toUri(p.join(cachePath, "$k-$v", "lib", "")); | |
213 }); | |
214 var buffer = new StringBuffer(); | |
215 packages_file.write(buffer, mapping); | |
216 contents = UTF8.encode(buffer.toString()); | |
217 } | |
218 return Chain.track(new File(p.join(parent, name)) | |
nweiz
2015/06/12 23:48:08
Chain.track isn't necessary here anymore.
Lasse Reichstein Nielsen
2015/06/23 14:54:33
Done.
| |
219 .writeAsBytes(contents)); | |
220 }, "creating file '$name'"); | |
221 | |
222 Future validate([String parent]) => | |
223 schedule(() => validateNow(parent), "validating file '$name'"); | |
224 | |
225 Future validateNow([String parent]) { | |
226 // Copied from FileDescriptor in scheduled_test. | |
227 if (parent == null) parent = defaultRoot; | |
228 var fullPath = p.join(parent, name); | |
229 if (!new File(fullPath).existsSync()) { | |
230 fail("File not found: '$fullPath'."); | |
231 } | |
232 return Chain.track(new File(fullPath).readAsBytes()) | |
nweiz
2015/06/12 23:48:08
Ditto.
Lasse Reichstein Nielsen
2015/06/23 14:54:33
Done.
| |
233 .then((bytes) => _validateNow(bytes, fullPath)); | |
234 } | |
235 | |
236 // TODO(nweiz): rather than setting up an inheritance chain, just store a | |
237 // Matcher for validation. This would require better error messages from the | |
238 // matcher library, though. | |
nweiz
2015/06/12 23:48:08
Remove this TODO.
Lasse Reichstein Nielsen
2015/06/23 14:54:34
Done.
| |
239 /// A function that throws an error if [binaryContents] doesn't match the | |
240 /// expected contents of the descriptor. | |
241 void _validateNow(List<int> binaryContents, String fullPath) { | |
242 var fileUri = p.toUri(fullPath); | |
243 var map = packages_file.parse(binaryContents, fileUri); | |
244 | |
245 for (var packageName in _dependencies.keys) { | |
246 if (!map.containsKey(packageName)) { | |
247 fail(".packages does not contain $packageName entry"); | |
248 } | |
249 var version = _dependencies[packageName]; | |
250 if (!map[packageName].path.contains(version)) { | |
251 fail(".packages of $packageName has incorrect version. " | |
252 "Expected $version, found location: ${map[packageName]}."); | |
253 } | |
254 } | |
255 | |
256 if (map.length != _dependencies.length) { | |
257 for (var key in map.keys) { | |
258 if (!_dependencies.containsKey(key)) { | |
259 fail(".packages file contains unexpected entry: $key"); | |
260 } | |
261 } | |
262 } | |
263 } | |
264 | |
265 String describe() => name; | |
266 } | |
OLD | NEW |