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'; |
11 | 11 |
12 const _pluginOptionScope = 'plugins'; | 12 const _pluginOptionScope = 'plugins'; |
13 | 13 |
14 /// Parse the given string into a plugin manifest. | |
15 PluginManifest parsePluginManifestString(String manifestSource) { | |
16 var yaml = loadYaml(manifestSource); | |
17 _verifyMap(yaml, 'plugin manifest'); | |
18 PluginInfo analyzerPlugin = _parsePlugin(yaml['analyzer-plugin']); | |
Brian Wilkerson
2015/09/24 19:22:57
I'm confused. I thought we were going to (a) have
pquitslund
2015/09/24 19:32:36
I guess I didn't want to completely rule out the p
| |
19 PluginInfo serverPlugin = _parsePlugin(yaml['server-plugin']); | |
20 return new PluginManifest( | |
21 analyzerPlugin: analyzerPlugin, serverPlugin: serverPlugin); | |
22 } | |
23 | |
24 String _asString(var yaml) { | |
25 if (yaml != null && yaml is! String) { | |
26 throw new PluginConfigFormatException( | |
27 'Unable to parse pugin manifest, ' | |
28 'expected `String`, got `${yaml.runtimeType}`', | |
29 yaml); | |
30 } | |
31 return yaml; | |
32 } | |
33 | |
34 PluginInfo _parsePlugin(dynamic yaml) { | |
35 if (yaml != null) { | |
36 _verifyMap(yaml, 'plugin manifest'); | |
37 return new PluginInfo._fromYaml(details: yaml); | |
38 } | |
39 return null; | |
40 } | |
41 | |
14 PluginInfo _processPluginMapping(dynamic name, dynamic details) { | 42 PluginInfo _processPluginMapping(dynamic name, dynamic details) { |
15 if (name is String) { | 43 if (name is String) { |
16 if (details is String) { | 44 if (details is String) { |
17 return new PluginInfo(name: name, version: details); | 45 return new PluginInfo(name: name, version: details); |
18 } | 46 } |
19 if (details is YamlMap) { | 47 if (details is YamlMap) { |
20 return new PluginInfo( | 48 return new PluginInfo._fromYaml(name: name, details: details); |
21 name: name, | |
22 version: details['version'], | |
23 className: details['class_name'], | |
24 libraryUri: details['library_uri'], | |
25 packageName: details['package_name'], | |
26 path: details['path']); | |
27 } | 49 } |
28 } | 50 } |
29 | 51 |
30 return null; | 52 return null; |
31 } | 53 } |
32 | 54 |
55 _verifyMap(dynamic yaml, String context) { | |
56 if (yaml is! YamlMap) { | |
57 throw new PluginConfigFormatException( | |
58 'Unable to parse $context, ' | |
59 'expected `YamlMap`, got `${yaml.runtimeType}`', | |
60 yaml); | |
61 } | |
62 } | |
63 | |
33 /// A callback for error handling. | 64 /// A callback for error handling. |
34 typedef ErrorHandler(Exception e); | 65 typedef ErrorHandler(Exception e); |
35 | 66 |
36 /// Describes plugin configuration information as extracted from an | 67 /// Describes plugin configuration information as extracted from an |
37 /// analysis options map. | 68 /// analysis options map or plugin manifest. |
38 class PluginConfig { | 69 class PluginConfig { |
39 final Iterable<PluginInfo> plugins; | 70 final Iterable<PluginInfo> plugins; |
40 PluginConfig(this.plugins); | 71 PluginConfig(this.plugins); |
41 | 72 |
42 /// Create a plugin configuration from an options map. | 73 /// Create a plugin configuration from an options map. |
43 factory PluginConfig.fromOptions(Map<String, YamlNode> options) { | 74 factory PluginConfig.fromOptions(Map<String, YamlNode> options) { |
44 List<PluginInfo> plugins = []; | 75 List<PluginInfo> plugins = []; |
45 var analyzerOptions = options[_analyzerOptionScope]; | 76 var analyzerOptions = options[_analyzerOptionScope]; |
46 if (analyzerOptions != null) { | 77 if (analyzerOptions != null) { |
47 if (analyzerOptions is YamlMap) { | 78 if (analyzerOptions is YamlMap) { |
48 var pluginConfig = analyzerOptions[_pluginOptionScope]; | 79 var pluginConfig = analyzerOptions[_pluginOptionScope]; |
49 if (pluginConfig is YamlMap) { | 80 if (pluginConfig is YamlMap) { |
50 pluginConfig.forEach((name, details) { | 81 pluginConfig.forEach((name, details) { |
51 var plugin = _processPluginMapping(name, details); | 82 var plugin = _processPluginMapping(name, details); |
52 if (plugin != null) { | 83 if (plugin != null) { |
53 plugins.add(plugin); | 84 plugins.add(plugin); |
54 } | 85 } |
55 }); | 86 }); |
56 } else { | 87 } else { |
57 // Anything but an empty list of plugins is treated as a format error. | 88 // Anything but an empty list of plugins is treated as a format error. |
58 if (pluginConfig != null) { | 89 if (pluginConfig != null) { |
59 throw new PluginConfigFormatException( | 90 throw new PluginConfigFormatException( |
60 'Unrecognized plugin config format (expected `YamlMap`, got `${p luginConfig.runtimeType}`)', | 91 'Unrecognized plugin config format, expected `YamlMap`, got `${p luginConfig.runtimeType}`', |
61 pluginConfig); | 92 pluginConfig); |
62 } | 93 } |
63 } | 94 } |
64 } | 95 } |
65 } | 96 } |
66 | 97 |
67 return new PluginConfig(plugins); | 98 return new PluginConfig(plugins); |
68 } | 99 } |
69 } | 100 } |
70 | 101 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 final String libraryUri; | 141 final String libraryUri; |
111 final String packageName; | 142 final String packageName; |
112 final String path; | 143 final String path; |
113 PluginInfo( | 144 PluginInfo( |
114 {this.name, | 145 {this.name, |
115 this.version, | 146 this.version, |
116 this.className, | 147 this.className, |
117 this.libraryUri, | 148 this.libraryUri, |
118 this.packageName, | 149 this.packageName, |
119 this.path}); | 150 this.path}); |
151 | |
152 factory PluginInfo._fromYaml({String name, YamlMap details}) => | |
153 new PluginInfo( | |
154 name: name, | |
155 version: _asString(details['version']), | |
156 className: _asString(details['class_name']), | |
157 libraryUri: _asString(details['library_uri']), | |
158 packageName: _asString(details['package_name']), | |
159 path: _asString(details['path'])); | |
120 } | 160 } |
161 | |
162 /// Plugin manifests accompany plugin packages, providing | |
163 /// configuration information for published plugins. | |
164 /// | |
165 /// Provisionally, plugin manifests live in a file `plugin.yaml` | |
166 /// at the root of the plugin package. | |
167 /// | |
168 /// my_plugin/ | |
169 /// bin/ | |
170 /// lib/ | |
171 /// plugin.yaml | |
172 /// pubspec.yaml | |
173 /// | |
174 /// Provisional manifest file format: | |
175 /// | |
176 /// analyzer-plugin: | |
177 /// class_name: MyAnalyzerPlugin | |
178 /// library_uri: 'my_plugin/my_analyzer_plugin.dart' | |
179 /// server-plugin: | |
180 /// class_name: MyServerPlugin | |
181 /// library_uri: 'my_plugin/my_server_plugin.dart' | |
182 /// | |
183 class PluginManifest { | |
184 PluginInfo analyzerPlugin; | |
185 PluginInfo serverPlugin; | |
186 PluginManifest({this.analyzerPlugin, this.serverPlugin}); | |
187 } | |
OLD | NEW |