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'; | |
14 import 'package:analyzer/file_system/file_system.dart'; | 13 import 'package:analyzer/file_system/file_system.dart'; |
15 import 'package:analyzer/instrumentation/instrumentation.dart'; | 14 import 'package:analyzer/instrumentation/instrumentation.dart'; |
16 import 'package:analyzer/plugin/options.dart'; | |
17 import 'package:analyzer/plugin/resolver_provider.dart'; | 15 import 'package:analyzer/plugin/resolver_provider.dart'; |
18 import 'package:analyzer/source/analysis_options_provider.dart'; | 16 import 'package:analyzer/source/analysis_options_provider.dart'; |
19 import 'package:analyzer/source/package_map_provider.dart'; | 17 import 'package:analyzer/source/package_map_provider.dart'; |
20 import 'package:analyzer/source/package_map_resolver.dart'; | 18 import 'package:analyzer/source/package_map_resolver.dart'; |
21 import 'package:analyzer/source/path_filter.dart'; | 19 import 'package:analyzer/source/path_filter.dart'; |
22 import 'package:analyzer/source/pub_package_map_provider.dart'; | 20 import 'package:analyzer/source/pub_package_map_provider.dart'; |
23 import 'package:analyzer/source/sdk_ext.dart'; | 21 import 'package:analyzer/source/sdk_ext.dart'; |
24 import 'package:analyzer/src/context/builder.dart'; | 22 import 'package:analyzer/src/context/builder.dart'; |
25 import 'package:analyzer/src/context/context.dart' as context; | 23 import 'package:analyzer/src/context/context.dart' as context; |
26 import 'package:analyzer/src/dart/analysis/driver.dart'; | 24 import 'package:analyzer/src/dart/analysis/driver.dart'; |
27 import 'package:analyzer/src/dart/sdk/sdk.dart'; | 25 import 'package:analyzer/src/dart/sdk/sdk.dart'; |
28 import 'package:analyzer/src/generated/engine.dart'; | 26 import 'package:analyzer/src/generated/engine.dart'; |
29 import 'package:analyzer/src/generated/java_io.dart'; | 27 import 'package:analyzer/src/generated/java_io.dart'; |
30 import 'package:analyzer/src/generated/sdk.dart'; | 28 import 'package:analyzer/src/generated/sdk.dart'; |
31 import 'package:analyzer/src/generated/source.dart'; | 29 import 'package:analyzer/src/generated/source.dart'; |
32 import 'package:analyzer/src/generated/source_io.dart'; | 30 import 'package:analyzer/src/generated/source_io.dart'; |
33 import 'package:analyzer/src/lint/config.dart'; | |
34 import 'package:analyzer/src/lint/linter.dart'; | |
35 import 'package:analyzer/src/lint/registry.dart'; | |
36 import 'package:analyzer/src/task/options.dart'; | 31 import 'package:analyzer/src/task/options.dart'; |
37 import 'package:analyzer/src/util/absolute_path.dart'; | 32 import 'package:analyzer/src/util/absolute_path.dart'; |
38 import 'package:analyzer/src/util/glob.dart'; | 33 import 'package:analyzer/src/util/glob.dart'; |
39 import 'package:analyzer/src/util/yaml.dart'; | 34 import 'package:analyzer/src/util/yaml.dart'; |
40 import 'package:package_config/packages.dart'; | 35 import 'package:package_config/packages.dart'; |
41 import 'package:package_config/packages_file.dart' as pkgfile show parse; | 36 import 'package:package_config/packages_file.dart' as pkgfile show parse; |
42 import 'package:package_config/src/packages_impl.dart' show MapPackages; | 37 import 'package:package_config/src/packages_impl.dart' show MapPackages; |
43 import 'package:path/path.dart' as pathos; | 38 import 'package:path/path.dart' as pathos; |
44 import 'package:watcher/watcher.dart'; | 39 import 'package:watcher/watcher.dart'; |
45 import 'package:yaml/yaml.dart'; | 40 import 'package:yaml/yaml.dart'; |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 */ | 334 */ |
340 AnalysisDriver addAnalysisDriver(Folder folder, AnalysisOptions options); | 335 AnalysisDriver addAnalysisDriver(Folder folder, AnalysisOptions options); |
341 | 336 |
342 /** | 337 /** |
343 * Create and return a new analysis context rooted at the given [folder], with | 338 * Create and return a new analysis context rooted at the given [folder], with |
344 * the given analysis [options]. | 339 * the given analysis [options]. |
345 */ | 340 */ |
346 AnalysisContext addContext(Folder folder, AnalysisOptions options); | 341 AnalysisContext addContext(Folder folder, AnalysisOptions options); |
347 | 342 |
348 /** | 343 /** |
349 * The given [file] was removed from the folder analyzed in the [driver]. | |
350 */ | |
351 void applyFileRemoved(AnalysisDriver driver, String file); | |
352 | |
353 /** | |
354 * Called when the set of files associated with a context have changed (or | 344 * Called when the set of files associated with a context have changed (or |
355 * some of those files have been modified). [changeSet] is the set of | 345 * some of those files have been modified). [changeSet] is the set of |
356 * changes that need to be applied to the context. | 346 * changes that need to be applied to the context. |
357 */ | 347 */ |
358 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet); | 348 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet); |
359 | 349 |
360 /** | 350 /** |
| 351 * The given [file] was removed from the folder analyzed in the [driver]. |
| 352 */ |
| 353 void applyFileRemoved(AnalysisDriver driver, String file); |
| 354 |
| 355 /** |
361 * Signals that the context manager has started to compute a package map (if | 356 * Signals that the context manager has started to compute a package map (if |
362 * [computing] is `true`) or has finished (if [computing] is `false`). | 357 * [computing] is `true`) or has finished (if [computing] is `false`). |
363 */ | 358 */ |
364 void computingPackageMap(bool computing); | 359 void computingPackageMap(bool computing); |
365 | 360 |
366 /** | 361 /** |
367 * Create and return a context builder that can be used to create a context | 362 * Create and return a context builder that can be used to create a context |
368 * for the files in the given [folder] when analyzed using the given [options]
. | 363 * for the files in the given [folder] when analyzed using the given [options]
. |
369 */ | 364 */ |
370 ContextBuilder createContextBuilder(Folder folder, AnalysisOptions options); | 365 ContextBuilder createContextBuilder(Folder folder, AnalysisOptions options); |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 | 623 |
629 /** | 624 /** |
630 * Process [options] for the given context [info]. | 625 * Process [options] for the given context [info]. |
631 */ | 626 */ |
632 void processOptionsForContext(ContextInfo info, Map<String, Object> options, | 627 void processOptionsForContext(ContextInfo info, Map<String, Object> options, |
633 {bool optionsRemoved: false}) { | 628 {bool optionsRemoved: false}) { |
634 if (options == null && !optionsRemoved) { | 629 if (options == null && !optionsRemoved) { |
635 return; | 630 return; |
636 } | 631 } |
637 | 632 |
638 // In case options files are removed, revert to defaults. | 633 AnalysisOptionsImpl analysisOptions; |
639 if (optionsRemoved) { | 634 if (optionsRemoved) { |
640 // Start with defaults. | 635 // In case options files are removed, revert to defaults. |
641 info.context.analysisOptions = new AnalysisOptionsImpl(); | 636 analysisOptions = new AnalysisOptionsImpl.from(defaultContextOptions); |
642 | |
643 // Apply inherited options. | 637 // Apply inherited options. |
644 options = _toStringMap(_getEmbeddedOptions(info)); | 638 options = _toStringMap(_getEmbeddedOptions(info)); |
645 if (options != null) { | |
646 configureContextOptions(info.context, options); | |
647 } | |
648 } else { | 639 } else { |
| 640 analysisOptions = |
| 641 new AnalysisOptionsImpl.from(info.context.analysisOptions); |
649 // Check for embedded options. | 642 // Check for embedded options. |
650 Map embeddedOptions = _getEmbeddedOptions(info); | 643 Map embeddedOptions = _getEmbeddedOptions(info); |
651 if (embeddedOptions != null) { | 644 if (embeddedOptions != null) { |
652 options = _toStringMap(new Merger().merge(embeddedOptions, options)); | 645 options = _toStringMap(new Merger().merge(embeddedOptions, options)); |
653 } | 646 } |
654 } | 647 } |
655 | 648 if (options != null) { |
656 // Notify options processors. | 649 applyToAnalysisOptions(analysisOptions, options); |
657 AnalysisEngine.instance.optionsPlugin.optionsProcessors | 650 } |
658 .forEach((OptionsProcessor p) { | 651 info.context.analysisOptions = analysisOptions; |
659 try { | |
660 p.optionsProcessed(info.context, options); | |
661 } catch (e, stacktrace) { | |
662 AnalysisEngine.instance.logger.logError( | |
663 'Error processing analysis options', | |
664 new CaughtException(e, stacktrace)); | |
665 } | |
666 }); | |
667 | |
668 configureContextOptions(info.context, options); | |
669 | 652 |
670 // Nothing more to do. | 653 // Nothing more to do. |
671 if (options == null) { | 654 if (options == null) { |
672 return; | 655 return; |
673 } | 656 } |
674 | 657 |
675 var analyzer = options[AnalyzerOptions.analyzer]; | 658 var analyzer = options[AnalyzerOptions.analyzer]; |
676 if (analyzer is Map) { | 659 if (analyzer is Map) { |
677 // Set ignore patterns. | 660 // Set ignore patterns. |
678 YamlList exclude = analyzer[AnalyzerOptions.exclude]; | 661 YamlList exclude = analyzer[AnalyzerOptions.exclude]; |
(...skipping 25 matching lines...) Expand all Loading... |
704 applyToAnalysisOptions(analysisOptions, options); | 687 applyToAnalysisOptions(analysisOptions, options); |
705 } | 688 } |
706 } else { | 689 } else { |
707 // Check for embedded options. | 690 // Check for embedded options. |
708 Map embeddedOptions = _getEmbeddedOptions(info); | 691 Map embeddedOptions = _getEmbeddedOptions(info); |
709 if (embeddedOptions != null) { | 692 if (embeddedOptions != null) { |
710 options = _toStringMap(new Merger().merge(embeddedOptions, options)); | 693 options = _toStringMap(new Merger().merge(embeddedOptions, options)); |
711 } | 694 } |
712 } | 695 } |
713 | 696 |
714 var lintOptions = options['linter']; | |
715 if (lintOptions != null) { | |
716 LintConfig config = new LintConfig.parseMap(lintOptions); | |
717 Iterable<LintRule> lintRules = Registry.ruleRegistry.enabled(config); | |
718 if (lintRules.isNotEmpty) { | |
719 analysisOptions.lint = true; | |
720 analysisOptions.lintRules = lintRules.toList(); | |
721 } | |
722 } | |
723 | |
724 applyToAnalysisOptions(analysisOptions, options); | 697 applyToAnalysisOptions(analysisOptions, options); |
725 | 698 |
726 // Nothing more to do. | 699 // Nothing more to do. |
727 if (options == null) { | 700 if (options == null) { |
728 return; | 701 return; |
729 } | 702 } |
730 | 703 |
731 var analyzer = options[AnalyzerOptions.analyzer]; | 704 var analyzer = options[AnalyzerOptions.analyzer]; |
732 if (analyzer is Map) { | 705 if (analyzer is Map) { |
733 // Set ignore patterns. | 706 // Set ignore patterns. |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 } | 970 } |
998 | 971 |
999 void _checkForPackagespecUpdate( | 972 void _checkForPackagespecUpdate( |
1000 String path, ContextInfo info, Folder folder) { | 973 String path, ContextInfo info, Folder folder) { |
1001 // Check to see if this is the .packages file for this context and if so, | 974 // Check to see if this is the .packages file for this context and if so, |
1002 // update the context's source factory. | 975 // update the context's source factory. |
1003 if (absolutePathContext.basename(path) == PACKAGE_SPEC_NAME) { | 976 if (absolutePathContext.basename(path) == PACKAGE_SPEC_NAME) { |
1004 String contextRoot = info.folder.path; | 977 String contextRoot = info.folder.path; |
1005 ContextBuilder builder = | 978 ContextBuilder builder = |
1006 callbacks.createContextBuilder(info.folder, defaultContextOptions); | 979 callbacks.createContextBuilder(info.folder, defaultContextOptions); |
1007 AnalysisOptions options = | 980 AnalysisOptions options = builder.getAnalysisOptions(contextRoot); |
1008 builder.getAnalysisOptions(info.context, contextRoot); | |
1009 SourceFactory factory = builder.createSourceFactory(contextRoot, options); | 981 SourceFactory factory = builder.createSourceFactory(contextRoot, options); |
1010 info.context.analysisOptions = options; | 982 info.context.analysisOptions = options; |
1011 info.context.sourceFactory = factory; | 983 info.context.sourceFactory = factory; |
1012 } | 984 } |
1013 } | 985 } |
1014 | 986 |
1015 /** | 987 /** |
1016 * Compute the set of files that are being flushed, this is defined as | 988 * Compute the set of files that are being flushed, this is defined as |
1017 * the set of sources in the removed context (context.sources), that are | 989 * the set of sources in the removed context (context.sources), that are |
1018 * orphaned by this context being removed (no other context includes this | 990 * orphaned by this context being removed (no other context includes this |
(...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1931 } | 1903 } |
1932 return _embedderLocator; | 1904 return _embedderLocator; |
1933 } | 1905 } |
1934 | 1906 |
1935 @override | 1907 @override |
1936 SdkExtensionFinder getSdkExtensionFinder(ResourceProvider resourceProvider) { | 1908 SdkExtensionFinder getSdkExtensionFinder(ResourceProvider resourceProvider) { |
1937 return _sdkExtensionFinder ??= | 1909 return _sdkExtensionFinder ??= |
1938 new SdkExtensionFinder(buildPackageMap(resourceProvider)); | 1910 new SdkExtensionFinder(buildPackageMap(resourceProvider)); |
1939 } | 1911 } |
1940 } | 1912 } |
OLD | NEW |