| 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 file_system; | 11 import 'package:analyzer/file_system/file_system.dart' as file_system; |
| 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/embedded_resolver_provider.dart'; | |
| 14 import 'package:analyzer/plugin/options.dart'; | 13 import 'package:analyzer/plugin/options.dart'; |
| 15 import 'package:analyzer/plugin/resolver_provider.dart'; | 14 import 'package:analyzer/plugin/resolver_provider.dart'; |
| 16 import 'package:analyzer/source/analysis_options_provider.dart'; | 15 import 'package:analyzer/source/analysis_options_provider.dart'; |
| 17 import 'package:analyzer/source/embedder.dart'; | 16 import 'package:analyzer/source/embedder.dart'; |
| 18 import 'package:analyzer/source/package_map_provider.dart'; | 17 import 'package:analyzer/source/package_map_provider.dart'; |
| 19 import 'package:analyzer/source/package_map_resolver.dart'; | 18 import 'package:analyzer/source/package_map_resolver.dart'; |
| 20 import 'package:analyzer/source/pub_package_map_provider.dart'; | 19 import 'package:analyzer/source/pub_package_map_provider.dart'; |
| 21 import 'package:analyzer/source/sdk_ext.dart'; | 20 import 'package:analyzer/source/sdk_ext.dart'; |
| 22 import 'package:analyzer/src/generated/constant.dart'; | 21 import 'package:analyzer/src/generated/constant.dart'; |
| 23 import 'package:analyzer/src/generated/engine.dart'; | 22 import 'package:analyzer/src/generated/engine.dart'; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 /// The total number of source files loaded by an AnalysisContext. | 82 /// The total number of source files loaded by an AnalysisContext. |
| 84 int _analyzedFileCount = 0; | 83 int _analyzedFileCount = 0; |
| 85 | 84 |
| 86 /// If [_context] is not `null`, the [CommandLineOptions] that guided its | 85 /// If [_context] is not `null`, the [CommandLineOptions] that guided its |
| 87 /// creation. | 86 /// creation. |
| 88 CommandLineOptions _previousOptions; | 87 CommandLineOptions _previousOptions; |
| 89 | 88 |
| 90 IncrementalAnalysisSession incrementalSession; | 89 IncrementalAnalysisSession incrementalSession; |
| 91 | 90 |
| 92 @override | 91 @override |
| 93 EmbeddedResolverProvider embeddedUriResolverProvider; | |
| 94 | |
| 95 @override | |
| 96 ResolverProvider packageResolverProvider; | 92 ResolverProvider packageResolverProvider; |
| 97 | 93 |
| 98 /// SDK instance. | 94 /// SDK instance. |
| 99 DartSdk sdk; | 95 DartSdk sdk; |
| 100 | 96 |
| 101 /// Collected analysis statistics. | 97 /// Collected analysis statistics. |
| 102 final AnalysisStats stats = new AnalysisStats(); | 98 final AnalysisStats stats = new AnalysisStats(); |
| 103 | 99 |
| 104 /// This Driver's current analysis context. | 100 /// This Driver's current analysis context. |
| 105 /// | 101 /// |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 /// [options] and [customUrlMappings] settings, and return a | 335 /// [options] and [customUrlMappings] settings, and return a |
| 340 /// [SourceFactory] that has been configured accordingly. | 336 /// [SourceFactory] that has been configured accordingly. |
| 341 SourceFactory _chooseUriResolutionPolicy(CommandLineOptions options, | 337 SourceFactory _chooseUriResolutionPolicy(CommandLineOptions options, |
| 342 Map<file_system.Folder, YamlMap> embedderMap, _PackageInfo packageInfo) { | 338 Map<file_system.Folder, YamlMap> embedderMap, _PackageInfo packageInfo) { |
| 343 // Create a custom package resolver if one has been specified. | 339 // Create a custom package resolver if one has been specified. |
| 344 if (packageResolverProvider != null) { | 340 if (packageResolverProvider != null) { |
| 345 file_system.Folder folder = | 341 file_system.Folder folder = |
| 346 PhysicalResourceProvider.INSTANCE.getResource('.'); | 342 PhysicalResourceProvider.INSTANCE.getResource('.'); |
| 347 UriResolver resolver = packageResolverProvider(folder); | 343 UriResolver resolver = packageResolverProvider(folder); |
| 348 if (resolver != null) { | 344 if (resolver != null) { |
| 349 UriResolver sdkResolver; | 345 UriResolver sdkResolver = new DartUriResolver(sdk); |
| 350 | |
| 351 // Check for a resolver provider. | |
| 352 if (embeddedUriResolverProvider != null) { | |
| 353 EmbedderUriResolver embedderUriResolver = | |
| 354 embeddedUriResolverProvider(folder); | |
| 355 if (embedderUriResolver != null && embedderUriResolver.length != 0) { | |
| 356 sdkResolver = embedderUriResolver; | |
| 357 } | |
| 358 } | |
| 359 | |
| 360 // Default to a Dart URI resolver if no embedder is found. | |
| 361 sdkResolver ??= new DartUriResolver(sdk); | |
| 362 | 346 |
| 363 // TODO(brianwilkerson) This doesn't handle sdk extensions. | 347 // TODO(brianwilkerson) This doesn't handle sdk extensions. |
| 364 List<UriResolver> resolvers = <UriResolver>[ | 348 List<UriResolver> resolvers = <UriResolver>[ |
| 365 sdkResolver, | 349 sdkResolver, |
| 366 resolver, | 350 resolver, |
| 367 new FileUriResolver() | 351 new FileUriResolver() |
| 368 ]; | 352 ]; |
| 369 return new SourceFactory(resolvers); | 353 return new SourceFactory(resolvers); |
| 370 } | 354 } |
| 371 } | 355 } |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 plugins.add(linterPlugin); | 604 plugins.add(linterPlugin); |
| 621 plugins.addAll(_userDefinedPlugins); | 605 plugins.addAll(_userDefinedPlugins); |
| 622 | 606 |
| 623 ExtensionManager manager = new ExtensionManager(); | 607 ExtensionManager manager = new ExtensionManager(); |
| 624 manager.processPlugins(plugins); | 608 manager.processPlugins(plugins); |
| 625 } | 609 } |
| 626 | 610 |
| 627 /// Analyze a single source. | 611 /// Analyze a single source. |
| 628 ErrorSeverity _runAnalyzer(Source source, CommandLineOptions options) { | 612 ErrorSeverity _runAnalyzer(Source source, CommandLineOptions options) { |
| 629 int startTime = currentTimeMillis(); | 613 int startTime = currentTimeMillis(); |
| 630 AnalyzerImpl analyzer = | 614 AnalyzerImpl analyzer = new AnalyzerImpl( |
| 631 new AnalyzerImpl(_context, incrementalSession, source, options, stats, s
tartTime); | 615 _context, incrementalSession, source, options, stats, startTime); |
| 632 var errorSeverity = analyzer.analyzeSync(); | 616 var errorSeverity = analyzer.analyzeSync(); |
| 633 if (errorSeverity == ErrorSeverity.ERROR) { | 617 if (errorSeverity == ErrorSeverity.ERROR) { |
| 634 exitCode = errorSeverity.ordinal; | 618 exitCode = errorSeverity.ordinal; |
| 635 } | 619 } |
| 636 if (options.warningsAreFatal && errorSeverity == ErrorSeverity.WARNING) { | 620 if (options.warningsAreFatal && errorSeverity == ErrorSeverity.WARNING) { |
| 637 exitCode = errorSeverity.ordinal; | 621 exitCode = errorSeverity.ordinal; |
| 638 } | 622 } |
| 639 return errorSeverity; | 623 return errorSeverity; |
| 640 } | 624 } |
| 641 | 625 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 for (var package in packages) { | 840 for (var package in packages) { |
| 857 var packageName = path.basename(package.path); | 841 var packageName = path.basename(package.path); |
| 858 var realPath = package.resolveSymbolicLinksSync(); | 842 var realPath = package.resolveSymbolicLinksSync(); |
| 859 result[packageName] = [ | 843 result[packageName] = [ |
| 860 PhysicalResourceProvider.INSTANCE.getFolder(realPath) | 844 PhysicalResourceProvider.INSTANCE.getFolder(realPath) |
| 861 ]; | 845 ]; |
| 862 } | 846 } |
| 863 return result; | 847 return result; |
| 864 } | 848 } |
| 865 } | 849 } |
| OLD | NEW |