| 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 11 matching lines...) Expand all Loading... |
| 22 import 'package:analyzer/source/pub_package_map_provider.dart'; | 22 import 'package:analyzer/source/pub_package_map_provider.dart'; |
| 23 import 'package:analyzer/source/sdk_ext.dart'; | 23 import 'package:analyzer/source/sdk_ext.dart'; |
| 24 import 'package:analyzer/src/context/context.dart' as context; | 24 import 'package:analyzer/src/context/context.dart' as context; |
| 25 import 'package:analyzer/src/generated/engine.dart'; | 25 import 'package:analyzer/src/generated/engine.dart'; |
| 26 import 'package:analyzer/src/generated/java_engine.dart'; | 26 import 'package:analyzer/src/generated/java_engine.dart'; |
| 27 import 'package:analyzer/src/generated/java_io.dart'; | 27 import 'package:analyzer/src/generated/java_io.dart'; |
| 28 import 'package:analyzer/src/generated/source.dart'; | 28 import 'package:analyzer/src/generated/source.dart'; |
| 29 import 'package:analyzer/src/generated/source_io.dart'; | 29 import 'package:analyzer/src/generated/source_io.dart'; |
| 30 import 'package:analyzer/src/task/options.dart'; | 30 import 'package:analyzer/src/task/options.dart'; |
| 31 import 'package:analyzer/src/util/absolute_path.dart'; | 31 import 'package:analyzer/src/util/absolute_path.dart'; |
| 32 import 'package:analyzer/src/util/yaml.dart'; |
| 32 import 'package:package_config/packages.dart'; | 33 import 'package:package_config/packages.dart'; |
| 33 import 'package:package_config/packages_file.dart' as pkgfile show parse; | 34 import 'package:package_config/packages_file.dart' as pkgfile show parse; |
| 34 import 'package:package_config/src/packages_impl.dart' show MapPackages; | 35 import 'package:package_config/src/packages_impl.dart' show MapPackages; |
| 35 import 'package:path/path.dart' as pathos; | 36 import 'package:path/path.dart' as pathos; |
| 36 import 'package:watcher/watcher.dart'; | 37 import 'package:watcher/watcher.dart'; |
| 37 import 'package:yaml/yaml.dart'; | 38 import 'package:yaml/yaml.dart'; |
| 38 | 39 |
| 39 /** | 40 /** |
| 40 * Information tracked by the [ContextManager] for each context. | 41 * Information tracked by the [ContextManager] for each context. |
| 41 */ | 42 */ |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 .forEach((OptionsProcessor p) { | 494 .forEach((OptionsProcessor p) { |
| 494 try { | 495 try { |
| 495 p.optionsProcessed(info.context, options); | 496 p.optionsProcessed(info.context, options); |
| 496 } catch (e, stacktrace) { | 497 } catch (e, stacktrace) { |
| 497 AnalysisEngine.instance.logger.logError( | 498 AnalysisEngine.instance.logger.logError( |
| 498 'Error processing .analysis_options', | 499 'Error processing .analysis_options', |
| 499 new CaughtException(e, stacktrace)); | 500 new CaughtException(e, stacktrace)); |
| 500 } | 501 } |
| 501 }); | 502 }); |
| 502 | 503 |
| 503 // In case options files are removed, revert to default options. | 504 // In case options files are removed, revert to defaults. |
| 504 if (optionsRemoved) { | 505 if (optionsRemoved) { |
| 506 // Start with defaults. |
| 505 info.context.analysisOptions = new AnalysisOptionsImpl(); | 507 info.context.analysisOptions = new AnalysisOptionsImpl(); |
| 508 |
| 509 // Apply inherited options. |
| 510 YamlMap embeddedOptions = _getEmbeddedOptions(info.context); |
| 511 if (embeddedOptions != null) { |
| 512 configureContextOptions(info.context, embeddedOptions); |
| 513 } |
| 506 return; | 514 return; |
| 507 } | 515 } |
| 508 | 516 |
| 517 // Check for embedded options. |
| 518 YamlMap embeddedOptions = _getEmbeddedOptions(info.context); |
| 519 if (embeddedOptions != null) { |
| 520 options = new Merger().merge(embeddedOptions, options); |
| 521 } |
| 522 |
| 509 // Analysis options are processed 'in-line'. | 523 // Analysis options are processed 'in-line'. |
| 510 var analyzer = options[AnalyzerOptions.analyzer]; | 524 var analyzer = options[AnalyzerOptions.analyzer]; |
| 511 if (analyzer is! YamlMap) { | 525 if (analyzer is! Map) { |
| 512 // No options for analyzer. | 526 // No options for analyzer. |
| 513 return; | 527 return; |
| 514 } | 528 } |
| 515 | 529 |
| 516 configureContextOptions(info.context, options); | 530 configureContextOptions(info.context, options); |
| 517 | 531 |
| 518 // Set ignore patterns. | 532 // Set ignore patterns. |
| 519 YamlList exclude = analyzer[AnalyzerOptions.exclude]; | 533 YamlList exclude = analyzer[AnalyzerOptions.exclude]; |
| 520 if (exclude != null) { | 534 if (exclude != null) { |
| 521 setIgnorePatternsForContext(info, exclude); | 535 setIgnorePatternsForContext(info, exclude); |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 // Start by looking for .packages. | 1015 // Start by looking for .packages. |
| 1002 packageSpec = folder.getChild(PACKAGE_SPEC_NAME); | 1016 packageSpec = folder.getChild(PACKAGE_SPEC_NAME); |
| 1003 | 1017 |
| 1004 // Fall back to looking for a pubspec. | 1018 // Fall back to looking for a pubspec. |
| 1005 if (packageSpec == null || !packageSpec.exists) { | 1019 if (packageSpec == null || !packageSpec.exists) { |
| 1006 packageSpec = folder.getChild(PUBSPEC_NAME); | 1020 packageSpec = folder.getChild(PUBSPEC_NAME); |
| 1007 } | 1021 } |
| 1008 return packageSpec; | 1022 return packageSpec; |
| 1009 } | 1023 } |
| 1010 | 1024 |
| 1025 /// Get analysis options associated with an `_embedder.yaml`. If there is |
| 1026 /// more than one `_embedder.yaml` associated with the given context, `null` |
| 1027 /// is returned. |
| 1028 YamlMap _getEmbeddedOptions(AnalysisContext context) { |
| 1029 if (context is InternalAnalysisContext) { |
| 1030 EmbedderYamlLocator locator = context.embedderYamlLocator; |
| 1031 Iterable<YamlMap> maps = locator.embedderYamls.values; |
| 1032 if (maps.length == 1) { |
| 1033 return maps.first; |
| 1034 } |
| 1035 } |
| 1036 return null; |
| 1037 } |
| 1038 |
| 1011 /** | 1039 /** |
| 1012 * Return the [ContextInfo] for the "innermost" context whose associated | 1040 * Return the [ContextInfo] for the "innermost" context whose associated |
| 1013 * folder is or contains the given path. ("innermost" refers to the nesting | 1041 * folder is or contains the given path. ("innermost" refers to the nesting |
| 1014 * of contexts, so if there is a context for path /foo and a context for | 1042 * of contexts, so if there is a context for path /foo and a context for |
| 1015 * path /foo/bar, then the innermost context containing /foo/bar/baz.dart is | 1043 * path /foo/bar, then the innermost context containing /foo/bar/baz.dart is |
| 1016 * the context for /foo/bar.) | 1044 * the context for /foo/bar.) |
| 1017 * | 1045 * |
| 1018 * If no context contains the given path, `null` is returned. | 1046 * If no context contains the given path, `null` is returned. |
| 1019 */ | 1047 */ |
| 1020 ContextInfo _getInnermostContextInfoFor(String path) { | 1048 ContextInfo _getInnermostContextInfoFor(String path) { |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1447 } | 1475 } |
| 1448 | 1476 |
| 1449 /** | 1477 /** |
| 1450 * Concrete [FolderDisposition] object indicating that the context for a given | 1478 * Concrete [FolderDisposition] object indicating that the context for a given |
| 1451 * folder should resolve packages using a ".packages" file. | 1479 * folder should resolve packages using a ".packages" file. |
| 1452 */ | 1480 */ |
| 1453 class PackagesFileDisposition extends FolderDisposition { | 1481 class PackagesFileDisposition extends FolderDisposition { |
| 1454 @override | 1482 @override |
| 1455 final Packages packages; | 1483 final Packages packages; |
| 1456 | 1484 |
| 1485 PackagesFileDisposition(this.packages) {} |
| 1486 |
| 1487 @override |
| 1488 String get packageRoot => null; |
| 1489 |
| 1457 Map<String, List<Folder>> buildPackageMap(ResourceProvider resourceProvider) { | 1490 Map<String, List<Folder>> buildPackageMap(ResourceProvider resourceProvider) { |
| 1458 Map<String, List<Folder>> packageMap = <String, List<Folder>>{}; | 1491 Map<String, List<Folder>> packageMap = <String, List<Folder>>{}; |
| 1459 if (packages == null) { | 1492 if (packages == null) { |
| 1460 return packageMap; | 1493 return packageMap; |
| 1461 } | 1494 } |
| 1462 packages.asMap().forEach((String name, Uri uri) { | 1495 packages.asMap().forEach((String name, Uri uri) { |
| 1463 if (uri.scheme == 'file' || uri.scheme == '' /* unspecified */) { | 1496 if (uri.scheme == 'file' || uri.scheme == '' /* unspecified */) { |
| 1464 var path = resourceProvider.pathContext.fromUri(uri); | 1497 var path = resourceProvider.pathContext.fromUri(uri); |
| 1465 packageMap[name] = <Folder>[resourceProvider.getFolder(path)]; | 1498 packageMap[name] = <Folder>[resourceProvider.getFolder(path)]; |
| 1466 } | 1499 } |
| 1467 }); | 1500 }); |
| 1468 return packageMap; | 1501 return packageMap; |
| 1469 } | 1502 } |
| 1470 | 1503 |
| 1471 PackagesFileDisposition(this.packages) {} | |
| 1472 | |
| 1473 @override | |
| 1474 String get packageRoot => null; | |
| 1475 | |
| 1476 @override | 1504 @override |
| 1477 Iterable<UriResolver> createPackageUriResolvers( | 1505 Iterable<UriResolver> createPackageUriResolvers( |
| 1478 ResourceProvider resourceProvider) { | 1506 ResourceProvider resourceProvider) { |
| 1479 if (packages != null) { | 1507 if (packages != null) { |
| 1480 // Construct package map for the SdkExtUriResolver. | 1508 // Construct package map for the SdkExtUriResolver. |
| 1481 Map<String, List<Folder>> packageMap = | 1509 Map<String, List<Folder>> packageMap = buildPackageMap(resourceProvider); |
| 1482 buildPackageMap(resourceProvider); | |
| 1483 return <UriResolver>[new SdkExtUriResolver(packageMap)]; | 1510 return <UriResolver>[new SdkExtUriResolver(packageMap)]; |
| 1484 } else { | 1511 } else { |
| 1485 return const <UriResolver>[]; | 1512 return const <UriResolver>[]; |
| 1486 } | 1513 } |
| 1487 } | 1514 } |
| 1488 } | 1515 } |
| OLD | NEW |