| 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 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'entrypoint.dart'; | 9 import 'entrypoint.dart'; |
| 10 import 'log.dart' as log; | 10 import 'log.dart' as log; |
| 11 import 'io.dart'; | 11 import 'io.dart'; |
| 12 import 'system_cache.dart'; | 12 import 'system_cache.dart'; |
| 13 import 'utils.dart'; | 13 import 'utils.dart'; |
| 14 import 'validator/dependency.dart'; | 14 import 'validator/dependency.dart'; |
| 15 import 'validator/directory.dart'; | 15 import 'validator/directory.dart'; |
| 16 import 'validator/lib.dart'; | 16 import 'validator/lib.dart'; |
| 17 import 'validator/license.dart'; | 17 import 'validator/license.dart'; |
| 18 import 'validator/name.dart'; | 18 import 'validator/name.dart'; |
| 19 import 'validator/pubspec_field.dart'; | 19 import 'validator/pubspec_field.dart'; |
| 20 import 'validator/utf8_readme.dart'; |
| 20 | 21 |
| 21 /// The base class for validators that check whether a package is fit for | 22 /// The base class for validators that check whether a package is fit for |
| 22 /// uploading. Each validator should override [errors], [warnings], or both to | 23 /// uploading. Each validator should override [errors], [warnings], or both to |
| 23 /// return lists of errors or warnings to display to the user. Errors will cause | 24 /// return lists of errors or warnings to display to the user. Errors will cause |
| 24 /// the package not to be uploaded; warnings will require the user to confirm | 25 /// the package not to be uploaded; warnings will require the user to confirm |
| 25 /// the upload. | 26 /// the upload. |
| 26 abstract class Validator { | 27 abstract class Validator { |
| 27 /// The entrypoint that's being validated. | 28 /// The entrypoint that's being validated. |
| 28 final Entrypoint entrypoint; | 29 final Entrypoint entrypoint; |
| 29 | 30 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 43 /// The future will complete with the error and warning messages, | 44 /// The future will complete with the error and warning messages, |
| 44 /// respectively. | 45 /// respectively. |
| 45 static Future<Pair<List<String>, List<String>>> runAll( | 46 static Future<Pair<List<String>, List<String>>> runAll( |
| 46 Entrypoint entrypoint) { | 47 Entrypoint entrypoint) { |
| 47 var validators = [ | 48 var validators = [ |
| 48 new LibValidator(entrypoint), | 49 new LibValidator(entrypoint), |
| 49 new LicenseValidator(entrypoint), | 50 new LicenseValidator(entrypoint), |
| 50 new NameValidator(entrypoint), | 51 new NameValidator(entrypoint), |
| 51 new PubspecFieldValidator(entrypoint), | 52 new PubspecFieldValidator(entrypoint), |
| 52 new DependencyValidator(entrypoint), | 53 new DependencyValidator(entrypoint), |
| 53 new DirectoryValidator(entrypoint) | 54 new DirectoryValidator(entrypoint), |
| 55 new Utf8ReadmeValidator(entrypoint) |
| 54 ]; | 56 ]; |
| 55 | 57 |
| 56 return Future.wait(validators.mappedBy((validator) => validator.validate())) | 58 return Future.wait(validators.mappedBy((validator) => validator.validate())) |
| 57 .then((_) { | 59 .then((_) { |
| 58 var errors = | 60 var errors = |
| 59 flatten(validators.mappedBy((validator) => validator.errors)); | 61 flatten(validators.mappedBy((validator) => validator.errors)); |
| 60 var warnings = | 62 var warnings = |
| 61 flatten(validators.mappedBy((validator) => validator.warnings)); | 63 flatten(validators.mappedBy((validator) => validator.warnings)); |
| 62 | 64 |
| 63 if (!errors.isEmpty) { | 65 if (!errors.isEmpty) { |
| 64 log.error("Missing requirements:"); | 66 log.error("Missing requirements:"); |
| 65 for (var error in errors) { | 67 for (var error in errors) { |
| 66 log.error("* ${Strings.join(error.split('\n'), '\n ')}"); | 68 log.error("* ${Strings.join(error.split('\n'), '\n ')}"); |
| 67 } | 69 } |
| 68 log.error(""); | 70 log.error(""); |
| 69 } | 71 } |
| 70 | 72 |
| 71 if (!warnings.isEmpty) { | 73 if (!warnings.isEmpty) { |
| 72 log.warning("Suggestions:"); | 74 log.warning("Suggestions:"); |
| 73 for (var warning in warnings) { | 75 for (var warning in warnings) { |
| 74 log.warning("* ${Strings.join(warning.split('\n'), '\n ')}"); | 76 log.warning("* ${Strings.join(warning.split('\n'), '\n ')}"); |
| 75 } | 77 } |
| 76 log.warning(""); | 78 log.warning(""); |
| 77 } | 79 } |
| 78 | 80 |
| 79 return new Pair<List<String>, List<String>>(errors, warnings); | 81 return new Pair<List<String>, List<String>>(errors, warnings); |
| 80 }); | 82 }); |
| 81 } | 83 } |
| 82 } | 84 } |
| OLD | NEW |