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 'package:oauth2/oauth2.dart' as oauth2; | 8 import 'package:oauth2/oauth2.dart' as oauth2; |
9 import 'package:scheduled_test/scheduled_server.dart'; | 9 import 'package:scheduled_test/scheduled_server.dart'; |
10 import 'package:scheduled_test/descriptor.dart'; | 10 import 'package:scheduled_test/descriptor.dart'; |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 /// Creates a new [GitRepoDescriptor] with [name] and [contents]. | 22 /// Creates a new [GitRepoDescriptor] with [name] and [contents]. |
23 GitRepoDescriptor git(String name, [Iterable<Descriptor> contents]) => | 23 GitRepoDescriptor git(String name, [Iterable<Descriptor> contents]) => |
24 new GitRepoDescriptor(name, contents == null ? <Descriptor>[] : contents); | 24 new GitRepoDescriptor(name, contents == null ? <Descriptor>[] : contents); |
25 | 25 |
26 /// Creates a new [TarRepoDescriptor] with [name] and [contents]. | 26 /// Creates a new [TarRepoDescriptor] with [name] and [contents]. |
27 TarFileDescriptor tar(String name, [Iterable<Descriptor> contents]) => | 27 TarFileDescriptor tar(String name, [Iterable<Descriptor> contents]) => |
28 new TarFileDescriptor(name, contents == null ? <Descriptor>[] : contents); | 28 new TarFileDescriptor(name, contents == null ? <Descriptor>[] : contents); |
29 | 29 |
30 /// Describes a package that passes all validation. | 30 /// Describes a package that passes all validation. |
31 Descriptor get validPackage => dir(appPath, [ | 31 Descriptor get validPackage => |
32 libPubspec("test_pkg", "1.0.0"), | 32 dir( |
33 file("LICENSE", "Eh, do what you want."), | 33 appPath, |
34 dir("lib", [ | 34 [ |
35 file("test_pkg.dart", "int i = 1;") | 35 libPubspec("test_pkg", "1.0.0"), |
36 ]) | 36 file("LICENSE", "Eh, do what you want."), |
37 ]); | 37 dir("lib", [file("test_pkg.dart", "int i = 1;")])]); |
38 | 38 |
39 /// Returns a descriptor of a snapshot that can't be run by the current VM. | 39 /// Returns a descriptor of a snapshot that can't be run by the current VM. |
40 /// | 40 /// |
41 /// This snapshot was generated by the VM on r39611, the revision immediately | 41 /// This snapshot was generated by the VM on r39611, the revision immediately |
42 /// before snapshot versioning was added. | 42 /// before snapshot versioning was added. |
43 FileDescriptor outOfDateSnapshot(String name) => | 43 FileDescriptor outOfDateSnapshot(String name) => |
44 binaryFile(name, readBinaryFile(testAssetPath('out-of-date.snapshot'))); | 44 binaryFile(name, readBinaryFile(testAssetPath('out-of-date.snapshot'))); |
45 | 45 |
46 /// Describes a file named `pubspec.yaml` with the given YAML-serialized | 46 /// Describes a file named `pubspec.yaml` with the given YAML-serialized |
47 /// [contents], which should be a serializable object. | 47 /// [contents], which should be a serializable object. |
48 /// | 48 /// |
49 /// [contents] may contain [Future]s that resolve to serializable objects, | 49 /// [contents] may contain [Future]s that resolve to serializable objects, |
50 /// which may in turn contain [Future]s recursively. | 50 /// which may in turn contain [Future]s recursively. |
51 Descriptor pubspec(Map contents) { | 51 Descriptor pubspec(Map contents) { |
52 return async(awaitObject(contents).then((resolvedContents) => | 52 return async( |
53 file("pubspec.yaml", yaml(resolvedContents)))); | 53 awaitObject( |
| 54 contents).then( |
| 55 (resolvedContents) => file("pubspec.yaml", yaml(resolvedContents))
)); |
54 } | 56 } |
55 | 57 |
56 /// Describes a file named `pubspec.yaml` for an application package with the | 58 /// Describes a file named `pubspec.yaml` for an application package with the |
57 /// given [dependencies]. | 59 /// given [dependencies]. |
58 Descriptor appPubspec([Map dependencies]) { | 60 Descriptor appPubspec([Map dependencies]) { |
59 var map = {"name": "myapp"}; | 61 var map = { |
| 62 "name": "myapp" |
| 63 }; |
60 if (dependencies != null) map["dependencies"] = dependencies; | 64 if (dependencies != null) map["dependencies"] = dependencies; |
61 return pubspec(map); | 65 return pubspec(map); |
62 } | 66 } |
63 | 67 |
64 /// Describes a file named `pubspec.yaml` for a library package with the given | 68 /// Describes a file named `pubspec.yaml` for a library package with the given |
65 /// [name], [version], and [deps]. If "sdk" is given, then it adds an SDK | 69 /// [name], [version], and [deps]. If "sdk" is given, then it adds an SDK |
66 /// constraint on that version. | 70 /// constraint on that version. |
67 Descriptor libPubspec(String name, String version, {Map deps, String sdk}) { | 71 Descriptor libPubspec(String name, String version, {Map deps, String sdk}) { |
68 var map = packageMap(name, version, deps); | 72 var map = packageMap(name, version, deps); |
69 if (sdk != null) map["environment"] = {"sdk": sdk}; | 73 if (sdk != null) map["environment"] = { |
| 74 "sdk": sdk |
| 75 }; |
70 return pubspec(map); | 76 return pubspec(map); |
71 } | 77 } |
72 | 78 |
73 /// Describes a directory named `lib` containing a single dart file named | 79 /// Describes a directory named `lib` containing a single dart file named |
74 /// `<name>.dart` that contains a line of Dart code. | 80 /// `<name>.dart` that contains a line of Dart code. |
75 Descriptor libDir(String name, [String code]) { | 81 Descriptor libDir(String name, [String code]) { |
76 // Default to printing the name if no other code was given. | 82 // Default to printing the name if no other code was given. |
77 if (code == null) code = name; | 83 if (code == null) code = name; |
78 return dir("lib", [ | 84 return dir("lib", [file("$name.dart", 'main() => "$code";')]); |
79 file("$name.dart", 'main() => "$code";') | |
80 ]); | |
81 } | 85 } |
82 | 86 |
83 /// Describes a directory for a Git package. This directory is of the form | 87 /// Describes a directory for a Git package. This directory is of the form |
84 /// found in the revision cache of the global package cache. | 88 /// found in the revision cache of the global package cache. |
85 Descriptor gitPackageRevisionCacheDir(String name, [int modifier]) { | 89 Descriptor gitPackageRevisionCacheDir(String name, [int modifier]) { |
86 var value = name; | 90 var value = name; |
87 if (modifier != null) value = "$name $modifier"; | 91 if (modifier != null) value = "$name $modifier"; |
88 return pattern(new RegExp("$name${r'-[a-f0-9]+'}"), | 92 return pattern( |
| 93 new RegExp("$name${r'-[a-f0-9]+'}"), |
89 (dirName) => dir(dirName, [libDir(name, value)])); | 94 (dirName) => dir(dirName, [libDir(name, value)])); |
90 } | 95 } |
91 | 96 |
92 /// Describes a directory for a Git package. This directory is of the form | 97 /// Describes a directory for a Git package. This directory is of the form |
93 /// found in the repo cache of the global package cache. | 98 /// found in the repo cache of the global package cache. |
94 Descriptor gitPackageRepoCacheDir(String name) { | 99 Descriptor gitPackageRepoCacheDir(String name) { |
95 return pattern(new RegExp("$name${r'-[a-f0-9]+'}"), | 100 return pattern( |
96 (dirName) => dir(dirName, [ | 101 new RegExp("$name${r'-[a-f0-9]+'}"), |
97 dir('hooks'), | 102 (dirName) => |
98 dir('info'), | 103 dir(dirName, [dir('hooks'), dir('info'), dir('objects'), dir('refs')])
); |
99 dir('objects'), | |
100 dir('refs') | |
101 ])); | |
102 } | 104 } |
103 | 105 |
104 /// Describes the `packages/` directory containing all the given [packages], | 106 /// Describes the `packages/` directory containing all the given [packages], |
105 /// which should be name/version pairs. The packages will be validated against | 107 /// which should be name/version pairs. The packages will be validated against |
106 /// the format produced by the mock package server. | 108 /// the format produced by the mock package server. |
107 /// | 109 /// |
108 /// A package with a null version should not be downloaded. | 110 /// A package with a null version should not be downloaded. |
109 Descriptor packagesDir(Map<String, String> packages) { | 111 Descriptor packagesDir(Map<String, String> packages) { |
110 var contents = <Descriptor>[]; | 112 var contents = <Descriptor>[]; |
111 packages.forEach((name, version) { | 113 packages.forEach((name, version) { |
112 if (version == null) { | 114 if (version == null) { |
113 contents.add(nothing(name)); | 115 contents.add(nothing(name)); |
114 } else { | 116 } else { |
115 contents.add(dir(name, [ | 117 contents.add( |
116 file("$name.dart", 'main() => "$name $version";') | 118 dir(name, [file("$name.dart", 'main() => "$name $version";')])); |
117 ])); | |
118 } | 119 } |
119 }); | 120 }); |
120 return dir(packagesPath, contents); | 121 return dir(packagesPath, contents); |
121 } | 122 } |
122 | 123 |
123 /// Describes the global package cache directory containing all the given | 124 /// Describes the global package cache directory containing all the given |
124 /// [packages], which should be name/version pairs. The packages will be | 125 /// [packages], which should be name/version pairs. The packages will be |
125 /// validated against the format produced by the mock package server. | 126 /// validated against the format produced by the mock package server. |
126 /// | 127 /// |
127 /// A package's value may also be a list of versions, in which case all | 128 /// A package's value may also be a list of versions, in which case all |
(...skipping 16 matching lines...) Expand all Loading... |
144 contents.add(dir("$name-$version", packageContents)); | 145 contents.add(dir("$name-$version", packageContents)); |
145 } | 146 } |
146 }); | 147 }); |
147 | 148 |
148 return hostedCache(contents); | 149 return hostedCache(contents); |
149 } | 150 } |
150 | 151 |
151 /// Describes the main cache directory containing cached hosted packages | 152 /// Describes the main cache directory containing cached hosted packages |
152 /// downloaded from the mock package server. | 153 /// downloaded from the mock package server. |
153 Descriptor hostedCache(Iterable<Descriptor> contents) { | 154 Descriptor hostedCache(Iterable<Descriptor> contents) { |
154 return dir(cachePath, [ | 155 return dir( |
155 dir('hosted', [ | 156 cachePath, |
156 async(port.then((p) => dir('localhost%58$p', contents))) | 157 [dir('hosted', [async(port.then((p) => dir('localhost%58$p', contents)))])
]); |
157 ]) | |
158 ]); | |
159 } | 158 } |
160 | 159 |
161 /// Describes the file in the system cache that contains the client's OAuth2 | 160 /// Describes the file in the system cache that contains the client's OAuth2 |
162 /// credentials. The URL "/token" on [server] will be used as the token | 161 /// credentials. The URL "/token" on [server] will be used as the token |
163 /// endpoint for refreshing the access token. | 162 /// endpoint for refreshing the access token. |
164 Descriptor credentialsFile( | 163 Descriptor credentialsFile(ScheduledServer server, String accessToken, |
165 ScheduledServer server, | 164 {String refreshToken, DateTime expiration}) { |
166 String accessToken, | |
167 {String refreshToken, | |
168 DateTime expiration}) { | |
169 return async(server.url.then((url) { | 165 return async(server.url.then((url) { |
170 return dir(cachePath, [ | 166 return dir( |
171 file('credentials.json', new oauth2.Credentials( | 167 cachePath, |
172 accessToken, | 168 [ |
173 refreshToken, | 169 file( |
174 url.resolve('/token'), | 170 'credentials.json', |
175 ['https://www.googleapis.com/auth/userinfo.email'], | 171 new oauth2.Credentials( |
176 expiration).toJson()) | 172 accessToken, |
177 ]); | 173 refreshToken, |
| 174 url.resolve('/token'), |
| 175 ['https://www.googleapis.com/auth/userinfo.email'], |
| 176 expiration).toJson())]); |
178 })); | 177 })); |
179 } | 178 } |
180 | 179 |
181 /// Describes the application directory, containing only a pubspec specifying | 180 /// Describes the application directory, containing only a pubspec specifying |
182 /// the given [dependencies]. | 181 /// the given [dependencies]. |
183 DirectoryDescriptor appDir([Map dependencies]) => | 182 DirectoryDescriptor appDir([Map dependencies]) => |
184 dir(appPath, [appPubspec(dependencies)]); | 183 dir(appPath, [appPubspec(dependencies)]); |
OLD | NEW |