Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(920)

Unified Diff: pkg/analyzer/lib/src/plugin/plugin_configuration.dart

Issue 1366023002: Plugin manifest parsing. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/CHANGELOG.md ('k') | pkg/analyzer/pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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});
}
« no previous file with comments | « pkg/analyzer/CHANGELOG.md ('k') | pkg/analyzer/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698