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

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

Issue 2754473005: Improve performance of PluginLocator by caching results (Closed)
Patch Set: Created 3 years, 9 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 | no next file » | 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:analyzer/file_system/file_system.dart'; 5 import 'package:analyzer/file_system/file_system.dart';
6 import 'package:yaml/yaml.dart'; 6 import 'package:yaml/yaml.dart';
7 7
8 /** 8 /**
9 * An object used to locate a plugin within a package. 9 * An object used to locate a plugin within a package.
10 */ 10 */
(...skipping 19 matching lines...) Expand all
30 * The name of the `tools` directory, in which the default plugin directory is 30 * The name of the `tools` directory, in which the default plugin directory is
31 * located. 31 * located.
32 */ 32 */
33 static const String toolsFolderName = 'tools'; 33 static const String toolsFolderName = 'tools';
34 34
35 /** 35 /**
36 * The resource provider used to access the file system. 36 * The resource provider used to access the file system.
37 */ 37 */
38 final ResourceProvider resourceProvider; 38 final ResourceProvider resourceProvider;
39 39
40 final Map<String, String> pluginMap = <String, String>{};
41
40 /** 42 /**
41 * Initialize a newly created plugin locator to use the given 43 * Initialize a newly created plugin locator to use the given
42 * [resourceProvider] to access the file system. 44 * [resourceProvider] to access the file system.
43 */ 45 */
44 PluginLocator(this.resourceProvider); 46 PluginLocator(this.resourceProvider);
45 47
46 /** 48 /**
47 * Given the root directory of a package (the [packageRoot]), return the path 49 * Given the root directory of a package (the [packageRoot]), return the path
48 * to the plugin associated with the package, or `null` if there is no plugin 50 * to the plugin associated with the package, or `null` if there is no plugin
49 * associated with the package. 51 * associated with the package.
50 * 52 *
51 * This will look first in the `pubspec.yaml` file in the package root for a 53 * This will look first in the `pubspec.yaml` file in the package root for a
52 * key indicating where the plugin is located. If such a key is not defined, 54 * key indicating where the plugin is located. If such a key is not defined,
53 * then it will fall back to a well known location within the package. 55 * then it will fall back to a well known location within the package.
54 * 56 *
55 * This method does not validate the content of the plugin directory before 57 * This method does not validate the content of the plugin directory before
56 * returning it. 58 * returning it.
57 */ 59 */
58 String findPlugin(String packageRoot) { 60 String findPlugin(String packageRoot) {
61 return pluginMap.putIfAbsent(packageRoot, () => _findPlugin(packageRoot));
62 }
63
64 /**
65 * The implementation of [findPlugin].
66 */
67 String _findPlugin(String packageRoot) {
59 Folder packageFolder = resourceProvider.getFolder(packageRoot); 68 Folder packageFolder = resourceProvider.getFolder(packageRoot);
60 File pubspecFile = packageFolder.getChildAssumingFile(pubspecFileName); 69 File pubspecFile = packageFolder.getChildAssumingFile(pubspecFileName);
61 if (pubspecFile.exists) { 70 if (pubspecFile.exists) {
62 try { 71 try {
63 YamlDocument document = loadYamlDocument(pubspecFile.readAsStringSync(), 72 YamlDocument document = loadYamlDocument(pubspecFile.readAsStringSync(),
64 sourceUrl: pubspecFile.toUri()); 73 sourceUrl: pubspecFile.toUri());
65 YamlNode contents = document.contents; 74 YamlNode contents = document.contents;
66 if (contents is YamlMap) { 75 if (contents is YamlMap) {
67 String pluginPath = contents[analysisPluginKey]; 76 String pluginPath = contents[analysisPluginKey];
68 if (pluginPath != null) { 77 if (pluginPath != null) {
(...skipping 10 matching lines...) Expand all
79 } 88 }
80 Folder pluginFolder = packageFolder 89 Folder pluginFolder = packageFolder
81 .getChildAssumingFolder(toolsFolderName) 90 .getChildAssumingFolder(toolsFolderName)
82 .getChildAssumingFolder(defaultPluginFolderName); 91 .getChildAssumingFolder(defaultPluginFolderName);
83 if (pluginFolder.exists) { 92 if (pluginFolder.exists) {
84 return pluginFolder.path; 93 return pluginFolder.path;
85 } 94 }
86 return null; 95 return null;
87 } 96 }
88 } 97 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698