| 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.engine_plugin; | 5 library analyzer.src.plugin.engine_plugin; |
| 6 | 6 |
| 7 import 'package:analyzer/plugin/task.dart'; | 7 import 'package:analyzer/plugin/task.dart'; |
| 8 import 'package:analyzer/src/generated/engine.dart' |
| 9 show InternalAnalysisContext; |
| 8 import 'package:analyzer/src/task/dart.dart'; | 10 import 'package:analyzer/src/task/dart.dart'; |
| 11 import 'package:analyzer/src/task/dart_work_manager.dart'; |
| 9 import 'package:analyzer/src/task/general.dart'; | 12 import 'package:analyzer/src/task/general.dart'; |
| 10 import 'package:analyzer/src/task/html.dart'; | 13 import 'package:analyzer/src/task/html.dart'; |
| 14 import 'package:analyzer/src/task/html_work_manager.dart'; |
| 11 import 'package:analyzer/task/model.dart'; | 15 import 'package:analyzer/task/model.dart'; |
| 12 import 'package:plugin/plugin.dart'; | 16 import 'package:plugin/plugin.dart'; |
| 13 | 17 |
| 14 /** | 18 /** |
| 15 * A plugin that defines the extension points and extensions that are inherently | 19 * A plugin that defines the extension points and extensions that are inherently |
| 16 * defined by the analysis engine. | 20 * defined by the analysis engine. |
| 17 */ | 21 */ |
| 18 class EnginePlugin implements Plugin { | 22 class EnginePlugin implements Plugin { |
| 19 /** | 23 /** |
| 20 * The simple identifier of the extension point that allows plugins to | 24 * The simple identifier of the extension point that allows plugins to |
| 21 * register new analysis tasks with the analysis engine. | 25 * register new analysis tasks with the analysis engine. |
| 22 */ | 26 */ |
| 23 static const String TASK_EXTENSION_POINT = 'task'; | 27 static const String TASK_EXTENSION_POINT = 'task'; |
| 24 | 28 |
| 25 /** | 29 /** |
| 30 * The simple identifier of the extension point that allows plugins to |
| 31 * register new work manager factories with the analysis engine. |
| 32 */ |
| 33 static const String WORK_MANAGER_FACTORY_EXTENSION_POINT = |
| 34 'workManagerFactory'; |
| 35 |
| 36 /** |
| 26 * The unique identifier of this plugin. | 37 * The unique identifier of this plugin. |
| 27 */ | 38 */ |
| 28 static const String UNIQUE_IDENTIFIER = 'analysis_engine.core'; | 39 static const String UNIQUE_IDENTIFIER = 'analysis_engine.core'; |
| 29 | 40 |
| 30 /** | 41 /** |
| 31 * The extension point that allows plugins to register new analysis tasks with | 42 * The extension point that allows plugins to register new analysis tasks with |
| 32 * the analysis engine. | 43 * the analysis engine. |
| 33 */ | 44 */ |
| 34 ExtensionPoint taskExtensionPoint; | 45 ExtensionPoint taskExtensionPoint; |
| 35 | 46 |
| 36 /** | 47 /** |
| 48 * The extension point that allows plugins to register new work manager |
| 49 * factories with the analysis engine. |
| 50 */ |
| 51 ExtensionPoint workManagerFactoryExtensionPoint; |
| 52 |
| 53 /** |
| 37 * Initialize a newly created plugin. | 54 * Initialize a newly created plugin. |
| 38 */ | 55 */ |
| 39 EnginePlugin(); | 56 EnginePlugin(); |
| 40 | 57 |
| 41 /** | 58 /** |
| 42 * Return a list containing all of the task descriptors that were contributed. | 59 * Return a list containing all of the task descriptors that were contributed. |
| 43 */ | 60 */ |
| 44 List<TaskDescriptor> get taskDescriptors => taskExtensionPoint.extensions; | 61 List<TaskDescriptor> get taskDescriptors => taskExtensionPoint.extensions; |
| 45 | 62 |
| 46 @override | 63 @override |
| 47 String get uniqueIdentifier => UNIQUE_IDENTIFIER; | 64 String get uniqueIdentifier => UNIQUE_IDENTIFIER; |
| 48 | 65 |
| 66 /** |
| 67 * Return a list containing all of the work manager factories that were |
| 68 * contributed. |
| 69 */ |
| 70 List<WorkManagerFactory> get workManagerFactories => |
| 71 workManagerFactoryExtensionPoint.extensions; |
| 72 |
| 49 @override | 73 @override |
| 50 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) { | 74 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) { |
| 51 taskExtensionPoint = | 75 taskExtensionPoint = |
| 52 registerExtensionPoint(TASK_EXTENSION_POINT, _validateTaskExtension); | 76 registerExtensionPoint(TASK_EXTENSION_POINT, _validateTaskExtension); |
| 77 workManagerFactoryExtensionPoint = registerExtensionPoint( |
| 78 WORK_MANAGER_FACTORY_EXTENSION_POINT, |
| 79 _validateWorkManagerFactoryExtension); |
| 53 } | 80 } |
| 54 | 81 |
| 55 @override | 82 @override |
| 56 void registerExtensions(RegisterExtension registerExtension) { | 83 void registerExtensions(RegisterExtension registerExtension) { |
| 84 _registerTaskExtensions(registerExtension); |
| 85 _registerWorkManagerFactoryExtensions(registerExtension); |
| 86 } |
| 87 |
| 88 void _registerTaskExtensions(RegisterExtension registerExtension) { |
| 57 String taskId = TASK_EXTENSION_POINT_ID; | 89 String taskId = TASK_EXTENSION_POINT_ID; |
| 58 // | 90 // |
| 59 // Register general tasks. | 91 // Register general tasks. |
| 60 // | 92 // |
| 61 registerExtension(taskId, GetContentTask.DESCRIPTOR); | 93 registerExtension(taskId, GetContentTask.DESCRIPTOR); |
| 62 // | 94 // |
| 63 // Register Dart tasks. | 95 // Register Dart tasks. |
| 64 // | 96 // |
| 65 registerExtension(taskId, BuildCompilationUnitElementTask.DESCRIPTOR); | 97 registerExtension(taskId, BuildCompilationUnitElementTask.DESCRIPTOR); |
| 66 registerExtension(taskId, BuildDirectiveElementsTask.DESCRIPTOR); | 98 registerExtension(taskId, BuildDirectiveElementsTask.DESCRIPTOR); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 90 registerExtension(taskId, ScanDartTask.DESCRIPTOR); | 122 registerExtension(taskId, ScanDartTask.DESCRIPTOR); |
| 91 registerExtension(taskId, VerifyUnitTask.DESCRIPTOR); | 123 registerExtension(taskId, VerifyUnitTask.DESCRIPTOR); |
| 92 // | 124 // |
| 93 // Register HTML tasks. | 125 // Register HTML tasks. |
| 94 // | 126 // |
| 95 registerExtension(taskId, DartScriptsTask.DESCRIPTOR); | 127 registerExtension(taskId, DartScriptsTask.DESCRIPTOR); |
| 96 registerExtension(taskId, HtmlErrorsTask.DESCRIPTOR); | 128 registerExtension(taskId, HtmlErrorsTask.DESCRIPTOR); |
| 97 registerExtension(taskId, ParseHtmlTask.DESCRIPTOR); | 129 registerExtension(taskId, ParseHtmlTask.DESCRIPTOR); |
| 98 } | 130 } |
| 99 | 131 |
| 132 void _registerWorkManagerFactoryExtensions( |
| 133 RegisterExtension registerExtension) { |
| 134 String taskId = WORK_MANAGER_EXTENSION_POINT_ID; |
| 135 registerExtension(taskId, |
| 136 (InternalAnalysisContext context) => new DartWorkManager(context)); |
| 137 registerExtension(taskId, |
| 138 (InternalAnalysisContext context) => new HtmlWorkManager(context)); |
| 139 } |
| 140 |
| 100 /** | 141 /** |
| 101 * Validate the given extension by throwing an [ExtensionError] if it is not a | 142 * Validate the given extension by throwing an [ExtensionError] if it is not a |
| 102 * valid domain. | 143 * valid domain. |
| 103 */ | 144 */ |
| 104 void _validateTaskExtension(Object extension) { | 145 void _validateTaskExtension(Object extension) { |
| 105 if (extension is! TaskDescriptor) { | 146 if (extension is! TaskDescriptor) { |
| 106 String id = taskExtensionPoint.uniqueIdentifier; | 147 String id = taskExtensionPoint.uniqueIdentifier; |
| 107 throw new ExtensionError('Extensions to $id must be a TaskDescriptor'); | 148 throw new ExtensionError('Extensions to $id must be a TaskDescriptor'); |
| 108 } | 149 } |
| 109 } | 150 } |
| 151 |
| 152 /** |
| 153 * Validate the given extension by throwing an [ExtensionError] if it is not a |
| 154 * valid domain. |
| 155 */ |
| 156 void _validateWorkManagerFactoryExtension(Object extension) { |
| 157 if (extension is! WorkManagerFactory) { |
| 158 String id = taskExtensionPoint.uniqueIdentifier; |
| 159 throw new ExtensionError( |
| 160 'Extensions to $id must be a WorkManagerFactory'); |
| 161 } |
| 162 } |
| 110 } | 163 } |
| OLD | NEW |