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'; | 10 import 'dart:core'; |
11 | 11 |
12 import 'package:analysis_server/src/analysis_server.dart'; | 12 import 'package:analysis_server/src/analysis_server.dart'; |
13 import 'package:analyzer/exception/exception.dart'; | 13 import 'package:analyzer/exception/exception.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/plugin/options.dart'; | 16 import 'package:analyzer/plugin/options.dart'; |
17 import 'package:analyzer/plugin/resolver_provider.dart'; | 17 import 'package:analyzer/plugin/resolver_provider.dart'; |
18 import 'package:analyzer/source/analysis_options_provider.dart'; | 18 import 'package:analyzer/source/analysis_options_provider.dart'; |
19 import 'package:analyzer/source/config.dart'; | 19 import 'package:analyzer/source/config.dart'; |
20 import 'package:analyzer/source/package_map_provider.dart'; | 20 import 'package:analyzer/source/package_map_provider.dart'; |
21 import 'package:analyzer/source/package_map_resolver.dart'; | 21 import 'package:analyzer/source/package_map_resolver.dart'; |
22 import 'package:analyzer/source/path_filter.dart'; | 22 import 'package:analyzer/source/path_filter.dart'; |
23 import 'package:analyzer/source/pub_package_map_provider.dart'; | 23 import 'package:analyzer/source/pub_package_map_provider.dart'; |
24 import 'package:analyzer/source/sdk_ext.dart'; | 24 import 'package:analyzer/source/sdk_ext.dart'; |
25 import 'package:analyzer/src/context/builder.dart'; | 25 import 'package:analyzer/src/context/builder.dart'; |
26 import 'package:analyzer/src/context/context.dart' as context; | 26 import 'package:analyzer/src/context/context.dart' as context; |
27 import 'package:analyzer/src/dart/analysis/driver.dart'; | |
27 import 'package:analyzer/src/dart/sdk/sdk.dart'; | 28 import 'package:analyzer/src/dart/sdk/sdk.dart'; |
28 import 'package:analyzer/src/generated/engine.dart'; | 29 import 'package:analyzer/src/generated/engine.dart'; |
29 import 'package:analyzer/src/generated/java_io.dart'; | 30 import 'package:analyzer/src/generated/java_io.dart'; |
30 import 'package:analyzer/src/generated/sdk.dart'; | 31 import 'package:analyzer/src/generated/sdk.dart'; |
31 import 'package:analyzer/src/generated/source.dart'; | 32 import 'package:analyzer/src/generated/source.dart'; |
32 import 'package:analyzer/src/generated/source_io.dart'; | 33 import 'package:analyzer/src/generated/source_io.dart'; |
33 import 'package:analyzer/src/task/options.dart'; | 34 import 'package:analyzer/src/task/options.dart'; |
34 import 'package:analyzer/src/util/absolute_path.dart'; | 35 import 'package:analyzer/src/util/absolute_path.dart'; |
35 import 'package:analyzer/src/util/glob.dart'; | 36 import 'package:analyzer/src/util/glob.dart'; |
36 import 'package:analyzer/src/util/yaml.dart'; | 37 import 'package:analyzer/src/util/yaml.dart'; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 /** | 84 /** |
84 * Paths to files which determine the folder disposition and package map. | 85 * Paths to files which determine the folder disposition and package map. |
85 * | 86 * |
86 * TODO(paulberry): if any of these files are outside of [folder], they won't | 87 * TODO(paulberry): if any of these files are outside of [folder], they won't |
87 * be watched for changes. I believe the use case for watching these files | 88 * be watched for changes. I believe the use case for watching these files |
88 * is no longer relevant. | 89 * is no longer relevant. |
89 */ | 90 */ |
90 Set<String> _dependencies = new Set<String>(); | 91 Set<String> _dependencies = new Set<String>(); |
91 | 92 |
92 /** | 93 /** |
94 * The analysis driver that was created for the [folder]. | |
95 */ | |
96 AnalysisDriver analysisDriver; | |
97 | |
98 /** | |
93 * The analysis context that was created for the [folder]. | 99 * The analysis context that was created for the [folder]. |
94 */ | 100 */ |
95 AnalysisContext context; | 101 AnalysisContext context; |
96 | 102 |
97 /** | 103 /** |
98 * Map from full path to the [Source] object, for each source that has been | 104 * Map from full path to the [Source] object, for each source that has been |
99 * added to the context. | 105 * added to the context. |
100 */ | 106 */ |
101 Map<String, Source> sources = new HashMap<String, Source>(); | 107 Map<String, Source> sources = new HashMap<String, Source>(); |
102 | 108 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 * created, destroyed or updated, (b) inform the client when "pub list" | 320 * created, destroyed or updated, (b) inform the client when "pub list" |
315 * operations are in progress, and (c) determine which files should be | 321 * operations are in progress, and (c) determine which files should be |
316 * analyzed. | 322 * analyzed. |
317 * | 323 * |
318 * TODO(paulberry): eliminate this interface, and instead have [ContextManager] | 324 * TODO(paulberry): eliminate this interface, and instead have [ContextManager] |
319 * operations return data structures describing how context state should be | 325 * operations return data structures describing how context state should be |
320 * modified. | 326 * modified. |
321 */ | 327 */ |
322 abstract class ContextManagerCallbacks { | 328 abstract class ContextManagerCallbacks { |
323 /** | 329 /** |
330 * Create and return a new analysis driver rooted at the given [folder], with | |
331 * the given analysis [options]. | |
332 */ | |
333 AnalysisDriver addAnalysisDriver(Folder folder, AnalysisOptions options); | |
Brian Wilkerson
2016/10/31 15:42:58
I really want to get rid of ContextManagerCallback
scheglov
2016/10/31 16:54:20
I'm all for removing extra layers.
But in this CL
| |
334 | |
335 /** | |
324 * Create and return a new analysis context rooted at the given [folder], with | 336 * Create and return a new analysis context rooted at the given [folder], with |
325 * the given analysis [options]. | 337 * the given analysis [options]. |
326 */ | 338 */ |
327 AnalysisContext addContext(Folder folder, AnalysisOptions options); | 339 AnalysisContext addContext(Folder folder, AnalysisOptions options); |
328 | 340 |
329 /** | 341 /** |
330 * Called when the set of files associated with a context have changed (or | 342 * Called when the set of files associated with a context have changed (or |
331 * some of those files have been modified). [changeSet] is the set of | 343 * some of those files have been modified). [changeSet] is the set of |
332 * changes that need to be applied to the context. | 344 * changes that need to be applied to the context. |
333 */ | 345 */ |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
472 /** | 484 /** |
473 * The default options used to create new analysis contexts. | 485 * The default options used to create new analysis contexts. |
474 */ | 486 */ |
475 final AnalysisOptionsImpl defaultContextOptions; | 487 final AnalysisOptionsImpl defaultContextOptions; |
476 | 488 |
477 /** | 489 /** |
478 * The instrumentation service used to report instrumentation data. | 490 * The instrumentation service used to report instrumentation data. |
479 */ | 491 */ |
480 final InstrumentationService _instrumentationService; | 492 final InstrumentationService _instrumentationService; |
481 | 493 |
494 final bool enableNewAnalysisDriver; | |
495 | |
482 @override | 496 @override |
483 ContextManagerCallbacks callbacks; | 497 ContextManagerCallbacks callbacks; |
484 | 498 |
485 /** | 499 /** |
486 * Virtual [ContextInfo] which acts as the ancestor of all other | 500 * Virtual [ContextInfo] which acts as the ancestor of all other |
487 * [ContextInfo]s. | 501 * [ContextInfo]s. |
488 */ | 502 */ |
489 final ContextInfo rootInfo = new ContextInfo._root(); | 503 final ContextInfo rootInfo = new ContextInfo._root(); |
490 | 504 |
491 /** | 505 /** |
492 * A table mapping [Folder]s to the [AnalysisContext]s associated with them. | 506 * A table mapping [Folder]s to the [AnalysisContext]s associated with them. |
493 */ | 507 */ |
494 @override | 508 final Map<Folder, AnalysisContext> _folderMap = |
495 final Map<Folder, AnalysisContext> folderMap = | |
496 new HashMap<Folder, AnalysisContext>(); | 509 new HashMap<Folder, AnalysisContext>(); |
497 | 510 |
498 /** | 511 /** |
499 * Stream subscription we are using to watch each analysis root directory for | 512 * Stream subscription we are using to watch each analysis root directory for |
500 * changes. | 513 * changes. |
501 */ | 514 */ |
502 final Map<Folder, StreamSubscription<WatchEvent>> changeSubscriptions = | 515 final Map<Folder, StreamSubscription<WatchEvent>> changeSubscriptions = |
503 <Folder, StreamSubscription<WatchEvent>>{}; | 516 <Folder, StreamSubscription<WatchEvent>>{}; |
504 | 517 |
505 ContextManagerImpl( | 518 ContextManagerImpl( |
506 this.resourceProvider, | 519 this.resourceProvider, |
507 this.sdkManager, | 520 this.sdkManager, |
508 this.packageResolverProvider, | 521 this.packageResolverProvider, |
509 this._packageMapProvider, | 522 this._packageMapProvider, |
510 this.analyzedFilesGlobs, | 523 this.analyzedFilesGlobs, |
511 this._instrumentationService, | 524 this._instrumentationService, |
512 this.defaultContextOptions) { | 525 this.defaultContextOptions, |
526 this.enableNewAnalysisDriver) { | |
513 absolutePathContext = resourceProvider.absolutePathContext; | 527 absolutePathContext = resourceProvider.absolutePathContext; |
514 pathContext = resourceProvider.pathContext; | 528 pathContext = resourceProvider.pathContext; |
515 } | 529 } |
516 | 530 |
517 @override | 531 @override |
518 Iterable<AnalysisContext> get analysisContexts => folderMap.values; | 532 Iterable<AnalysisContext> get analysisContexts => folderMap.values; |
519 | 533 |
534 Map<Folder, AnalysisContext> get folderMap { | |
535 if (enableNewAnalysisDriver) { | |
536 throw new StateError('Should not be used with the new analysis driver'); | |
537 } else { | |
538 return _folderMap; | |
539 } | |
540 } | |
541 | |
520 @override | 542 @override |
521 List<AnalysisContext> contextsInAnalysisRoot(Folder analysisRoot) { | 543 List<AnalysisContext> contextsInAnalysisRoot(Folder analysisRoot) { |
522 List<AnalysisContext> contexts = <AnalysisContext>[]; | 544 List<AnalysisContext> contexts = <AnalysisContext>[]; |
523 ContextInfo innermostContainingInfo = | 545 ContextInfo innermostContainingInfo = |
524 _getInnermostContextInfoFor(analysisRoot.path); | 546 _getInnermostContextInfoFor(analysisRoot.path); |
525 void addContextAndDescendants(ContextInfo info) { | 547 void addContextAndDescendants(ContextInfo info) { |
526 contexts.add(info.context); | 548 contexts.add(info.context); |
527 info.children.forEach(addContextAndDescendants); | 549 info.children.forEach(addContextAndDescendants); |
528 } | 550 } |
529 | 551 |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1026 _computeFolderDisposition(folder, dependencies.add, packagespecFile); | 1048 _computeFolderDisposition(folder, dependencies.add, packagespecFile); |
1027 ContextInfo info = new ContextInfo(this, parent, folder, packagespecFile, | 1049 ContextInfo info = new ContextInfo(this, parent, folder, packagespecFile, |
1028 normalizedPackageRoots[folder.path], disposition); | 1050 normalizedPackageRoots[folder.path], disposition); |
1029 | 1051 |
1030 Map<String, Object> optionMap = readOptions(info.folder); | 1052 Map<String, Object> optionMap = readOptions(info.folder); |
1031 AnalysisOptions options = | 1053 AnalysisOptions options = |
1032 new AnalysisOptionsImpl.from(defaultContextOptions); | 1054 new AnalysisOptionsImpl.from(defaultContextOptions); |
1033 applyToAnalysisOptions(options, optionMap); | 1055 applyToAnalysisOptions(options, optionMap); |
1034 | 1056 |
1035 info.setDependencies(dependencies); | 1057 info.setDependencies(dependencies); |
1036 info.context = callbacks.addContext(folder, options); | 1058 if (enableNewAnalysisDriver) { |
1037 folderMap[folder] = info.context; | 1059 info.analysisDriver = callbacks.addAnalysisDriver(folder, options); |
1038 info.context.name = folder.path; | 1060 } else { |
1061 info.context = callbacks.addContext(folder, options); | |
1062 _folderMap[folder] = info.context; | |
1063 info.context.name = folder.path; | |
1064 } | |
1039 | 1065 |
1040 // Look for pubspec-specified analysis configuration. | 1066 // Look for pubspec-specified analysis configuration. |
1041 File pubspec; | 1067 File pubspec; |
1042 if (packagespecFile?.exists == true) { | 1068 if (packagespecFile?.exists == true) { |
1043 if (packagespecFile.shortName == PUBSPEC_NAME) { | 1069 if (packagespecFile.shortName == PUBSPEC_NAME) { |
1044 pubspec = packagespecFile; | 1070 pubspec = packagespecFile; |
1045 } | 1071 } |
1046 } | 1072 } |
1047 if (pubspec == null) { | 1073 if (pubspec == null) { |
1048 Resource child = folder.getChild(PUBSPEC_NAME); | 1074 Resource child = folder.getChild(PUBSPEC_NAME); |
1049 if (child.exists && child is File) { | 1075 if (child.exists && child is File) { |
1050 pubspec = child; | 1076 pubspec = child; |
1051 } | 1077 } |
1052 } | 1078 } |
1053 if (pubspec != null) { | 1079 if (pubspec != null) { |
1054 File pubSource = resourceProvider.getFile(pubspec.path); | 1080 File pubSource = resourceProvider.getFile(pubspec.path); |
1055 setConfiguration( | 1081 if (enableNewAnalysisDriver) { |
1056 info.context, | 1082 // TODO(scheglov) implement for the new analysis driver |
1057 new AnalysisConfiguration.fromPubspec( | 1083 } else { |
1058 pubSource, resourceProvider, disposition.packages)); | 1084 setConfiguration( |
1085 info.context, | |
1086 new AnalysisConfiguration.fromPubspec( | |
1087 pubSource, resourceProvider, disposition.packages)); | |
1088 } | |
1059 } | 1089 } |
1060 | 1090 |
1061 processOptionsForContext(info, optionMap); | 1091 if (enableNewAnalysisDriver) { |
1092 // TODO(scheglov) implement for the new analysis driver | |
1093 } else { | |
1094 processOptionsForContext(info, optionMap); | |
1095 } | |
1062 | 1096 |
1063 return info; | 1097 return info; |
1064 } | 1098 } |
1065 | 1099 |
1066 /** | 1100 /** |
1067 * Potentially create a new context associated with the given [folder]. | 1101 * Potentially create a new context associated with the given [folder]. |
1068 * | 1102 * |
1069 * If there are subfolders with 'pubspec.yaml' files, separate contexts are | 1103 * If there are subfolders with 'pubspec.yaml' files, separate contexts are |
1070 * created for them and excluded from the context associated with the | 1104 * created for them and excluded from the context associated with the |
1071 * [folder]. | 1105 * [folder]. |
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1815 } | 1849 } |
1816 return _embedderLocator; | 1850 return _embedderLocator; |
1817 } | 1851 } |
1818 | 1852 |
1819 @override | 1853 @override |
1820 SdkExtensionFinder getSdkExtensionFinder(ResourceProvider resourceProvider) { | 1854 SdkExtensionFinder getSdkExtensionFinder(ResourceProvider resourceProvider) { |
1821 return _sdkExtensionFinder ??= | 1855 return _sdkExtensionFinder ??= |
1822 new SdkExtensionFinder(buildPackageMap(resourceProvider)); | 1856 new SdkExtensionFinder(buildPackageMap(resourceProvider)); |
1823 } | 1857 } |
1824 } | 1858 } |
OLD | NEW |