| Index: utils/pub/validator.dart
|
| diff --git a/utils/pub/validator.dart b/utils/pub/validator.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d5ab53c6c1874a84d7112455b489d11ade340ef0
|
| --- /dev/null
|
| +++ b/utils/pub/validator.dart
|
| @@ -0,0 +1,71 @@
|
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +library validator;
|
| +
|
| +import 'entrypoint.dart';
|
| +import 'io.dart';
|
| +import 'system_cache.dart';
|
| +import 'utils.dart';
|
| +import 'validator/pubspec_field.dart';
|
| +
|
| +/// The base class for validators that check whether a package is fit for
|
| +/// uploading. Each validator should override [errors], [warnings], or both to
|
| +/// return lists of errors or warnings to display to the user. Errors will cause
|
| +/// the package not to be uploaded; warnings will require the user to confirm
|
| +/// the upload.
|
| +abstract class Validator {
|
| + /// The entrypoint that's being validated.
|
| + final Entrypoint entrypoint;
|
| +
|
| + /// The accumulated errors for this validator. Filled by calling [validate].
|
| + final errors = <String>[];
|
| +
|
| + /// The accumulated warnings for this validator. Filled by calling [validate].
|
| + final warnings = <String>[];
|
| +
|
| + Validator(this.entrypoint);
|
| +
|
| + /// Validates the entrypoint, adding any errors and warnings to [errors] and
|
| + /// [warnings], respectively.
|
| + Future validate();
|
| +
|
| + /// Run all validators on the [entrypoint] package and print their results.
|
| + /// The future will complete with the error and warning messages,
|
| + /// respectively.
|
| + static Future<Pair<List<String>, List<String>>> runAll(
|
| + Entrypoint entrypoint) {
|
| + var validators = [
|
| + new PubspecFieldValidator(entrypoint)
|
| + ];
|
| +
|
| + // TODO(nweiz): The sleep 0 here forces us to go async. This works around
|
| + // 3356, which causes a bug if all validators are (synchronously) using
|
| + // Future.immediate and an error is thrown before a handler is set up.
|
| + return sleep(0).chain((_) {
|
| + return Futures.wait(validators.map((validator) => validator.validate()));
|
| + }).transform((_) {
|
| + var errors = flatten(validators.map((validator) => validator.errors));
|
| + var warnings = flatten(validators.map((validator) => validator.warnings));
|
| +
|
| + if (!errors.isEmpty) {
|
| + printError("== Errors:");
|
| + for (var error in errors) {
|
| + printError("* $error");
|
| + }
|
| + printError("");
|
| + }
|
| +
|
| + if (!warnings.isEmpty) {
|
| + printError("== Warnings:");
|
| + for (var warning in warnings) {
|
| + printError("* $warning");
|
| + }
|
| + printError("");
|
| + }
|
| +
|
| + return new Pair<List<String>, List<String>>(errors, warnings);
|
| + });
|
| + }
|
| +}
|
|
|