| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 * Map from full path to the [Source] object, for each source that has been | 87 * Map from full path to the [Source] object, for each source that has been |
| 88 * added to the context. | 88 * added to the context. |
| 89 */ | 89 */ |
| 90 Map<String, Source> sources = new HashMap<String, Source>(); | 90 Map<String, Source> sources = new HashMap<String, Source>(); |
| 91 | 91 |
| 92 ContextInfo(ContextManagerImpl contextManager, this.parent, Folder folder, | 92 ContextInfo(ContextManagerImpl contextManager, this.parent, Folder folder, |
| 93 File packagespecFile, this.packageRoot) | 93 File packagespecFile, this.packageRoot) |
| 94 : contextManager = contextManager, | 94 : contextManager = contextManager, |
| 95 folder = folder, | 95 folder = folder, |
| 96 pathFilter = new PathFilter( | 96 pathFilter = new PathFilter( |
| 97 contextManager.resourceProvider.pathContext, folder.path, null) { | 97 folder.path, null, contextManager.resourceProvider.pathContext) { |
| 98 packageDescriptionPath = packagespecFile.path; | 98 packageDescriptionPath = packagespecFile.path; |
| 99 parent.children.add(this); | 99 parent.children.add(this); |
| 100 } | 100 } |
| 101 | 101 |
| 102 /** | 102 /** |
| 103 * Create the virtual [ContextInfo] which acts as an ancestor to all other | 103 * Create the virtual [ContextInfo] which acts as an ancestor to all other |
| 104 * [ContextInfo]s. | 104 * [ContextInfo]s. |
| 105 */ | 105 */ |
| 106 ContextInfo._root() | 106 ContextInfo._root() |
| 107 : contextManager = null, | 107 : contextManager = null, |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 | 304 |
| 305 /** | 305 /** |
| 306 * Class that maintains a mapping from included/excluded paths to a set of | 306 * Class that maintains a mapping from included/excluded paths to a set of |
| 307 * folders that should correspond to analysis contexts. | 307 * folders that should correspond to analysis contexts. |
| 308 */ | 308 */ |
| 309 class ContextManagerImpl implements ContextManager { | 309 class ContextManagerImpl implements ContextManager { |
| 310 /** | 310 /** |
| 311 * Temporary flag to hide WIP .packages support (DEP 5). | 311 * Temporary flag to hide WIP .packages support (DEP 5). |
| 312 */ | 312 */ |
| 313 static bool ENABLE_PACKAGESPEC_SUPPORT = serverOptions.isSet( | 313 static bool ENABLE_PACKAGESPEC_SUPPORT = serverOptions.isSet( |
| 314 'ContextManagerImpl.ENABLE_PACKAGESPEC_SUPPORT', defaultValue: true); | 314 'ContextManagerImpl.ENABLE_PACKAGESPEC_SUPPORT', |
| 315 defaultValue: true); |
| 315 | 316 |
| 316 /** | 317 /** |
| 317 * The name of the `lib` directory. | 318 * The name of the `lib` directory. |
| 318 */ | 319 */ |
| 319 static const String LIB_DIR_NAME = 'lib'; | 320 static const String LIB_DIR_NAME = 'lib'; |
| 320 | 321 |
| 321 /** | 322 /** |
| 322 * The name of `packages` folders. | 323 * The name of `packages` folders. |
| 323 */ | 324 */ |
| 324 static const String PACKAGES_NAME = 'packages'; | 325 static const String PACKAGES_NAME = 'packages'; |
| (...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 990 return; | 991 return; |
| 991 } | 992 } |
| 992 | 993 |
| 993 Resource resource = resourceProvider.getResource(path); | 994 Resource resource = resourceProvider.getResource(path); |
| 994 | 995 |
| 995 if (ENABLE_PACKAGESPEC_SUPPORT) { | 996 if (ENABLE_PACKAGESPEC_SUPPORT) { |
| 996 String directoryPath = pathContext.dirname(path); | 997 String directoryPath = pathContext.dirname(path); |
| 997 | 998 |
| 998 // Check to see if we need to create a new context. | 999 // Check to see if we need to create a new context. |
| 999 if (info.isTopLevel) { | 1000 if (info.isTopLevel) { |
| 1000 | |
| 1001 // Only create a new context if this is not the same directory | 1001 // Only create a new context if this is not the same directory |
| 1002 // described by our info object. | 1002 // described by our info object. |
| 1003 if (info.folder.path != directoryPath) { | 1003 if (info.folder.path != directoryPath) { |
| 1004 if (_isPubspec(path)) { | 1004 if (_isPubspec(path)) { |
| 1005 // Check for a sibling .packages file. | 1005 // Check for a sibling .packages file. |
| 1006 if (!resourceProvider.getFile( | 1006 if (!resourceProvider |
| 1007 pathos.join(directoryPath, PACKAGE_SPEC_NAME)).exists) { | 1007 .getFile(pathos.join(directoryPath, PACKAGE_SPEC_NAME)) |
| 1008 .exists) { |
| 1008 _extractContext(info, resource); | 1009 _extractContext(info, resource); |
| 1009 return; | 1010 return; |
| 1010 } | 1011 } |
| 1011 } | 1012 } |
| 1012 if (_isPackagespec(path)) { | 1013 if (_isPackagespec(path)) { |
| 1013 // Check for a sibling pubspec.yaml file. | 1014 // Check for a sibling pubspec.yaml file. |
| 1014 if (!resourceProvider | 1015 if (!resourceProvider |
| 1015 .getFile(pathos.join(directoryPath, PUBSPEC_NAME)).exists) { | 1016 .getFile(pathos.join(directoryPath, PUBSPEC_NAME)) |
| 1017 .exists) { |
| 1016 _extractContext(info, resource); | 1018 _extractContext(info, resource); |
| 1017 return; | 1019 return; |
| 1018 } | 1020 } |
| 1019 } | 1021 } |
| 1020 } | 1022 } |
| 1021 } | 1023 } |
| 1022 } else { | 1024 } else { |
| 1023 // pubspec was added in a sub-folder, extract a new context | 1025 // pubspec was added in a sub-folder, extract a new context |
| 1024 if (_isPubspec(path) && | 1026 if (_isPubspec(path) && |
| 1025 info.isTopLevel && | 1027 info.isTopLevel && |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1049 // Note that it's important to verify that there is NEITHER a .packages
nor a | 1051 // Note that it's important to verify that there is NEITHER a .packages
nor a |
| 1050 // lingering pubspec.yaml before merging. | 1052 // lingering pubspec.yaml before merging. |
| 1051 if (!info.isTopLevel) { | 1053 if (!info.isTopLevel) { |
| 1052 if (ENABLE_PACKAGESPEC_SUPPORT) { | 1054 if (ENABLE_PACKAGESPEC_SUPPORT) { |
| 1053 String directoryPath = pathContext.dirname(path); | 1055 String directoryPath = pathContext.dirname(path); |
| 1054 | 1056 |
| 1055 // Only merge if this is the same directory described by our info ob
ject. | 1057 // Only merge if this is the same directory described by our info ob
ject. |
| 1056 if (info.folder.path == directoryPath) { | 1058 if (info.folder.path == directoryPath) { |
| 1057 if (_isPubspec(path)) { | 1059 if (_isPubspec(path)) { |
| 1058 // Check for a sibling .packages file. | 1060 // Check for a sibling .packages file. |
| 1059 if (!resourceProvider.getFile( | 1061 if (!resourceProvider |
| 1060 pathos.join(directoryPath, PACKAGE_SPEC_NAME)).exists) { | 1062 .getFile(pathos.join(directoryPath, PACKAGE_SPEC_NAME)) |
| 1063 .exists) { |
| 1061 _mergeContext(info); | 1064 _mergeContext(info); |
| 1062 return; | 1065 return; |
| 1063 } | 1066 } |
| 1064 } | 1067 } |
| 1065 if (_isPackagespec(path)) { | 1068 if (_isPackagespec(path)) { |
| 1066 // Check for a sibling pubspec.yaml file. | 1069 // Check for a sibling pubspec.yaml file. |
| 1067 if (!resourceProvider | 1070 if (!resourceProvider |
| 1068 .getFile(pathos.join(directoryPath, PUBSPEC_NAME)).exists) { | 1071 .getFile(pathos.join(directoryPath, PUBSPEC_NAME)) |
| 1072 .exists) { |
| 1069 _mergeContext(info); | 1073 _mergeContext(info); |
| 1070 return; | 1074 return; |
| 1071 } | 1075 } |
| 1072 } | 1076 } |
| 1073 } | 1077 } |
| 1074 } else { | 1078 } else { |
| 1075 if (info.isPathToPackageDescription(path)) { | 1079 if (info.isPathToPackageDescription(path)) { |
| 1076 _mergeContext(info); | 1080 _mergeContext(info); |
| 1077 return; | 1081 return; |
| 1078 } | 1082 } |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1220 final List<AnalysisContext> changed; | 1224 final List<AnalysisContext> changed; |
| 1221 | 1225 |
| 1222 /** | 1226 /** |
| 1223 * The contexts that were removed from the server. | 1227 * The contexts that were removed from the server. |
| 1224 */ | 1228 */ |
| 1225 final List<AnalysisContext> removed; | 1229 final List<AnalysisContext> removed; |
| 1226 | 1230 |
| 1227 /** | 1231 /** |
| 1228 * Initialize a newly created event to indicate which contexts have changed. | 1232 * Initialize a newly created event to indicate which contexts have changed. |
| 1229 */ | 1233 */ |
| 1230 ContextsChangedEvent({this.added: AnalysisContext.EMPTY_LIST, | 1234 ContextsChangedEvent( |
| 1235 {this.added: AnalysisContext.EMPTY_LIST, |
| 1231 this.changed: AnalysisContext.EMPTY_LIST, | 1236 this.changed: AnalysisContext.EMPTY_LIST, |
| 1232 this.removed: AnalysisContext.EMPTY_LIST}); | 1237 this.removed: AnalysisContext.EMPTY_LIST}); |
| 1233 } | 1238 } |
| 1234 | 1239 |
| 1235 /** | 1240 /** |
| 1236 * Concrete [FolderDisposition] object indicating that the context for a given | 1241 * Concrete [FolderDisposition] object indicating that the context for a given |
| 1237 * folder should resolve package URIs using a custom URI resolver. | 1242 * folder should resolve package URIs using a custom URI resolver. |
| 1238 */ | 1243 */ |
| 1239 class CustomPackageResolverDisposition extends FolderDisposition { | 1244 class CustomPackageResolverDisposition extends FolderDisposition { |
| 1240 /** | 1245 /** |
| 1241 * The [UriResolver] that should be used to resolve package URIs. | 1246 * The [UriResolver] that should be used to resolve package URIs. |
| 1242 */ | 1247 */ |
| 1243 UriResolver resolver; | 1248 UriResolver resolver; |
| 1244 | 1249 |
| 1245 CustomPackageResolverDisposition(this.resolver); | 1250 CustomPackageResolverDisposition(this.resolver); |
| 1246 | 1251 |
| 1247 @override | 1252 @override |
| 1248 String get packageRoot => null; | 1253 String get packageRoot => null; |
| 1249 | 1254 |
| 1250 @override | 1255 @override |
| 1251 Packages get packages => null; | 1256 Packages get packages => null; |
| 1252 | 1257 |
| 1253 @override | 1258 @override |
| 1254 Iterable<UriResolver> createPackageUriResolvers( | 1259 Iterable<UriResolver> createPackageUriResolvers( |
| 1255 ResourceProvider resourceProvider) => <UriResolver>[resolver]; | 1260 ResourceProvider resourceProvider) => |
| 1261 <UriResolver>[resolver]; |
| 1256 } | 1262 } |
| 1257 | 1263 |
| 1258 /** | 1264 /** |
| 1259 * An instance of the class [FolderDisposition] represents the information | 1265 * An instance of the class [FolderDisposition] represents the information |
| 1260 * gathered by the [ContextManagerImpl] to determine how to create an | 1266 * gathered by the [ContextManagerImpl] to determine how to create an |
| 1261 * [AnalysisContext] for a given folder. | 1267 * [AnalysisContext] for a given folder. |
| 1262 * | 1268 * |
| 1263 * Note: [ContextManagerImpl] may use equality testing and hash codes to | 1269 * Note: [ContextManagerImpl] may use equality testing and hash codes to |
| 1264 * determine when two folders should share the same context, so derived classes | 1270 * determine when two folders should share the same context, so derived classes |
| 1265 * may need to override operator== and hashCode() if object identity is | 1271 * may need to override operator== and hashCode() if object identity is |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1303 @override | 1309 @override |
| 1304 final String packageRoot; | 1310 final String packageRoot; |
| 1305 | 1311 |
| 1306 NoPackageFolderDisposition({this.packageRoot}); | 1312 NoPackageFolderDisposition({this.packageRoot}); |
| 1307 | 1313 |
| 1308 @override | 1314 @override |
| 1309 Packages get packages => null; | 1315 Packages get packages => null; |
| 1310 | 1316 |
| 1311 @override | 1317 @override |
| 1312 Iterable<UriResolver> createPackageUriResolvers( | 1318 Iterable<UriResolver> createPackageUriResolvers( |
| 1313 ResourceProvider resourceProvider) => const <UriResolver>[]; | 1319 ResourceProvider resourceProvider) => |
| 1320 const <UriResolver>[]; |
| 1314 } | 1321 } |
| 1315 | 1322 |
| 1316 /** | 1323 /** |
| 1317 * Concrete [FolderDisposition] object indicating that the context for a given | 1324 * Concrete [FolderDisposition] object indicating that the context for a given |
| 1318 * folder should resolve packages using a package map. | 1325 * folder should resolve packages using a package map. |
| 1319 */ | 1326 */ |
| 1320 class PackageMapDisposition extends FolderDisposition { | 1327 class PackageMapDisposition extends FolderDisposition { |
| 1321 final Map<String, List<Folder>> packageMap; | 1328 final Map<String, List<Folder>> packageMap; |
| 1322 | 1329 |
| 1323 @override | 1330 @override |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1342 @override | 1349 @override |
| 1343 final Packages packages; | 1350 final Packages packages; |
| 1344 | 1351 |
| 1345 PackagesFileDisposition(this.packages) {} | 1352 PackagesFileDisposition(this.packages) {} |
| 1346 | 1353 |
| 1347 @override | 1354 @override |
| 1348 String get packageRoot => null; | 1355 String get packageRoot => null; |
| 1349 | 1356 |
| 1350 @override | 1357 @override |
| 1351 Iterable<UriResolver> createPackageUriResolvers( | 1358 Iterable<UriResolver> createPackageUriResolvers( |
| 1352 ResourceProvider resourceProvider) => const <UriResolver>[]; | 1359 ResourceProvider resourceProvider) => |
| 1360 const <UriResolver>[]; |
| 1353 } | 1361 } |
| OLD | NEW |