| 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/package_map_provider.dart'; | 15 import 'package:analyzer/source/package_map_provider.dart'; |
| 16 import 'package:analyzer/source/package_map_resolver.dart'; | 16 import 'package:analyzer/source/package_map_resolver.dart'; |
| 17 import 'package:analyzer/source/pub_package_map_provider.dart'; | 17 import 'package:analyzer/source/pub_package_map_provider.dart'; |
| 18 import 'package:analyzer/source/sdk_ext.dart'; | 18 import 'package:analyzer/source/sdk_ext.dart'; |
| 19 import 'package:analyzer/src/generated/constant.dart'; | 19 import 'package:analyzer/src/generated/constant.dart'; |
| 20 import 'package:analyzer/src/generated/engine.dart'; | 20 import 'package:analyzer/src/generated/engine.dart'; |
| 21 import 'package:analyzer/src/generated/error.dart'; | 21 import 'package:analyzer/src/generated/error.dart'; |
| 22 import 'package:analyzer/src/generated/interner.dart'; | 22 import 'package:analyzer/src/generated/interner.dart'; |
| 23 import 'package:analyzer/src/generated/java_engine.dart'; | 23 import 'package:analyzer/src/generated/java_engine.dart'; |
| 24 import 'package:analyzer/src/generated/java_io.dart'; | 24 import 'package:analyzer/src/generated/java_io.dart'; |
| 25 import 'package:analyzer/src/generated/sdk_io.dart'; | 25 import 'package:analyzer/src/generated/sdk_io.dart'; |
| 26 import 'package:analyzer/src/generated/source.dart'; | 26 import 'package:analyzer/src/generated/source.dart'; |
| 27 import 'package:analyzer/src/generated/source_io.dart'; | 27 import 'package:analyzer/src/generated/source_io.dart'; |
| 28 import 'package:analyzer/src/plugin/plugin_configuration.dart'; | |
| 29 import 'package:analyzer_cli/src/analyzer_impl.dart'; | 28 import 'package:analyzer_cli/src/analyzer_impl.dart'; |
| 30 import 'package:analyzer_cli/src/options.dart'; | 29 import 'package:analyzer_cli/src/options.dart'; |
| 31 import 'package:analyzer_cli/src/plugin/plugin_config_processor_plugin.dart'; | |
| 32 import 'package:dev_compiler/strong_mode.dart'; | 30 import 'package:dev_compiler/strong_mode.dart'; |
| 33 import 'package:linter/src/plugin/linter_plugin.dart'; | 31 import 'package:linter/src/plugin/linter_plugin.dart'; |
| 34 import 'package:package_config/discovery.dart' as pkgDiscovery; | 32 import 'package:package_config/discovery.dart' as pkgDiscovery; |
| 35 import 'package:package_config/packages.dart' show Packages; | 33 import 'package:package_config/packages.dart' show Packages; |
| 36 import 'package:package_config/packages_file.dart' as pkgfile show parse; | 34 import 'package:package_config/packages_file.dart' as pkgfile show parse; |
| 37 import 'package:package_config/src/packages_impl.dart' show MapPackages; | 35 import 'package:package_config/src/packages_impl.dart' show MapPackages; |
| 38 import 'package:path/path.dart' as path; | 36 import 'package:path/path.dart' as path; |
| 39 import 'package:plugin/manager.dart'; | 37 import 'package:plugin/manager.dart'; |
| 40 import 'package:plugin/plugin.dart'; | 38 import 'package:plugin/plugin.dart'; |
| 41 import 'package:source_span/source_span.dart'; | |
| 42 import 'package:yaml/yaml.dart'; | 39 import 'package:yaml/yaml.dart'; |
| 43 | 40 |
| 44 /// The maximum number of sources for which AST structures should be kept in the
cache. | 41 /// The maximum number of sources for which AST structures should be kept in the
cache. |
| 45 const int _maxCacheSize = 512; | 42 const int _maxCacheSize = 512; |
| 46 | 43 |
| 47 /// Shared IO sink for standard error reporting. | 44 /// Shared IO sink for standard error reporting. |
| 48 /// | 45 /// |
| 49 /// *Visible for testing.* | 46 /// *Visible for testing.* |
| 50 StringSink errorSink = stderr; | 47 StringSink errorSink = stderr; |
| 51 | 48 |
| 52 /// Shared IO sink for standard out reporting. | 49 /// Shared IO sink for standard out reporting. |
| 53 /// | 50 /// |
| 54 /// *Visible for testing.* | 51 /// *Visible for testing.* |
| 55 StringSink outSink = stdout; | 52 StringSink outSink = stdout; |
| 56 | 53 |
| 57 typedef ErrorSeverity _BatchRunnerHandler(List<String> args); | 54 typedef ErrorSeverity _BatchRunnerHandler(List<String> args); |
| 58 | 55 |
| 59 class Driver { | 56 class Driver { |
| 60 /// Emits an error message to [errorSink] if plugin config can't be read. | |
| 61 static final ErrorHandler _pluginConfigErrorHandler = (Exception e) { | |
| 62 String details; | |
| 63 if (e is PluginConfigFormatException) { | |
| 64 details = e.message; | |
| 65 var node = e.yamlNode; | |
| 66 if (node is YamlNode) { | |
| 67 SourceLocation location = node.span.start; | |
| 68 details += ' (line ${location.line}, column ${location.column})'; | |
| 69 } | |
| 70 } else { | |
| 71 details = e.toString(); | |
| 72 } | |
| 73 | |
| 74 errorSink.writeln('Plugin configuration skipped: $details'); | |
| 75 }; | |
| 76 | |
| 77 /// The plugins that are defined outside the `analyzer_cli` package. | 57 /// The plugins that are defined outside the `analyzer_cli` package. |
| 78 List<Plugin> _userDefinedPlugins = <Plugin>[]; | 58 List<Plugin> _userDefinedPlugins = <Plugin>[]; |
| 79 | 59 |
| 80 /// Indicates whether the analyzer is running in batch mode. | 60 /// Indicates whether the analyzer is running in batch mode. |
| 81 bool _isBatch; | 61 bool _isBatch; |
| 82 | 62 |
| 83 /// The context that was most recently created by a call to [_analyzeAll], or | 63 /// The context that was most recently created by a call to [_analyzeAll], or |
| 84 /// `null` if [_analyzeAll] hasn't been called yet. | 64 /// `null` if [_analyzeAll] hasn't been called yet. |
| 85 AnalysisContext _context; | 65 AnalysisContext _context; |
| 86 | 66 |
| 87 /// Reads plugin config info from `.analysis_options`. | |
| 88 PluginConfigProcessorPlugin _pluginConfigProcessorPlugin; | |
| 89 | |
| 90 /// The strong mode checker corresponding to [_context], or `null` if strong | 67 /// The strong mode checker corresponding to [_context], or `null` if strong |
| 91 /// mode is not enabled or a context is not available yet. | 68 /// mode is not enabled or a context is not available yet. |
| 92 StrongChecker _strongChecker; | 69 StrongChecker _strongChecker; |
| 93 | 70 |
| 94 /// If [_context] is not `null`, the [CommandLineOptions] that guided its | 71 /// If [_context] is not `null`, the [CommandLineOptions] that guided its |
| 95 /// creation. | 72 /// creation. |
| 96 CommandLineOptions _previousOptions; | 73 CommandLineOptions _previousOptions; |
| 97 | 74 |
| 98 Driver() | |
| 99 : _pluginConfigProcessorPlugin = | |
| 100 new PluginConfigProcessorPlugin(_pluginConfigErrorHandler); | |
| 101 | |
| 102 /// This Driver's current analysis context. | 75 /// This Driver's current analysis context. |
| 103 /// | 76 /// |
| 104 /// *Visible for testing.* | 77 /// *Visible for testing.* |
| 105 AnalysisContext get context => _context; | 78 AnalysisContext get context => _context; |
| 106 | 79 |
| 107 /// Plugin configuration as processed from `.analysis_options`. | |
| 108 PluginConfig get pluginConfig => _pluginConfigProcessorPlugin.pluginConfig; | |
| 109 | |
| 110 /// Set the [plugins] that are defined outside the `analyzer_cli` package. | 80 /// Set the [plugins] that are defined outside the `analyzer_cli` package. |
| 111 void set userDefinedPlugins(List<Plugin> plugins) { | 81 void set userDefinedPlugins(List<Plugin> plugins) { |
| 112 _userDefinedPlugins = plugins == null ? <Plugin>[] : plugins; | 82 _userDefinedPlugins = plugins == null ? <Plugin>[] : plugins; |
| 113 } | 83 } |
| 114 | 84 |
| 115 /// Use the given command-line [args] to start this analysis driver. | 85 /// Use the given command-line [args] to start this analysis driver. |
| 116 void start(List<String> args) { | 86 void start(List<String> args) { |
| 117 StringUtilities.INTERNER = new MappedInterner(); | 87 StringUtilities.INTERNER = new MappedInterner(); |
| 118 | 88 |
| 119 _processPlugins(); | 89 _processPlugins(); |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 analysisOptionsProvider.getOptionsFromFile(file); | 447 analysisOptionsProvider.getOptionsFromFile(file); |
| 478 optionsProcessors | 448 optionsProcessors |
| 479 .forEach((OptionsProcessor p) => p.optionsProcessed(options)); | 449 .forEach((OptionsProcessor p) => p.optionsProcessed(options)); |
| 480 } on Exception catch (e) { | 450 } on Exception catch (e) { |
| 481 optionsProcessors.forEach((OptionsProcessor p) => p.onError(e)); | 451 optionsProcessors.forEach((OptionsProcessor p) => p.onError(e)); |
| 482 } | 452 } |
| 483 } | 453 } |
| 484 | 454 |
| 485 void _processPlugins() { | 455 void _processPlugins() { |
| 486 List<Plugin> plugins = <Plugin>[]; | 456 List<Plugin> plugins = <Plugin>[]; |
| 487 plugins.add(_pluginConfigProcessorPlugin); | |
| 488 plugins.add(linterPlugin); | 457 plugins.add(linterPlugin); |
| 489 plugins.addAll(AnalysisEngine.instance.supportedPlugins); | 458 plugins.addAll(AnalysisEngine.instance.supportedPlugins); |
| 490 plugins.addAll(_userDefinedPlugins); | 459 plugins.addAll(_userDefinedPlugins); |
| 491 ExtensionManager manager = new ExtensionManager(); | 460 ExtensionManager manager = new ExtensionManager(); |
| 492 manager.processPlugins(plugins); | 461 manager.processPlugins(plugins); |
| 493 } | 462 } |
| 494 | 463 |
| 495 /// Analyze a single source. | 464 /// Analyze a single source. |
| 496 ErrorSeverity _runAnalyzer(Source source, CommandLineOptions options) { | 465 ErrorSeverity _runAnalyzer(Source source, CommandLineOptions options) { |
| 497 int startTime = currentTimeMillis(); | 466 int startTime = currentTimeMillis(); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 for (var package in packages) { | 586 for (var package in packages) { |
| 618 var packageName = path.basename(package.path); | 587 var packageName = path.basename(package.path); |
| 619 var realPath = package.resolveSymbolicLinksSync(); | 588 var realPath = package.resolveSymbolicLinksSync(); |
| 620 result[packageName] = [ | 589 result[packageName] = [ |
| 621 PhysicalResourceProvider.INSTANCE.getFolder(realPath) | 590 PhysicalResourceProvider.INSTANCE.getFolder(realPath) |
| 622 ]; | 591 ]; |
| 623 } | 592 } |
| 624 return result; | 593 return result; |
| 625 } | 594 } |
| 626 } | 595 } |
| OLD | NEW |