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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 * created, destroyed or updated, (b) inform the client when "pub list" | 299 * created, destroyed or updated, (b) inform the client when "pub list" |
300 * operations are in progress, and (c) determine which files should be | 300 * operations are in progress, and (c) determine which files should be |
301 * analyzed. | 301 * analyzed. |
302 * | 302 * |
303 * TODO(paulberry): eliminate this interface, and instead have [ContextManager] | 303 * TODO(paulberry): eliminate this interface, and instead have [ContextManager] |
304 * operations return data structures describing how context state should be | 304 * operations return data structures describing how context state should be |
305 * modified. | 305 * modified. |
306 */ | 306 */ |
307 abstract class ContextManagerCallbacks { | 307 abstract class ContextManagerCallbacks { |
308 /** | 308 /** |
309 * Create and return a new analysis context, allowing [disposition] to govern | 309 * Return the default analysis options to be used when creating an analysis |
310 * details of how the context is to be created. | 310 * context. |
311 */ | 311 */ |
312 AnalysisContext addContext(Folder folder, FolderDisposition disposition); | 312 AnalysisOptions get defaultAnalysisOptions; |
| 313 |
| 314 /** |
| 315 * Create and return a new analysis context rooted at the given [folder], with |
| 316 * the given analysis [options], allowing [disposition] to govern details of |
| 317 * how the context is to be created. |
| 318 */ |
| 319 AnalysisContext addContext( |
| 320 Folder folder, AnalysisOptions options, FolderDisposition disposition); |
313 | 321 |
314 /** | 322 /** |
315 * Called when the set of files associated with a context have changed (or | 323 * Called when the set of files associated with a context have changed (or |
316 * some of those files have been modified). [changeSet] is the set of | 324 * some of those files have been modified). [changeSet] is the set of |
317 * changes that need to be applied to the context. | 325 * changes that need to be applied to the context. |
318 */ | 326 */ |
319 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet); | 327 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet); |
320 | 328 |
321 /** | 329 /** |
322 * Called when the ContextManager is about to start computing the package | 330 * Called when the ContextManager is about to start computing the package |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 return true; | 550 return true; |
543 } | 551 } |
544 } | 552 } |
545 // no | 553 // no |
546 return false; | 554 return false; |
547 } | 555 } |
548 | 556 |
549 /** | 557 /** |
550 * Process [options] for the given context [info]. | 558 * Process [options] for the given context [info]. |
551 */ | 559 */ |
552 void processOptionsForContext(ContextInfo info, Folder folder, | 560 void processOptionsForContext(ContextInfo info, Map<String, Object> options, |
553 {bool optionsRemoved: false}) { | 561 {bool optionsRemoved: false}) { |
554 Map<String, Object> options; | |
555 try { | |
556 options = analysisOptionsProvider.getOptions(folder); | |
557 } catch (_) { | |
558 // Parse errors are reported by GenerateOptionsErrorsTask. | |
559 } | |
560 | |
561 if (options == null && !optionsRemoved) { | 562 if (options == null && !optionsRemoved) { |
562 return; | 563 return; |
563 } | 564 } |
564 | 565 |
565 // In case options files are removed, revert to defaults. | 566 // In case options files are removed, revert to defaults. |
566 if (optionsRemoved) { | 567 if (optionsRemoved) { |
567 // Start with defaults. | 568 // Start with defaults. |
568 info.context.analysisOptions = new AnalysisOptionsImpl(); | 569 info.context.analysisOptions = new AnalysisOptionsImpl(); |
569 | 570 |
570 // Apply inherited options. | 571 // Apply inherited options. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 return; | 606 return; |
606 } | 607 } |
607 | 608 |
608 // Set ignore patterns. | 609 // Set ignore patterns. |
609 YamlList exclude = analyzer[AnalyzerOptions.exclude]; | 610 YamlList exclude = analyzer[AnalyzerOptions.exclude]; |
610 if (exclude != null) { | 611 if (exclude != null) { |
611 setIgnorePatternsForContext(info, exclude); | 612 setIgnorePatternsForContext(info, exclude); |
612 } | 613 } |
613 } | 614 } |
614 | 615 |
| 616 /** |
| 617 * Return the options from the analysis options file in the given [folder], or |
| 618 * `null` if there is no file in the folder or if the contents of the file are |
| 619 * not valid YAML. |
| 620 */ |
| 621 Map<String, Object> readOptions(Folder folder) { |
| 622 try { |
| 623 return analysisOptionsProvider.getOptions(folder); |
| 624 } catch (_) { |
| 625 // Parse errors are reported by GenerateOptionsErrorsTask. |
| 626 } |
| 627 return null; |
| 628 } |
| 629 |
615 @override | 630 @override |
616 void refresh(List<Resource> roots) { | 631 void refresh(List<Resource> roots) { |
617 // Destroy old contexts | 632 // Destroy old contexts |
618 List<ContextInfo> contextInfos = rootInfo.descendants.toList(); | 633 List<ContextInfo> contextInfos = rootInfo.descendants.toList(); |
619 if (roots == null) { | 634 if (roots == null) { |
620 contextInfos.forEach(_destroyContext); | 635 contextInfos.forEach(_destroyContext); |
621 } else { | 636 } else { |
622 roots.forEach((Resource resource) { | 637 roots.forEach((Resource resource) { |
623 contextInfos.forEach((ContextInfo contextInfo) { | 638 contextInfos.forEach((ContextInfo contextInfo) { |
624 if (resource is Folder && | 639 if (resource is Folder && |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 _addSourceFiles(changeSet, child, info); | 842 _addSourceFiles(changeSet, child, info); |
828 } | 843 } |
829 } | 844 } |
830 } | 845 } |
831 | 846 |
832 void _checkForAnalysisOptionsUpdate( | 847 void _checkForAnalysisOptionsUpdate( |
833 String path, ContextInfo info, ChangeType changeType) { | 848 String path, ContextInfo info, ChangeType changeType) { |
834 if (AnalysisEngine.isAnalysisOptionsFileName(path, pathContext)) { | 849 if (AnalysisEngine.isAnalysisOptionsFileName(path, pathContext)) { |
835 var analysisContext = info.context; | 850 var analysisContext = info.context; |
836 if (analysisContext is context.AnalysisContextImpl) { | 851 if (analysisContext is context.AnalysisContextImpl) { |
837 processOptionsForContext(info, info.folder, | 852 // TODO(brianwilkerson) This doesn't correctly update the source factory |
| 853 // if the changes necessitate it (such as by changing the setting of the |
| 854 // strong-mode option). |
| 855 Map<String, Object> options = readOptions(info.folder); |
| 856 processOptionsForContext(info, options, |
838 optionsRemoved: changeType == ChangeType.REMOVE); | 857 optionsRemoved: changeType == ChangeType.REMOVE); |
839 analysisContext.invalidateCachedResults(); | 858 analysisContext.invalidateCachedResults(); |
840 callbacks.applyChangesToContext(info.folder, new ChangeSet()); | 859 callbacks.applyChangesToContext(info.folder, new ChangeSet()); |
841 } | 860 } |
842 } | 861 } |
843 } | 862 } |
844 | 863 |
845 void _checkForPackagespecUpdate( | 864 void _checkForPackagespecUpdate( |
846 String path, ContextInfo info, Folder folder) { | 865 String path, ContextInfo info, Folder folder) { |
847 // Check to see if this is the .packages file for this context and if so, | 866 // Check to see if this is the .packages file for this context and if so, |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 | 987 |
969 FolderDisposition disposition; | 988 FolderDisposition disposition; |
970 List<String> dependencies = <String>[]; | 989 List<String> dependencies = <String>[]; |
971 | 990 |
972 // Next resort to a package uri resolver. | 991 // Next resort to a package uri resolver. |
973 if (disposition == null) { | 992 if (disposition == null) { |
974 disposition = | 993 disposition = |
975 _computeFolderDisposition(folder, dependencies.add, packagespecFile); | 994 _computeFolderDisposition(folder, dependencies.add, packagespecFile); |
976 } | 995 } |
977 | 996 |
| 997 Map<String, Object> optionMap = readOptions(info.folder); |
| 998 AnalysisOptions options = |
| 999 new AnalysisOptionsImpl.from(callbacks.defaultAnalysisOptions); |
| 1000 applyToAnalysisOptions(options, optionMap); |
| 1001 |
978 info.setDependencies(dependencies); | 1002 info.setDependencies(dependencies); |
979 info.context = callbacks.addContext(folder, disposition); | 1003 info.context = callbacks.addContext(folder, options, disposition); |
980 info.context.name = folder.path; | 1004 info.context.name = folder.path; |
981 | 1005 |
982 processOptionsForContext(info, folder); | 1006 processOptionsForContext(info, optionMap); |
983 | 1007 |
984 return info; | 1008 return info; |
985 } | 1009 } |
986 | 1010 |
987 /** | 1011 /** |
988 * Potentially create a new context associated with the given [folder]. | 1012 * Potentially create a new context associated with the given [folder]. |
989 * | 1013 * |
990 * If there are subfolders with 'pubspec.yaml' files, separate contexts are | 1014 * If there are subfolders with 'pubspec.yaml' files, separate contexts are |
991 * created for them and excluded from the context associated with the | 1015 * created for them and excluded from the context associated with the |
992 * [folder]. | 1016 * [folder]. |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1602 ResourceProvider resourceProvider) { | 1626 ResourceProvider resourceProvider) { |
1603 if (packages != null) { | 1627 if (packages != null) { |
1604 // Construct package map for the SdkExtUriResolver. | 1628 // Construct package map for the SdkExtUriResolver. |
1605 Map<String, List<Folder>> packageMap = buildPackageMap(resourceProvider); | 1629 Map<String, List<Folder>> packageMap = buildPackageMap(resourceProvider); |
1606 return <UriResolver>[new SdkExtUriResolver(packageMap)]; | 1630 return <UriResolver>[new SdkExtUriResolver(packageMap)]; |
1607 } else { | 1631 } else { |
1608 return const <UriResolver>[]; | 1632 return const <UriResolver>[]; |
1609 } | 1633 } |
1610 } | 1634 } |
1611 } | 1635 } |
OLD | NEW |