| 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/embedded_resolver_provider.dart'; | 15 import 'package:analyzer/plugin/embedded_resolver_provider.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/embedder.dart'; | 19 import 'package:analyzer/source/embedder.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/context.dart' as context; | 25 import 'package:analyzer/src/context/context.dart' as context; |
| 26 import 'package:analyzer/src/context/source.dart'; |
| 26 import 'package:analyzer/src/generated/engine.dart'; | 27 import 'package:analyzer/src/generated/engine.dart'; |
| 27 import 'package:analyzer/src/generated/java_engine.dart'; | 28 import 'package:analyzer/src/generated/java_engine.dart'; |
| 28 import 'package:analyzer/src/generated/java_io.dart'; | 29 import 'package:analyzer/src/generated/java_io.dart'; |
| 29 import 'package:analyzer/src/generated/source.dart'; | 30 import 'package:analyzer/src/generated/source.dart'; |
| 30 import 'package:analyzer/src/generated/source_io.dart'; | 31 import 'package:analyzer/src/generated/source_io.dart'; |
| 31 import 'package:analyzer/src/task/options.dart'; | 32 import 'package:analyzer/src/task/options.dart'; |
| 32 import 'package:analyzer/src/util/absolute_path.dart'; | 33 import 'package:analyzer/src/util/absolute_path.dart'; |
| 33 import 'package:analyzer/src/util/yaml.dart'; | 34 import 'package:analyzer/src/util/yaml.dart'; |
| 34 import 'package:package_config/packages.dart'; | 35 import 'package:package_config/packages.dart'; |
| 35 import 'package:package_config/packages_file.dart' as pkgfile show parse; | 36 import 'package:package_config/packages_file.dart' as pkgfile show parse; |
| (...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 analysisContext.invalidateCachedResults(); | 840 analysisContext.invalidateCachedResults(); |
| 840 callbacks.applyChangesToContext(info.folder, new ChangeSet()); | 841 callbacks.applyChangesToContext(info.folder, new ChangeSet()); |
| 841 } | 842 } |
| 842 } | 843 } |
| 843 } | 844 } |
| 844 | 845 |
| 845 void _checkForPackagespecUpdate( | 846 void _checkForPackagespecUpdate( |
| 846 String path, ContextInfo info, Folder folder) { | 847 String path, ContextInfo info, Folder folder) { |
| 847 // Check to see if this is the .packages file for this context and if so, | 848 // Check to see if this is the .packages file for this context and if so, |
| 848 // update the context's source factory. | 849 // update the context's source factory. |
| 849 if (absolutePathContext.basename(path) == PACKAGE_SPEC_NAME && | 850 if (absolutePathContext.basename(path) == PACKAGE_SPEC_NAME) { |
| 850 info.isPathToPackageDescription(path)) { | |
| 851 File packagespec = resourceProvider.getFile(path); | 851 File packagespec = resourceProvider.getFile(path); |
| 852 if (packagespec.exists) { | 852 if (packagespec.exists) { |
| 853 Packages packages = _readPackagespec(packagespec); | 853 // Locate embedder yamls for this .packages file. |
| 854 if (packages != null) { | 854 // If any embedder libs are contributed and this context does not |
| 855 callbacks.updateContextPackageUriResolver( | 855 // have an embedded URI resolver, we need to create a new context. |
| 856 folder, new PackagesFileDisposition(packages)); | 856 |
| 857 List<int> bytes = packagespec.readAsStringSync().codeUnits; |
| 858 Map<String, Uri> packages = |
| 859 pkgfile.parse(bytes, new Uri.file(packagespec.path)); |
| 860 |
| 861 Map<String, List<Folder>> packageMap = |
| 862 new PackagesFileDisposition(new MapPackages(packages)) |
| 863 .buildPackageMap(resourceProvider); |
| 864 Map<Folder, YamlMap> embedderYamls = |
| 865 new EmbedderYamlLocator(packageMap).embedderYamls; |
| 866 |
| 867 SourceFactory sourceFactory = info.context.sourceFactory; |
| 868 |
| 869 // Check for library embedders. |
| 870 if (embedderYamls.values.any(definesEmbeddedLibs)) { |
| 871 // If there is no embedded URI resolver, a new source factory needs to |
| 872 // be recreated. |
| 873 if (sourceFactory is SourceFactoryImpl) { |
| 874 if (!sourceFactory.resolvers |
| 875 .any((UriResolver r) => r is EmbedderUriResolver)) { |
| 876 |
| 877 // Get all but the dart: Uri resolver. |
| 878 List<UriResolver> resolvers = sourceFactory.resolvers |
| 879 .where((r) => r is! DartUriResolver) |
| 880 .toList(); |
| 881 // Add an embedded URI resolver in its place. |
| 882 resolvers.add(new EmbedderUriResolver(embedderYamls)); |
| 883 |
| 884 // Set a new source factory. |
| 885 SourceFactoryImpl newFactory = sourceFactory.clone(); |
| 886 newFactory.resolvers.clear(); |
| 887 newFactory.resolvers.addAll(resolvers); |
| 888 info.context.sourceFactory = newFactory; |
| 889 return; |
| 890 } |
| 891 } |
| 892 } |
| 893 |
| 894 // Next check for package URI updates. |
| 895 if (info.isPathToPackageDescription(path)) { |
| 896 Packages packages = _readPackagespec(packagespec); |
| 897 if (packages != null) { |
| 898 callbacks.updateContextPackageUriResolver( |
| 899 folder, new PackagesFileDisposition(packages)); |
| 900 } |
| 857 } | 901 } |
| 858 } | 902 } |
| 859 } | 903 } |
| 860 } | 904 } |
| 861 | 905 |
| 862 /** | 906 /** |
| 863 * Compute the set of files that are being flushed, this is defined as | 907 * Compute the set of files that are being flushed, this is defined as |
| 864 * the set of sources in the removed context (context.sources), that are | 908 * the set of sources in the removed context (context.sources), that are |
| 865 * orphaned by this context being removed (no other context includes this | 909 * orphaned by this context being removed (no other context includes this |
| 866 * file.) | 910 * file.) |
| (...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1602 ResourceProvider resourceProvider) { | 1646 ResourceProvider resourceProvider) { |
| 1603 if (packages != null) { | 1647 if (packages != null) { |
| 1604 // Construct package map for the SdkExtUriResolver. | 1648 // Construct package map for the SdkExtUriResolver. |
| 1605 Map<String, List<Folder>> packageMap = buildPackageMap(resourceProvider); | 1649 Map<String, List<Folder>> packageMap = buildPackageMap(resourceProvider); |
| 1606 return <UriResolver>[new SdkExtUriResolver(packageMap)]; | 1650 return <UriResolver>[new SdkExtUriResolver(packageMap)]; |
| 1607 } else { | 1651 } else { |
| 1608 return const <UriResolver>[]; | 1652 return const <UriResolver>[]; |
| 1609 } | 1653 } |
| 1610 } | 1654 } |
| 1611 } | 1655 } |
| OLD | NEW |