| 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 import 'package:glob/glob.dart'; | 5 import 'package:glob/glob.dart'; |
| 6 import 'package:path/path.dart' as p; | 6 import 'package:path/path.dart' as p; |
| 7 import 'package:source_span/source_span.dart'; | 7 import 'package:source_span/source_span.dart'; |
| 8 import 'package:yaml/yaml.dart'; | 8 import 'package:yaml/yaml.dart'; |
| 9 | 9 |
| 10 import 'transformer_id.dart'; | 10 import 'transformer_id.dart'; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 72 |
| 73 /// Parses [identifier] as a [TransformerId] with [configuration]. | 73 /// Parses [identifier] as a [TransformerId] with [configuration]. |
| 74 /// | 74 /// |
| 75 /// [identifierSpan] is the source span for [identifier]. | 75 /// [identifierSpan] is the source span for [identifier]. |
| 76 factory TransformerConfig.parse(String identifier, SourceSpan identifierSpan, | 76 factory TransformerConfig.parse(String identifier, SourceSpan identifierSpan, |
| 77 YamlMap configuration) => | 77 YamlMap configuration) => |
| 78 new TransformerConfig(new TransformerId.parse(identifier, identifierSpan), | 78 new TransformerConfig(new TransformerId.parse(identifier, identifierSpan), |
| 79 configuration); | 79 configuration); |
| 80 | 80 |
| 81 factory TransformerConfig(TransformerId id, YamlMap configurationNode) { | 81 factory TransformerConfig(TransformerId id, YamlMap configurationNode) { |
| 82 parseField(key) { | 82 Set<Glob> parseField(String key) { |
| 83 if (!configurationNode.containsKey(key)) return null; | 83 if (!configurationNode.containsKey(key)) return null; |
| 84 var fieldNode = configurationNode.nodes[key]; | 84 var fieldNode = configurationNode.nodes[key]; |
| 85 var field = fieldNode.value; | 85 var field = fieldNode.value; |
| 86 | 86 |
| 87 if (field is String) { | 87 if (field is String) { |
| 88 return new Set.from([new Glob(field, context: p.url, recursive: true)]); | 88 return new Set.from([new Glob(field, context: p.url, recursive: true)]); |
| 89 } | 89 } |
| 90 | 90 |
| 91 if (field is! List) { | 91 if (field is! List) { |
| 92 throw new SourceSpanFormatException( | 92 throw new SourceSpanFormatException( |
| 93 '"$key" field must be a string or list.', fieldNode.span); | 93 '"$key" field must be a string or list.', fieldNode.span); |
| 94 } | 94 } |
| 95 | 95 |
| 96 return new Set.from(field.nodes.map((node) { | 96 return new Set.from(field.nodes.map((node) { |
| 97 if (node.value is String) { | 97 if (node.value is String) { |
| 98 return new Glob(node.value, context: p.url, recursive: true); | 98 return new Glob(node.value, context: p.url, recursive: true); |
| 99 } | 99 } |
| 100 | 100 |
| 101 throw new SourceSpanFormatException( | 101 throw new SourceSpanFormatException( |
| 102 '"$key" field may contain only strings.', node.span); | 102 '"$key" field may contain only strings.', node.span); |
| 103 })); | 103 })); |
| 104 } | 104 } |
| 105 | 105 |
| 106 var includes = null; | 106 Set<Glob> includes; |
| 107 var excludes = null; | 107 Set<Glob> excludes; |
| 108 | 108 Map configuration; |
| 109 var configuration; | 109 SourceSpan span; |
| 110 var span; | |
| 111 if (configurationNode == null) { | 110 if (configurationNode == null) { |
| 112 configuration = {}; | 111 configuration = {}; |
| 113 span = id.span; | 112 span = id.span; |
| 114 } else { | 113 } else { |
| 115 // Don't write to the immutable YAML map. | 114 // Don't write to the immutable YAML map. |
| 116 configuration = new Map.from(configurationNode); | 115 configuration = new Map.from(configurationNode); |
| 117 span = configurationNode.span; | 116 span = configurationNode.span; |
| 118 | 117 |
| 119 // Pull out the exclusions/inclusions. | 118 // Pull out the exclusions/inclusions. |
| 120 includes = parseField("\$include"); | 119 includes = parseField("\$include"); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 149 for (var exclude in excludes) { | 148 for (var exclude in excludes) { |
| 150 if (exclude.matches(pathWithinPackage)) return false; | 149 if (exclude.matches(pathWithinPackage)) return false; |
| 151 } | 150 } |
| 152 } | 151 } |
| 153 | 152 |
| 154 // If there are any includes, it must match one of them. | 153 // If there are any includes, it must match one of them. |
| 155 return includes == null || | 154 return includes == null || |
| 156 includes.any((include) => include.matches(pathWithinPackage)); | 155 includes.any((include) => include.matches(pathWithinPackage)); |
| 157 } | 156 } |
| 158 } | 157 } |
| OLD | NEW |