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

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

Issue 3003663002: Remove the auto-discovery of plugins (Closed)
Patch Set: Created 3 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
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';
10 import 'package:analyzer/src/dart/analysis/driver.dart'; 9 import 'package:analyzer/src/dart/analysis/driver.dart';
11 import 'package:analyzer/src/dart/analysis/file_state.dart';
12 import 'package:analyzer/src/util/absolute_path.dart'; 10 import 'package:analyzer/src/util/absolute_path.dart';
13 import 'package:front_end/src/base/source.dart'; 11 import 'package:front_end/src/base/source.dart';
14 import 'package:path/src/context.dart'; 12 import 'package:path/src/context.dart';
15 13
16 /** 14 /**
17 * An object that watches the results produced by analysis drivers to identify 15 * An object that watches the results produced by analysis drivers to identify
18 * references to previously unseen packages and, if those packages have plugins 16 * references to previously unseen packages and, if those packages have plugins
19 * associated with them, causes the plugin to be associated with the driver's 17 * associated with them, causes the plugin to be associated with the driver's
20 * context root (which in turn might cause the plugin to be started). 18 * context root (which in turn might cause the plugin to be started).
21 */ 19 */
(...skipping 26 matching lines...) Expand all
48 : _locator = new PluginLocator(resourceProvider); 46 : _locator = new PluginLocator(resourceProvider);
49 47
50 /** 48 /**
51 * The context manager has just added the given analysis [driver]. This method 49 * The context manager has just added the given analysis [driver]. This method
52 * must be called before the driver has been allowed to perform any analysis. 50 * must be called before the driver has been allowed to perform any analysis.
53 */ 51 */
54 void addedDriver(AnalysisDriver driver, ContextRoot contextRoot) { 52 void addedDriver(AnalysisDriver driver, ContextRoot contextRoot) {
55 _driverInfo[driver] = new _DriverInfo( 53 _driverInfo[driver] = new _DriverInfo(
56 contextRoot, <String>[contextRoot.root, _getSdkPath(driver)]); 54 contextRoot, <String>[contextRoot.root, _getSdkPath(driver)]);
57 List<String> enabledPlugins = driver.analysisOptions.enabledPluginNames; 55 List<String> enabledPlugins = driver.analysisOptions.enabledPluginNames;
58 if (enabledPlugins.isNotEmpty) { 56 for (String package in enabledPlugins) {
59 for (String package in enabledPlugins) { 57 //
58 // Determine whether the package exists and defines a plugin.
59 //
60 Source source =
61 driver.sourceFactory.forUri('package:$package/$package.dart');
62 Context context = resourceProvider.pathContext;
63 String packageRoot = context.dirname(context.dirname(source.fullName));
64 String pluginPath = _locator.findPlugin(packageRoot);
65 if (pluginPath != null) {
60 // 66 //
61 // Determine whether the package exists and defines a plugin. 67 // Add the plugin to the context root.
62 // 68 //
63 Source source = 69 // TODO(brianwilkerson) Do we need to wait for the plugin to be added?
64 driver.sourceFactory.forUri('package:$package/$package.dart'); 70 // If we don't, then tests don't have any way to know when to expect
65 Context context = resourceProvider.pathContext; 71 // that the list of plugins has been updated.
66 String packageRoot = context.dirname(context.dirname(source.fullName)); 72 manager.addPluginToContextRoot(contextRoot, pluginPath);
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 }
77 } 73 }
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 } 74 }
90 } 75 }
91 76
92 /** 77 /**
93 * The context manager has just removed the given analysis [driver]. 78 * The context manager has just removed the given analysis [driver].
94 */ 79 */
95 void removedDriver(AnalysisDriver driver) { 80 void removedDriver(AnalysisDriver driver) {
96 _DriverInfo info = _driverInfo[driver]; 81 _DriverInfo info = _driverInfo[driver];
97 if (info == null) { 82 if (info == null) {
98 throw new StateError('Cannot remove a driver that was not added'); 83 throw new StateError('Cannot remove a driver that was not added');
99 } 84 }
100 manager.removedContextRoot(info.contextRoot); 85 manager.removedContextRoot(info.contextRoot);
101 _driverInfo.remove(driver); 86 _driverInfo.remove(driver);
102 } 87 }
103 88
104 /** 89 /**
105 * Check all of the files that have been analyzed so far by the given [driver]
106 * to see whether any of them are in a package that had not previously been
107 * seen that defines a plugin. Return a list of the roots of all such plugins
108 * that are found.
109 */
110 List<String> _checkPluginsFor(
111 AnalysisDriver driver, KnownFilesSetChange change) {
112 _DriverInfo info = _driverInfo[driver];
113 if (info == null) {
114 // The driver must have been removed prior to getting the notification of
115 // newly analyzed files.
116 return const <String>[];
117 }
118 List<String> packageRoots = info.packageRoots;
119 FileSystemState fileSystemState = driver.fsState;
120 AbsolutePathContext context = resourceProvider.absolutePathContext;
121
122 bool isInRoot(String path) {
123 for (String root in packageRoots) {
124 if (context.isWithin(root, path)) {
125 return true;
126 }
127 }
128 return false;
129 }
130
131 String getPackageRoot(String path, Uri uri) {
132 List<String> segments = uri.pathSegments.toList();
133 segments[0] = 'lib';
134 String suffix = resourceProvider.pathContext.joinAll(segments);
135 return path.substring(0, path.length - suffix.length - 1);
136 }
137
138 List<String> addedPluginPaths = <String>[];
139 for (String path in change.added) {
140 FileState state = fileSystemState.getFileForPath(path);
141 if (!isInRoot(path)) {
142 // Found a file not in a previously known package.
143 Uri uri = state.uri;
144 if (PackageMapUriResolver.isPackageUri(uri)) {
145 String packageRoot = getPackageRoot(path, uri);
146 packageRoots.add(packageRoot);
147 String pluginPath = _locator.findPlugin(packageRoot);
148 if (pluginPath != null) {
149 addedPluginPaths.add(pluginPath);
150 }
151 }
152 }
153 }
154 return addedPluginPaths;
155 }
156
157 /**
158 * Return the path to the root of the SDK being used by the given analysis 90 * Return the path to the root of the SDK being used by the given analysis
159 * [driver]. 91 * [driver].
160 */ 92 */
161 String _getSdkPath(AnalysisDriver driver) { 93 String _getSdkPath(AnalysisDriver driver) {
162 AbsolutePathContext context = resourceProvider.absolutePathContext; 94 AbsolutePathContext context = resourceProvider.absolutePathContext;
163 String sdkRoot = driver.sourceFactory.forUri('dart:core').fullName; 95 String sdkRoot = driver.sourceFactory.forUri('dart:core').fullName;
164 while (context.basename(sdkRoot) != 'lib') { 96 while (context.basename(sdkRoot) != 'lib') {
165 String parent = context.dirname(sdkRoot); 97 String parent = context.dirname(sdkRoot);
166 if (parent == sdkRoot) { 98 if (parent == sdkRoot) {
167 break; 99 break;
(...skipping 17 matching lines...) Expand all
185 * A list of the absolute paths of directories inside of which we have already 117 * A list of the absolute paths of directories inside of which we have already
186 * searched for a plugin. 118 * searched for a plugin.
187 */ 119 */
188 final List<String> packageRoots; 120 final List<String> packageRoots;
189 121
190 /** 122 /**
191 * Initialize a newly created information holder. 123 * Initialize a newly created information holder.
192 */ 124 */
193 _DriverInfo(this.contextRoot, this.packageRoots); 125 _DriverInfo(this.contextRoot, this.packageRoots);
194 } 126 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/plugin/plugin_manager.dart ('k') | pkg/analysis_server/test/analysis_abstract.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698