Index: pkg/analyzer/lib/src/plugin/plugin_configuration.dart |
diff --git a/pkg/analyzer/lib/src/plugin/plugin_configuration.dart b/pkg/analyzer/lib/src/plugin/plugin_configuration.dart |
index 9809bdcfea4178342983ae43647eb0e7075945c7..baa4d64f5f49770f581c7fe9b0e9329d8ac6a020 100644 |
--- a/pkg/analyzer/lib/src/plugin/plugin_configuration.dart |
+++ b/pkg/analyzer/lib/src/plugin/plugin_configuration.dart |
@@ -11,30 +11,61 @@ const _analyzerOptionScope = 'analyzer'; |
const _pluginOptionScope = 'plugins'; |
+/// Parse the given string into a plugin manifest. |
+PluginManifest parsePluginManifestString(String manifestSource) { |
+ var yaml = loadYaml(manifestSource); |
+ _verifyMap(yaml, 'plugin manifest'); |
+ 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
|
+ PluginInfo serverPlugin = _parsePlugin(yaml['server-plugin']); |
+ return new PluginManifest( |
+ analyzerPlugin: analyzerPlugin, serverPlugin: serverPlugin); |
+} |
+ |
+String _asString(var yaml) { |
+ if (yaml != null && yaml is! String) { |
+ throw new PluginConfigFormatException( |
+ 'Unable to parse pugin manifest, ' |
+ 'expected `String`, got `${yaml.runtimeType}`', |
+ yaml); |
+ } |
+ return yaml; |
+} |
+ |
+PluginInfo _parsePlugin(dynamic yaml) { |
+ if (yaml != null) { |
+ _verifyMap(yaml, 'plugin manifest'); |
+ return new PluginInfo._fromYaml(details: yaml); |
+ } |
+ return null; |
+} |
+ |
PluginInfo _processPluginMapping(dynamic name, dynamic details) { |
if (name is String) { |
if (details is String) { |
return new PluginInfo(name: name, version: details); |
} |
if (details is YamlMap) { |
- return new PluginInfo( |
- name: name, |
- version: details['version'], |
- className: details['class_name'], |
- libraryUri: details['library_uri'], |
- packageName: details['package_name'], |
- path: details['path']); |
+ return new PluginInfo._fromYaml(name: name, details: details); |
} |
} |
return null; |
} |
+_verifyMap(dynamic yaml, String context) { |
+ if (yaml is! YamlMap) { |
+ throw new PluginConfigFormatException( |
+ 'Unable to parse $context, ' |
+ 'expected `YamlMap`, got `${yaml.runtimeType}`', |
+ yaml); |
+ } |
+} |
+ |
/// A callback for error handling. |
typedef ErrorHandler(Exception e); |
/// Describes plugin configuration information as extracted from an |
-/// analysis options map. |
+/// analysis options map or plugin manifest. |
class PluginConfig { |
final Iterable<PluginInfo> plugins; |
PluginConfig(this.plugins); |
@@ -57,7 +88,7 @@ class PluginConfig { |
// Anything but an empty list of plugins is treated as a format error. |
if (pluginConfig != null) { |
throw new PluginConfigFormatException( |
- 'Unrecognized plugin config format (expected `YamlMap`, got `${pluginConfig.runtimeType}`)', |
+ 'Unrecognized plugin config format, expected `YamlMap`, got `${pluginConfig.runtimeType}`', |
pluginConfig); |
} |
} |
@@ -117,4 +148,40 @@ class PluginInfo { |
this.libraryUri, |
this.packageName, |
this.path}); |
+ |
+ factory PluginInfo._fromYaml({String name, YamlMap details}) => |
+ new PluginInfo( |
+ name: name, |
+ version: _asString(details['version']), |
+ className: _asString(details['class_name']), |
+ libraryUri: _asString(details['library_uri']), |
+ packageName: _asString(details['package_name']), |
+ path: _asString(details['path'])); |
+} |
+ |
+/// Plugin manifests accompany plugin packages, providing |
+/// configuration information for published plugins. |
+/// |
+/// Provisionally, plugin manifests live in a file `plugin.yaml` |
+/// at the root of the plugin package. |
+/// |
+/// my_plugin/ |
+/// bin/ |
+/// lib/ |
+/// plugin.yaml |
+/// pubspec.yaml |
+/// |
+/// Provisional manifest file format: |
+/// |
+/// analyzer-plugin: |
+/// class_name: MyAnalyzerPlugin |
+/// library_uri: 'my_plugin/my_analyzer_plugin.dart' |
+/// server-plugin: |
+/// class_name: MyServerPlugin |
+/// library_uri: 'my_plugin/my_server_plugin.dart' |
+/// |
+class PluginManifest { |
+ PluginInfo analyzerPlugin; |
+ PluginInfo serverPlugin; |
+ PluginManifest({this.analyzerPlugin, this.serverPlugin}); |
} |