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 'io.dart'; | 8 import 'io.dart'; |
9 import 'system_cache.dart'; | 9 import 'system_cache.dart'; |
10 import 'utils.dart'; | 10 import 'utils.dart'; |
| 11 import 'validator/license.dart'; |
11 import 'validator/name.dart'; | 12 import 'validator/name.dart'; |
12 import 'validator/pubspec_field.dart'; | 13 import 'validator/pubspec_field.dart'; |
13 | 14 |
14 /// The base class for validators that check whether a package is fit for | 15 /// The base class for validators that check whether a package is fit for |
15 /// uploading. Each validator should override [errors], [warnings], or both to | 16 /// 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 | 17 /// 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 | 18 /// the package not to be uploaded; warnings will require the user to confirm |
18 /// the upload. | 19 /// the upload. |
19 abstract class Validator { | 20 abstract class Validator { |
20 /// The entrypoint that's being validated. | 21 /// The entrypoint that's being validated. |
(...skipping 10 matching lines...) Loading... |
31 /// Validates the entrypoint, adding any errors and warnings to [errors] and | 32 /// Validates the entrypoint, adding any errors and warnings to [errors] and |
32 /// [warnings], respectively. | 33 /// [warnings], respectively. |
33 Future validate(); | 34 Future validate(); |
34 | 35 |
35 /// Run all validators on the [entrypoint] package and print their results. | 36 /// Run all validators on the [entrypoint] package and print their results. |
36 /// The future will complete with the error and warning messages, | 37 /// The future will complete with the error and warning messages, |
37 /// respectively. | 38 /// respectively. |
38 static Future<Pair<List<String>, List<String>>> runAll( | 39 static Future<Pair<List<String>, List<String>>> runAll( |
39 Entrypoint entrypoint) { | 40 Entrypoint entrypoint) { |
40 var validators = [ | 41 var validators = [ |
| 42 new LicenseValidator(entrypoint), |
41 new NameValidator(entrypoint), | 43 new NameValidator(entrypoint), |
42 new PubspecFieldValidator(entrypoint) | 44 new PubspecFieldValidator(entrypoint) |
43 ]; | 45 ]; |
44 | 46 |
45 // TODO(nweiz): The sleep 0 here forces us to go async. This works around | 47 // TODO(nweiz): The sleep 0 here forces us to go async. This works around |
46 // 3356, which causes a bug if all validators are (synchronously) using | 48 // 3356, which causes a bug if all validators are (synchronously) using |
47 // Future.immediate and an error is thrown before a handler is set up. | 49 // Future.immediate and an error is thrown before a handler is set up. |
48 return sleep(0).chain((_) { | 50 return sleep(0).chain((_) { |
49 return Futures.wait(validators.map((validator) => validator.validate())); | 51 return Futures.wait(validators.map((validator) => validator.validate())); |
50 }).transform((_) { | 52 }).transform((_) { |
(...skipping 13 matching lines...) Loading... |
64 for (var warning in warnings) { | 66 for (var warning in warnings) { |
65 printError("* $warning"); | 67 printError("* $warning"); |
66 } | 68 } |
67 printError(""); | 69 printError(""); |
68 } | 70 } |
69 | 71 |
70 return new Pair<List<String>, List<String>>(errors, warnings); | 72 return new Pair<List<String>, List<String>>(errors, warnings); |
71 }); | 73 }); |
72 } | 74 } |
73 } | 75 } |
OLD | NEW |