| 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:analysis_server/src/source/optimizing_pub_package_map_provider.d
art'; | |
| 14 import 'package:analysis_server/uri/resolver_provider.dart'; | 13 import 'package:analysis_server/uri/resolver_provider.dart'; |
| 15 import 'package:analyzer/file_system/file_system.dart'; | 14 import 'package:analyzer/file_system/file_system.dart'; |
| 16 import 'package:analyzer/instrumentation/instrumentation.dart'; | 15 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| 17 import 'package:analyzer/source/analysis_options_provider.dart'; | 16 import 'package:analyzer/source/analysis_options_provider.dart'; |
| 17 import 'package:analyzer/source/package_map_provider.dart'; |
| 18 import 'package:analyzer/source/package_map_resolver.dart'; | 18 import 'package:analyzer/source/package_map_resolver.dart'; |
| 19 import 'package:analyzer/source/path_filter.dart'; | 19 import 'package:analyzer/source/path_filter.dart'; |
| 20 import 'package:analyzer/source/pub_package_map_provider.dart'; |
| 20 import 'package:analyzer/src/generated/engine.dart'; | 21 import 'package:analyzer/src/generated/engine.dart'; |
| 21 import 'package:analyzer/src/generated/java_io.dart'; | 22 import 'package:analyzer/src/generated/java_io.dart'; |
| 22 import 'package:analyzer/src/generated/source.dart'; | 23 import 'package:analyzer/src/generated/source.dart'; |
| 23 import 'package:analyzer/src/generated/source_io.dart'; | 24 import 'package:analyzer/src/generated/source_io.dart'; |
| 24 import 'package:package_config/packages.dart'; | 25 import 'package:package_config/packages.dart'; |
| 25 import 'package:package_config/packages_file.dart' as pkgfile show parse; | 26 import 'package:package_config/packages_file.dart' as pkgfile show parse; |
| 26 import 'package:package_config/src/packages_impl.dart' show MapPackages; | 27 import 'package:package_config/src/packages_impl.dart' show MapPackages; |
| 27 import 'package:path/path.dart' as pathos; | 28 import 'package:path/path.dart' as pathos; |
| 28 import 'package:watcher/watcher.dart'; | 29 import 'package:watcher/watcher.dart'; |
| 29 import 'package:yaml/yaml.dart'; | 30 import 'package:yaml/yaml.dart'; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 * Map from full path to the [Source] object, for each source that has been | 85 * Map from full path to the [Source] object, for each source that has been |
| 85 * added to the context. | 86 * added to the context. |
| 86 */ | 87 */ |
| 87 Map<String, Source> sources = new HashMap<String, Source>(); | 88 Map<String, Source> sources = new HashMap<String, Source>(); |
| 88 | 89 |
| 89 /** | 90 /** |
| 90 * Info returned by the last call to | 91 * Info returned by the last call to |
| 91 * [OptimizingPubPackageMapProvider.computePackageMap], or `null` if the | 92 * [OptimizingPubPackageMapProvider.computePackageMap], or `null` if the |
| 92 * package map hasn't been computed for this context yet. | 93 * package map hasn't been computed for this context yet. |
| 93 */ | 94 */ |
| 94 OptimizingPubPackageMapInfo packageMapInfo; | 95 PackageMapInfo packageMapInfo; |
| 95 | 96 |
| 96 ContextInfo( | 97 ContextInfo( |
| 97 this.parent, Folder folder, File packagespecFile, this.packageRoot) | 98 this.parent, Folder folder, File packagespecFile, this.packageRoot) |
| 98 : folder = folder, | 99 : folder = folder, |
| 99 pathFilter = new PathFilter(folder.path, null) { | 100 pathFilter = new PathFilter(folder.path, null) { |
| 100 packageDescriptionPath = packagespecFile.path; | 101 packageDescriptionPath = packagespecFile.path; |
| 101 parent.children.add(this); | 102 parent.children.add(this); |
| 102 } | 103 } |
| 103 | 104 |
| 104 /** | 105 /** |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 * A function that will return a [UriResolver] that can be used to resolve | 358 * A function that will return a [UriResolver] that can be used to resolve |
| 358 * `package:` URI's within a given folder, or `null` if we should fall back | 359 * `package:` URI's within a given folder, or `null` if we should fall back |
| 359 * to the standard URI resolver. | 360 * to the standard URI resolver. |
| 360 */ | 361 */ |
| 361 final ResolverProvider packageResolverProvider; | 362 final ResolverProvider packageResolverProvider; |
| 362 | 363 |
| 363 /** | 364 /** |
| 364 * Provider which is used to determine the mapping from package name to | 365 * Provider which is used to determine the mapping from package name to |
| 365 * package folder. | 366 * package folder. |
| 366 */ | 367 */ |
| 367 final OptimizingPubPackageMapProvider _packageMapProvider; | 368 final PubPackageMapProvider _packageMapProvider; |
| 368 | 369 |
| 369 /// Provider of analysis options. | 370 /// Provider of analysis options. |
| 370 AnalysisOptionsProvider analysisOptionsProvider = | 371 AnalysisOptionsProvider analysisOptionsProvider = |
| 371 new AnalysisOptionsProvider(); | 372 new AnalysisOptionsProvider(); |
| 372 | 373 |
| 373 /** | 374 /** |
| 374 * The instrumentation service used to report instrumentation data. | 375 * The instrumentation service used to report instrumentation data. |
| 375 */ | 376 */ |
| 376 final InstrumentationService _instrumentationService; | 377 final InstrumentationService _instrumentationService; |
| 377 | 378 |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 // resolve packages. | 746 // resolve packages. |
| 746 return new NoPackageFolderDisposition(); | 747 return new NoPackageFolderDisposition(); |
| 747 } else { | 748 } else { |
| 748 callbacks.beginComputePackageMap(); | 749 callbacks.beginComputePackageMap(); |
| 749 if (packageResolverProvider != null) { | 750 if (packageResolverProvider != null) { |
| 750 UriResolver resolver = packageResolverProvider(folder); | 751 UriResolver resolver = packageResolverProvider(folder); |
| 751 if (resolver != null) { | 752 if (resolver != null) { |
| 752 return new CustomPackageResolverDisposition(resolver); | 753 return new CustomPackageResolverDisposition(resolver); |
| 753 } | 754 } |
| 754 } | 755 } |
| 755 OptimizingPubPackageMapInfo packageMapInfo; | 756 PackageMapInfo packageMapInfo; |
| 756 ServerPerformanceStatistics.pub.makeCurrentWhile(() { | 757 ServerPerformanceStatistics.pub.makeCurrentWhile(() { |
| 757 packageMapInfo = | 758 packageMapInfo = _packageMapProvider.computePackageMap(folder); |
| 758 _packageMapProvider.computePackageMap(folder, info.packageMapInfo); | |
| 759 }); | 759 }); |
| 760 callbacks.endComputePackageMap(); | 760 callbacks.endComputePackageMap(); |
| 761 for (String dependencyPath in packageMapInfo.dependencies) { | 761 for (String dependencyPath in packageMapInfo.dependencies) { |
| 762 Resource resource = resourceProvider.getResource(dependencyPath); | 762 Resource resource = resourceProvider.getResource(dependencyPath); |
| 763 if (resource is File) { | 763 if (resource is File) { |
| 764 StreamSubscription<WatchEvent> subscription; | 764 StreamSubscription<WatchEvent> subscription; |
| 765 subscription = resource.changes.listen((WatchEvent event) { | 765 subscription = resource.changes.listen((WatchEvent event) { |
| 766 if (info.packageMapInfo != null && | 766 if (info.packageMapInfo != null && |
| 767 info.packageMapInfo.isChangedDependency( | 767 info.packageMapInfo.dependencies.contains(dependencyPath)) { |
| 768 dependencyPath, resourceProvider)) { | |
| 769 _recomputeFolderDisposition(info); | 768 _recomputeFolderDisposition(info); |
| 770 } | 769 } |
| 771 }, onError: (error, StackTrace stackTrace) { | 770 }, onError: (error, StackTrace stackTrace) { |
| 772 // Gracefully degrade if file is or becomes unwatchable | 771 // Gracefully degrade if file is or becomes unwatchable |
| 773 _instrumentationService.logException(error, stackTrace); | 772 _instrumentationService.logException(error, stackTrace); |
| 774 subscription.cancel(); | 773 subscription.cancel(); |
| 775 info.dependencySubscriptions.remove(subscription); | 774 info.dependencySubscriptions.remove(subscription); |
| 776 }); | 775 }); |
| 777 info.dependencySubscriptions.add(subscription); | 776 info.dependencySubscriptions.add(subscription); |
| 778 } | 777 } |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1082 }); | 1081 }); |
| 1083 callbacks.applyChangesToContext(folder, changeSet); | 1082 callbacks.applyChangesToContext(folder, changeSet); |
| 1084 } | 1083 } |
| 1085 break; | 1084 break; |
| 1086 } | 1085 } |
| 1087 | 1086 |
| 1088 //TODO(pquitslund): find the right place for this | 1087 //TODO(pquitslund): find the right place for this |
| 1089 _checkForPackagespecUpdate(path, info, folder); | 1088 _checkForPackagespecUpdate(path, info, folder); |
| 1090 | 1089 |
| 1091 if (info.packageMapInfo != null && | 1090 if (info.packageMapInfo != null && |
| 1092 info.packageMapInfo.isChangedDependency(path, resourceProvider)) { | 1091 info.packageMapInfo.dependencies.contains(path)) { |
| 1093 _recomputeFolderDisposition(info); | 1092 _recomputeFolderDisposition(info); |
| 1094 } | 1093 } |
| 1095 } | 1094 } |
| 1096 | 1095 |
| 1097 /** | 1096 /** |
| 1098 * Returns `true` if the given [path] is excluded by [excludedPaths]. | 1097 * Returns `true` if the given [path] is excluded by [excludedPaths]. |
| 1099 */ | 1098 */ |
| 1100 bool _isExcluded(String path) => _isExcludedBy(excludedPaths, path); | 1099 bool _isExcluded(String path) => _isExcludedBy(excludedPaths, path); |
| 1101 | 1100 |
| 1102 /** | 1101 /** |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1314 class PackagesFileDisposition extends FolderDisposition { | 1313 class PackagesFileDisposition extends FolderDisposition { |
| 1315 @override | 1314 @override |
| 1316 final Packages packages; | 1315 final Packages packages; |
| 1317 | 1316 |
| 1318 PackagesFileDisposition(this.packages) {} | 1317 PackagesFileDisposition(this.packages) {} |
| 1319 | 1318 |
| 1320 @override | 1319 @override |
| 1321 Iterable<UriResolver> createPackageUriResolvers( | 1320 Iterable<UriResolver> createPackageUriResolvers( |
| 1322 ResourceProvider resourceProvider) => const <UriResolver>[]; | 1321 ResourceProvider resourceProvider) => const <UriResolver>[]; |
| 1323 } | 1322 } |
| OLD | NEW |