| 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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 */ | 243 */ |
| 244 List<String> get excludedPaths; | 244 List<String> get excludedPaths; |
| 245 | 245 |
| 246 /** | 246 /** |
| 247 * Return the list of included paths (folders and files) most recently passed | 247 * Return the list of included paths (folders and files) most recently passed |
| 248 * to [setRoots]. | 248 * to [setRoots]. |
| 249 */ | 249 */ |
| 250 List<String> get includedPaths; | 250 List<String> get includedPaths; |
| 251 | 251 |
| 252 /** | 252 /** |
| 253 * The stream that is notified when we are starting or ending the computation | |
| 254 * of a package map. A value of `true` is added when the computation starts | |
| 255 * and a value of `false` is added when the computation ends. | |
| 256 */ | |
| 257 Stream<bool> get onComputingPackageMap; | |
| 258 | |
| 259 /** | |
| 260 * Return a list of all of the contexts reachable from the given | 253 * Return a list of all of the contexts reachable from the given |
| 261 * [analysisRoot] (the context associated with [analysisRoot] and all of its | 254 * [analysisRoot] (the context associated with [analysisRoot] and all of its |
| 262 * descendants). | 255 * descendants). |
| 263 */ | 256 */ |
| 264 List<AnalysisContext> contextsInAnalysisRoot(Folder analysisRoot); | 257 List<AnalysisContext> contextsInAnalysisRoot(Folder analysisRoot); |
| 265 | 258 |
| 266 /** | 259 /** |
| 267 * Return the [AnalysisContext] for the "innermost" context whose associated | 260 * Return the [AnalysisContext] for the "innermost" context whose associated |
| 268 * folder is or contains the given path. ("innermost" refers to the nesting | 261 * folder is or contains the given path. ("innermost" refers to the nesting |
| 269 * of contexts, so if there is a context for path /foo and a context for | 262 * of contexts, so if there is a context for path /foo and a context for |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 Folder folder, AnalysisOptions options, FolderDisposition disposition); | 315 Folder folder, AnalysisOptions options, FolderDisposition disposition); |
| 323 | 316 |
| 324 /** | 317 /** |
| 325 * Called when the set of files associated with a context have changed (or | 318 * Called when the set of files associated with a context have changed (or |
| 326 * some of those files have been modified). [changeSet] is the set of | 319 * some of those files have been modified). [changeSet] is the set of |
| 327 * changes that need to be applied to the context. | 320 * changes that need to be applied to the context. |
| 328 */ | 321 */ |
| 329 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet); | 322 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet); |
| 330 | 323 |
| 331 /** | 324 /** |
| 325 * Signals that the context manager has started to compute a package map (if |
| 326 * [computing] is `true`) or has finished (if [computing] is `false`). |
| 327 */ |
| 328 void computingPackageMap(bool computing); |
| 329 |
| 330 /** |
| 332 * Remove the context associated with the given [folder]. [flushedFiles] is | 331 * Remove the context associated with the given [folder]. [flushedFiles] is |
| 333 * a list of the files which will be "orphaned" by removing this context | 332 * a list of the files which will be "orphaned" by removing this context |
| 334 * (they will no longer be analyzed by any context). | 333 * (they will no longer be analyzed by any context). |
| 335 */ | 334 */ |
| 336 void removeContext(Folder folder, List<String> flushedFiles); | 335 void removeContext(Folder folder, List<String> flushedFiles); |
| 337 | 336 |
| 338 /** | 337 /** |
| 339 * Return `true` if the given [file] should be analyzed. | 338 * Return `true` if the given [file] should be analyzed. |
| 340 */ | 339 */ |
| 341 bool shouldFileBeAnalyzed(File file); | 340 bool shouldFileBeAnalyzed(File file); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 @override | 453 @override |
| 455 ContextManagerCallbacks callbacks; | 454 ContextManagerCallbacks callbacks; |
| 456 | 455 |
| 457 /** | 456 /** |
| 458 * Virtual [ContextInfo] which acts as the ancestor of all other | 457 * Virtual [ContextInfo] which acts as the ancestor of all other |
| 459 * [ContextInfo]s. | 458 * [ContextInfo]s. |
| 460 */ | 459 */ |
| 461 final ContextInfo rootInfo = new ContextInfo._root(); | 460 final ContextInfo rootInfo = new ContextInfo._root(); |
| 462 | 461 |
| 463 /** | 462 /** |
| 464 * The controller that is notified when we are starting or ending the | |
| 465 * computation of a package map. | |
| 466 */ | |
| 467 StreamController<bool> _onComputingPackageMapController; | |
| 468 | |
| 469 /** | |
| 470 * Stream subscription we are using to watch each analysis root directory for | 463 * Stream subscription we are using to watch each analysis root directory for |
| 471 * changes. | 464 * changes. |
| 472 */ | 465 */ |
| 473 final Map<Folder, StreamSubscription<WatchEvent>> changeSubscriptions = | 466 final Map<Folder, StreamSubscription<WatchEvent>> changeSubscriptions = |
| 474 <Folder, StreamSubscription<WatchEvent>>{}; | 467 <Folder, StreamSubscription<WatchEvent>>{}; |
| 475 | 468 |
| 476 ContextManagerImpl( | 469 ContextManagerImpl( |
| 477 this.resourceProvider, | 470 this.resourceProvider, |
| 478 this.packageResolverProvider, | 471 this.packageResolverProvider, |
| 479 this.embeddedUriResolverProvider, | 472 this.embeddedUriResolverProvider, |
| 480 this._packageMapProvider, | 473 this._packageMapProvider, |
| 481 this._instrumentationService, | 474 this._instrumentationService, |
| 482 this.defaultContextOptions) { | 475 this.defaultContextOptions) { |
| 483 absolutePathContext = resourceProvider.absolutePathContext; | 476 absolutePathContext = resourceProvider.absolutePathContext; |
| 484 pathContext = resourceProvider.pathContext; | 477 pathContext = resourceProvider.pathContext; |
| 485 _onComputingPackageMapController = new StreamController.broadcast(); | |
| 486 } | 478 } |
| 487 | 479 |
| 488 @override | 480 @override |
| 489 Stream<bool> get onComputingPackageMap { | |
| 490 return _onComputingPackageMapController.stream; | |
| 491 } | |
| 492 | |
| 493 @override | |
| 494 List<AnalysisContext> contextsInAnalysisRoot(Folder analysisRoot) { | 481 List<AnalysisContext> contextsInAnalysisRoot(Folder analysisRoot) { |
| 495 List<AnalysisContext> contexts = <AnalysisContext>[]; | 482 List<AnalysisContext> contexts = <AnalysisContext>[]; |
| 496 ContextInfo innermostContainingInfo = | 483 ContextInfo innermostContainingInfo = |
| 497 _getInnermostContextInfoFor(analysisRoot.path); | 484 _getInnermostContextInfoFor(analysisRoot.path); |
| 498 void addContextAndDescendants(ContextInfo info) { | 485 void addContextAndDescendants(ContextInfo info) { |
| 499 contexts.add(info.context); | 486 contexts.add(info.context); |
| 500 info.children.forEach(addContextAndDescendants); | 487 info.children.forEach(addContextAndDescendants); |
| 501 } | 488 } |
| 502 if (innermostContainingInfo != null) { | 489 if (innermostContainingInfo != null) { |
| 503 if (analysisRoot == innermostContainingInfo.folder) { | 490 if (analysisRoot == innermostContainingInfo.folder) { |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 991 } | 978 } |
| 992 } | 979 } |
| 993 // The package root does not exist (or is not a folder). Since | 980 // The package root does not exist (or is not a folder). Since |
| 994 // [setRoots] ignores any package roots that don't exist (or aren't | 981 // [setRoots] ignores any package roots that don't exist (or aren't |
| 995 // folders), the only way we should be able to get here is due to a race | 982 // folders), the only way we should be able to get here is due to a race |
| 996 // condition. In any case, the package root folder is gone, so we can't | 983 // condition. In any case, the package root folder is gone, so we can't |
| 997 // resolve packages. | 984 // resolve packages. |
| 998 return new NoPackageFolderDisposition(packageRoot: packageRoot); | 985 return new NoPackageFolderDisposition(packageRoot: packageRoot); |
| 999 } else { | 986 } else { |
| 1000 PackageMapInfo packageMapInfo; | 987 PackageMapInfo packageMapInfo; |
| 1001 _onComputingPackageMapController.add(true); | 988 callbacks.computingPackageMap(true); |
| 1002 try { | 989 try { |
| 1003 // Try .packages first. | 990 // Try .packages first. |
| 1004 if (absolutePathContext.basename(packagespecFile.path) == | 991 if (absolutePathContext.basename(packagespecFile.path) == |
| 1005 PACKAGE_SPEC_NAME) { | 992 PACKAGE_SPEC_NAME) { |
| 1006 Packages packages = _readPackagespec(packagespecFile); | 993 Packages packages = _readPackagespec(packagespecFile); |
| 1007 return new PackagesFileDisposition(packages); | 994 return new PackagesFileDisposition(packages); |
| 1008 } | 995 } |
| 1009 if (packageResolverProvider != null) { | 996 if (packageResolverProvider != null) { |
| 1010 UriResolver resolver = packageResolverProvider(folder); | 997 UriResolver resolver = packageResolverProvider(folder); |
| 1011 if (resolver != null) { | 998 if (resolver != null) { |
| 1012 return new CustomPackageResolverDisposition(resolver); | 999 return new CustomPackageResolverDisposition(resolver); |
| 1013 } | 1000 } |
| 1014 } | 1001 } |
| 1015 | 1002 |
| 1016 ServerPerformanceStatistics.pub.makeCurrentWhile(() { | 1003 ServerPerformanceStatistics.pub.makeCurrentWhile(() { |
| 1017 packageMapInfo = _packageMapProvider.computePackageMap(folder); | 1004 packageMapInfo = _packageMapProvider.computePackageMap(folder); |
| 1018 }); | 1005 }); |
| 1019 } finally { | 1006 } finally { |
| 1020 _onComputingPackageMapController.add(false); | 1007 callbacks.computingPackageMap(false); |
| 1021 } | 1008 } |
| 1022 for (String dependencyPath in packageMapInfo.dependencies) { | 1009 for (String dependencyPath in packageMapInfo.dependencies) { |
| 1023 addDependency(dependencyPath); | 1010 addDependency(dependencyPath); |
| 1024 } | 1011 } |
| 1025 if (packageMapInfo.packageMap == null) { | 1012 if (packageMapInfo.packageMap == null) { |
| 1026 return new NoPackageFolderDisposition(); | 1013 return new NoPackageFolderDisposition(); |
| 1027 } | 1014 } |
| 1028 return new PackageMapDisposition(packageMapInfo.packageMap); | 1015 return new PackageMapDisposition(packageMapInfo.packageMap); |
| 1029 } | 1016 } |
| 1030 } | 1017 } |
| (...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1679 ResourceProvider resourceProvider) { | 1666 ResourceProvider resourceProvider) { |
| 1680 if (packages != null) { | 1667 if (packages != null) { |
| 1681 // Construct package map for the SdkExtUriResolver. | 1668 // Construct package map for the SdkExtUriResolver. |
| 1682 Map<String, List<Folder>> packageMap = buildPackageMap(resourceProvider); | 1669 Map<String, List<Folder>> packageMap = buildPackageMap(resourceProvider); |
| 1683 return <UriResolver>[new SdkExtUriResolver(packageMap)]; | 1670 return <UriResolver>[new SdkExtUriResolver(packageMap)]; |
| 1684 } else { | 1671 } else { |
| 1685 return const <UriResolver>[]; | 1672 return const <UriResolver>[]; |
| 1686 } | 1673 } |
| 1687 } | 1674 } |
| 1688 } | 1675 } |
| OLD | NEW |