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.src.plugin.plugin_configuration; | 5 library analyzer.src.plugin.plugin_configuration; |
6 | 6 |
7 import 'package:analyzer/plugin/options.dart'; | 7 import 'package:analyzer/plugin/options.dart'; |
8 import 'package:yaml/yaml.dart'; | 8 import 'package:yaml/yaml.dart'; |
9 | 9 |
10 const _analyzerOptionScope = 'analyzer'; | 10 const _analyzerOptionScope = 'analyzer'; |
(...skipping 13 matching lines...) Expand all Loading... |
24 libraryUri: details['library_uri'], | 24 libraryUri: details['library_uri'], |
25 packageName: details['package_name'], | 25 packageName: details['package_name'], |
26 path: details['path']); | 26 path: details['path']); |
27 } | 27 } |
28 } | 28 } |
29 | 29 |
30 return null; | 30 return null; |
31 } | 31 } |
32 | 32 |
33 PluginInfo _processPluginNode(dynamic node) { | 33 PluginInfo _processPluginNode(dynamic node) { |
34 if (node is String) { | |
35 return new PluginInfo(name: node); | |
36 } | |
37 if (node is YamlMap) { | 34 if (node is YamlMap) { |
38 if (node.length == 1) { | 35 if (node.length == 1) { |
39 return new PluginInfo(name: node.keys.first, version: node.values.first); | 36 return new PluginInfo(name: node.keys.first, version: node.values.first); |
40 } | 37 } |
41 } | 38 } |
42 return null; | 39 return null; |
43 } | 40 } |
44 | 41 |
45 typedef ErrorHandler(Exception); | 42 typedef ErrorHandler(Exception); |
46 | 43 |
(...skipping 11 matching lines...) Expand all Loading... |
58 if (analyzerOptions is YamlMap) { | 55 if (analyzerOptions is YamlMap) { |
59 var pluginConfig = analyzerOptions[_pluginOptionScope]; | 56 var pluginConfig = analyzerOptions[_pluginOptionScope]; |
60 if (pluginConfig is YamlMap) { | 57 if (pluginConfig is YamlMap) { |
61 pluginConfig.forEach((name, details) { | 58 pluginConfig.forEach((name, details) { |
62 var plugin = _processPluginMapping(name, details); | 59 var plugin = _processPluginMapping(name, details); |
63 if (plugin != null) { | 60 if (plugin != null) { |
64 plugins.add(plugin); | 61 plugins.add(plugin); |
65 } | 62 } |
66 }); | 63 }); |
67 } else { | 64 } else { |
68 var plugin = _processPluginNode(pluginConfig); | 65 // Anything but an empty list of plugins is treated as a format error. |
69 if (plugin != null) { | 66 if (pluginConfig != null) { |
70 plugins.add(plugin); | 67 throw new PluginConfigFormatException( |
| 68 'Unrecognized plugin config format (expected `YamlMap`, got `${p
luginConfig.runtimeType}`)', |
| 69 pluginConfig); |
71 } | 70 } |
72 } | 71 } |
73 } | 72 } |
74 } | 73 } |
75 | 74 |
76 return new PluginConfig(plugins); | 75 return new PluginConfig(plugins); |
77 } | 76 } |
78 } | 77 } |
79 | 78 |
| 79 /// Thrown on bad plugin config format. |
| 80 class PluginConfigFormatException implements Exception { |
| 81 /// Descriptive message. |
| 82 final message; |
| 83 |
| 84 /// The `plugin:` yaml node for generating detailed error feedback. |
| 85 final yamlNode; |
| 86 PluginConfigFormatException(this.message, this.yamlNode); |
| 87 } |
| 88 |
80 /// Extracts plugin config details from analysis options. | 89 /// Extracts plugin config details from analysis options. |
81 class PluginConfigOptionsProcessor extends OptionsProcessor { | 90 class PluginConfigOptionsProcessor extends OptionsProcessor { |
82 final ErrorHandler _errorHandler; | 91 final ErrorHandler _errorHandler; |
83 | 92 |
84 PluginConfig _config; | 93 PluginConfig _config; |
85 | 94 |
86 PluginConfigOptionsProcessor([this._errorHandler]); | 95 PluginConfigOptionsProcessor([this._errorHandler]); |
87 | 96 |
88 /// The processed plugin config. | 97 /// The processed plugin config. |
89 PluginConfig get config => _config; | 98 PluginConfig get config => _config; |
(...skipping 20 matching lines...) Expand all Loading... |
110 final String packageName; | 119 final String packageName; |
111 final String path; | 120 final String path; |
112 PluginInfo( | 121 PluginInfo( |
113 {this.name, | 122 {this.name, |
114 this.version, | 123 this.version, |
115 this.className, | 124 this.className, |
116 this.libraryUri, | 125 this.libraryUri, |
117 this.packageName, | 126 this.packageName, |
118 this.path}); | 127 this.path}); |
119 } | 128 } |
OLD | NEW |