Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(426)

Side by Side Diff: sdk/lib/_internal/pub_generated/lib/src/validator.dart

Issue 937243002: Revert "Revert "Use native async/await support in pub."" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library pub.validator;
6
7 import 'dart:async';
8
9 import 'entrypoint.dart';
10 import 'log.dart' as log;
11 import 'utils.dart';
12 import 'validator/compiled_dartdoc.dart';
13 import 'validator/dependency.dart';
14 import 'validator/dependency_override.dart';
15 import 'validator/directory.dart';
16 import 'validator/executable.dart';
17 import 'validator/license.dart';
18 import 'validator/name.dart';
19 import 'validator/pubspec_field.dart';
20 import 'validator/sdk_constraint.dart';
21 import 'validator/size.dart';
22 import 'validator/utf8_readme.dart';
23
24 /// The base class for validators that check whether a package is fit for
25 /// uploading.
26 ///
27 /// Each validator should override [errors], [warnings], or both to return
28 /// lists of errors or warnings to display to the user. Errors will cause the
29 /// package not to be uploaded; warnings will require the user to confirm the
30 /// upload.
31 abstract class Validator {
32 /// The entrypoint that's being validated.
33 final Entrypoint entrypoint;
34
35 /// The accumulated errors for this validator.
36 ///
37 /// Filled by calling [validate].
38 final errors = <String>[];
39
40 /// The accumulated warnings for this validator.
41 ///
42 /// Filled by calling [validate].
43 final warnings = <String>[];
44
45 Validator(this.entrypoint);
46
47 /// Validates the entrypoint, adding any errors and warnings to [errors] and
48 /// [warnings], respectively.
49 Future validate();
50
51 /// Run all validators on the [entrypoint] package and print their results.
52 ///
53 /// The future completes with the error and warning messages, respectively.
54 ///
55 /// [packageSize], if passed, should complete to the size of the tarred
56 /// package, in bytes. This is used to validate that it's not too big to
57 /// upload to the server.
58 static Future<Pair<List<String>, List<String>>> runAll(Entrypoint entrypoint,
59 [Future<int> packageSize]) {
60 var validators = [
61 new LicenseValidator(entrypoint),
62 new NameValidator(entrypoint),
63 new PubspecFieldValidator(entrypoint),
64 new DependencyValidator(entrypoint),
65 new DependencyOverrideValidator(entrypoint),
66 new DirectoryValidator(entrypoint),
67 new ExecutableValidator(entrypoint),
68 new CompiledDartdocValidator(entrypoint),
69 new Utf8ReadmeValidator(entrypoint),
70 new SdkConstraintValidator(entrypoint)];
71 if (packageSize != null) {
72 validators.add(new SizeValidator(entrypoint, packageSize));
73 }
74
75 return Future.wait(
76 validators.map((validator) => validator.validate())).then((_) {
77 var errors = flatten(validators.map((validator) => validator.errors));
78 var warnings = flatten(validators.map((validator) => validator.warnings));
79
80 if (!errors.isEmpty) {
81 log.error("Missing requirements:");
82 for (var error in errors) {
83 log.error("* ${error.split('\n').join('\n ')}");
84 }
85 log.error("");
86 }
87
88 if (!warnings.isEmpty) {
89 log.warning("Suggestions:");
90 for (var warning in warnings) {
91 log.warning("* ${warning.split('\n').join('\n ')}");
92 }
93 log.warning("");
94 }
95
96 return new Pair<List<String>, List<String>>(errors, warnings);
97 });
98 }
99 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698