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

Side by Side Diff: utils/pub/command_lish.dart

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « utils/pub/command_install.dart ('k') | utils/pub/command_update.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 command_lish; 5 library command_lish;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 import 'dart:json'; 8 import 'dart:json';
9 import 'dart:uri'; 9 import 'dart:uri';
10 10
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 if (fields is! Map) invalidServerResponse(response); 56 if (fields is! Map) invalidServerResponse(response);
57 fields.forEach((key, value) { 57 fields.forEach((key, value) {
58 if (value is! String) invalidServerResponse(response); 58 if (value is! String) invalidServerResponse(response);
59 request.fields[key] = value; 59 request.fields[key] = value;
60 }); 60 });
61 61
62 request.followRedirects = false; 62 request.followRedirects = false;
63 request.files.add(new http.MultipartFile.fromBytes( 63 request.files.add(new http.MultipartFile.fromBytes(
64 'file', packageBytes, filename: 'package.tar.gz')); 64 'file', packageBytes, filename: 'package.tar.gz'));
65 return client.send(request); 65 return client.send(request);
66 }).chain(http.Response.fromStream).transform((response) { 66 }).chain(http.Response.fromStream).then((response) {
67 var location = response.headers['location']; 67 var location = response.headers['location'];
68 if (location == null) throw new PubHttpException(response); 68 if (location == null) throw new PubHttpException(response);
69 return location; 69 return location;
70 }).chain((location) => client.get(location)) 70 }).then((location) => client.get(location))
71 .transform(handleJsonSuccess); 71 .then(handleJsonSuccess);
72 }).transformException((e) { 72 }).transformException((e) {
73 if (e is! PubHttpException) throw e; 73 if (e is! PubHttpException) throw e;
74 var url = e.response.request.url; 74 var url = e.response.request.url;
75 if (url.toString() == cloudStorageUrl.toString()) { 75 if (url.toString() == cloudStorageUrl.toString()) {
76 // TODO(nweiz): the response may have XML-formatted information about 76 // TODO(nweiz): the response may have XML-formatted information about
77 // the error. Try to parse that out once we have an easily-accessible 77 // the error. Try to parse that out once we have an easily-accessible
78 // XML parser. 78 // XML parser.
79 throw 'Failed to upload the package.'; 79 throw 'Failed to upload the package.';
80 } else if (url.origin == server.origin) { 80 } else if (url.origin == server.origin) {
81 handleJsonError(e.response); 81 handleJsonError(e.response);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 git.isInstalled 119 git.isInstalled
120 ]).chain((results) { 120 ]).chain((results) {
121 if (results[0] && results[1]) { 121 if (results[0] && results[1]) {
122 // List all files that aren't gitignored, including those not checked 122 // List all files that aren't gitignored, including those not checked
123 // in to Git. 123 // in to Git.
124 return git.run(["ls-files", "--cached", "--others", 124 return git.run(["ls-files", "--cached", "--others",
125 "--exclude-standard"]); 125 "--exclude-standard"]);
126 } 126 }
127 127
128 return listDir(rootDir, recursive: true).chain((entries) { 128 return listDir(rootDir, recursive: true).chain((entries) {
129 return Futures.wait(entries.map((entry) { 129 return Futures.wait(entries.mappedBy((entry) {
130 return fileExists(entry).transform((isFile) { 130 return fileExists(entry).then((isFile) {
131 // Skip directories. 131 // Skip directories.
132 if (!isFile) return null; 132 if (!isFile) return null;
133 133
134 // TODO(rnystrom): Making these relative will break archive 134 // TODO(rnystrom): Making these relative will break archive
135 // creation if the cwd is ever *not* the package root directory. 135 // creation if the cwd is ever *not* the package root directory.
136 // Should instead only make these relative right before generating 136 // Should instead only make these relative right before generating
137 // the tree display (which is what really needs them to be). 137 // the tree display (which is what really needs them to be).
138 // Make it relative to the package root. 138 // Make it relative to the package root.
139 return relativeTo(entry, rootDir); 139 return relativeTo(entry, rootDir);
140 }); 140 });
141 })); 141 }));
142 }); 142 });
143 }).transform((files) => files.filter((file) { 143 }).then((files) => files.where((file) {
144 if (file == null || _BLACKLISTED_FILES.contains(basename(file))) { 144 if (file == null || _BLACKLISTED_FILES.contains(basename(file))) {
145 return false; 145 return false;
146 } 146 }
147 147
148 return !splitPath(file).some(_BLACKLISTED_DIRECTORIES.contains); 148 return !splitPath(file).some(_BLACKLISTED_DIRECTORIES.contains);
149 })); 149 }).toList());
150 } 150 }
151 151
152 /// Returns the value associated with [key] in [map]. Throws a user-friendly 152 /// Returns the value associated with [key] in [map]. Throws a user-friendly
153 /// error if [map] doens't contain [key]. 153 /// error if [map] doens't contain [key].
154 _expectField(Map map, String key, http.Response response) { 154 _expectField(Map map, String key, http.Response response) {
155 if (map.containsKey(key)) return map[key]; 155 if (map.containsKey(key)) return map[key];
156 invalidServerResponse(response); 156 invalidServerResponse(response);
157 } 157 }
158 158
159 /// Validates the package. Throws an exception if it's invalid. 159 /// Validates the package. Throws an exception if it's invalid.
160 Future _validate() { 160 Future _validate() {
161 return Validator.runAll(entrypoint).chain((pair) { 161 return Validator.runAll(entrypoint).chain((pair) {
162 var errors = pair.first; 162 var errors = pair.first;
163 var warnings = pair.last; 163 var warnings = pair.last;
164 164
165 if (!errors.isEmpty) { 165 if (!errors.isEmpty) {
166 throw "Sorry, your package is missing " 166 throw "Sorry, your package is missing "
167 "${(errors.length > 1) ? 'some requirements' : 'a requirement'} " 167 "${(errors.length > 1) ? 'some requirements' : 'a requirement'} "
168 "and can't be published yet.\nFor more information, see: " 168 "and can't be published yet.\nFor more information, see: "
169 "http://pub.dartlang.org/doc/pub-lish.html.\n"; 169 "http://pub.dartlang.org/doc/pub-lish.html.\n";
170 } 170 }
171 171
172 var message = 'Looks great! Are you ready to upload your package'; 172 var message = 'Looks great! Are you ready to upload your package';
173 173
174 if (!warnings.isEmpty) { 174 if (!warnings.isEmpty) {
175 var s = warnings.length == 1 ? '' : 's'; 175 var s = warnings.length == 1 ? '' : 's';
176 message = "Package has ${warnings.length} warning$s. Upload anyway"; 176 message = "Package has ${warnings.length} warning$s. Upload anyway";
177 } 177 }
178 178
179 return confirm(message).transform((confirmed) { 179 return confirm(message).then((confirmed) {
180 if (!confirmed) throw "Package upload canceled."; 180 if (!confirmed) throw "Package upload canceled.";
181 }); 181 });
182 }); 182 });
183 } 183 }
184 } 184 }
OLDNEW
« no previous file with comments | « utils/pub/command_install.dart ('k') | utils/pub/command_update.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698