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

Side by Side Diff: pkg/analysis_server/lib/src/plugin/plugin_watcher.dart

Issue 2988343002: Initial support for an explicit plugin list (Closed)
Patch Set: Created 3 years, 4 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/analysis_server/lib/src/status/diagnostics.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 import 'package:analysis_server/src/plugin/plugin_locator.dart'; 5 import 'package:analysis_server/src/plugin/plugin_locator.dart';
6 import 'package:analysis_server/src/plugin/plugin_manager.dart'; 6 import 'package:analysis_server/src/plugin/plugin_manager.dart';
7 import 'package:analyzer/context/context_root.dart'; 7 import 'package:analyzer/context/context_root.dart';
8 import 'package:analyzer/file_system/file_system.dart'; 8 import 'package:analyzer/file_system/file_system.dart';
9 import 'package:analyzer/source/package_map_resolver.dart'; 9 import 'package:analyzer/source/package_map_resolver.dart';
10 import 'package:analyzer/src/dart/analysis/driver.dart'; 10 import 'package:analyzer/src/dart/analysis/driver.dart';
11 import 'package:analyzer/src/dart/analysis/file_state.dart'; 11 import 'package:analyzer/src/dart/analysis/file_state.dart';
12 import 'package:analyzer/src/util/absolute_path.dart'; 12 import 'package:analyzer/src/util/absolute_path.dart';
13 import 'package:front_end/src/base/source.dart';
14 import 'package:path/src/context.dart';
13 15
14 /** 16 /**
15 * An object that watches the results produced by analysis drivers to identify 17 * An object that watches the results produced by analysis drivers to identify
16 * references to previously unseen packages and, if those packages have plugins 18 * references to previously unseen packages and, if those packages have plugins
17 * associated with them, causes the plugin to be associated with the driver's 19 * associated with them, causes the plugin to be associated with the driver's
18 * context root (which in turn might cause the plugin to be started). 20 * context root (which in turn might cause the plugin to be started).
19 */ 21 */
20 class PluginWatcher implements DriverWatcher { 22 class PluginWatcher implements DriverWatcher {
21 /** 23 /**
22 * The resource provider used to access the file system. 24 * The resource provider used to access the file system.
(...skipping 22 matching lines...) Expand all
45 PluginWatcher(this.resourceProvider, this.manager) 47 PluginWatcher(this.resourceProvider, this.manager)
46 : _locator = new PluginLocator(resourceProvider); 48 : _locator = new PluginLocator(resourceProvider);
47 49
48 /** 50 /**
49 * The context manager has just added the given analysis [driver]. This method 51 * The context manager has just added the given analysis [driver]. This method
50 * must be called before the driver has been allowed to perform any analysis. 52 * must be called before the driver has been allowed to perform any analysis.
51 */ 53 */
52 void addedDriver(AnalysisDriver driver, ContextRoot contextRoot) { 54 void addedDriver(AnalysisDriver driver, ContextRoot contextRoot) {
53 _driverInfo[driver] = new _DriverInfo( 55 _driverInfo[driver] = new _DriverInfo(
54 contextRoot, <String>[contextRoot.root, _getSdkPath(driver)]); 56 contextRoot, <String>[contextRoot.root, _getSdkPath(driver)]);
55 driver.fsState.knownFilesSetChanges.listen((KnownFilesSetChange change) { 57 List<String> enabledPlugins = driver.analysisOptions.enabledPluginNames;
56 List<String> addedPluginPaths = _checkPluginsFor(driver, change); 58 if (enabledPlugins.isNotEmpty) {
57 for (String pluginPath in addedPluginPaths) { 59 for (String package in enabledPlugins) {
58 manager.addPluginToContextRoot(contextRoot, pluginPath); 60 //
61 // Determine whether the package exists and defines a plugin.
62 //
63 Source source =
64 driver.sourceFactory.forUri('package:$package/$package.dart');
65 Context context = resourceProvider.pathContext;
66 String packageRoot = context.dirname(context.dirname(source.fullName));
67 String pluginPath = _locator.findPlugin(packageRoot);
68 if (pluginPath != null) {
69 //
70 // Add the plugin to the context root.
71 //
72 // TODO(brianwilkerson) Do we need to wait for the plugin to be added?
73 // If we don't, then tests don't have any way to know when to expect
74 // that the list of plugins has been updated.
75 manager.addPluginToContextRoot(contextRoot, pluginPath);
76 }
59 } 77 }
60 }); 78 } else {
79 //
80 // Remove this code after users are switched over to use an explicit list
81 // of plugins.
82 //
83 driver.fsState.knownFilesSetChanges.listen((KnownFilesSetChange change) {
84 List<String> addedPluginPaths = _checkPluginsFor(driver, change);
85 for (String pluginPath in addedPluginPaths) {
86 manager.addPluginToContextRoot(contextRoot, pluginPath);
87 }
88 });
89 }
61 } 90 }
62 91
63 /** 92 /**
64 * The context manager has just removed the given analysis [driver]. 93 * The context manager has just removed the given analysis [driver].
65 */ 94 */
66 void removedDriver(AnalysisDriver driver) { 95 void removedDriver(AnalysisDriver driver) {
67 _DriverInfo info = _driverInfo[driver]; 96 _DriverInfo info = _driverInfo[driver];
68 if (info == null) { 97 if (info == null) {
69 throw new StateError('Cannot remove a driver that was not added'); 98 throw new StateError('Cannot remove a driver that was not added');
70 } 99 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 * A list of the absolute paths of directories inside of which we have already 185 * A list of the absolute paths of directories inside of which we have already
157 * searched for a plugin. 186 * searched for a plugin.
158 */ 187 */
159 final List<String> packageRoots; 188 final List<String> packageRoots;
160 189
161 /** 190 /**
162 * Initialize a newly created information holder. 191 * Initialize a newly created information holder.
163 */ 192 */
164 _DriverInfo(this.contextRoot, this.packageRoots); 193 _DriverInfo(this.contextRoot, this.packageRoots);
165 } 194 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/status/diagnostics.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698