Chromium Code Reviews| 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:convert'; | 9 import 'dart:convert'; |
| 10 import 'dart:core' hide Resource; | 10 import 'dart:core' hide Resource; |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 void updateContextPackageUriResolver( | 305 void updateContextPackageUriResolver( |
| 306 Folder contextFolder, FolderDisposition disposition); | 306 Folder contextFolder, FolderDisposition disposition); |
| 307 } | 307 } |
| 308 | 308 |
| 309 /** | 309 /** |
| 310 * Class that maintains a mapping from included/excluded paths to a set of | 310 * Class that maintains a mapping from included/excluded paths to a set of |
| 311 * folders that should correspond to analysis contexts. | 311 * folders that should correspond to analysis contexts. |
| 312 */ | 312 */ |
| 313 class ContextManagerImpl implements ContextManager { | 313 class ContextManagerImpl implements ContextManager { |
| 314 /** | 314 /** |
| 315 * The name of the `doc` directory. | |
| 316 */ | |
| 317 static const String DOC_DIR_NAME = 'doc'; | |
| 318 | |
| 319 /** | |
| 315 * The name of the `lib` directory. | 320 * The name of the `lib` directory. |
| 316 */ | 321 */ |
| 317 static const String LIB_DIR_NAME = 'lib'; | 322 static const String LIB_DIR_NAME = 'lib'; |
| 318 | 323 |
| 319 /** | 324 /** |
| 320 * The name of `packages` folders. | 325 * The name of `packages` folders. |
| 321 */ | 326 */ |
| 322 static const String PACKAGES_NAME = 'packages'; | 327 static const String PACKAGES_NAME = 'packages'; |
| 323 | 328 |
| 324 /** | 329 /** |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 680 } | 685 } |
| 681 _addPreviouslyExcludedSources(info, changeSet, child, oldExcludedPaths); | 686 _addPreviouslyExcludedSources(info, changeSet, child, oldExcludedPaths); |
| 682 } | 687 } |
| 683 } | 688 } |
| 684 } | 689 } |
| 685 | 690 |
| 686 /** | 691 /** |
| 687 * Recursively adds all Dart and HTML files to the [changeSet]. | 692 * Recursively adds all Dart and HTML files to the [changeSet]. |
| 688 */ | 693 */ |
| 689 void _addSourceFiles(ChangeSet changeSet, Folder folder, ContextInfo info) { | 694 void _addSourceFiles(ChangeSet changeSet, Folder folder, ContextInfo info) { |
| 690 if (info.excludesResource(folder) || folder.shortName.startsWith('.')) { | 695 if (info.excludesResource(folder) || |
| 696 folder.shortName.startsWith('.') || | |
| 697 folder.shortName == DOC_DIR_NAME) { | |
|
Brian Wilkerson
2015/11/11 19:27:16
Do we really want to exclude all directories named
| |
| 691 return; | 698 return; |
| 692 } | 699 } |
| 693 List<Resource> children = null; | 700 List<Resource> children = null; |
| 694 try { | 701 try { |
| 695 children = folder.getChildren(); | 702 children = folder.getChildren(); |
| 696 } on FileSystemException { | 703 } on FileSystemException { |
| 697 // The directory either doesn't exist or cannot be read. Either way, there | 704 // The directory either doesn't exist or cannot be read. Either way, there |
| 698 // are no children that need to be added. | 705 // are no children that need to be added. |
| 699 return; | 706 return; |
| 700 } | 707 } |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1038 _instrumentationService.logWatchEvent( | 1045 _instrumentationService.logWatchEvent( |
| 1039 info.folder.path, event.path, event.type.toString()); | 1046 info.folder.path, event.path, event.type.toString()); |
| 1040 String path = event.path; | 1047 String path = event.path; |
| 1041 // First handle changes that affect folderDisposition (since these need to | 1048 // First handle changes that affect folderDisposition (since these need to |
| 1042 // be processed regardless of whether they are part of an excluded/ignored | 1049 // be processed regardless of whether they are part of an excluded/ignored |
| 1043 // path). | 1050 // path). |
| 1044 if (info.hasDependency(path)) { | 1051 if (info.hasDependency(path)) { |
| 1045 _recomputeFolderDisposition(info); | 1052 _recomputeFolderDisposition(info); |
| 1046 } | 1053 } |
| 1047 // maybe excluded globally | 1054 // maybe excluded globally |
| 1048 if (_isExcluded(path) || _isContainedInDotFolder(info.folder.path, path)) { | 1055 if (_isExcluded(path) || |
| 1056 _isContainedInDotFolder(info.folder.path, path) || | |
| 1057 _isInPackagesDir(info.folder.path, path) || | |
| 1058 _isInDocDir(info.folder.path, path)) { | |
| 1049 return; | 1059 return; |
| 1050 } | 1060 } |
| 1051 // maybe excluded from the context, so other context will handle it | 1061 // maybe excluded from the context, so other context will handle it |
| 1052 if (info.excludes(path)) { | 1062 if (info.excludes(path)) { |
| 1053 return; | 1063 return; |
| 1054 } | 1064 } |
| 1055 if (info.ignored(path)) { | 1065 if (info.ignored(path)) { |
| 1056 return; | 1066 return; |
| 1057 } | 1067 } |
| 1058 // handle the change | 1068 // handle the change |
| 1059 switch (event.type) { | 1069 switch (event.type) { |
| 1060 case ChangeType.ADD: | 1070 case ChangeType.ADD: |
| 1061 if (_isInPackagesDir(path, info.folder)) { | |
| 1062 return; | |
| 1063 } | |
| 1064 | |
| 1065 Resource resource = resourceProvider.getResource(path); | 1071 Resource resource = resourceProvider.getResource(path); |
| 1066 | 1072 |
| 1067 String directoryPath = pathContext.dirname(path); | 1073 String directoryPath = pathContext.dirname(path); |
| 1068 | 1074 |
| 1069 // Check to see if we need to create a new context. | 1075 // Check to see if we need to create a new context. |
| 1070 if (info.isTopLevel) { | 1076 if (info.isTopLevel) { |
| 1071 // Only create a new context if this is not the same directory | 1077 // Only create a new context if this is not the same directory |
| 1072 // described by our info object. | 1078 // described by our info object. |
| 1073 if (info.folder.path != directoryPath) { | 1079 if (info.folder.path != directoryPath) { |
| 1074 if (_isPubspec(path)) { | 1080 if (_isPubspec(path)) { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1190 bool _isExcludedBy(List<String> excludedPaths, String path) { | 1196 bool _isExcludedBy(List<String> excludedPaths, String path) { |
| 1191 return excludedPaths.any((excludedPath) { | 1197 return excludedPaths.any((excludedPath) { |
| 1192 if (pathContext.isWithin(excludedPath, path)) { | 1198 if (pathContext.isWithin(excludedPath, path)) { |
| 1193 return true; | 1199 return true; |
| 1194 } | 1200 } |
| 1195 return path == excludedPath; | 1201 return path == excludedPath; |
| 1196 }); | 1202 }); |
| 1197 } | 1203 } |
| 1198 | 1204 |
| 1199 /** | 1205 /** |
| 1200 * Determine if the path from [folder] to [path] contains a 'packages' | 1206 * Determine whether the given [path], when interpreted relative to the |
| 1201 * directory. | 1207 * context root [root], contains a 'doc' folder. |
| 1202 */ | 1208 */ |
| 1203 bool _isInPackagesDir(String path, Folder folder) { | 1209 bool _isInDocDir(String root, String path) { |
| 1204 String relativePath = pathContext.relative(path, from: folder.path); | 1210 String relativePath = pathContext.relative(path, from: root); |
| 1211 List<String> pathParts = pathContext.split(relativePath); | |
| 1212 return pathParts.contains(DOC_DIR_NAME); | |
| 1213 } | |
| 1214 | |
| 1215 /** | |
| 1216 * Determine whether the given [path], when interpreted relative to the | |
| 1217 * context root [root], contains a 'packages' folder. | |
| 1218 */ | |
| 1219 bool _isInPackagesDir(String root, String path) { | |
| 1220 String relativePath = pathContext.relative(path, from: root); | |
| 1205 List<String> pathParts = pathContext.split(relativePath); | 1221 List<String> pathParts = pathContext.split(relativePath); |
| 1206 return pathParts.contains(PACKAGES_NAME); | 1222 return pathParts.contains(PACKAGES_NAME); |
| 1207 } | 1223 } |
| 1208 | 1224 |
| 1209 bool _isPackagespec(String path) => | 1225 bool _isPackagespec(String path) => |
| 1210 pathContext.basename(path) == PACKAGE_SPEC_NAME; | 1226 pathContext.basename(path) == PACKAGE_SPEC_NAME; |
| 1211 | 1227 |
| 1212 bool _isPubspec(String path) => pathContext.basename(path) == PUBSPEC_NAME; | 1228 bool _isPubspec(String path) => pathContext.basename(path) == PUBSPEC_NAME; |
| 1213 | 1229 |
| 1214 /** | 1230 /** |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1438 var path = resourceProvider.pathContext.fromUri(uri); | 1454 var path = resourceProvider.pathContext.fromUri(uri); |
| 1439 packageMap[name] = <Folder>[resourceProvider.getFolder(path)]; | 1455 packageMap[name] = <Folder>[resourceProvider.getFolder(path)]; |
| 1440 } | 1456 } |
| 1441 }); | 1457 }); |
| 1442 return <UriResolver>[new SdkExtUriResolver(packageMap)]; | 1458 return <UriResolver>[new SdkExtUriResolver(packageMap)]; |
| 1443 } else { | 1459 } else { |
| 1444 return const <UriResolver>[]; | 1460 return const <UriResolver>[]; |
| 1445 } | 1461 } |
| 1446 } | 1462 } |
| 1447 } | 1463 } |
| OLD | NEW |