Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 analyzer_cli.src.driver; | 5 library analyzer_cli.src.driver; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 | 10 |
| 11 import 'package:analyzer/file_system/file_system.dart' as fileSystem; | 11 import 'package:analyzer/file_system/file_system.dart' as fileSystem; |
| 12 import 'package:analyzer/file_system/physical_file_system.dart'; | 12 import 'package:analyzer/file_system/physical_file_system.dart'; |
| 13 import 'package:analyzer/plugin/options.dart'; | 13 import 'package:analyzer/plugin/options.dart'; |
| 14 import 'package:analyzer/source/analysis_options_provider.dart'; | 14 import 'package:analyzer/source/analysis_options_provider.dart'; |
| 15 import 'package:analyzer/source/embedder.dart'; | |
| 15 import 'package:analyzer/source/package_map_provider.dart'; | 16 import 'package:analyzer/source/package_map_provider.dart'; |
| 16 import 'package:analyzer/source/package_map_resolver.dart'; | 17 import 'package:analyzer/source/package_map_resolver.dart'; |
| 17 import 'package:analyzer/source/pub_package_map_provider.dart'; | 18 import 'package:analyzer/source/pub_package_map_provider.dart'; |
| 18 import 'package:analyzer/source/sdk_ext.dart'; | 19 import 'package:analyzer/source/sdk_ext.dart'; |
| 19 import 'package:analyzer/src/generated/constant.dart'; | 20 import 'package:analyzer/src/generated/constant.dart'; |
| 20 import 'package:analyzer/src/generated/engine.dart'; | 21 import 'package:analyzer/src/generated/engine.dart'; |
| 21 import 'package:analyzer/src/generated/error.dart'; | 22 import 'package:analyzer/src/generated/error.dart'; |
| 22 import 'package:analyzer/src/generated/interner.dart'; | 23 import 'package:analyzer/src/generated/interner.dart'; |
| 23 import 'package:analyzer/src/generated/java_engine.dart'; | 24 import 'package:analyzer/src/generated/java_engine.dart'; |
| 24 import 'package:analyzer/src/generated/java_io.dart'; | 25 import 'package:analyzer/src/generated/java_io.dart'; |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 } | 296 } |
| 296 } else { | 297 } else { |
| 297 return true; | 298 return true; |
| 298 } | 299 } |
| 299 }; | 300 }; |
| 300 } | 301 } |
| 301 | 302 |
| 302 /// Decide on the appropriate method for resolving URIs based on the given | 303 /// Decide on the appropriate method for resolving URIs based on the given |
| 303 /// [options] and [customUrlMappings] settings, and return a | 304 /// [options] and [customUrlMappings] settings, and return a |
| 304 /// [SourceFactory] that has been configured accordingly. | 305 /// [SourceFactory] that has been configured accordingly. |
| 305 SourceFactory _chooseUriResolutionPolicy(CommandLineOptions options) { | 306 SourceFactory _chooseUriResolutionPolicy( |
| 307 CommandLineOptions options, AnalysisContext context) { | |
|
Brian Wilkerson
2016/01/26 19:12:33
Given that the only thing we need from the context
pquitslund
2016/01/26 19:22:19
Done.
| |
| 306 Packages packages; | 308 Packages packages; |
| 307 Map<String, List<fileSystem.Folder>> packageMap; | 309 Map<String, List<fileSystem.Folder>> packageMap; |
| 308 UriResolver packageUriResolver; | 310 UriResolver packageUriResolver; |
| 309 | 311 |
| 310 // Process options, caching package resolution details. | 312 // Process options, caching package resolution details. |
| 311 if (options.packageConfigPath != null) { | 313 if (options.packageConfigPath != null) { |
| 312 String packageConfigPath = options.packageConfigPath; | 314 String packageConfigPath = options.packageConfigPath; |
| 313 Uri fileUri = new Uri.file(packageConfigPath); | 315 Uri fileUri = new Uri.file(packageConfigPath); |
| 314 try { | 316 try { |
| 315 File configFile = new File.fromUri(fileUri).absolute; | 317 File configFile = new File.fromUri(fileUri).absolute; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 349 // If it failed, that's not a problem; it simply means we have no way | 351 // If it failed, that's not a problem; it simply means we have no way |
| 350 // to resolve packages. | 352 // to resolve packages. |
| 351 if (packageMapInfo.packageMap != null) { | 353 if (packageMapInfo.packageMap != null) { |
| 352 packageUriResolver = new PackageMapUriResolver( | 354 packageUriResolver = new PackageMapUriResolver( |
| 353 PhysicalResourceProvider.INSTANCE, packageMap); | 355 PhysicalResourceProvider.INSTANCE, packageMap); |
| 354 } | 356 } |
| 355 } | 357 } |
| 356 } | 358 } |
| 357 | 359 |
| 358 // Now, build our resolver list. | 360 // Now, build our resolver list. |
| 361 List<UriResolver> resolvers = []; | |
| 359 | 362 |
| 360 // 'dart:' URIs come first. | 363 // 'dart:' URIs come first. |
| 361 List<UriResolver> resolvers = [new DartUriResolver(sdk)]; | 364 |
| 365 // Setup embedding. | |
| 366 EmbedderYamlLocator yamlLocator = | |
| 367 (context as InternalAnalysisContext).embedderYamlLocator; | |
| 368 yamlLocator.refresh(packageMap); | |
| 369 | |
| 370 EmbedderUriResolver embedderUriResolver = | |
| 371 new EmbedderUriResolver(yamlLocator.embedderYamls); | |
| 372 if (embedderUriResolver.length == 0) { | |
| 373 // The embedder uri resolver has no mappings. Use the default Dart SDK | |
| 374 // uri resolver. | |
| 375 resolvers.add(new DartUriResolver(sdk)); | |
| 376 } else { | |
| 377 // The embedder uri resolver has mappings, use it instead of the default | |
| 378 // Dart SDK uri resolver. | |
| 379 resolvers.add(embedderUriResolver); | |
| 380 } | |
| 362 | 381 |
| 363 // Next SdkExts. | 382 // Next SdkExts. |
| 364 if (packageMap != null) { | 383 if (packageMap != null) { |
| 365 resolvers.add(new SdkExtUriResolver(packageMap)); | 384 resolvers.add(new SdkExtUriResolver(packageMap)); |
| 366 } | 385 } |
| 367 | 386 |
| 368 // Then package URIs. | 387 // Then package URIs. |
| 369 if (packageUriResolver != null) { | 388 if (packageUriResolver != null) { |
| 370 resolvers.add(packageUriResolver); | 389 resolvers.add(packageUriResolver); |
| 371 } | 390 } |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 394 return new FileBasedSource(sourceFile, uri); | 413 return new FileBasedSource(sourceFile, uri); |
| 395 } | 414 } |
| 396 | 415 |
| 397 /// Create an analysis context that is prepared to analyze sources according | 416 /// Create an analysis context that is prepared to analyze sources according |
| 398 /// to the given [options], and store it in [_context]. | 417 /// to the given [options], and store it in [_context]. |
| 399 void _createAnalysisContext(CommandLineOptions options) { | 418 void _createAnalysisContext(CommandLineOptions options) { |
| 400 if (_canContextBeReused(options)) { | 419 if (_canContextBeReused(options)) { |
| 401 return; | 420 return; |
| 402 } | 421 } |
| 403 _previousOptions = options; | 422 _previousOptions = options; |
| 423 | |
| 424 // Create a context. | |
| 425 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); | |
| 426 | |
| 404 // Choose a package resolution policy and a diet parsing policy based on | 427 // Choose a package resolution policy and a diet parsing policy based on |
| 405 // the command-line options. | 428 // the command-line options. |
| 406 SourceFactory sourceFactory = _chooseUriResolutionPolicy(options); | 429 SourceFactory sourceFactory = _chooseUriResolutionPolicy(options, context); |
| 407 AnalyzeFunctionBodiesPredicate dietParsingPolicy = | 430 AnalyzeFunctionBodiesPredicate dietParsingPolicy = |
| 408 _chooseDietParsingPolicy(options); | 431 _chooseDietParsingPolicy(options); |
| 409 // Create a context using these policies. | |
| 410 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); | |
| 411 | 432 |
| 412 context.sourceFactory = sourceFactory; | 433 context.sourceFactory = sourceFactory; |
| 413 | 434 |
| 414 Map<String, String> definedVariables = options.definedVariables; | 435 Map<String, String> definedVariables = options.definedVariables; |
| 415 if (!definedVariables.isEmpty) { | 436 if (!definedVariables.isEmpty) { |
| 416 DeclaredVariables declaredVariables = context.declaredVariables; | 437 DeclaredVariables declaredVariables = context.declaredVariables; |
| 417 definedVariables.forEach((String variableName, String value) { | 438 definedVariables.forEach((String variableName, String value) { |
| 418 declaredVariables.define(variableName, value); | 439 declaredVariables.define(variableName, value); |
| 419 }); | 440 }); |
| 420 } | 441 } |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 649 for (var package in packages) { | 670 for (var package in packages) { |
| 650 var packageName = path.basename(package.path); | 671 var packageName = path.basename(package.path); |
| 651 var realPath = package.resolveSymbolicLinksSync(); | 672 var realPath = package.resolveSymbolicLinksSync(); |
| 652 result[packageName] = [ | 673 result[packageName] = [ |
| 653 PhysicalResourceProvider.INSTANCE.getFolder(realPath) | 674 PhysicalResourceProvider.INSTANCE.getFolder(realPath) |
| 654 ]; | 675 ]; |
| 655 } | 676 } |
| 656 return result; | 677 return result; |
| 657 } | 678 } |
| 658 } | 679 } |
| OLD | NEW |