OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 context.directory.manager; | 5 library context.directory.manager; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 import 'dart:core' hide Resource; | 9 import 'dart:core' hide Resource; |
10 | 10 |
11 import 'package:analysis_server/src/analysis_server.dart'; | 11 import 'package:analysis_server/src/analysis_server.dart'; |
12 import 'package:analysis_server/src/source/optimizing_pub_package_map_provider.d
art'; | 12 import 'package:analysis_server/src/source/optimizing_pub_package_map_provider.d
art'; |
13 import 'package:analysis_server/uri/resolver_provider.dart'; | 13 import 'package:analysis_server/uri/resolver_provider.dart'; |
14 import 'package:analyzer/file_system/file_system.dart'; | 14 import 'package:analyzer/file_system/file_system.dart'; |
15 import 'package:analyzer/instrumentation/instrumentation.dart'; | 15 import 'package:analyzer/instrumentation/instrumentation.dart'; |
16 import 'package:analyzer/source/package_map_resolver.dart'; | 16 import 'package:analyzer/source/package_map_resolver.dart'; |
| 17 import 'package:analyzer/source/path_filter.dart'; |
17 import 'package:analyzer/src/generated/engine.dart'; | 18 import 'package:analyzer/src/generated/engine.dart'; |
18 import 'package:analyzer/src/generated/java_io.dart'; | 19 import 'package:analyzer/src/generated/java_io.dart'; |
19 import 'package:analyzer/src/generated/source.dart'; | 20 import 'package:analyzer/src/generated/source.dart'; |
20 import 'package:analyzer/src/generated/source_io.dart'; | 21 import 'package:analyzer/src/generated/source_io.dart'; |
21 import 'package:path/path.dart' as pathos; | 22 import 'package:path/path.dart' as pathos; |
22 import 'package:watcher/watcher.dart'; | 23 import 'package:watcher/watcher.dart'; |
23 | 24 |
24 /** | 25 /** |
25 * Class that maintains a mapping from included/excluded paths to a set of | 26 * Class that maintains a mapping from included/excluded paths to a set of |
26 * folders that should correspond to analysis contexts. | 27 * folders that should correspond to analysis contexts. |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 return contexts; | 157 return contexts; |
157 } | 158 } |
158 | 159 |
159 /** | 160 /** |
160 * We have finished computing the package map. | 161 * We have finished computing the package map. |
161 */ | 162 */ |
162 void endComputePackageMap() { | 163 void endComputePackageMap() { |
163 // Do nothing. | 164 // Do nothing. |
164 } | 165 } |
165 | 166 |
| 167 // Sets the [ignorePatterns] for the context [folder]. |
| 168 void setIgnorePatternsForContext(Folder folder, List<String> ignorePatterns) { |
| 169 _ContextInfo info = _contexts[folder]; |
| 170 if (info == null) { |
| 171 return; |
| 172 } |
| 173 var pathFilter = info.pathFilter; |
| 174 pathFilter.setIgnorePatterns(ignorePatterns); |
| 175 } |
| 176 |
166 @override | 177 @override |
167 bool isInAnalysisRoot(String path) { | 178 bool isInAnalysisRoot(String path) { |
168 // check if excluded | 179 // check if excluded |
169 if (_isExcluded(path)) { | 180 if (_isExcluded(path)) { |
170 return false; | 181 return false; |
171 } | 182 } |
172 // check if in of the roots | 183 // check if in of the roots |
173 for (Folder root in _contexts.keys) { | 184 for (Folder root in _contexts.keys) { |
174 if (root.contains(path)) { | 185 if (root.contains(path)) { |
175 return true; | 186 return true; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 List<Resource> children; | 322 List<Resource> children; |
312 try { | 323 try { |
313 children = folder.getChildren(); | 324 children = folder.getChildren(); |
314 } on FileSystemException { | 325 } on FileSystemException { |
315 // The folder no longer exists, or cannot be read, to there's nothing to | 326 // The folder no longer exists, or cannot be read, to there's nothing to |
316 // do. | 327 // do. |
317 return; | 328 return; |
318 } | 329 } |
319 for (Resource child in children) { | 330 for (Resource child in children) { |
320 String path = child.path; | 331 String path = child.path; |
| 332 // Path is being ignored. |
| 333 if (info.ignored(path)) { |
| 334 continue; |
| 335 } |
321 // add files, recurse into folders | 336 // add files, recurse into folders |
322 if (child is File) { | 337 if (child is File) { |
323 // ignore if should not be analyzed at all | 338 // ignore if should not be analyzed at all |
324 if (!shouldFileBeAnalyzed(child)) { | 339 if (!shouldFileBeAnalyzed(child)) { |
325 continue; | 340 continue; |
326 } | 341 } |
327 // ignore if was not excluded | 342 // ignore if was not excluded |
328 bool wasExcluded = _isExcludedBy(oldExcludedPaths, path) && | 343 bool wasExcluded = _isExcludedBy(oldExcludedPaths, path) && |
329 !_isExcludedBy(excludedPaths, path); | 344 !_isExcludedBy(excludedPaths, path); |
330 if (!wasExcluded) { | 345 if (!wasExcluded) { |
(...skipping 23 matching lines...) Expand all Loading... |
354 try { | 369 try { |
355 children = folder.getChildren(); | 370 children = folder.getChildren(); |
356 } on FileSystemException { | 371 } on FileSystemException { |
357 // The directory either doesn't exist or cannot be read. Either way, there | 372 // The directory either doesn't exist or cannot be read. Either way, there |
358 // are no children that need to be added. | 373 // are no children that need to be added. |
359 return; | 374 return; |
360 } | 375 } |
361 for (Resource child in children) { | 376 for (Resource child in children) { |
362 String path = child.path; | 377 String path = child.path; |
363 // ignore excluded files or folders | 378 // ignore excluded files or folders |
364 if (_isExcluded(path) || info.excludes(path)) { | 379 if (_isExcluded(path) || info.excludes(path) || info.ignored(path)) { |
365 continue; | 380 continue; |
366 } | 381 } |
367 // add files, recurse into folders | 382 // add files, recurse into folders |
368 if (child is File) { | 383 if (child is File) { |
369 if (shouldFileBeAnalyzed(child)) { | 384 if (shouldFileBeAnalyzed(child)) { |
370 Source source = createSourceInContext(info.context, child); | 385 Source source = createSourceInContext(info.context, child); |
371 changeSet.addedSource(source); | 386 changeSet.addedSource(source); |
372 info.sources[path] = source; | 387 info.sources[path] = source; |
373 } | 388 } |
374 } else if (child is Folder) { | 389 } else if (child is Folder) { |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 folder.path, event.path, event.type.toString()); | 614 folder.path, event.path, event.type.toString()); |
600 String path = event.path; | 615 String path = event.path; |
601 // maybe excluded globally | 616 // maybe excluded globally |
602 if (_isExcluded(path)) { | 617 if (_isExcluded(path)) { |
603 return; | 618 return; |
604 } | 619 } |
605 // maybe excluded from the context, so other context will handle it | 620 // maybe excluded from the context, so other context will handle it |
606 if (info.excludes(path)) { | 621 if (info.excludes(path)) { |
607 return; | 622 return; |
608 } | 623 } |
| 624 if (info.ignored(path)) { |
| 625 return; |
| 626 } |
609 // handle the change | 627 // handle the change |
610 switch (event.type) { | 628 switch (event.type) { |
611 case ChangeType.ADD: | 629 case ChangeType.ADD: |
612 if (_isInPackagesDir(path, folder)) { | 630 if (_isInPackagesDir(path, folder)) { |
613 return; | 631 return; |
614 } | 632 } |
615 Resource resource = resourceProvider.getResource(path); | 633 Resource resource = resourceProvider.getResource(path); |
616 // pubspec was added in a sub-folder, extract a new context | 634 // pubspec was added in a sub-folder, extract a new context |
617 if (_isPubspec(path) && info.isRoot && !info.isPubspec(path)) { | 635 if (_isPubspec(path) && info.isRoot && !info.isPubspec(path)) { |
618 _extractContext(info, resource); | 636 _extractContext(info, resource); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 | 870 |
853 /** | 871 /** |
854 * Information tracked by the [ContextManager] for each context. | 872 * Information tracked by the [ContextManager] for each context. |
855 */ | 873 */ |
856 class _ContextInfo { | 874 class _ContextInfo { |
857 /** | 875 /** |
858 * The [Folder] for which this information object is created. | 876 * The [Folder] for which this information object is created. |
859 */ | 877 */ |
860 final Folder folder; | 878 final Folder folder; |
861 | 879 |
| 880 /// The [PathFilter] used to filter sources from being analyzed. |
| 881 final PathFilter pathFilter; |
| 882 |
862 /** | 883 /** |
863 * The enclosed pubspec-based contexts. | 884 * The enclosed pubspec-based contexts. |
864 */ | 885 */ |
865 final List<_ContextInfo> children; | 886 final List<_ContextInfo> children; |
866 | 887 |
867 /** | 888 /** |
868 * The package root for this context, or null if there is no package root. | 889 * The package root for this context, or null if there is no package root. |
869 */ | 890 */ |
870 String packageRoot; | 891 String packageRoot; |
871 | 892 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 */ | 924 */ |
904 Map<String, Source> sources = new HashMap<String, Source>(); | 925 Map<String, Source> sources = new HashMap<String, Source>(); |
905 | 926 |
906 /** | 927 /** |
907 * Info returned by the last call to | 928 * Info returned by the last call to |
908 * [OptimizingPubPackageMapProvider.computePackageMap], or `null` if the | 929 * [OptimizingPubPackageMapProvider.computePackageMap], or `null` if the |
909 * package map hasn't been computed for this context yet. | 930 * package map hasn't been computed for this context yet. |
910 */ | 931 */ |
911 OptimizingPubPackageMapInfo packageMapInfo; | 932 OptimizingPubPackageMapInfo packageMapInfo; |
912 | 933 |
913 _ContextInfo(this.folder, File pubspecFile, this.children, this.packageRoot) { | 934 _ContextInfo(Folder folder, File pubspecFile, this.children, this.packageRoot) |
| 935 : folder = folder, |
| 936 pathFilter = new PathFilter(folder.path, null) { |
914 pubspecPath = pubspecFile.path; | 937 pubspecPath = pubspecFile.path; |
915 for (_ContextInfo child in children) { | 938 for (_ContextInfo child in children) { |
916 child.parent = this; | 939 child.parent = this; |
917 } | 940 } |
918 } | 941 } |
919 | 942 |
920 /** | 943 /** |
921 * Returns `true` if this context is root folder based. | 944 * Returns `true` if this context is root folder based. |
922 */ | 945 */ |
923 bool get isRoot => parent == null; | 946 bool get isRoot => parent == null; |
924 | 947 |
925 /** | 948 /** |
926 * Returns `true` if [path] is excluded, as it is in one of the children. | 949 * Returns `true` if [path] is excluded, as it is in one of the children. |
927 */ | 950 */ |
928 bool excludes(String path) { | 951 bool excludes(String path) { |
929 return children.any((child) { | 952 return children.any((child) { |
930 return child.folder.contains(path); | 953 return child.folder.contains(path); |
931 }); | 954 }); |
932 } | 955 } |
933 | 956 |
| 957 /// Returns `true` if [path] should be ignored. |
| 958 bool ignored(String path) => pathFilter.ignored(path); |
| 959 |
934 /** | 960 /** |
935 * Returns `true` if [resource] is excluded, as it is in one of the children. | 961 * Returns `true` if [resource] is excluded, as it is in one of the children. |
936 */ | 962 */ |
937 bool excludesResource(Resource resource) { | 963 bool excludesResource(Resource resource) { |
938 return excludes(resource.path); | 964 return excludes(resource.path); |
939 } | 965 } |
940 | 966 |
941 /** | 967 /** |
942 * Returns `true` if [path] is the pubspec file of this context. | 968 * Returns `true` if [path] is the pubspec file of this context. |
943 */ | 969 */ |
944 bool isPubspec(String path) { | 970 bool isPubspec(String path) { |
945 return path == pubspecPath; | 971 return path == pubspecPath; |
946 } | 972 } |
947 } | 973 } |
OLD | NEW |