| 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 | 9 |
| 10 import 'package:analysis_server/src/analysis_server.dart'; |
| 10 import 'package:analyzer/file_system/file_system.dart'; | 11 import 'package:analyzer/file_system/file_system.dart'; |
| 11 import 'package:analyzer/source/package_map_provider.dart'; | 12 import 'package:analyzer/source/package_map_provider.dart'; |
| 12 import 'package:analyzer/source/package_map_resolver.dart'; | 13 import 'package:analyzer/source/package_map_resolver.dart'; |
| 13 import 'package:analyzer/src/generated/engine.dart'; | 14 import 'package:analyzer/src/generated/engine.dart'; |
| 14 import 'package:analyzer/src/generated/java_io.dart'; | 15 import 'package:analyzer/src/generated/java_io.dart'; |
| 15 import 'package:analyzer/src/generated/source.dart'; | 16 import 'package:analyzer/src/generated/source.dart'; |
| 16 import 'package:analyzer/src/generated/source_io.dart'; | 17 import 'package:analyzer/src/generated/source_io.dart'; |
| 17 import 'package:path/path.dart' as pathos; | 18 import 'package:path/path.dart' as pathos; |
| 18 import 'package:watcher/watcher.dart'; | 19 import 'package:watcher/watcher.dart'; |
| 19 | 20 |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 * Compute the appropriate package URI resolver for [folder], and store | 320 * Compute the appropriate package URI resolver for [folder], and store |
| 320 * dependency information in [info]. Return `null` if no package map can | 321 * dependency information in [info]. Return `null` if no package map can |
| 321 * be computed. | 322 * be computed. |
| 322 */ | 323 */ |
| 323 UriResolver _computePackageUriResolver(Folder folder, _ContextInfo info) { | 324 UriResolver _computePackageUriResolver(Folder folder, _ContextInfo info) { |
| 324 if (info.packageRoot != null) { | 325 if (info.packageRoot != null) { |
| 325 info.packageMapDependencies = new Set<String>(); | 326 info.packageMapDependencies = new Set<String>(); |
| 326 return new PackageUriResolver([new JavaFile(info.packageRoot)]); | 327 return new PackageUriResolver([new JavaFile(info.packageRoot)]); |
| 327 } else { | 328 } else { |
| 328 beginComputePackageMap(); | 329 beginComputePackageMap(); |
| 329 PackageMapInfo packageMapInfo = | 330 PackageMapInfo packageMapInfo; |
| 330 _packageMapProvider.computePackageMap(folder); | 331 ServerPerformanceStatistics.pub.makeCurrentWhile(() { |
| 332 packageMapInfo = _packageMapProvider.computePackageMap(folder); |
| 333 }); |
| 331 endComputePackageMap(); | 334 endComputePackageMap(); |
| 332 info.packageMapDependencies = packageMapInfo.dependencies; | 335 info.packageMapDependencies = packageMapInfo.dependencies; |
| 333 if (packageMapInfo.packageMap == null) { | 336 if (packageMapInfo.packageMap == null) { |
| 334 return null; | 337 return null; |
| 335 } | 338 } |
| 336 return new PackageMapUriResolver( | 339 return new PackageMapUriResolver( |
| 337 resourceProvider, | 340 resourceProvider, |
| 338 packageMapInfo.packageMap); | 341 packageMapInfo.packageMap); |
| 339 // TODO(paulberry): if any of the dependencies is outside of [folder], | 342 // TODO(paulberry): if any of the dependencies is outside of [folder], |
| 340 // we'll need to watch their parent folders as well. | 343 // we'll need to watch their parent folders as well. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 354 _contexts[folder] = info; | 357 _contexts[folder] = info; |
| 355 info.changeSubscription = folder.changes.listen((WatchEvent event) { | 358 info.changeSubscription = folder.changes.listen((WatchEvent event) { |
| 356 _handleWatchEvent(folder, info, event); | 359 _handleWatchEvent(folder, info, event); |
| 357 }); | 360 }); |
| 358 UriResolver packageUriResolver = _computePackageUriResolver(folder, info); | 361 UriResolver packageUriResolver = _computePackageUriResolver(folder, info); |
| 359 info.context = addContext(folder, packageUriResolver); | 362 info.context = addContext(folder, packageUriResolver); |
| 360 return info; | 363 return info; |
| 361 } | 364 } |
| 362 | 365 |
| 363 /** | 366 /** |
| 364 * Create a new context associated with the given [folder]. The [pubspecFile] | |
| 365 * is the `pubspec.yaml` file contained in the folder. Add any sources that | |
| 366 * are not included in one of the [children] to the context. | |
| 367 */ | |
| 368 _ContextInfo _createContextWithSources(Folder folder, File pubspecFile, | |
| 369 List<_ContextInfo> children) { | |
| 370 _ContextInfo info = _createContext(folder, pubspecFile, children); | |
| 371 ChangeSet changeSet = new ChangeSet(); | |
| 372 _addSourceFiles(changeSet, folder, info); | |
| 373 applyChangesToContext(folder, changeSet); | |
| 374 return info; | |
| 375 } | |
| 376 | |
| 377 /** | |
| 378 * Creates a new context associated with [folder]. | 367 * Creates a new context associated with [folder]. |
| 379 * | 368 * |
| 380 * If there are subfolders with 'pubspec.yaml' files, separate contexts | 369 * If there are subfolders with 'pubspec.yaml' files, separate contexts |
| 381 * are created for them, and excluded from the context associated with | 370 * are created for them, and excluded from the context associated with |
| 382 * [folder]. | 371 * [folder]. |
| 383 * | 372 * |
| 384 * If [folder] itself contains a 'pubspec.yaml' file, subfolders are ignored. | 373 * If [folder] itself contains a 'pubspec.yaml' file, subfolders are ignored. |
| 385 * | 374 * |
| 386 * If [withPubspecOnly] is `true`, a context will be created only if there | 375 * If [withPubspecOnly] is `true`, a context will be created only if there |
| 387 * is a 'pubspec.yaml' file in [folder]. | 376 * is a 'pubspec.yaml' file in [folder]. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 407 // no pubspec, done | 396 // no pubspec, done |
| 408 if (withPubspecOnly) { | 397 if (withPubspecOnly) { |
| 409 return children; | 398 return children; |
| 410 } | 399 } |
| 411 // OK, create a context without a pubspec | 400 // OK, create a context without a pubspec |
| 412 _createContextWithSources(folder, pubspecFile, children); | 401 _createContextWithSources(folder, pubspecFile, children); |
| 413 return children; | 402 return children; |
| 414 } | 403 } |
| 415 | 404 |
| 416 /** | 405 /** |
| 406 * Create a new context associated with the given [folder]. The [pubspecFile] |
| 407 * is the `pubspec.yaml` file contained in the folder. Add any sources that |
| 408 * are not included in one of the [children] to the context. |
| 409 */ |
| 410 _ContextInfo _createContextWithSources(Folder folder, File pubspecFile, |
| 411 List<_ContextInfo> children) { |
| 412 _ContextInfo info = _createContext(folder, pubspecFile, children); |
| 413 ChangeSet changeSet = new ChangeSet(); |
| 414 _addSourceFiles(changeSet, folder, info); |
| 415 applyChangesToContext(folder, changeSet); |
| 416 return info; |
| 417 } |
| 418 |
| 419 /** |
| 417 * Clean up and destroy the context associated with the given folder. | 420 * Clean up and destroy the context associated with the given folder. |
| 418 */ | 421 */ |
| 419 void _destroyContext(Folder folder) { | 422 void _destroyContext(Folder folder) { |
| 420 _contexts[folder].changeSubscription.cancel(); | 423 _contexts[folder].changeSubscription.cancel(); |
| 421 _contexts.remove(folder); | 424 _contexts.remove(folder); |
| 422 removeContext(folder); | 425 removeContext(folder); |
| 423 } | 426 } |
| 424 | 427 |
| 425 /** | 428 /** |
| 426 * Extract a new [pubspecFile]-based context from [oldInfo]. | 429 * Extract a new [pubspecFile]-based context from [oldInfo]. |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 return excludes(resource.path); | 702 return excludes(resource.path); |
| 700 } | 703 } |
| 701 | 704 |
| 702 /** | 705 /** |
| 703 * Returns `true` if [path] is the pubspec file of this context. | 706 * Returns `true` if [path] is the pubspec file of this context. |
| 704 */ | 707 */ |
| 705 bool isPubspec(String path) { | 708 bool isPubspec(String path) { |
| 706 return path == pubspecPath; | 709 return path == pubspecPath; |
| 707 } | 710 } |
| 708 } | 711 } |
| OLD | NEW |