| 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'; |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 * to the standard URI resolver. | 470 * to the standard URI resolver. |
| 471 */ | 471 */ |
| 472 final ResolverProvider packageResolverProvider; | 472 final ResolverProvider packageResolverProvider; |
| 473 | 473 |
| 474 /** | 474 /** |
| 475 * Provider which is used to determine the mapping from package name to | 475 * Provider which is used to determine the mapping from package name to |
| 476 * package folder. | 476 * package folder. |
| 477 */ | 477 */ |
| 478 final PubPackageMapProvider _packageMapProvider; | 478 final PubPackageMapProvider _packageMapProvider; |
| 479 | 479 |
| 480 /// Provider of analysis options. | |
| 481 AnalysisOptionsProvider analysisOptionsProvider = | |
| 482 new AnalysisOptionsProvider(); | |
| 483 | |
| 484 /** | 480 /** |
| 485 * A list of the globs used to determine which files should be analyzed. | 481 * A list of the globs used to determine which files should be analyzed. |
| 486 */ | 482 */ |
| 487 final List<Glob> analyzedFilesGlobs; | 483 final List<Glob> analyzedFilesGlobs; |
| 488 | 484 |
| 489 /** | 485 /** |
| 490 * The default options used to create new analysis contexts. | 486 * The default options used to create new analysis contexts. |
| 491 */ | 487 */ |
| 492 final AnalysisOptionsImpl defaultContextOptions; | 488 final AnalysisOptionsImpl defaultContextOptions; |
| 493 | 489 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 setIgnorePatternsForContext(info, excludeList); | 674 setIgnorePatternsForContext(info, excludeList); |
| 679 } | 675 } |
| 680 } | 676 } |
| 681 } | 677 } |
| 682 | 678 |
| 683 /** | 679 /** |
| 684 * Return the options from the analysis options file in the given [folder] | 680 * Return the options from the analysis options file in the given [folder] |
| 685 * if exists, or in one of the parent folders, or `null` if no analysis | 681 * if exists, or in one of the parent folders, or `null` if no analysis |
| 686 * options file is found or if the contents of the file are not valid YAML. | 682 * options file is found or if the contents of the file are not valid YAML. |
| 687 */ | 683 */ |
| 688 Map<String, Object> readOptions(Folder folder) { | 684 Map<String, Object> readOptions(Folder folder, Packages packages) { |
| 689 try { | 685 try { |
| 690 return analysisOptionsProvider.getOptions(folder, crawlUp: true); | 686 Map<String, List<Folder>> packageMap = |
| 687 new ContextBuilder(resourceProvider, null, null) |
| 688 .convertPackagesToMap(packages); |
| 689 List<UriResolver> resolvers = <UriResolver>[ |
| 690 new ResourceUriResolver(resourceProvider), |
| 691 new PackageMapUriResolver(resourceProvider, packageMap), |
| 692 ]; |
| 693 SourceFactory sourceFactory = |
| 694 new SourceFactory(resolvers, packages, resourceProvider); |
| 695 return new AnalysisOptionsProvider(sourceFactory) |
| 696 .getOptions(folder, crawlUp: true); |
| 691 } catch (_) { | 697 } catch (_) { |
| 692 // Parse errors are reported by GenerateOptionsErrorsTask. | 698 // Parse errors are reported by GenerateOptionsErrorsTask. |
| 693 } | 699 } |
| 694 return null; | 700 return null; |
| 695 } | 701 } |
| 696 | 702 |
| 697 @override | 703 @override |
| 698 void refresh(List<Resource> roots) { | 704 void refresh(List<Resource> roots) { |
| 699 // Destroy old contexts | 705 // Destroy old contexts |
| 700 List<ContextInfo> contextInfos = rootInfo.descendants.toList(); | 706 List<ContextInfo> contextInfos = rootInfo.descendants.toList(); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 _addSourceFiles(changeSet, child, info); | 915 _addSourceFiles(changeSet, child, info); |
| 910 } | 916 } |
| 911 } | 917 } |
| 912 } | 918 } |
| 913 | 919 |
| 914 void _checkForAnalysisOptionsUpdate( | 920 void _checkForAnalysisOptionsUpdate( |
| 915 String path, ContextInfo info, ChangeType changeType) { | 921 String path, ContextInfo info, ChangeType changeType) { |
| 916 if (AnalysisEngine.isAnalysisOptionsFileName(path, pathContext)) { | 922 if (AnalysisEngine.isAnalysisOptionsFileName(path, pathContext)) { |
| 917 var analysisContext = info.context; | 923 var analysisContext = info.context; |
| 918 if (analysisContext is context.AnalysisContextImpl) { | 924 if (analysisContext is context.AnalysisContextImpl) { |
| 919 Map<String, Object> options = readOptions(info.folder); | 925 Map<String, Object> options = |
| 926 readOptions(info.folder, info.disposition.packages); |
| 920 processOptionsForContext(info, options, | 927 processOptionsForContext(info, options, |
| 921 optionsRemoved: changeType == ChangeType.REMOVE); | 928 optionsRemoved: changeType == ChangeType.REMOVE); |
| 922 analysisContext.sourceFactory = _createSourceFactory( | 929 analysisContext.sourceFactory = _createSourceFactory( |
| 923 analysisContext, analysisContext.analysisOptions, info.folder); | 930 analysisContext, analysisContext.analysisOptions, info.folder); |
| 924 callbacks.applyChangesToContext(info.folder, new ChangeSet()); | 931 callbacks.applyChangesToContext(info.folder, new ChangeSet()); |
| 925 } | 932 } |
| 926 } | 933 } |
| 927 } | 934 } |
| 928 | 935 |
| 929 void _checkForPackagespecUpdate( | 936 void _checkForPackagespecUpdate( |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1062 * [parent] and using [packagespecFile] to resolve package URI's. | 1069 * [parent] and using [packagespecFile] to resolve package URI's. |
| 1063 */ | 1070 */ |
| 1064 ContextInfo _createContext( | 1071 ContextInfo _createContext( |
| 1065 ContextInfo parent, Folder folder, File packagespecFile) { | 1072 ContextInfo parent, Folder folder, File packagespecFile) { |
| 1066 List<String> dependencies = <String>[]; | 1073 List<String> dependencies = <String>[]; |
| 1067 FolderDisposition disposition = | 1074 FolderDisposition disposition = |
| 1068 _computeFolderDisposition(folder, dependencies.add, packagespecFile); | 1075 _computeFolderDisposition(folder, dependencies.add, packagespecFile); |
| 1069 ContextInfo info = new ContextInfo(this, parent, folder, packagespecFile, | 1076 ContextInfo info = new ContextInfo(this, parent, folder, packagespecFile, |
| 1070 normalizedPackageRoots[folder.path], disposition); | 1077 normalizedPackageRoots[folder.path], disposition); |
| 1071 | 1078 |
| 1072 Map<String, Object> optionMap = readOptions(info.folder); | 1079 Map<String, Object> optionMap = |
| 1080 readOptions(info.folder, disposition.packages); |
| 1073 AnalysisOptions options = | 1081 AnalysisOptions options = |
| 1074 new AnalysisOptionsImpl.from(defaultContextOptions); | 1082 new AnalysisOptionsImpl.from(defaultContextOptions); |
| 1075 applyToAnalysisOptions(options, optionMap); | 1083 applyToAnalysisOptions(options, optionMap); |
| 1076 | 1084 |
| 1077 info.setDependencies(dependencies); | 1085 info.setDependencies(dependencies); |
| 1078 if (enableNewAnalysisDriver) { | 1086 if (enableNewAnalysisDriver) { |
| 1079 info.analysisDriver = callbacks.addAnalysisDriver(folder, options); | 1087 info.analysisDriver = callbacks.addAnalysisDriver(folder, options); |
| 1080 } else { | 1088 } else { |
| 1081 info.context = callbacks.addContext(folder, options); | 1089 info.context = callbacks.addContext(folder, options); |
| 1082 _folderMap[folder] = info.context; | 1090 _folderMap[folder] = info.context; |
| (...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1883 } | 1891 } |
| 1884 return _embedderLocator; | 1892 return _embedderLocator; |
| 1885 } | 1893 } |
| 1886 | 1894 |
| 1887 @override | 1895 @override |
| 1888 SdkExtensionFinder getSdkExtensionFinder(ResourceProvider resourceProvider) { | 1896 SdkExtensionFinder getSdkExtensionFinder(ResourceProvider resourceProvider) { |
| 1889 return _sdkExtensionFinder ??= | 1897 return _sdkExtensionFinder ??= |
| 1890 new SdkExtensionFinder(buildPackageMap(resourceProvider)); | 1898 new SdkExtensionFinder(buildPackageMap(resourceProvider)); |
| 1891 } | 1899 } |
| 1892 } | 1900 } |
| OLD | NEW |