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 pub.validator.license; | 5 library pub.validator.license; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:path/path.dart' as path; | 9 import 'package:path/path.dart' as path; |
10 | 10 |
11 import '../entrypoint.dart'; | 11 import '../entrypoint.dart'; |
12 import '../utils.dart'; | 12 import '../utils.dart'; |
13 import '../validator.dart'; | 13 import '../validator.dart'; |
14 | 14 |
15 /// A validator that checks that a LICENSE-like file exists. | 15 /// A validator that checks that a LICENSE-like file exists. |
16 class LicenseValidator extends Validator { | 16 class LicenseValidator extends Validator { |
17 LicenseValidator(Entrypoint entrypoint) | 17 LicenseValidator(Entrypoint entrypoint) |
18 : super(entrypoint); | 18 : super(entrypoint); |
19 | 19 |
20 Future validate() { | 20 Future validate() { |
21 return new Future.sync(() { | 21 return new Future.sync(() { |
22 var licenseLike = new RegExp( | 22 var licenseLike = |
23 r"^([a-zA-Z0-9]+[-_])?(LICENSE|COPYING)(\..*)?$"); | 23 new RegExp(r"^([a-zA-Z0-9]+[-_])?(LICENSE|COPYING)(\..*)?$"); |
24 if (entrypoint.root.listFiles(recursive: false) | 24 if (entrypoint.root.listFiles( |
25 .map(path.basename) | 25 recursive: false).map(path.basename).any(licenseLike.hasMatch)) { |
26 .any(licenseLike.hasMatch)) { | |
27 return; | 26 return; |
28 } | 27 } |
29 | 28 |
30 errors.add( | 29 errors.add( |
31 "You must have a COPYING or LICENSE file in the root directory.\n" | 30 "You must have a COPYING or LICENSE file in the root directory.\n" |
32 "An open-source license helps ensure people can legally use your " | 31 "An open-source license helps ensure people can legally use your "
"code."); |
33 "code."); | |
34 }); | 32 }); |
35 } | 33 } |
36 } | 34 } |
OLD | NEW |