| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:io'; | 5 import 'dart:io'; |
| 6 | 6 |
| 7 import 'package:boolean_selector/boolean_selector.dart'; | 7 import 'package:boolean_selector/boolean_selector.dart'; |
| 8 import 'package:glob/glob.dart'; | 8 import 'package:glob/glob.dart'; |
| 9 import 'package:path/path.dart' as p; | 9 import 'package:path/path.dart' as p; |
| 10 import 'package:source_span/source_span.dart'; | 10 import 'package:source_span/source_span.dart'; |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 _validate(pathNode, "Paths must be relative.", p.url.isRelative); | 170 _validate(pathNode, "Paths must be relative.", p.url.isRelative); |
| 171 | 171 |
| 172 return _parseNode(pathNode, "path", p.fromUri); | 172 return _parseNode(pathNode, "path", p.fromUri); |
| 173 }); | 173 }); |
| 174 | 174 |
| 175 var filename = _parseValue("filename", (value) => new Glob(value)); | 175 var filename = _parseValue("filename", (value) => new Glob(value)); |
| 176 | 176 |
| 177 var chosenPresets = _getList("add_presets", | 177 var chosenPresets = _getList("add_presets", |
| 178 (presetNode) => _parseIdentifierLike(presetNode, "Preset name")); | 178 (presetNode) => _parseIdentifierLike(presetNode, "Preset name")); |
| 179 | 179 |
| 180 var includeTags = _parseBooleanSelector("include_tags"); |
| 181 var excludeTags = _parseBooleanSelector("exclude_tags"); |
| 182 |
| 180 return new Configuration( | 183 return new Configuration( |
| 181 reporter: reporter, | 184 reporter: reporter, |
| 182 pubServePort: pubServePort, | 185 pubServePort: pubServePort, |
| 183 concurrency: concurrency, | 186 concurrency: concurrency, |
| 184 patterns: patterns, | 187 patterns: patterns, |
| 185 platforms: platforms, | 188 platforms: platforms, |
| 186 paths: paths, | 189 paths: paths, |
| 187 filename: filename, | 190 filename: filename, |
| 188 chosenPresets: chosenPresets); | 191 chosenPresets: chosenPresets, |
| 192 includeTags: includeTags, |
| 193 excludeTags: excludeTags); |
| 189 } | 194 } |
| 190 | 195 |
| 191 /// Throws an exception with [message] if [test] returns `false` when passed | 196 /// Throws an exception with [message] if [test] returns `false` when passed |
| 192 /// [node]'s value. | 197 /// [node]'s value. |
| 193 void _validate(YamlNode node, String message, bool test(value)) { | 198 void _validate(YamlNode node, String message, bool test(value)) { |
| 194 if (test(node.value)) return; | 199 if (test(node.value)) return; |
| 195 throw new SourceSpanFormatException(message, node.span, _source); | 200 throw new SourceSpanFormatException(message, node.span, _source); |
| 196 } | 201 } |
| 197 | 202 |
| 198 /// Returns the value of the node at [field]. | 203 /// Returns the value of the node at [field]. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 (value) => value is String); | 264 (value) => value is String); |
| 260 | 265 |
| 261 return valueNode.value; | 266 return valueNode.value; |
| 262 }; | 267 }; |
| 263 | 268 |
| 264 return mapMap(node.nodes, | 269 return mapMap(node.nodes, |
| 265 key: (keyNode, _) => key(keyNode), | 270 key: (keyNode, _) => key(keyNode), |
| 266 value: (_, valueNode) => value(valueNode)); | 271 value: (_, valueNode) => value(valueNode)); |
| 267 } | 272 } |
| 268 | 273 |
| 274 /// Verifies that [node]'s value is an optionally hyphenated Dart identifier, |
| 275 /// and returns it |
| 269 String _parseIdentifierLike(YamlNode node, String name) { | 276 String _parseIdentifierLike(YamlNode node, String name) { |
| 270 _validate(node, "$name must be a string.", (value) => value is String); | 277 _validate(node, "$name must be a string.", (value) => value is String); |
| 271 _validate( | 278 _validate( |
| 272 node, | 279 node, |
| 273 "$name must be an (optionally hyphenated) Dart identifier.", | 280 "$name must be an (optionally hyphenated) Dart identifier.", |
| 274 (value) => value.contains(anchoredHyphenatedIdentifier)); | 281 (value) => value.contains(anchoredHyphenatedIdentifier)); |
| 275 return node.value; | 282 return node.value; |
| 276 } | 283 } |
| 277 | 284 |
| 285 /// Parses [node]'s value as a boolean selector. |
| 286 BooleanSelector _parseBooleanSelector(String name) => |
| 287 _parseValue(name, (value) => new BooleanSelector.parse(value)); |
| 288 |
| 278 /// Asserts that [node] is a string, passes its value to [parse], and returns | 289 /// Asserts that [node] is a string, passes its value to [parse], and returns |
| 279 /// the result. | 290 /// the result. |
| 280 /// | 291 /// |
| 281 /// If [parse] throws a [FormatException], it's wrapped to include [node]'s | 292 /// If [parse] throws a [FormatException], it's wrapped to include [node]'s |
| 282 /// span. | 293 /// span. |
| 283 _parseNode(YamlNode node, String name, parse(String value)) { | 294 _parseNode(YamlNode node, String name, parse(String value)) { |
| 284 _validate(node, "$name must be a string.", (value) => value is String); | 295 _validate(node, "$name must be a string.", (value) => value is String); |
| 285 | 296 |
| 286 try { | 297 try { |
| 287 return parse(node.value); | 298 return parse(node.value); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 if (!_document.containsKey(field)) return; | 333 if (!_document.containsKey(field)) return; |
| 323 _error("$field isn't supported here.", field); | 334 _error("$field isn't supported here.", field); |
| 324 } | 335 } |
| 325 | 336 |
| 326 /// Throws a [SourceSpanFormatException] with [message] about [field]. | 337 /// Throws a [SourceSpanFormatException] with [message] about [field]. |
| 327 void _error(String message, String field) { | 338 void _error(String message, String field) { |
| 328 throw new SourceSpanFormatException( | 339 throw new SourceSpanFormatException( |
| 329 message, _document.nodes[field].span, _source); | 340 message, _document.nodes[field].span, _source); |
| 330 } | 341 } |
| 331 } | 342 } |
| OLD | NEW |