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.bootloader; | 5 library analyzer_cli.src.bootloader; |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 import 'dart:isolate'; | 8 import 'dart:isolate'; |
9 | 9 |
10 import 'package:analyzer/file_system/physical_file_system.dart'; | 10 import 'package:analyzer/file_system/physical_file_system.dart'; |
11 import 'package:analyzer/plugin/options.dart'; | |
12 import 'package:analyzer/source/analysis_options_provider.dart'; | 11 import 'package:analyzer/source/analysis_options_provider.dart'; |
13 import 'package:analyzer/src/generated/engine.dart'; | |
14 import 'package:analyzer/src/plugin/plugin_configuration.dart'; | 12 import 'package:analyzer/src/plugin/plugin_configuration.dart'; |
15 import 'package:analyzer_cli/src/driver.dart'; | 13 import 'package:analyzer_cli/src/driver.dart'; |
16 import 'package:analyzer_cli/src/options.dart'; | 14 import 'package:analyzer_cli/src/options.dart'; |
17 import 'package:analyzer_cli/src/plugin/plugin_config_processor_plugin.dart'; | |
18 import 'package:plugin/manager.dart'; | |
19 import 'package:plugin/plugin.dart'; | |
20 import 'package:source_span/source_span.dart'; | 15 import 'package:source_span/source_span.dart'; |
21 import 'package:yaml/src/yaml_node.dart'; | 16 import 'package:yaml/src/yaml_node.dart'; |
22 | 17 |
23 const _analyzerPackageName = 'analyzer'; | 18 const _analyzerPackageName = 'analyzer'; |
24 | 19 |
25 /// Source code assembler. | 20 /// Source code assembler. |
26 class Assembler { | 21 class Assembler { |
27 /// Plugin configuration info. | 22 /// Plugin configuration info. |
28 final PluginConfig _config; | 23 final PluginConfig _config; |
29 | 24 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 details += ' (line ${location.line}, column ${location.column})'; | 74 details += ' (line ${location.line}, column ${location.column})'; |
80 } | 75 } |
81 } else { | 76 } else { |
82 details = e.toString(); | 77 details = e.toString(); |
83 } | 78 } |
84 | 79 |
85 errorSink.writeln('Plugin configuration skipped: $details'); | 80 errorSink.writeln('Plugin configuration skipped: $details'); |
86 }; | 81 }; |
87 | 82 |
88 /// Reads plugin config info from `.analysis_options`. | 83 /// Reads plugin config info from `.analysis_options`. |
89 PluginConfigProcessorPlugin _pluginConfigProcessorPlugin = | 84 PluginConfigOptionsProcessor _pluginOptionsProcessor = |
90 new PluginConfigProcessorPlugin(_pluginConfigErrorHandler); | 85 new PluginConfigOptionsProcessor(_pluginConfigErrorHandler); |
91 | 86 |
92 /// Create a loadable analyzer image configured with plugins derived from | 87 /// Create a loadable analyzer image configured with plugins derived from |
93 /// the given analyzer command-line `args`. | 88 /// the given analyzer command-line `args`. |
94 Image createImage(List<String> args) { | 89 Image createImage(List<String> args) { |
95 _processPlugins(); | |
96 | |
97 // Parse commandline options. | 90 // Parse commandline options. |
98 CommandLineOptions options = CommandLineOptions.parse(args); | 91 CommandLineOptions options = CommandLineOptions.parse(args); |
99 | 92 |
100 // Process analysis options file (and notify all interested parties). | 93 // Process analysis options file (and notify all interested parties). |
101 _processAnalysisOptions(options); | 94 _processAnalysisOptions(options); |
102 | 95 |
103 // TODO(pquitslund): Pass in .packages info | 96 // TODO(pquitslund): Pass in .packages info |
104 return new Image(_pluginConfigProcessorPlugin.pluginConfig, | 97 return new Image(_pluginOptionsProcessor.config, |
105 args: args, packageRootPath: options.packageRootPath); | 98 args: args, packageRootPath: options.packageRootPath); |
106 } | 99 } |
107 | 100 |
108 void _processAnalysisOptions(CommandLineOptions options) { | 101 void _processAnalysisOptions(CommandLineOptions options) { |
109 // Determine options file path. | 102 // Determine options file path. |
110 var filePath = options.analysisOptionsFile != null | 103 var filePath = options.analysisOptionsFile != null |
111 ? options.analysisOptionsFile | 104 ? options.analysisOptionsFile |
112 : AnalysisOptionsProvider.ANALYSIS_OPTIONS_NAME; | 105 : AnalysisOptionsProvider.ANALYSIS_OPTIONS_NAME; |
113 List<OptionsProcessor> optionsProcessors = | |
114 AnalysisEngine.instance.optionsPlugin.optionsProcessors; | |
115 try { | 106 try { |
116 var file = PhysicalResourceProvider.INSTANCE.getFile(filePath); | 107 var file = PhysicalResourceProvider.INSTANCE.getFile(filePath); |
117 AnalysisOptionsProvider analysisOptionsProvider = | 108 AnalysisOptionsProvider analysisOptionsProvider = |
118 new AnalysisOptionsProvider(); | 109 new AnalysisOptionsProvider(); |
119 Map<String, YamlNode> options = | 110 Map<String, YamlNode> options = |
120 analysisOptionsProvider.getOptionsFromFile(file); | 111 analysisOptionsProvider.getOptionsFromFile(file); |
121 optionsProcessors | 112 _pluginOptionsProcessor.optionsProcessed(options); |
122 .forEach((OptionsProcessor p) => p.optionsProcessed(options)); | |
123 } on Exception catch (e) { | 113 } on Exception catch (e) { |
124 optionsProcessors.forEach((OptionsProcessor p) => p.onError(e)); | 114 _pluginOptionsProcessor.onError(e); |
125 } | 115 } |
126 } | 116 } |
127 | |
128 void _processPlugins() { | |
129 List<Plugin> plugins = <Plugin>[]; | |
130 plugins.add(_pluginConfigProcessorPlugin); | |
131 plugins.addAll(AnalysisEngine.instance.supportedPlugins); | |
132 ExtensionManager manager = new ExtensionManager(); | |
133 manager.processPlugins(plugins); | |
134 } | |
135 } | 117 } |
136 | 118 |
137 /// A loadable "image" of a a configured analyzer instance. | 119 /// A loadable "image" of a a configured analyzer instance. |
138 class Image { | 120 class Image { |
139 /// (Optional) package root path. | 121 /// (Optional) package root path. |
140 final String packageRootPath; | 122 final String packageRootPath; |
141 | 123 |
142 /// (Optional) package map. | 124 /// (Optional) package map. |
143 final Map<String, Uri> packages; | 125 final Map<String, Uri> packages; |
144 | 126 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 // TODO(pquitslund): add .packages support once the VM implements it. | 166 // TODO(pquitslund): add .packages support once the VM implements it. |
185 Isolate.spawnUri(uri, args, null /* msg */, | 167 Isolate.spawnUri(uri, args, null /* msg */, |
186 packageRoot: packageUri, | 168 packageRoot: packageUri, |
187 onError: errorListener.sendPort, | 169 onError: errorListener.sendPort, |
188 onExit: exitListener.sendPort); | 170 onExit: exitListener.sendPort); |
189 | 171 |
190 // TODO(pquitslund): consider starting paused | 172 // TODO(pquitslund): consider starting paused |
191 // http://stackoverflow.com/questions/29247374/what-is-the-best-way-to-track
-the-state-of-an-isolate-in-dart | 173 // http://stackoverflow.com/questions/29247374/what-is-the-best-way-to-track
-the-state-of-an-isolate-in-dart |
192 } | 174 } |
193 } | 175 } |
OLD | NEW |