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 lib_validator; | 5 library lib_validator; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
| 10 import '../../../pkg/path/lib/path.dart' as path; |
| 11 |
10 import '../entrypoint.dart'; | 12 import '../entrypoint.dart'; |
11 import '../io.dart'; | 13 import '../io.dart'; |
12 import '../system_cache.dart'; | 14 import '../system_cache.dart'; |
13 import '../utils.dart'; | 15 import '../utils.dart'; |
14 import '../validator.dart'; | 16 import '../validator.dart'; |
15 | 17 |
16 // TODO(nweiz): When issue 7196 is fixed, complain about non-Dart files in lib. | 18 // TODO(nweiz): When issue 7196 is fixed, complain about non-Dart files in lib. |
17 /// A validator that checks that libraries in "lib/" (and not "lib/src/") exist | 19 /// A validator that checks that libraries in "lib/" (and not "lib/src/") exist |
18 /// and are well-formed. | 20 /// and are well-formed. |
19 class LibValidator extends Validator { | 21 class LibValidator extends Validator { |
20 LibValidator(Entrypoint entrypoint) | 22 LibValidator(Entrypoint entrypoint) |
21 : super(entrypoint); | 23 : super(entrypoint); |
22 | 24 |
23 Future validate() { | 25 Future validate() { |
24 var libDir = join(entrypoint.root.dir, "lib"); | 26 var libDir = join(entrypoint.root.dir, "lib"); |
25 | 27 |
26 return defer(() { | 28 return defer(() { |
27 if (!dirExists(libDir)) { | 29 if (!dirExists(libDir)) { |
28 errors.add('You must have a "lib" directory.\n' | 30 errors.add('You must have a "lib" directory.\n' |
29 "Without that, users cannot import any code from your package."); | 31 "Without that, users cannot import any code from your package."); |
30 return; | 32 return; |
31 } | 33 } |
32 | 34 |
33 return listDir(libDir).then((files) { | 35 return listDir(libDir).then((files) { |
34 files = files.map((file) => relativeTo(file, libDir)).toList(); | 36 files = files.map((file) => path.relative(file, from: libDir)).toList(); |
35 if (files.isEmpty) { | 37 if (files.isEmpty) { |
36 errors.add('You must have a non-empty "lib" directory.\n' | 38 errors.add('You must have a non-empty "lib" directory.\n' |
37 "Without that, users cannot import any code from your package."); | 39 "Without that, users cannot import any code from your package."); |
38 } else if (files.length == 1 && files.first == "src") { | 40 } else if (files.length == 1 && files.first == "src") { |
39 errors.add('The "lib" directory must contain something other than ' | 41 errors.add('The "lib" directory must contain something other than ' |
40 '"src".\n' | 42 '"src".\n' |
41 "Otherwise, users cannot import any code from your package."); | 43 "Otherwise, users cannot import any code from your package."); |
42 } | 44 } |
43 }); | 45 }); |
44 }); | 46 }); |
45 } | 47 } |
46 } | 48 } |
OLD | NEW |