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 'log.dart' as log; |
9 import 'io.dart'; | 9 import 'io.dart'; |
10 import 'system_cache.dart'; | 10 import 'system_cache.dart'; |
11 import 'utils.dart'; | 11 import 'utils.dart'; |
12 import 'validator/dependency.dart'; | 12 import 'validator/dependency.dart'; |
| 13 import 'validator/directory.dart'; |
13 import 'validator/lib.dart'; | 14 import 'validator/lib.dart'; |
14 import 'validator/license.dart'; | 15 import 'validator/license.dart'; |
15 import 'validator/name.dart'; | 16 import 'validator/name.dart'; |
16 import 'validator/pubspec_field.dart'; | 17 import 'validator/pubspec_field.dart'; |
17 | 18 |
18 /// The base class for validators that check whether a package is fit for | 19 /// The base class for validators that check whether a package is fit for |
19 /// uploading. Each validator should override [errors], [warnings], or both to | 20 /// uploading. Each validator should override [errors], [warnings], or both to |
20 /// return lists of errors or warnings to display to the user. Errors will cause | 21 /// return lists of errors or warnings to display to the user. Errors will cause |
21 /// the package not to be uploaded; warnings will require the user to confirm | 22 /// the package not to be uploaded; warnings will require the user to confirm |
22 /// the upload. | 23 /// the upload. |
(...skipping 16 matching lines...) Expand all Loading... |
39 /// Run all validators on the [entrypoint] package and print their results. | 40 /// Run all validators on the [entrypoint] package and print their results. |
40 /// The future will complete with the error and warning messages, | 41 /// The future will complete with the error and warning messages, |
41 /// respectively. | 42 /// respectively. |
42 static Future<Pair<List<String>, List<String>>> runAll( | 43 static Future<Pair<List<String>, List<String>>> runAll( |
43 Entrypoint entrypoint) { | 44 Entrypoint entrypoint) { |
44 var validators = [ | 45 var validators = [ |
45 new LibValidator(entrypoint), | 46 new LibValidator(entrypoint), |
46 new LicenseValidator(entrypoint), | 47 new LicenseValidator(entrypoint), |
47 new NameValidator(entrypoint), | 48 new NameValidator(entrypoint), |
48 new PubspecFieldValidator(entrypoint), | 49 new PubspecFieldValidator(entrypoint), |
49 new DependencyValidator(entrypoint) | 50 new DependencyValidator(entrypoint), |
| 51 new DirectoryValidator(entrypoint) |
50 ]; | 52 ]; |
51 | 53 |
52 // TODO(nweiz): The sleep 0 here forces us to go async. This works around | 54 // TODO(nweiz): The sleep 0 here forces us to go async. This works around |
53 // 3356, which causes a bug if all validators are (synchronously) using | 55 // 3356, which causes a bug if all validators are (synchronously) using |
54 // Future.immediate and an error is thrown before a handler is set up. | 56 // Future.immediate and an error is thrown before a handler is set up. |
55 return sleep(0).chain((_) { | 57 return sleep(0).chain((_) { |
56 return Futures.wait(validators.map((validator) => validator.validate())); | 58 return Futures.wait(validators.map((validator) => validator.validate())); |
57 }).transform((_) { | 59 }).transform((_) { |
58 var errors = flatten(validators.map((validator) => validator.errors)); | 60 var errors = flatten(validators.map((validator) => validator.errors)); |
59 var warnings = flatten(validators.map((validator) => validator.warnings)); | 61 var warnings = flatten(validators.map((validator) => validator.warnings)); |
(...skipping 11 matching lines...) Expand all Loading... |
71 for (var warning in warnings) { | 73 for (var warning in warnings) { |
72 log.warning("* ${Strings.join(warning.split('\n'), '\n ')}"); | 74 log.warning("* ${Strings.join(warning.split('\n'), '\n ')}"); |
73 } | 75 } |
74 log.warning(""); | 76 log.warning(""); |
75 } | 77 } |
76 | 78 |
77 return new Pair<List<String>, List<String>>(errors, warnings); | 79 return new Pair<List<String>, List<String>>(errors, warnings); |
78 }); | 80 }); |
79 } | 81 } |
80 } | 82 } |
OLD | NEW |