| 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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 */ | 336 */ |
| 337 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet); | 337 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet); |
| 338 | 338 |
| 339 /** | 339 /** |
| 340 * Signals that the context manager has started to compute a package map (if | 340 * Signals that the context manager has started to compute a package map (if |
| 341 * [computing] is `true`) or has finished (if [computing] is `false`). | 341 * [computing] is `true`) or has finished (if [computing] is `false`). |
| 342 */ | 342 */ |
| 343 void computingPackageMap(bool computing); | 343 void computingPackageMap(bool computing); |
| 344 | 344 |
| 345 /** | 345 /** |
| 346 * Create and return a context builder that can be used to create a context |
| 347 * for the files in the given [folder] when analyzed using the given [options]
. |
| 348 */ |
| 349 ContextBuilder createContextBuilder(Folder folder, AnalysisOptions options); |
| 350 |
| 351 /** |
| 346 * Called when the context manager changes the folder with which a context is | 352 * 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. | 353 * associated. Currently this is mostly FYI, and used only in tests. |
| 348 */ | 354 */ |
| 349 void moveContext(Folder from, Folder to); | 355 void moveContext(Folder from, Folder to); |
| 350 | 356 |
| 351 /** | 357 /** |
| 352 * Remove the context associated with the given [folder]. [flushedFiles] is | 358 * Remove the context associated with the given [folder]. [flushedFiles] is |
| 353 * a list of the files which will be "orphaned" by removing this context | 359 * a list of the files which will be "orphaned" by removing this context |
| 354 * (they will no longer be analyzed by any context). | 360 * (they will no longer be analyzed by any context). |
| 355 */ | 361 */ |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 callbacks.applyChangesToContext(info.folder, new ChangeSet()); | 898 callbacks.applyChangesToContext(info.folder, new ChangeSet()); |
| 893 } | 899 } |
| 894 } | 900 } |
| 895 } | 901 } |
| 896 | 902 |
| 897 void _checkForPackagespecUpdate( | 903 void _checkForPackagespecUpdate( |
| 898 String path, ContextInfo info, Folder folder) { | 904 String path, ContextInfo info, Folder folder) { |
| 899 // Check to see if this is the .packages file for this context and if so, | 905 // Check to see if this is the .packages file for this context and if so, |
| 900 // update the context's source factory. | 906 // update the context's source factory. |
| 901 if (absolutePathContext.basename(path) == PACKAGE_SPEC_NAME) { | 907 if (absolutePathContext.basename(path) == PACKAGE_SPEC_NAME) { |
| 902 File packagespec = resourceProvider.getFile(path); | 908 String contextRoot = info.folder.path; |
| 903 if (packagespec.exists) { | 909 ContextBuilder builder = |
| 904 // Locate embedder yamls for this .packages file. | 910 callbacks.createContextBuilder(info.folder, defaultContextOptions); |
| 905 // If any embedder libs are contributed and this context does not | 911 AnalysisOptions options = |
| 906 // have an embedded URI resolver, we need to create a new context. | 912 builder.getAnalysisOptions(info.context, contextRoot); |
| 907 | 913 SourceFactory factory = builder.createSourceFactory(contextRoot, options); |
| 908 List<int> bytes = packagespec.readAsStringSync().codeUnits; | 914 info.context.analysisOptions = options; |
| 909 Map<String, Uri> packages = | 915 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 } | 916 } |
| 952 } | 917 } |
| 953 | 918 |
| 954 /** | 919 /** |
| 955 * Compute the set of files that are being flushed, this is defined as | 920 * 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 | 921 * the set of sources in the removed context (context.sources), that are |
| 957 * orphaned by this context being removed (no other context includes this | 922 * orphaned by this context being removed (no other context includes this |
| 958 * file.) | 923 * file.) |
| 959 */ | 924 */ |
| 960 List<String> _computeFlushedFiles(ContextInfo info) { | 925 List<String> _computeFlushedFiles(ContextInfo info) { |
| (...skipping 929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1890 } | 1855 } |
| 1891 return _embedderLocator; | 1856 return _embedderLocator; |
| 1892 } | 1857 } |
| 1893 | 1858 |
| 1894 @override | 1859 @override |
| 1895 SdkExtensionFinder getSdkExtensionFinder(ResourceProvider resourceProvider) { | 1860 SdkExtensionFinder getSdkExtensionFinder(ResourceProvider resourceProvider) { |
| 1896 return _sdkExtensionFinder ??= | 1861 return _sdkExtensionFinder ??= |
| 1897 new SdkExtensionFinder(buildPackageMap(resourceProvider)); | 1862 new SdkExtensionFinder(buildPackageMap(resourceProvider)); |
| 1898 } | 1863 } |
| 1899 } | 1864 } |
| OLD | NEW |