Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: sdk/lib/_internal/pub/test/descriptor.dart

Issue 1165473002: Start pulling pub from its own repo. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Code review changes Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /// Pub-specific scheduled_test descriptors.
6 library descriptor;
7
8 import 'package:oauth2/oauth2.dart' as oauth2;
9 import 'package:scheduled_test/scheduled_server.dart';
10 import 'package:scheduled_test/descriptor.dart';
11
12 import '../lib/src/io.dart';
13 import '../lib/src/utils.dart';
14 import 'descriptor/git.dart';
15 import 'descriptor/tar.dart';
16 import 'test_pub.dart';
17
18 export 'package:scheduled_test/descriptor.dart';
19 export 'descriptor/git.dart';
20 export 'descriptor/tar.dart';
21
22 /// Creates a new [GitRepoDescriptor] with [name] and [contents].
23 GitRepoDescriptor git(String name, [Iterable<Descriptor> contents]) =>
24 new GitRepoDescriptor(name, contents == null ? <Descriptor>[] : contents);
25
26 /// Creates a new [TarRepoDescriptor] with [name] and [contents].
27 TarFileDescriptor tar(String name, [Iterable<Descriptor> contents]) =>
28 new TarFileDescriptor(name, contents == null ? <Descriptor>[] : contents);
29
30 /// Describes a package that passes all validation.
31 Descriptor get validPackage => dir(appPath, [
32 libPubspec("test_pkg", "1.0.0"),
33 file("LICENSE", "Eh, do what you want."),
34 dir("lib", [
35 file("test_pkg.dart", "int i = 1;")
36 ])
37 ]);
38
39 /// Returns a descriptor of a snapshot that can't be run by the current VM.
40 ///
41 /// This snapshot was generated by the VM on r39611, the revision immediately
42 /// before snapshot versioning was added.
43 FileDescriptor outOfDateSnapshot(String name) =>
44 binaryFile(name, readBinaryFile(testAssetPath('out-of-date.snapshot')));
45
46 /// Describes a file named `pubspec.yaml` with the given YAML-serialized
47 /// [contents], which should be a serializable object.
48 ///
49 /// [contents] may contain [Future]s that resolve to serializable objects,
50 /// which may in turn contain [Future]s recursively.
51 Descriptor pubspec(Map contents) {
52 return async(awaitObject(contents).then((resolvedContents) =>
53 file("pubspec.yaml", yaml(resolvedContents))));
54 }
55
56 /// Describes a file named `pubspec.yaml` for an application package with the
57 /// given [dependencies].
58 Descriptor appPubspec([Map dependencies]) {
59 var map = {"name": "myapp"};
60 if (dependencies != null) map["dependencies"] = dependencies;
61 return pubspec(map);
62 }
63
64 /// 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
66 /// constraint on that version.
67 Descriptor libPubspec(String name, String version, {Map deps, String sdk}) {
68 var map = packageMap(name, version, deps);
69 if (sdk != null) map["environment"] = {"sdk": sdk};
70 return pubspec(map);
71 }
72
73 /// Describes a directory named `lib` containing a single dart file named
74 /// `<name>.dart` that contains a line of Dart code.
75 Descriptor libDir(String name, [String code]) {
76 // Default to printing the name if no other code was given.
77 if (code == null) code = name;
78 return dir("lib", [
79 file("$name.dart", 'main() => "$code";')
80 ]);
81 }
82
83 /// Describes a directory for a Git package. This directory is of the form
84 /// found in the revision cache of the global package cache.
85 Descriptor gitPackageRevisionCacheDir(String name, [int modifier]) {
86 var value = name;
87 if (modifier != null) value = "$name $modifier";
88 return pattern(new RegExp("$name${r'-[a-f0-9]+'}"),
89 (dirName) => dir(dirName, [libDir(name, value)]));
90 }
91
92 /// Describes a directory for a Git package. This directory is of the form
93 /// found in the repo cache of the global package cache.
94 Descriptor gitPackageRepoCacheDir(String name) {
95 return pattern(new RegExp("$name${r'-[a-f0-9]+'}"),
96 (dirName) => dir(dirName, [
97 dir('hooks'),
98 dir('info'),
99 dir('objects'),
100 dir('refs')
101 ]));
102 }
103
104 /// Describes the `packages/` directory containing all the given [packages],
105 /// which should be name/version pairs. The packages will be validated against
106 /// the format produced by the mock package server.
107 ///
108 /// A package with a null version should not be downloaded.
109 Descriptor packagesDir(Map<String, String> packages) {
110 var contents = <Descriptor>[];
111 packages.forEach((name, version) {
112 if (version == null) {
113 contents.add(nothing(name));
114 } else {
115 contents.add(dir(name, [
116 file("$name.dart", 'main() => "$name $version";')
117 ]));
118 }
119 });
120 return dir(packagesPath, contents);
121 }
122
123 /// Describes the global package cache directory containing all the given
124 /// [packages], which should be name/version pairs. The packages will be
125 /// validated against the format produced by the mock package server.
126 ///
127 /// A package's value may also be a list of versions, in which case all
128 /// versions are expected to be downloaded.
129 ///
130 /// If [includePubspecs] is `true`, then pubspecs will be created for each
131 /// package. Defaults to `false` so that the contents of pubspecs are not
132 /// validated since they will often lack the dependencies section that the
133 /// real pubspec being compared against has. You usually only need to pass
134 /// `true` for this if you plan to call [create] on the resulting descriptor.
135 Descriptor cacheDir(Map packages, {bool includePubspecs: false}) {
136 var contents = <Descriptor>[];
137 packages.forEach((name, versions) {
138 if (versions is! List) versions = [versions];
139 for (var version in versions) {
140 var packageContents = [libDir(name, '$name $version')];
141 if (includePubspecs) {
142 packageContents.add(libPubspec(name, version));
143 }
144 contents.add(dir("$name-$version", packageContents));
145 }
146 });
147
148 return hostedCache(contents);
149 }
150
151 /// Describes the main cache directory containing cached hosted packages
152 /// downloaded from the mock package server.
153 Descriptor hostedCache(Iterable<Descriptor> contents) {
154 return dir(cachePath, [
155 dir('hosted', [
156 async(port.then((p) => dir('localhost%58$p', contents)))
157 ])
158 ]);
159 }
160
161 /// 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
163 /// endpoint for refreshing the access token.
164 Descriptor credentialsFile(
165 ScheduledServer server,
166 String accessToken,
167 {String refreshToken,
168 DateTime expiration}) {
169 return async(server.url.then((url) {
170 return dir(cachePath, [
171 file('credentials.json', new oauth2.Credentials(
172 accessToken,
173 refreshToken,
174 url.resolve('/token'),
175 ['https://www.googleapis.com/auth/userinfo.email'],
176 expiration).toJson())
177 ]);
178 }));
179 }
180
181 /// Describes the application directory, containing only a pubspec specifying
182 /// the given [dependencies].
183 DirectoryDescriptor appDir([Map dependencies]) =>
184 dir(appPath, [appPubspec(dependencies)]);
OLDNEW
« no previous file with comments | « sdk/lib/_internal/pub/test/deps_test.dart ('k') | sdk/lib/_internal/pub/test/descriptor/git.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698