OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 descriptor.pattern; | 5 library descriptor.pattern; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:path/path.dart' as path; | 10 import 'package:path/path.dart' as path; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 /// matching [pattern], then passes each of their names to the [EntityCreator] | 42 /// matching [pattern], then passes each of their names to the [EntityCreator] |
43 /// and validates the result. If exactly one succeeds, [this] is considered | 43 /// and validates the result. If exactly one succeeds, [this] is considered |
44 /// valid. | 44 /// valid. |
45 Future validate([String parent]) => schedule(() => validateNow(parent), | 45 Future validate([String parent]) => schedule(() => validateNow(parent), |
46 "validating ${describe()}"); | 46 "validating ${describe()}"); |
47 | 47 |
48 Future validateNow([String parent]) { | 48 Future validateNow([String parent]) { |
49 if (parent == null) parent = defaultRoot; | 49 if (parent == null) parent = defaultRoot; |
50 // TODO(nweiz): make sure this works with symlinks. | 50 // TODO(nweiz): make sure this works with symlinks. |
51 var matchingEntries = new Directory(parent).listSync() | 51 var matchingEntries = new Directory(parent).listSync() |
52 .map((entry) => entry is File ? entry.fullPathSync() : entry.path) | 52 .map((entry) => entry is File ? entry.resolveSymbolicLinksSync() |
| 53 : entry.path) |
53 .where((entry) => fullMatch(path.basename(entry), pattern)) | 54 .where((entry) => fullMatch(path.basename(entry), pattern)) |
54 .toList(); | 55 .toList(); |
55 matchingEntries.sort(); | 56 matchingEntries.sort(); |
56 | 57 |
57 if (matchingEntries.isEmpty) { | 58 if (matchingEntries.isEmpty) { |
58 fail("No entry found in '$parent' matching ${_patternDescription}."); | 59 fail("No entry found in '$parent' matching ${_patternDescription}."); |
59 } | 60 } |
60 | 61 |
61 return Future.wait(matchingEntries.map((entry) { | 62 return Future.wait(matchingEntries.map((entry) { |
62 var descriptor = _fn(path.basename(entry)); | 63 var descriptor = _fn(path.basename(entry)); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 var regExp = pattern as RegExp; | 107 var regExp = pattern as RegExp; |
107 var flags = new StringBuffer(); | 108 var flags = new StringBuffer(); |
108 if (!regExp.isCaseSensitive) flags.write('i'); | 109 if (!regExp.isCaseSensitive) flags.write('i'); |
109 if (regExp.isMultiLine) flags.write('m'); | 110 if (regExp.isMultiLine) flags.write('m'); |
110 return '/${regExp.pattern}/$flags'; | 111 return '/${regExp.pattern}/$flags'; |
111 } | 112 } |
112 | 113 |
113 Future create([String parent]) => new Future.error( | 114 Future create([String parent]) => new Future.error( |
114 new UnsupportedError("Pattern descriptors don't support create().")); | 115 new UnsupportedError("Pattern descriptors don't support create().")); |
115 } | 116 } |
OLD | NEW |