| 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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 * created, destroyed or updated, (b) inform the client when "pub list" | 300 * created, destroyed or updated, (b) inform the client when "pub list" |
| 301 * operations are in progress, and (c) determine which files should be | 301 * operations are in progress, and (c) determine which files should be |
| 302 * analyzed. | 302 * analyzed. |
| 303 * | 303 * |
| 304 * TODO(paulberry): eliminate this interface, and instead have [ContextManager] | 304 * TODO(paulberry): eliminate this interface, and instead have [ContextManager] |
| 305 * operations return data structures describing how context state should be | 305 * operations return data structures describing how context state should be |
| 306 * modified. | 306 * modified. |
| 307 */ | 307 */ |
| 308 abstract class ContextManagerCallbacks { | 308 abstract class ContextManagerCallbacks { |
| 309 /** | 309 /** |
| 310 * Return the default analysis options to be used when creating an analysis | |
| 311 * context. | |
| 312 */ | |
| 313 AnalysisOptions get defaultAnalysisOptions; | |
| 314 | |
| 315 /** | |
| 316 * Create and return a new analysis context rooted at the given [folder], with | 310 * Create and return a new analysis context rooted at the given [folder], with |
| 317 * the given analysis [options], allowing [disposition] to govern details of | 311 * the given analysis [options], allowing [disposition] to govern details of |
| 318 * how the context is to be created. | 312 * how the context is to be created. |
| 319 */ | 313 */ |
| 320 AnalysisContext addContext( | 314 AnalysisContext addContext( |
| 321 Folder folder, AnalysisOptions options, FolderDisposition disposition); | 315 Folder folder, AnalysisOptions options, FolderDisposition disposition); |
| 322 | 316 |
| 323 /** | 317 /** |
| 324 * 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 |
| 325 * 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 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 | 447 |
| 454 /// Provider of analysis options. | 448 /// Provider of analysis options. |
| 455 AnalysisOptionsProvider analysisOptionsProvider = | 449 AnalysisOptionsProvider analysisOptionsProvider = |
| 456 new AnalysisOptionsProvider(); | 450 new AnalysisOptionsProvider(); |
| 457 | 451 |
| 458 /** | 452 /** |
| 459 * The instrumentation service used to report instrumentation data. | 453 * The instrumentation service used to report instrumentation data. |
| 460 */ | 454 */ |
| 461 final InstrumentationService _instrumentationService; | 455 final InstrumentationService _instrumentationService; |
| 462 | 456 |
| 457 /** |
| 458 * The default options used to create new analysis contexts. |
| 459 */ |
| 460 final AnalysisOptionsImpl defaultContextOptions; |
| 461 |
| 463 @override | 462 @override |
| 464 ContextManagerCallbacks callbacks; | 463 ContextManagerCallbacks callbacks; |
| 465 | 464 |
| 466 /** | 465 /** |
| 467 * Virtual [ContextInfo] which acts as the ancestor of all other | 466 * Virtual [ContextInfo] which acts as the ancestor of all other |
| 468 * [ContextInfo]s. | 467 * [ContextInfo]s. |
| 469 */ | 468 */ |
| 470 final ContextInfo rootInfo = new ContextInfo._root(); | 469 final ContextInfo rootInfo = new ContextInfo._root(); |
| 471 | 470 |
| 472 /** | 471 /** |
| 473 * Stream subscription we are using to watch each analysis root directory for | 472 * Stream subscription we are using to watch each analysis root directory for |
| 474 * changes. | 473 * changes. |
| 475 */ | 474 */ |
| 476 final Map<Folder, StreamSubscription<WatchEvent>> changeSubscriptions = | 475 final Map<Folder, StreamSubscription<WatchEvent>> changeSubscriptions = |
| 477 <Folder, StreamSubscription<WatchEvent>>{}; | 476 <Folder, StreamSubscription<WatchEvent>>{}; |
| 478 | 477 |
| 479 ContextManagerImpl( | 478 ContextManagerImpl( |
| 480 this.resourceProvider, | 479 this.resourceProvider, |
| 481 this.packageResolverProvider, | 480 this.packageResolverProvider, |
| 482 this.embeddedUriResolverProvider, | 481 this.embeddedUriResolverProvider, |
| 483 this._packageMapProvider, | 482 this._packageMapProvider, |
| 484 this._instrumentationService) { | 483 this._instrumentationService, |
| 484 this.defaultContextOptions) { |
| 485 absolutePathContext = resourceProvider.absolutePathContext; | 485 absolutePathContext = resourceProvider.absolutePathContext; |
| 486 pathContext = resourceProvider.pathContext; | 486 pathContext = resourceProvider.pathContext; |
| 487 } | 487 } |
| 488 | 488 |
| 489 @override | 489 @override |
| 490 List<AnalysisContext> contextsInAnalysisRoot(Folder analysisRoot) { | 490 List<AnalysisContext> contextsInAnalysisRoot(Folder analysisRoot) { |
| 491 List<AnalysisContext> contexts = <AnalysisContext>[]; | 491 List<AnalysisContext> contexts = <AnalysisContext>[]; |
| 492 ContextInfo innermostContainingInfo = | 492 ContextInfo innermostContainingInfo = |
| 493 _getInnermostContextInfoFor(analysisRoot.path); | 493 _getInnermostContextInfoFor(analysisRoot.path); |
| 494 void addContextAndDescendants(ContextInfo info) { | 494 void addContextAndDescendants(ContextInfo info) { |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 | 885 |
| 886 SourceFactory sourceFactory = info.context.sourceFactory; | 886 SourceFactory sourceFactory = info.context.sourceFactory; |
| 887 | 887 |
| 888 // Check for library embedders. | 888 // Check for library embedders. |
| 889 if (embedderYamls.values.any(definesEmbeddedLibs)) { | 889 if (embedderYamls.values.any(definesEmbeddedLibs)) { |
| 890 // If there is no embedded URI resolver, a new source factory needs to | 890 // If there is no embedded URI resolver, a new source factory needs to |
| 891 // be recreated. | 891 // be recreated. |
| 892 if (sourceFactory is SourceFactoryImpl) { | 892 if (sourceFactory is SourceFactoryImpl) { |
| 893 if (!sourceFactory.resolvers | 893 if (!sourceFactory.resolvers |
| 894 .any((UriResolver r) => r is EmbedderUriResolver)) { | 894 .any((UriResolver r) => r is EmbedderUriResolver)) { |
| 895 | |
| 896 // Get all but the dart: Uri resolver. | 895 // Get all but the dart: Uri resolver. |
| 897 List<UriResolver> resolvers = sourceFactory.resolvers | 896 List<UriResolver> resolvers = sourceFactory.resolvers |
| 898 .where((r) => r is! DartUriResolver) | 897 .where((r) => r is! DartUriResolver) |
| 899 .toList(); | 898 .toList(); |
| 900 // Add an embedded URI resolver in its place. | 899 // Add an embedded URI resolver in its place. |
| 901 resolvers.add(new EmbedderUriResolver(embedderYamls)); | 900 resolvers.add(new EmbedderUriResolver(embedderYamls)); |
| 902 | 901 |
| 903 // Set a new source factory. | 902 // Set a new source factory. |
| 904 SourceFactoryImpl newFactory = sourceFactory.clone(); | 903 SourceFactoryImpl newFactory = sourceFactory.clone(); |
| 905 newFactory.resolvers.clear(); | 904 newFactory.resolvers.clear(); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1039 List<String> dependencies = <String>[]; | 1038 List<String> dependencies = <String>[]; |
| 1040 | 1039 |
| 1041 // Next resort to a package uri resolver. | 1040 // Next resort to a package uri resolver. |
| 1042 if (disposition == null) { | 1041 if (disposition == null) { |
| 1043 disposition = | 1042 disposition = |
| 1044 _computeFolderDisposition(folder, dependencies.add, packagespecFile); | 1043 _computeFolderDisposition(folder, dependencies.add, packagespecFile); |
| 1045 } | 1044 } |
| 1046 | 1045 |
| 1047 Map<String, Object> optionMap = readOptions(info.folder); | 1046 Map<String, Object> optionMap = readOptions(info.folder); |
| 1048 AnalysisOptions options = | 1047 AnalysisOptions options = |
| 1049 new AnalysisOptionsImpl.from(callbacks.defaultAnalysisOptions); | 1048 new AnalysisOptionsImpl.from(defaultContextOptions); |
| 1050 applyToAnalysisOptions(options, optionMap); | 1049 applyToAnalysisOptions(options, optionMap); |
| 1051 | 1050 |
| 1052 info.setDependencies(dependencies); | 1051 info.setDependencies(dependencies); |
| 1053 info.context = callbacks.addContext(folder, options, disposition); | 1052 info.context = callbacks.addContext(folder, options, disposition); |
| 1054 info.context.name = folder.path; | 1053 info.context.name = folder.path; |
| 1055 | 1054 |
| 1056 processOptionsForContext(info, optionMap); | 1055 processOptionsForContext(info, optionMap); |
| 1057 | 1056 |
| 1058 return info; | 1057 return info; |
| 1059 } | 1058 } |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1676 ResourceProvider resourceProvider) { | 1675 ResourceProvider resourceProvider) { |
| 1677 if (packages != null) { | 1676 if (packages != null) { |
| 1678 // Construct package map for the SdkExtUriResolver. | 1677 // Construct package map for the SdkExtUriResolver. |
| 1679 Map<String, List<Folder>> packageMap = buildPackageMap(resourceProvider); | 1678 Map<String, List<Folder>> packageMap = buildPackageMap(resourceProvider); |
| 1680 return <UriResolver>[new SdkExtUriResolver(packageMap)]; | 1679 return <UriResolver>[new SdkExtUriResolver(packageMap)]; |
| 1681 } else { | 1680 } else { |
| 1682 return const <UriResolver>[]; | 1681 return const <UriResolver>[]; |
| 1683 } | 1682 } |
| 1684 } | 1683 } |
| 1685 } | 1684 } |
| OLD | NEW |