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; |
11 | 11 |
12 import 'package:analysis_server/src/analysis_server.dart'; | 12 import 'package:analysis_server/src/analysis_server.dart'; |
13 import 'package:analyzer/file_system/file_system.dart'; | 13 import 'package:analyzer/file_system/file_system.dart'; |
14 import 'package:analyzer/instrumentation/instrumentation.dart'; | 14 import 'package:analyzer/instrumentation/instrumentation.dart'; |
15 import 'package:analyzer/plugin/options.dart'; | 15 import 'package:analyzer/plugin/options.dart'; |
16 import 'package:analyzer/plugin/resolver_provider.dart'; | 16 import 'package:analyzer/plugin/resolver_provider.dart'; |
17 import 'package:analyzer/source/analysis_options_provider.dart'; | 17 import 'package:analyzer/source/analysis_options_provider.dart'; |
18 import 'package:analyzer/source/config.dart'; | 18 import 'package:analyzer/source/config.dart'; |
19 import 'package:analyzer/source/package_map_provider.dart'; | 19 import 'package:analyzer/source/package_map_provider.dart'; |
20 import 'package:analyzer/source/package_map_resolver.dart'; | 20 import 'package:analyzer/source/package_map_resolver.dart'; |
21 import 'package:analyzer/source/path_filter.dart'; | 21 import 'package:analyzer/source/path_filter.dart'; |
22 import 'package:analyzer/source/pub_package_map_provider.dart'; | 22 import 'package:analyzer/source/pub_package_map_provider.dart'; |
23 import 'package:analyzer/source/sdk_ext.dart'; | 23 import 'package:analyzer/source/sdk_ext.dart'; |
24 import 'package:analyzer/src/context/builder.dart'; | 24 import 'package:analyzer/src/context/builder.dart'; |
25 import 'package:analyzer/src/context/context.dart' as context; | 25 import 'package:analyzer/src/context/context.dart' as context; |
26 import 'package:analyzer/src/context/source.dart'; | |
27 import 'package:analyzer/src/dart/sdk/sdk.dart'; | 26 import 'package:analyzer/src/dart/sdk/sdk.dart'; |
28 import 'package:analyzer/src/generated/engine.dart'; | 27 import 'package:analyzer/src/generated/engine.dart'; |
29 import 'package:analyzer/src/generated/java_engine.dart'; | 28 import 'package:analyzer/src/generated/java_engine.dart'; |
30 import 'package:analyzer/src/generated/java_io.dart'; | 29 import 'package:analyzer/src/generated/java_io.dart'; |
31 import 'package:analyzer/src/generated/sdk.dart'; | 30 import 'package:analyzer/src/generated/sdk.dart'; |
32 import 'package:analyzer/src/generated/source.dart'; | 31 import 'package:analyzer/src/generated/source.dart'; |
33 import 'package:analyzer/src/generated/source_io.dart'; | 32 import 'package:analyzer/src/generated/source_io.dart'; |
34 import 'package:analyzer/src/task/options.dart'; | 33 import 'package:analyzer/src/task/options.dart'; |
35 import 'package:analyzer/src/util/absolute_path.dart'; | 34 import 'package:analyzer/src/util/absolute_path.dart'; |
36 import 'package:analyzer/src/util/glob.dart'; | 35 import 'package:analyzer/src/util/glob.dart'; |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 */ | 335 */ |
337 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet); | 336 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet); |
338 | 337 |
339 /** | 338 /** |
340 * Signals that the context manager has started to compute a package map (if | 339 * Signals that the context manager has started to compute a package map (if |
341 * [computing] is `true`) or has finished (if [computing] is `false`). | 340 * [computing] is `true`) or has finished (if [computing] is `false`). |
342 */ | 341 */ |
343 void computingPackageMap(bool computing); | 342 void computingPackageMap(bool computing); |
344 | 343 |
345 /** | 344 /** |
| 345 * Create and return a context builder that can be used to create a context |
| 346 * for the files in the given [folder] when analyzed using the given [options]
. |
| 347 */ |
| 348 ContextBuilder createContextBuilder(Folder folder, AnalysisOptions options); |
| 349 |
| 350 /** |
346 * Called when the context manager changes the folder with which a context is | 351 * Called when the context manager changes the folder with which a context is |
347 * associated. Currently this is mostly FYI, and used only in tests. | 352 * associated. Currently this is mostly FYI, and used only in tests. |
348 */ | 353 */ |
349 void moveContext(Folder from, Folder to); | 354 void moveContext(Folder from, Folder to); |
350 | 355 |
351 /** | 356 /** |
352 * Remove the context associated with the given [folder]. [flushedFiles] is | 357 * Remove the context associated with the given [folder]. [flushedFiles] is |
353 * a list of the files which will be "orphaned" by removing this context | 358 * a list of the files which will be "orphaned" by removing this context |
354 * (they will no longer be analyzed by any context). | 359 * (they will no longer be analyzed by any context). |
355 */ | 360 */ |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 callbacks.applyChangesToContext(info.folder, new ChangeSet()); | 897 callbacks.applyChangesToContext(info.folder, new ChangeSet()); |
893 } | 898 } |
894 } | 899 } |
895 } | 900 } |
896 | 901 |
897 void _checkForPackagespecUpdate( | 902 void _checkForPackagespecUpdate( |
898 String path, ContextInfo info, Folder folder) { | 903 String path, ContextInfo info, Folder folder) { |
899 // Check to see if this is the .packages file for this context and if so, | 904 // Check to see if this is the .packages file for this context and if so, |
900 // update the context's source factory. | 905 // update the context's source factory. |
901 if (absolutePathContext.basename(path) == PACKAGE_SPEC_NAME) { | 906 if (absolutePathContext.basename(path) == PACKAGE_SPEC_NAME) { |
902 File packagespec = resourceProvider.getFile(path); | 907 String contextRoot = info.folder.path; |
903 if (packagespec.exists) { | 908 ContextBuilder builder = |
904 // Locate embedder yamls for this .packages file. | 909 callbacks.createContextBuilder(info.folder, defaultContextOptions); |
905 // If any embedder libs are contributed and this context does not | 910 AnalysisOptions options = |
906 // have an embedded URI resolver, we need to create a new context. | 911 builder.getAnalysisOptions(info.context, contextRoot); |
907 | 912 SourceFactory factory = builder.createSourceFactory(contextRoot, options); |
908 List<int> bytes = packagespec.readAsStringSync().codeUnits; | 913 info.context.analysisOptions = options; |
909 Map<String, Uri> packages = | 914 info.context.sourceFactory = factory; |
910 pkgfile.parse(bytes, new Uri.file(packagespec.path)); | |
911 | |
912 Map<String, List<Folder>> packageMap = | |
913 new PackagesFileDisposition(new MapPackages(packages)) | |
914 .buildPackageMap(resourceProvider); | |
915 Map<Folder, YamlMap> embedderYamls = | |
916 new EmbedderYamlLocator(packageMap).embedderYamls; | |
917 | |
918 SourceFactory sourceFactory = info.context.sourceFactory; | |
919 | |
920 // Check for library embedders. | |
921 if (embedderYamls.values.any(definesEmbeddedLibs)) { | |
922 // If there is no embedded URI resolver, a new source factory needs to | |
923 // be recreated. | |
924 if (sourceFactory is SourceFactoryImpl) { | |
925 // Get all but the dart: Uri resolver. | |
926 List<UriResolver> resolvers = sourceFactory.resolvers | |
927 .where((r) => r is! DartUriResolver) | |
928 .toList(); | |
929 // Add an embedded URI resolver in its place. | |
930 resolvers.add(new DartUriResolver( | |
931 new EmbedderSdk(resourceProvider, embedderYamls))); | |
932 | |
933 // Set a new source factory. | |
934 SourceFactoryImpl newFactory = sourceFactory.clone(); | |
935 newFactory.resolvers.clear(); | |
936 newFactory.resolvers.addAll(resolvers); | |
937 info.context.sourceFactory = newFactory; | |
938 return; | |
939 } | |
940 } | |
941 | |
942 // Next check for package URI updates. | |
943 if (info.isPathToPackageDescription(path)) { | |
944 Packages packages = _readPackagespec(packagespec); | |
945 if (packages != null) { | |
946 _updateContextPackageUriResolver( | |
947 folder, new PackagesFileDisposition(packages)); | |
948 } | |
949 } | |
950 } | |
951 } | 915 } |
952 } | 916 } |
953 | 917 |
954 /** | 918 /** |
955 * Compute the set of files that are being flushed, this is defined as | 919 * Compute the set of files that are being flushed, this is defined as |
956 * the set of sources in the removed context (context.sources), that are | 920 * the set of sources in the removed context (context.sources), that are |
957 * orphaned by this context being removed (no other context includes this | 921 * orphaned by this context being removed (no other context includes this |
958 * file.) | 922 * file.) |
959 */ | 923 */ |
960 List<String> _computeFlushedFiles(ContextInfo info) { | 924 List<String> _computeFlushedFiles(ContextInfo info) { |
(...skipping 929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1890 } | 1854 } |
1891 return _embedderLocator; | 1855 return _embedderLocator; |
1892 } | 1856 } |
1893 | 1857 |
1894 @override | 1858 @override |
1895 SdkExtensionFinder getSdkExtensionFinder(ResourceProvider resourceProvider) { | 1859 SdkExtensionFinder getSdkExtensionFinder(ResourceProvider resourceProvider) { |
1896 return _sdkExtensionFinder ??= | 1860 return _sdkExtensionFinder ??= |
1897 new SdkExtensionFinder(buildPackageMap(resourceProvider)); | 1861 new SdkExtensionFinder(buildPackageMap(resourceProvider)); |
1898 } | 1862 } |
1899 } | 1863 } |
OLD | NEW |