Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: pkg/analysis_server/lib/src/context_manager.dart

Issue 1923973004: Pubspec-specified analysis configuration (#26359). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: typeo Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/test/context_manager_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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:analyzer/file_system/file_system.dart'; 13 import 'package:analyzer/file_system/file_system.dart';
14 import 'package:analyzer/instrumentation/instrumentation.dart'; 14 import 'package:analyzer/instrumentation/instrumentation.dart';
15 import 'package:analyzer/plugin/embedded_resolver_provider.dart'; 15 import 'package:analyzer/plugin/embedded_resolver_provider.dart';
16 import 'package:analyzer/plugin/options.dart'; 16 import 'package:analyzer/plugin/options.dart';
17 import 'package:analyzer/plugin/resolver_provider.dart'; 17 import 'package:analyzer/plugin/resolver_provider.dart';
18 import 'package:analyzer/source/analysis_options_provider.dart'; 18 import 'package:analyzer/source/analysis_options_provider.dart';
19 import 'package:analyzer/source/config.dart';
19 import 'package:analyzer/source/embedder.dart'; 20 import 'package:analyzer/source/embedder.dart';
20 import 'package:analyzer/source/package_map_provider.dart'; 21 import 'package:analyzer/source/package_map_provider.dart';
21 import 'package:analyzer/source/package_map_resolver.dart'; 22 import 'package:analyzer/source/package_map_resolver.dart';
22 import 'package:analyzer/source/path_filter.dart'; 23 import 'package:analyzer/source/path_filter.dart';
23 import 'package:analyzer/source/pub_package_map_provider.dart'; 24 import 'package:analyzer/source/pub_package_map_provider.dart';
24 import 'package:analyzer/source/sdk_ext.dart'; 25 import 'package:analyzer/source/sdk_ext.dart';
25 import 'package:analyzer/src/context/context.dart' as context; 26 import 'package:analyzer/src/context/context.dart' as context;
26 import 'package:analyzer/src/context/source.dart'; 27 import 'package:analyzer/src/context/source.dart';
27 import 'package:analyzer/src/generated/engine.dart'; 28 import 'package:analyzer/src/generated/engine.dart';
28 import 'package:analyzer/src/generated/java_engine.dart'; 29 import 'package:analyzer/src/generated/java_engine.dart';
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 // Start with defaults. 591 // Start with defaults.
591 info.context.analysisOptions = new AnalysisOptionsImpl(); 592 info.context.analysisOptions = new AnalysisOptionsImpl();
592 593
593 // Apply inherited options. 594 // Apply inherited options.
594 options = _toStringMap(_getEmbeddedOptions(info.context)); 595 options = _toStringMap(_getEmbeddedOptions(info.context));
595 if (options != null) { 596 if (options != null) {
596 configureContextOptions(info.context, options); 597 configureContextOptions(info.context, options);
597 } 598 }
598 } else { 599 } else {
599 // Check for embedded options. 600 // Check for embedded options.
600 YamlMap embeddedOptions = _getEmbeddedOptions(info.context); 601 Map embeddedOptions = _getEmbeddedOptions(info.context);
601 if (embeddedOptions != null) { 602 if (embeddedOptions != null) {
602 options = _toStringMap(new Merger().merge(embeddedOptions, options)); 603 options = _toStringMap(new Merger().merge(embeddedOptions, options));
603 } 604 }
604 } 605 }
605 606
606 // Notify options processors. 607 // Notify options processors.
607 AnalysisEngine.instance.optionsPlugin.optionsProcessors 608 AnalysisEngine.instance.optionsPlugin.optionsProcessors
608 .forEach((OptionsProcessor p) { 609 .forEach((OptionsProcessor p) {
609 try { 610 try {
610 p.optionsProcessed(info.context, options); 611 p.optionsProcessed(info.context, options);
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 Map<String, Object> optionMap = readOptions(info.folder); 1066 Map<String, Object> optionMap = readOptions(info.folder);
1066 AnalysisOptions options = 1067 AnalysisOptions options =
1067 new AnalysisOptionsImpl.from(defaultContextOptions); 1068 new AnalysisOptionsImpl.from(defaultContextOptions);
1068 applyToAnalysisOptions(options, optionMap); 1069 applyToAnalysisOptions(options, optionMap);
1069 1070
1070 info.setDependencies(dependencies); 1071 info.setDependencies(dependencies);
1071 info.context = callbacks.addContext(folder, options, disposition); 1072 info.context = callbacks.addContext(folder, options, disposition);
1072 folderMap[folder] = info.context; 1073 folderMap[folder] = info.context;
1073 info.context.name = folder.path; 1074 info.context.name = folder.path;
1074 1075
1076 // Look for pubspec-specified analysis configuration.
1077 File pubspec;
1078 if (packagespecFile?.exists == true) {
1079 if (packagespecFile.shortName == PUBSPEC_NAME) {
1080 pubspec = packagespecFile;
1081 }
1082 }
1083 if (pubspec == null) {
1084 Resource child = folder.getChild(PUBSPEC_NAME);
1085 if (child.exists && child is File) {
1086 pubspec = child;
1087 }
1088 }
1089 if (pubspec != null) {
1090 File pubSource = resourceProvider.getFile(pubspec.path);
1091 setConfiguration(
1092 info.context,
1093 new AnalysisConfiguration.fromPubspec(
1094 pubSource, resourceProvider, disposition.packages));
1095 }
1096
1075 processOptionsForContext(info, optionMap); 1097 processOptionsForContext(info, optionMap);
1076 1098
1077 return info; 1099 return info;
1078 } 1100 }
1079 1101
1080 /** 1102 /**
1081 * Potentially create a new context associated with the given [folder]. 1103 * Potentially create a new context associated with the given [folder].
1082 * 1104 *
1083 * If there are subfolders with 'pubspec.yaml' files, separate contexts are 1105 * If there are subfolders with 'pubspec.yaml' files, separate contexts are
1084 * created for them and excluded from the context associated with the 1106 * created for them and excluded from the context associated with the
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1228 // Start by looking for .packages. 1250 // Start by looking for .packages.
1229 packageSpec = folder.getChild(PACKAGE_SPEC_NAME); 1251 packageSpec = folder.getChild(PACKAGE_SPEC_NAME);
1230 1252
1231 // Fall back to looking for a pubspec. 1253 // Fall back to looking for a pubspec.
1232 if (packageSpec == null || !packageSpec.exists) { 1254 if (packageSpec == null || !packageSpec.exists) {
1233 packageSpec = folder.getChild(PUBSPEC_NAME); 1255 packageSpec = folder.getChild(PUBSPEC_NAME);
1234 } 1256 }
1235 return packageSpec; 1257 return packageSpec;
1236 } 1258 }
1237 1259
1238 /// Get analysis options associated with an `_embedder.yaml`. If there is 1260 /// Get analysis options inherited from an `_embedder.yaml` (deprecated)
1239 /// more than one `_embedder.yaml` associated with the given context, `null` 1261 /// and/or a package specified configuration. If more than one
1240 /// is returned. 1262 /// `_embedder.yaml` is associated with the given context, the embedder is
1241 YamlMap _getEmbeddedOptions(AnalysisContext context) { 1263 /// skipped.
1242 if (context is InternalAnalysisContext) { 1264 ///
1243 EmbedderYamlLocator locator = context.embedderYamlLocator; 1265 /// Returns null if there are no embedded/configured options.
1244 Iterable<YamlMap> maps = locator.embedderYamls.values; 1266 Map _getEmbeddedOptions(AnalysisContext context) {
1245 if (maps.length == 1) { 1267 if (context is! InternalAnalysisContext) {
Brian Wilkerson 2016/04/28 18:05:59 While I appreciate the fact that this style remove
pquitslund 2016/04/28 18:13:42 Done.
1246 return maps.first; 1268 return null;
1269 }
1270
1271 InternalAnalysisContext internalContext = context;
1272
1273 Map embeddedOptions;
1274 EmbedderYamlLocator locator = internalContext.embedderYamlLocator;
1275 Iterable<YamlMap> maps = locator.embedderYamls.values;
1276 if (maps.length == 1) {
1277 embeddedOptions = maps.first;
1278 }
1279
1280 AnalysisConfiguration configuration = getConfiguration(context);
1281 if (configuration != null) {
1282 Map configMap = configuration.options;
1283 if (configMap != null) {
1284 if (embeddedOptions != null) {
1285 embeddedOptions = new Merger().merge(embeddedOptions, configMap);
1286 } else {
1287 embeddedOptions = configMap;
1288 }
1247 } 1289 }
1248 } 1290 }
1249 return null; 1291
1292 return embeddedOptions;
1250 } 1293 }
1251 1294
1252 /** 1295 /**
1253 * Return the [ContextInfo] for the "innermost" context whose associated 1296 * Return the [ContextInfo] for the "innermost" context whose associated
1254 * folder is or contains the given path. ("innermost" refers to the nesting 1297 * folder is or contains the given path. ("innermost" refers to the nesting
1255 * of contexts, so if there is a context for path /foo and a context for 1298 * of contexts, so if there is a context for path /foo and a context for
1256 * path /foo/bar, then the innermost context containing /foo/bar/baz.dart is 1299 * path /foo/bar, then the innermost context containing /foo/bar/baz.dart is
1257 * the context for /foo/bar.) 1300 * the context for /foo/bar.)
1258 * 1301 *
1259 * If no context contains the given path, `null` is returned. 1302 * If no context contains the given path, `null` is returned.
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
1794 ResourceProvider resourceProvider) { 1837 ResourceProvider resourceProvider) {
1795 if (packages != null) { 1838 if (packages != null) {
1796 // Construct package map for the SdkExtUriResolver. 1839 // Construct package map for the SdkExtUriResolver.
1797 Map<String, List<Folder>> packageMap = buildPackageMap(resourceProvider); 1840 Map<String, List<Folder>> packageMap = buildPackageMap(resourceProvider);
1798 return <UriResolver>[new SdkExtUriResolver(packageMap)]; 1841 return <UriResolver>[new SdkExtUriResolver(packageMap)];
1799 } else { 1842 } else {
1800 return const <UriResolver>[]; 1843 return const <UriResolver>[];
1801 } 1844 }
1802 } 1845 }
1803 } 1846 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/context_manager_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698