| 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:analyzer/src/generated/engine.dart'; |
| 8 import 'package:yaml/yaml.dart'; | 9 import 'package:yaml/yaml.dart'; |
| 9 | 10 |
| 10 const _analyzerOptionScope = 'analyzer'; | 11 const _analyzerOptionScope = 'analyzer'; |
| 11 | 12 |
| 12 const _pluginOptionScope = 'plugins'; | 13 const _pluginOptionScope = 'plugins'; |
| 13 | 14 |
| 14 /// Parse the given string into a plugin manifest. | 15 /// Parse the given string into a plugin manifest. |
| 15 PluginManifest parsePluginManifestString(String manifestSource) { | 16 PluginManifest parsePluginManifestString(String manifestSource) { |
| 16 var yaml = loadYaml(manifestSource); | 17 var yaml = loadYaml(manifestSource); |
| 17 if (yaml == null) { | 18 if (yaml == null) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 31 yaml); | 32 yaml); |
| 32 } | 33 } |
| 33 return yaml; | 34 return yaml; |
| 34 } | 35 } |
| 35 | 36 |
| 36 Iterable<String> _parseHosts(dynamic yaml) { | 37 Iterable<String> _parseHosts(dynamic yaml) { |
| 37 List<String> hosts = <String>[]; | 38 List<String> hosts = <String>[]; |
| 38 if (yaml is String) { | 39 if (yaml is String) { |
| 39 hosts.add(yaml); | 40 hosts.add(yaml); |
| 40 } else if (yaml is YamlList) { | 41 } else if (yaml is YamlList) { |
| 41 yaml.forEach((h) { | 42 yaml.forEach((h) => hosts.add(_asString(h))); |
| 42 hosts.add(_asString(h)); | |
| 43 }); | |
| 44 } | 43 } |
| 45 return hosts; | 44 return hosts; |
| 46 } | 45 } |
| 47 | 46 |
| 48 PluginInfo _parsePlugin(dynamic yaml) { | 47 PluginInfo _parsePlugin(dynamic yaml) { |
| 49 if (yaml != null) { | 48 if (yaml != null) { |
| 50 _verifyMap(yaml, 'plugin manifest'); | 49 _verifyMap(yaml, 'plugin manifest'); |
| 51 return new PluginInfo._fromYaml(details: yaml); | 50 return new PluginInfo._fromYaml(details: yaml); |
| 52 } | 51 } |
| 53 return null; | 52 return null; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 pluginConfig.forEach((name, details) { | 94 pluginConfig.forEach((name, details) { |
| 96 var plugin = _processPluginMapping(name, details); | 95 var plugin = _processPluginMapping(name, details); |
| 97 if (plugin != null) { | 96 if (plugin != null) { |
| 98 plugins.add(plugin); | 97 plugins.add(plugin); |
| 99 } | 98 } |
| 100 }); | 99 }); |
| 101 } else { | 100 } else { |
| 102 // Anything but an empty list of plugins is treated as a format error. | 101 // Anything but an empty list of plugins is treated as a format error. |
| 103 if (pluginConfig != null) { | 102 if (pluginConfig != null) { |
| 104 throw new PluginConfigFormatException( | 103 throw new PluginConfigFormatException( |
| 105 'Unrecognized plugin config format, expected `YamlMap`, got `${p
luginConfig.runtimeType}`', | 104 'Unrecognized plugin config format, expected `YamlMap`, ' |
| 105 'got `${pluginConfig.runtimeType}`', |
| 106 pluginConfig); | 106 pluginConfig); |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 | 111 |
| 112 return new PluginConfig(plugins); | 112 return new PluginConfig(plugins); |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 | 115 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 135 PluginConfig get config => _config; | 135 PluginConfig get config => _config; |
| 136 | 136 |
| 137 @override | 137 @override |
| 138 void onError(Exception exception) { | 138 void onError(Exception exception) { |
| 139 if (_errorHandler != null) { | 139 if (_errorHandler != null) { |
| 140 _errorHandler(exception); | 140 _errorHandler(exception); |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 | 143 |
| 144 @override | 144 @override |
| 145 void optionsProcessed(Map<String, YamlNode> options) { | 145 void optionsProcessed( |
| 146 AnalysisContext context, Map<String, YamlNode> options) { |
| 146 _config = new PluginConfig.fromOptions(options); | 147 _config = new PluginConfig.fromOptions(options); |
| 147 } | 148 } |
| 148 } | 149 } |
| 149 | 150 |
| 150 /// Describes plugin information. | 151 /// Describes plugin information. |
| 151 class PluginInfo { | 152 class PluginInfo { |
| 152 final String name; | 153 final String name; |
| 153 final String className; | 154 final String className; |
| 154 final String version; | 155 final String version; |
| 155 final String libraryUri; | 156 final String libraryUri; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 /// Provisional manifest file format: | 189 /// Provisional manifest file format: |
| 189 /// | 190 /// |
| 190 /// class_name: MyAnalyzerPlugin | 191 /// class_name: MyAnalyzerPlugin |
| 191 /// library_uri: 'my_plugin/my_analyzer_plugin.dart' | 192 /// library_uri: 'my_plugin/my_analyzer_plugin.dart' |
| 192 /// contributes_to: analyzer | 193 /// contributes_to: analyzer |
| 193 class PluginManifest { | 194 class PluginManifest { |
| 194 PluginInfo plugin; | 195 PluginInfo plugin; |
| 195 Iterable<String> contributesTo; | 196 Iterable<String> contributesTo; |
| 196 PluginManifest({this.plugin, this.contributesTo}); | 197 PluginManifest({this.plugin, this.contributesTo}); |
| 197 } | 198 } |
| OLD | NEW |