| 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:core' hide Resource; | 9 import 'dart:core' hide Resource; |
| 10 | 10 |
| 11 import 'package:analysis_server/src/analysis_server.dart'; | 11 import 'package:analysis_server/src/analysis_server.dart'; |
| 12 import 'package:analysis_server/src/source/optimizing_pub_package_map_provider.d
art'; | 12 import 'package:analysis_server/src/source/optimizing_pub_package_map_provider.d
art'; |
| 13 import 'package:analysis_server/uri/resolver_provider.dart'; |
| 13 import 'package:analyzer/file_system/file_system.dart'; | 14 import 'package:analyzer/file_system/file_system.dart'; |
| 14 import 'package:analyzer/instrumentation/instrumentation.dart'; | 15 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| 15 import 'package:analyzer/source/package_map_resolver.dart'; | 16 import 'package:analyzer/source/package_map_resolver.dart'; |
| 16 import 'package:analyzer/src/generated/engine.dart'; | 17 import 'package:analyzer/src/generated/engine.dart'; |
| 17 import 'package:analyzer/src/generated/java_io.dart'; | 18 import 'package:analyzer/src/generated/java_io.dart'; |
| 18 import 'package:analyzer/src/generated/source.dart'; | 19 import 'package:analyzer/src/generated/source.dart'; |
| 19 import 'package:analyzer/src/generated/source_io.dart'; | 20 import 'package:analyzer/src/generated/source_io.dart'; |
| 20 import 'package:path/path.dart' as pathos; | 21 import 'package:path/path.dart' as pathos; |
| 21 import 'package:watcher/watcher.dart'; | 22 import 'package:watcher/watcher.dart'; |
| 22 | 23 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 */ | 74 */ |
| 74 Map<String, String> packageRoots = <String, String>{}; | 75 Map<String, String> packageRoots = <String, String>{}; |
| 75 | 76 |
| 76 /** | 77 /** |
| 77 * Same as [packageRoots], except that source folders have been normalized | 78 * Same as [packageRoots], except that source folders have been normalized |
| 78 * and non-folders have been removed. | 79 * and non-folders have been removed. |
| 79 */ | 80 */ |
| 80 Map<String, String> normalizedPackageRoots = <String, String>{}; | 81 Map<String, String> normalizedPackageRoots = <String, String>{}; |
| 81 | 82 |
| 82 /** | 83 /** |
| 84 * A function that will return a [UriResolver] that can be used to resolve |
| 85 * `package:` URI's within a given folder, or `null` if we should fall back |
| 86 * to the standard URI resolver. |
| 87 */ |
| 88 final ResolverProvider packageResolverProvider; |
| 89 |
| 90 /** |
| 83 * Provider which is used to determine the mapping from package name to | 91 * Provider which is used to determine the mapping from package name to |
| 84 * package folder. | 92 * package folder. |
| 85 */ | 93 */ |
| 86 final OptimizingPubPackageMapProvider _packageMapProvider; | 94 final OptimizingPubPackageMapProvider _packageMapProvider; |
| 87 | 95 |
| 88 /** | 96 /** |
| 89 * The instrumentation service used to report instrumentation data. | 97 * The instrumentation service used to report instrumentation data. |
| 90 */ | 98 */ |
| 91 final InstrumentationService _instrumentationService; | 99 final InstrumentationService _instrumentationService; |
| 92 | 100 |
| 93 ContextManager(this.resourceProvider, this._packageMapProvider, | 101 ContextManager(this.resourceProvider, this.packageResolverProvider, |
| 94 this._instrumentationService) { | 102 this._packageMapProvider, this._instrumentationService) { |
| 95 pathContext = resourceProvider.pathContext; | 103 pathContext = resourceProvider.pathContext; |
| 96 } | 104 } |
| 97 | 105 |
| 98 /** | 106 /** |
| 99 * Create and return a new analysis context. | 107 * Create and return a new analysis context. |
| 100 */ | 108 */ |
| 101 AnalysisContext addContext(Folder folder, UriResolver packageUriResolver); | 109 AnalysisContext addContext(Folder folder, UriResolver packageUriResolver); |
| 102 | 110 |
| 103 /** | 111 /** |
| 104 * Called when the set of files associated with a context have changed (or | 112 * Called when the set of files associated with a context have changed (or |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 if (res is Folder) { | 432 if (res is Folder) { |
| 425 packageMap[file.getName()] = <Folder>[res]; | 433 packageMap[file.getName()] = <Folder>[res]; |
| 426 } | 434 } |
| 427 } | 435 } |
| 428 return new PackageMapUriResolver(resourceProvider, packageMap); | 436 return new PackageMapUriResolver(resourceProvider, packageMap); |
| 429 } | 437 } |
| 430 //TODO(danrubel) remove this if it will never be called | 438 //TODO(danrubel) remove this if it will never be called |
| 431 return new PackageUriResolver([packagesDir]); | 439 return new PackageUriResolver([packagesDir]); |
| 432 } else { | 440 } else { |
| 433 beginComputePackageMap(); | 441 beginComputePackageMap(); |
| 442 if (packageResolverProvider != null) { |
| 443 UriResolver resolver = packageResolverProvider(folder); |
| 444 if (resolver != null) { |
| 445 return resolver; |
| 446 } |
| 447 } |
| 434 OptimizingPubPackageMapInfo packageMapInfo; | 448 OptimizingPubPackageMapInfo packageMapInfo; |
| 435 ServerPerformanceStatistics.pub.makeCurrentWhile(() { | 449 ServerPerformanceStatistics.pub.makeCurrentWhile(() { |
| 436 packageMapInfo = | 450 packageMapInfo = |
| 437 _packageMapProvider.computePackageMap(folder, info.packageMapInfo); | 451 _packageMapProvider.computePackageMap(folder, info.packageMapInfo); |
| 438 }); | 452 }); |
| 439 endComputePackageMap(); | 453 endComputePackageMap(); |
| 440 for (String dependencyPath in packageMapInfo.dependencies) { | 454 for (String dependencyPath in packageMapInfo.dependencies) { |
| 441 Resource resource = resourceProvider.getResource(dependencyPath); | 455 Resource resource = resourceProvider.getResource(dependencyPath); |
| 442 if (resource is File) { | 456 if (resource is File) { |
| 443 StreamSubscription<WatchEvent> subscription; | 457 StreamSubscription<WatchEvent> subscription; |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 return excludes(resource.path); | 853 return excludes(resource.path); |
| 840 } | 854 } |
| 841 | 855 |
| 842 /** | 856 /** |
| 843 * Returns `true` if [path] is the pubspec file of this context. | 857 * Returns `true` if [path] is the pubspec file of this context. |
| 844 */ | 858 */ |
| 845 bool isPubspec(String path) { | 859 bool isPubspec(String path) { |
| 846 return path == pubspecPath; | 860 return path == pubspecPath; |
| 847 } | 861 } |
| 848 } | 862 } |
| OLD | NEW |