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