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

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: Test updates. 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
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..9bd0da3973901528cfd16527d788b9e1a3027240 100644
--- a/pkg/analyzer/lib/src/plugin/plugin_configuration.dart
+++ b/pkg/analyzer/lib/src/plugin/plugin_configuration.dart
@@ -11,30 +11,75 @@ const _analyzerOptionScope = 'analyzer';
const _pluginOptionScope = 'plugins';
+/// Parse the given string into a plugin manifest.
+PluginManifest parsePluginManifestString(String manifestSource) {
+ var yaml = loadYaml(manifestSource);
+ if (yaml == null) {
+ return null;
+ }
+ _verifyMap(yaml, 'plugin manifest');
+ Iterable<String> pluginHost = _parseHosts(yaml['contributes_to']);
+ PluginInfo plugin = _parsePlugin(yaml);
+ return new PluginManifest(contributesTo: pluginHost, plugin: plugin);
+}
+
+String _asString(dynamic yaml) {
+ if (yaml != null && yaml is! String) {
+ throw new PluginConfigFormatException(
+ 'Unable to parse pugin manifest, '
+ 'expected `String`, got `${yaml.runtimeType}`',
+ yaml);
+ }
+ return yaml;
+}
+
+Iterable<String> _parseHosts(dynamic yaml) {
+ List<String> hosts = <String>[];
+ if (yaml is String) {
+ hosts.add(yaml);
+ } else if (yaml is YamlList) {
+ yaml.forEach((h) {
+ hosts.add(_asString(h));
+ });
+ }
+ return hosts;
+}
+
+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 +102,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 +162,36 @@ 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:
+///
+/// class_name: MyAnalyzerPlugin
+/// library_uri: 'my_plugin/my_analyzer_plugin.dart'
+/// contributes_to: analyzer
+class PluginManifest {
+ PluginInfo plugin;
+ Iterable<String> contributesTo;
+ PluginManifest({this.plugin, this.contributesTo});
}

Powered by Google App Engine
This is Rietveld 408576698