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

Side by Side Diff: pkg/analyzer/lib/src/plugin/plugin_configuration.dart

Issue 1364493004: Basic plugin config parsing. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: sync 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 unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/src/plugin/plugin_config_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library analyzer.src.plugin.plugin_configuration;
6
7 import 'package:analyzer/plugin/options.dart';
8 import 'package:yaml/yaml.dart';
9
10 const _analyzerOptionScope = 'analyzer';
11
12 const _pluginOptionScope = 'plugins';
13
14 PluginInfo _processPluginMapping(dynamic name, dynamic details) {
15 if (name is String) {
16 if (details is String) {
17 return new PluginInfo(name: name, version: details);
18 }
19 if (details is YamlMap) {
20 return new PluginInfo(
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 }
28 }
29
30 return null;
31 }
32
33 PluginInfo _processPluginNode(dynamic node) {
34 if (node is String) {
35 return new PluginInfo(name: node);
36 }
37 if (node is YamlMap) {
38 if (node.length == 1) {
39 return new PluginInfo(name: node.keys.first, version: node.values.first);
40 }
41 }
42 return null;
43 }
44
45 typedef ErrorHandler(Exception);
46
47 /// Describes plugin configuration information as extracted from an
48 /// analysis options map.
49 class PluginConfig {
50 final Iterable<PluginInfo> plugins;
51 PluginConfig(this.plugins);
52
53 /// Create a plugin configuration from an options map.
54 factory PluginConfig.fromOptions(Map<String, YamlNode> options) {
55 List<PluginInfo> plugins = [];
56 var analyzerOptions = options[_analyzerOptionScope];
57 if (analyzerOptions != null) {
58 if (analyzerOptions is YamlMap) {
59 var pluginConfig = analyzerOptions[_pluginOptionScope];
60 if (pluginConfig is YamlMap) {
61 pluginConfig.forEach((name, details) {
62 var plugin = _processPluginMapping(name, details);
63 if (plugin != null) {
64 plugins.add(plugin);
65 }
66 });
67 } else {
68 var plugin = _processPluginNode(pluginConfig);
69 if (plugin != null) {
70 plugins.add(plugin);
71 }
72 }
73 }
74 }
75
76 return new PluginConfig(plugins);
77 }
78 }
79
80 /// Extracts plugin config details from analysis options.
81 class PluginConfigOptionsProcessor extends OptionsProcessor {
82 final ErrorHandler _errorHandler;
83
84 PluginConfig _config;
85
86 PluginConfigOptionsProcessor([this._errorHandler]);
87
88 /// The processed plugin config.
89 PluginConfig get config => _config;
90
91 @override
92 void onError(Exception exception) {
93 if (_errorHandler != null) {
94 _errorHandler(exception);
95 }
96 }
97
98 @override
99 void optionsProcessed(Map<String, YamlNode> options) {
100 _config = new PluginConfig.fromOptions(options);
101 }
102 }
103
104 /// Describes plugin information.
105 class PluginInfo {
106 final String name;
107 final String className;
108 final String version;
109 final String libraryUri;
110 final String packageName;
111 final String path;
112 PluginInfo(
113 {this.name,
114 this.version,
115 this.className,
116 this.libraryUri,
117 this.packageName,
118 this.path});
119 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/plugin/plugin_config_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698