OLD | NEW |
(Empty) | |
| 1 library descriptor; |
| 2 import 'package:oauth2/oauth2.dart' as oauth2; |
| 3 import 'package:scheduled_test/scheduled_server.dart'; |
| 4 import 'package:scheduled_test/descriptor.dart'; |
| 5 import '../lib/src/io.dart'; |
| 6 import '../lib/src/utils.dart'; |
| 7 import 'descriptor/git.dart'; |
| 8 import 'descriptor/tar.dart'; |
| 9 import 'test_pub.dart'; |
| 10 export 'package:scheduled_test/descriptor.dart'; |
| 11 export 'descriptor/git.dart'; |
| 12 export 'descriptor/tar.dart'; |
| 13 GitRepoDescriptor git(String name, [Iterable<Descriptor> contents]) => |
| 14 new GitRepoDescriptor(name, contents == null ? <Descriptor>[] : contents); |
| 15 TarFileDescriptor tar(String name, [Iterable<Descriptor> contents]) => |
| 16 new TarFileDescriptor(name, contents == null ? <Descriptor>[] : contents); |
| 17 Descriptor get validPackage => |
| 18 dir( |
| 19 appPath, |
| 20 [ |
| 21 libPubspec("test_pkg", "1.0.0"), |
| 22 file("LICENSE", "Eh, do what you want."), |
| 23 dir("lib", [file("test_pkg.dart", "int i = 1;")])]); |
| 24 FileDescriptor outOfDateSnapshot(String name) => |
| 25 binaryFile(name, readBinaryFile(testAssetPath('out-of-date.snapshot'))); |
| 26 Descriptor pubspec(Map contents) { |
| 27 return async( |
| 28 awaitObject( |
| 29 contents).then( |
| 30 (resolvedContents) => file("pubspec.yaml", yaml(resolvedContents))
)); |
| 31 } |
| 32 Descriptor appPubspec([Map dependencies]) { |
| 33 var map = { |
| 34 "name": "myapp" |
| 35 }; |
| 36 if (dependencies != null) map["dependencies"] = dependencies; |
| 37 return pubspec(map); |
| 38 } |
| 39 Descriptor libPubspec(String name, String version, {Map deps, String sdk}) { |
| 40 var map = packageMap(name, version, deps); |
| 41 if (sdk != null) map["environment"] = { |
| 42 "sdk": sdk |
| 43 }; |
| 44 return pubspec(map); |
| 45 } |
| 46 Descriptor libDir(String name, [String code]) { |
| 47 if (code == null) code = name; |
| 48 return dir("lib", [file("$name.dart", 'main() => "$code";')]); |
| 49 } |
| 50 Descriptor gitPackageRevisionCacheDir(String name, [int modifier]) { |
| 51 var value = name; |
| 52 if (modifier != null) value = "$name $modifier"; |
| 53 return pattern( |
| 54 new RegExp("$name${r'-[a-f0-9]+'}"), |
| 55 (dirName) => dir(dirName, [libDir(name, value)])); |
| 56 } |
| 57 Descriptor gitPackageRepoCacheDir(String name) { |
| 58 return pattern( |
| 59 new RegExp("$name${r'-[a-f0-9]+'}"), |
| 60 (dirName) => |
| 61 dir(dirName, [dir('hooks'), dir('info'), dir('objects'), dir('refs')])
); |
| 62 } |
| 63 Descriptor packagesDir(Map<String, String> packages) { |
| 64 var contents = <Descriptor>[]; |
| 65 packages.forEach((name, version) { |
| 66 if (version == null) { |
| 67 contents.add(nothing(name)); |
| 68 } else { |
| 69 contents.add( |
| 70 dir(name, [file("$name.dart", 'main() => "$name $version";')])); |
| 71 } |
| 72 }); |
| 73 return dir(packagesPath, contents); |
| 74 } |
| 75 Descriptor cacheDir(Map packages, {bool includePubspecs: false}) { |
| 76 var contents = <Descriptor>[]; |
| 77 packages.forEach((name, versions) { |
| 78 if (versions is! List) versions = [versions]; |
| 79 for (var version in versions) { |
| 80 var packageContents = [libDir(name, '$name $version')]; |
| 81 if (includePubspecs) { |
| 82 packageContents.add(libPubspec(name, version)); |
| 83 } |
| 84 contents.add(dir("$name-$version", packageContents)); |
| 85 } |
| 86 }); |
| 87 return hostedCache(contents); |
| 88 } |
| 89 Descriptor hostedCache(Iterable<Descriptor> contents) { |
| 90 return dir( |
| 91 cachePath, |
| 92 [dir('hosted', [async(port.then((p) => dir('localhost%58$p', contents)))])
]); |
| 93 } |
| 94 Descriptor credentialsFile(ScheduledServer server, String accessToken, |
| 95 {String refreshToken, DateTime expiration}) { |
| 96 return async(server.url.then((url) { |
| 97 return dir( |
| 98 cachePath, |
| 99 [ |
| 100 file( |
| 101 'credentials.json', |
| 102 new oauth2.Credentials( |
| 103 accessToken, |
| 104 refreshToken, |
| 105 url.resolve('/token'), |
| 106 ['https://www.googleapis.com/auth/userinfo.email'], |
| 107 expiration).toJson())]); |
| 108 })); |
| 109 } |
| 110 DirectoryDescriptor appDir([Map dependencies]) => |
| 111 dir(appPath, [appPubspec(dependencies)]); |
OLD | NEW |