| 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.directory; | 5 library descriptor.directory; |
| 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 24 matching lines...) Expand all Loading... |
| 35 }); | 35 }); |
| 36 }, 'creating directory:\n${describe()}'); | 36 }, 'creating directory:\n${describe()}'); |
| 37 | 37 |
| 38 Future validate([String parent]) => schedule(() => validateNow(parent), | 38 Future validate([String parent]) => schedule(() => validateNow(parent), |
| 39 'validating directory:\n${describe()}'); | 39 'validating directory:\n${describe()}'); |
| 40 | 40 |
| 41 Future validateNow([String parent]) { | 41 Future validateNow([String parent]) { |
| 42 if (parent == null) parent = defaultRoot; | 42 if (parent == null) parent = defaultRoot; |
| 43 var fullPath = path.join(parent, name); | 43 var fullPath = path.join(parent, name); |
| 44 if (!new Directory(fullPath).existsSync()) { | 44 if (!new Directory(fullPath).existsSync()) { |
| 45 throw "Directory not found: '$fullPath'."; | 45 fail("Directory not found: '$fullPath'."); |
| 46 } | 46 } |
| 47 | 47 |
| 48 return Future.wait(contents.map((entry) { | 48 return Future.wait(contents.map((entry) { |
| 49 return new Future.sync(() => entry.validateNow(fullPath)) | 49 return new Future.sync(() => entry.validateNow(fullPath)) |
| 50 .then((_) => null) | 50 .then((_) => null) |
| 51 .catchError((e) => e); | 51 .catchError((e) => e); |
| 52 })).then((results) { | 52 })).then((results) { |
| 53 var errors = results.where((e) => e != null); | 53 var errors = results.where((e) => e != null); |
| 54 if (errors.isEmpty) return; | 54 if (errors.isEmpty) return; |
| 55 throw _DirectoryValidationError.merge(errors); | 55 throw _DirectoryValidationError.merge(errors); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 70 | 70 |
| 71 var requiresReadable = split.length == 1; | 71 var requiresReadable = split.length == 1; |
| 72 var matchingEntries = contents.where((entry) { | 72 var matchingEntries = contents.where((entry) { |
| 73 return entry.name == split.first && (requiresReadable ? | 73 return entry.name == split.first && (requiresReadable ? |
| 74 entry is ReadableDescriptor : | 74 entry is ReadableDescriptor : |
| 75 entry is LoadableDescriptor); | 75 entry is LoadableDescriptor); |
| 76 }).toList(); | 76 }).toList(); |
| 77 | 77 |
| 78 var adjective = requiresReadable ? 'readable' : 'loadable'; | 78 var adjective = requiresReadable ? 'readable' : 'loadable'; |
| 79 if (matchingEntries.length == 0) { | 79 if (matchingEntries.length == 0) { |
| 80 throw "Couldn't find a $adjective entry named '${split.first}' within " | 80 fail("Couldn't find a $adjective entry named '${split.first}' within " |
| 81 "'$name'."; | 81 "'$name'."); |
| 82 } else if (matchingEntries.length > 1) { | 82 } else if (matchingEntries.length > 1) { |
| 83 throw "Found multiple $adjective entries named '${split.first}' within " | 83 fail("Found multiple $adjective entries named '${split.first}' within " |
| 84 "'$name'."; | 84 "'$name'."); |
| 85 } else { | 85 } else { |
| 86 var remainingPath = split.sublist(1); | 86 var remainingPath = split.sublist(1); |
| 87 if (remainingPath.isEmpty) { | 87 if (remainingPath.isEmpty) { |
| 88 return (matchingEntries.first as ReadableDescriptor).read(); | 88 return (matchingEntries.first as ReadableDescriptor).read(); |
| 89 } else { | 89 } else { |
| 90 return (matchingEntries.first as LoadableDescriptor) | 90 return (matchingEntries.first as LoadableDescriptor) |
| 91 .load(_path.joinAll(remainingPath)); | 91 .load(_path.joinAll(remainingPath)); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 })); | 94 })); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 127 |
| 128 _DirectoryValidationError(Iterable errors) | 128 _DirectoryValidationError(Iterable errors) |
| 129 : errors = errors.map((e) => e.toString()).toList(); | 129 : errors = errors.map((e) => e.toString()).toList(); |
| 130 | 130 |
| 131 String toString() { | 131 String toString() { |
| 132 if (errors.length == 1) return errors.single; | 132 if (errors.length == 1) return errors.single; |
| 133 return errors.map((e) => prefixLines(e, prefix: ' ', firstPrefix: '* ')) | 133 return errors.map((e) => prefixLines(e, prefix: ' ', firstPrefix: '* ')) |
| 134 .join('\n'); | 134 .join('\n'); |
| 135 } | 135 } |
| 136 } | 136 } |
| OLD | NEW |