Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| 11 import '../../pkg/args/lib/args.dart'; | 11 import '../../pkg/args/lib/args.dart'; |
| 12 import '../../pkg/http/lib/http.dart' as http; | 12 import '../../pkg/http/lib/http.dart' as http; |
| 13 import 'git.dart' as git; | |
| 14 import 'io.dart'; | |
| 15 import 'log.dart' as log; | |
| 16 import 'oauth2.dart' as oauth2; | |
| 13 import 'pub.dart'; | 17 import 'pub.dart'; |
| 14 import 'io.dart'; | |
| 15 import 'git.dart' as git; | |
| 16 import 'oauth2.dart' as oauth2; | |
| 17 | 18 |
| 18 // TODO(nweiz): Make "publish" the primary name for this command. See issue | 19 // TODO(nweiz): Make "publish" the primary name for this command. See issue |
| 19 // 6949. | 20 // 6949. |
| 20 /// Handles the `lish` and `publish` pub commands. | 21 /// Handles the `lish` and `publish` pub commands. |
| 21 class LishCommand extends PubCommand { | 22 class LishCommand extends PubCommand { |
| 22 final description = "publish the current package to pub.dartlang.org"; | 23 final description = "publish the current package to pub.dartlang.org"; |
| 23 final usage = "pub publish [options]"; | 24 final usage = "pub publish [options]"; |
| 24 final aliases = const ["lish", "lush"]; | 25 final aliases = const ["lish", "lush"]; |
| 25 | 26 |
| 26 ArgParser get commandParser { | 27 ArgParser get commandParser { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 43 // oauth2 package should throw an AuthorizationException in this case | 44 // oauth2 package should throw an AuthorizationException in this case |
| 44 // (contingent on issue 6813 and 6275). We should have the user | 45 // (contingent on issue 6813 and 6275). We should have the user |
| 45 // re-authorize the client, then restart the command. We should also do | 46 // re-authorize the client, then restart the command. We should also do |
| 46 // this in case of an ExpirationException. See issue 6950. | 47 // this in case of an ExpirationException. See issue 6950. |
| 47 // | 48 // |
| 48 // * Cloud Storage can provide an XML-formatted error. We should report | 49 // * Cloud Storage can provide an XML-formatted error. We should report |
| 49 // that error and exit. | 50 // that error and exit. |
| 50 return Futures.wait([ | 51 return Futures.wait([ |
| 51 client.get(server.resolve("/packages/versions/new.json")), | 52 client.get(server.resolve("/packages/versions/new.json")), |
| 52 _filesToPublish.transform((files) { | 53 _filesToPublish.transform((files) { |
| 54 log.fine('Archiving and publishing:'); | |
| 55 files.forEach(log.fine); | |
|
nweiz
2012/12/05 23:56:54
Probably more readable if we indent these file nam
Bob Nystrom
2012/12/06 01:33:26
Done.
| |
| 53 return createTarGz(files, baseDir: entrypoint.root.dir); | 56 return createTarGz(files, baseDir: entrypoint.root.dir); |
| 54 }).chain(consumeInputStream) | 57 }).chain(consumeInputStream) |
| 55 ]).chain((results) { | 58 ]).chain((results) { |
| 56 var response = results[0]; | 59 var response = results[0]; |
| 57 var packageBytes = results[1]; | 60 var packageBytes = results[1]; |
| 58 var parameters = _parseJson(response); | 61 var parameters = _parseJson(response); |
| 59 | 62 |
| 60 var url = _expectField(parameters, 'url', response); | 63 var url = _expectField(parameters, 'url', response); |
| 61 if (url is! String) _invalidServerResponse(response); | 64 if (url is! String) _invalidServerResponse(response); |
| 62 cloudStorageUrl = new Uri.fromString(url); | 65 cloudStorageUrl = new Uri.fromString(url); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 77 var location = response.headers['location']; | 80 var location = response.headers['location']; |
| 78 if (location == null) throw new PubHttpException(response); | 81 if (location == null) throw new PubHttpException(response); |
| 79 return location; | 82 return location; |
| 80 }).chain((location) => client.get(location)).transform((response) { | 83 }).chain((location) => client.get(location)).transform((response) { |
| 81 var parsed = _parseJson(response); | 84 var parsed = _parseJson(response); |
| 82 if (parsed['success'] is! Map || | 85 if (parsed['success'] is! Map || |
| 83 !parsed['success'].containsKey('message') || | 86 !parsed['success'].containsKey('message') || |
| 84 parsed['success']['message'] is! String) { | 87 parsed['success']['message'] is! String) { |
| 85 _invalidServerResponse(response); | 88 _invalidServerResponse(response); |
| 86 } | 89 } |
| 87 print(parsed['success']['message']); | 90 log.message(parsed['success']['message']); |
| 88 }); | 91 }); |
| 89 }).transformException((e) { | 92 }).transformException((e) { |
| 90 if (e is PubHttpException) { | 93 if (e is PubHttpException) { |
| 91 var url = e.response.request.url; | 94 var url = e.response.request.url; |
| 92 if (url.toString() == cloudStorageUrl.toString()) { | 95 if (url.toString() == cloudStorageUrl.toString()) { |
| 93 // TODO(nweiz): the response may have XML-formatted information about | 96 // TODO(nweiz): the response may have XML-formatted information about |
| 94 // the error. Try to parse that out once we have an easily-accessible | 97 // the error. Try to parse that out once we have an easily-accessible |
| 95 // XML parser. | 98 // XML parser. |
| 96 throw 'Failed to upload the package.'; | 99 throw 'Failed to upload the package.'; |
| 97 } else if (url.origin == server.origin) { | 100 } else if (url.origin == server.origin) { |
| 98 var errorMap = _parseJson(e.response); | 101 var errorMap = _parseJson(e.response); |
| 99 if (errorMap['error'] is! Map || | 102 if (errorMap['error'] is! Map || |
| 100 !errorMap['error'].containsKey('message') || | 103 !errorMap['error'].containsKey('message') || |
| 101 errorMap['error']['message'] is! String) { | 104 errorMap['error']['message'] is! String) { |
| 102 _invalidServerResponse(e.response); | 105 _invalidServerResponse(e.response); |
| 103 } | 106 } |
| 104 throw errorMap['error']['message']; | 107 throw errorMap['error']['message']; |
| 105 } | 108 } |
| 106 } | 109 } |
| 107 | 110 |
| 108 if (e is! oauth2.ExpirationException) throw e; | 111 if (e is! oauth2.ExpirationException) throw e; |
| 109 | 112 |
| 110 printError("Pub's authorization to upload packages has expired and can't " | 113 log.error("Pub's authorization to upload packages has expired and can't " |
| 111 "be automatically refreshed."); | 114 "be automatically refreshed."); |
| 112 return onRun(); | 115 return onRun(); |
| 113 }); | 116 }); |
| 114 } | 117 } |
| 115 | 118 |
| 116 /// The basenames of files that are automatically excluded from archives. | 119 /// The basenames of files that are automatically excluded from archives. |
| 117 final _BLACKLISTED_FILES = const ['pubspec.lock']; | 120 final _BLACKLISTED_FILES = const ['pubspec.lock']; |
| 118 | 121 |
| 119 /// The basenames of directories that are automatically excluded from | 122 /// The basenames of directories that are automatically excluded from |
| 120 /// archives. | 123 /// archives. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 _expectField(Map map, String key, http.Response response) { | 171 _expectField(Map map, String key, http.Response response) { |
| 169 if (map.containsKey(key)) return map[key]; | 172 if (map.containsKey(key)) return map[key]; |
| 170 _invalidServerResponse(response); | 173 _invalidServerResponse(response); |
| 171 } | 174 } |
| 172 | 175 |
| 173 /// Throws an error describing an invalid response from the server. | 176 /// Throws an error describing an invalid response from the server. |
| 174 void _invalidServerResponse(http.Response response) { | 177 void _invalidServerResponse(http.Response response) { |
| 175 throw 'Invalid server response:\n${response.body}'; | 178 throw 'Invalid server response:\n${response.body}'; |
| 176 } | 179 } |
| 177 } | 180 } |
| OLD | NEW |