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

Side by Side Diff: utils/pub/validator.dart

Issue 14297021: Move pub into sdk/lib/_internal. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Disallow package: imports of pub. Created 7 years, 8 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
« no previous file with comments | « utils/pub/utils.dart ('k') | utils/pub/validator/compiled_dartdoc.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 validator;
6
7 import 'dart:async';
8
9 import 'entrypoint.dart';
10 import 'log.dart' as log;
11 import 'io.dart';
12 import 'system_cache.dart';
13 import 'utils.dart';
14 import 'validator/compiled_dartdoc.dart';
15 import 'validator/dependency.dart';
16 import 'validator/directory.dart';
17 import 'validator/lib.dart';
18 import 'validator/license.dart';
19 import 'validator/name.dart';
20 import 'validator/pubspec_field.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. Each validator should override [errors], [warnings], or both to
26 /// return lists of errors or warnings to display to the user. Errors will cause
27 /// the package not to be uploaded; warnings will require the user to confirm
28 /// the upload.
29 abstract class Validator {
30 /// The entrypoint that's being validated.
31 final Entrypoint entrypoint;
32
33 /// The accumulated errors for this validator. Filled by calling [validate].
34 final errors = <String>[];
35
36 /// The accumulated warnings for this validator. Filled by calling [validate].
37 final warnings = <String>[];
38
39 Validator(this.entrypoint);
40
41 /// Validates the entrypoint, adding any errors and warnings to [errors] and
42 /// [warnings], respectively.
43 Future validate();
44
45 /// Run all validators on the [entrypoint] package and print their results.
46 /// The future will complete with the error and warning messages,
47 /// respectively.
48 ///
49 /// [packageSize], if passed, should complete to the size of the tarred
50 /// package, in bytes. This is used to validate that it's not too big to
51 /// upload to the server.
52 static Future<Pair<List<String>, List<String>>> runAll(
53 Entrypoint entrypoint, [Future<int> packageSize]) {
54 var validators = [
55 new LibValidator(entrypoint),
56 new LicenseValidator(entrypoint),
57 new NameValidator(entrypoint),
58 new PubspecFieldValidator(entrypoint),
59 new DependencyValidator(entrypoint),
60 new DirectoryValidator(entrypoint),
61 new CompiledDartdocValidator(entrypoint),
62 new Utf8ReadmeValidator(entrypoint)
63 ];
64 if (packageSize != null) {
65 validators.add(new SizeValidator(entrypoint, packageSize));
66 }
67
68 return Future.wait(validators.map((validator) => validator.validate()))
69 .then((_) {
70 var errors =
71 flatten(validators.map((validator) => validator.errors));
72 var warnings =
73 flatten(validators.map((validator) => validator.warnings));
74
75 if (!errors.isEmpty) {
76 log.error("Missing requirements:");
77 for (var error in errors) {
78 log.error("* ${error.split('\n').join('\n ')}");
79 }
80 log.error("");
81 }
82
83 if (!warnings.isEmpty) {
84 log.warning("Suggestions:");
85 for (var warning in warnings) {
86 log.warning("* ${warning.split('\n').join('\n ')}");
87 }
88 log.warning("");
89 }
90
91 return new Pair<List<String>, List<String>>(errors, warnings);
92 });
93 }
94 }
OLDNEW
« no previous file with comments | « utils/pub/utils.dart ('k') | utils/pub/validator/compiled_dartdoc.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698