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 validator; | 5 library validator; |
6 | 6 |
7 import 'entrypoint.dart'; | 7 import 'entrypoint.dart'; |
| 8 import 'log.dart' as log; |
8 import 'io.dart'; | 9 import 'io.dart'; |
9 import 'system_cache.dart'; | 10 import 'system_cache.dart'; |
10 import 'utils.dart'; | 11 import 'utils.dart'; |
11 import 'validator/pubspec_field.dart'; | 12 import 'validator/pubspec_field.dart'; |
12 | 13 |
13 /// The base class for validators that check whether a package is fit for | 14 /// The base class for validators that check whether a package is fit for |
14 /// uploading. Each validator should override [errors], [warnings], or both to | 15 /// uploading. Each validator should override [errors], [warnings], or both to |
15 /// return lists of errors or warnings to display to the user. Errors will cause | 16 /// return lists of errors or warnings to display to the user. Errors will cause |
16 /// the package not to be uploaded; warnings will require the user to confirm | 17 /// the package not to be uploaded; warnings will require the user to confirm |
17 /// the upload. | 18 /// the upload. |
(...skipping 25 matching lines...) Expand all Loading... |
43 // TODO(nweiz): The sleep 0 here forces us to go async. This works around | 44 // TODO(nweiz): The sleep 0 here forces us to go async. This works around |
44 // 3356, which causes a bug if all validators are (synchronously) using | 45 // 3356, which causes a bug if all validators are (synchronously) using |
45 // Future.immediate and an error is thrown before a handler is set up. | 46 // Future.immediate and an error is thrown before a handler is set up. |
46 return sleep(0).chain((_) { | 47 return sleep(0).chain((_) { |
47 return Futures.wait(validators.map((validator) => validator.validate())); | 48 return Futures.wait(validators.map((validator) => validator.validate())); |
48 }).transform((_) { | 49 }).transform((_) { |
49 var errors = flatten(validators.map((validator) => validator.errors)); | 50 var errors = flatten(validators.map((validator) => validator.errors)); |
50 var warnings = flatten(validators.map((validator) => validator.warnings)); | 51 var warnings = flatten(validators.map((validator) => validator.warnings)); |
51 | 52 |
52 if (!errors.isEmpty) { | 53 if (!errors.isEmpty) { |
53 printError("== Errors:"); | 54 log.error("== Errors:"); |
54 for (var error in errors) { | 55 for (var error in errors) { |
55 printError("* $error"); | 56 log.error("* $error"); |
56 } | 57 } |
57 printError(""); | 58 log.error(""); |
58 } | 59 } |
59 | 60 |
60 if (!warnings.isEmpty) { | 61 if (!warnings.isEmpty) { |
61 printError("== Warnings:"); | 62 log.warning("== Warnings:"); |
62 for (var warning in warnings) { | 63 for (var warning in warnings) { |
63 printError("* $warning"); | 64 log.warning("* $warning"); |
64 } | 65 } |
65 printError(""); | 66 log.warning(""); |
66 } | 67 } |
67 | 68 |
68 return new Pair<List<String>, List<String>>(errors, warnings); | 69 return new Pair<List<String>, List<String>>(errors, warnings); |
69 }); | 70 }); |
70 } | 71 } |
71 } | 72 } |
OLD | NEW |