| OLD | NEW |
| 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'; | |
| 7 | 6 |
| 8 /** | 7 /** |
| 9 * An object used to locate a plugin within a package. | 8 * An object used to locate a plugin within a package. |
| 10 */ | 9 */ |
| 11 class PluginLocator { | 10 class PluginLocator { |
| 12 /** | 11 /** |
| 13 * The key used in the `pubspec.yaml` file to specify the location of the | 12 * The key used in the `pubspec.yaml` file to specify the location of the |
| 14 * analysis plugin. | 13 * analysis plugin. |
| 15 */ | 14 */ |
| 16 static const String analyzerPluginKey = 'analyzer_plugin'; | 15 static const String analyzerPluginKey = 'analyzer_plugin'; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 */ | 64 */ |
| 66 String findPlugin(String packageRoot) { | 65 String findPlugin(String packageRoot) { |
| 67 return pluginMap.putIfAbsent(packageRoot, () => _findPlugin(packageRoot)); | 66 return pluginMap.putIfAbsent(packageRoot, () => _findPlugin(packageRoot)); |
| 68 } | 67 } |
| 69 | 68 |
| 70 /** | 69 /** |
| 71 * The implementation of [findPlugin]. | 70 * The implementation of [findPlugin]. |
| 72 */ | 71 */ |
| 73 String _findPlugin(String packageRoot) { | 72 String _findPlugin(String packageRoot) { |
| 74 Folder packageFolder = resourceProvider.getFolder(packageRoot); | 73 Folder packageFolder = resourceProvider.getFolder(packageRoot); |
| 75 File pubspecFile = packageFolder.getChildAssumingFile(pubspecFileName); | 74 // TODO(brianwilkerson) Re-enable this after deciding how we want to deal |
| 76 if (pubspecFile.exists) { | 75 // with discovery of plugins. |
| 77 try { | 76 // import 'package:yaml/yaml.dart'; |
| 78 YamlDocument document = loadYamlDocument(pubspecFile.readAsStringSync(), | 77 // File pubspecFile = packageFolder.getChildAssumingFile(pubspecFileName); |
| 79 sourceUrl: pubspecFile.toUri()); | 78 // if (pubspecFile.exists) { |
| 80 YamlNode contents = document.contents; | 79 // try { |
| 81 if (contents is YamlMap) { | 80 // YamlDocument document = loadYamlDocument(pubspecFile.readAsStringSync(
), |
| 82 String pluginPath = contents[analyzerPluginKey]; | 81 // sourceUrl: pubspecFile.toUri()); |
| 83 if (pluginPath != null) { | 82 // YamlNode contents = document.contents; |
| 84 Folder pluginFolder = | 83 // if (contents is YamlMap) { |
| 85 packageFolder.getChildAssumingFolder(pluginPath); | 84 // String pluginPath = contents[analyzerPluginKey]; |
| 86 if (pluginFolder.exists) { | 85 // if (pluginPath != null) { |
| 87 return pluginFolder.path; | 86 // Folder pluginFolder = |
| 88 } | 87 // packageFolder.getChildAssumingFolder(pluginPath); |
| 89 } | 88 // if (pluginFolder.exists) { |
| 90 } | 89 // return pluginFolder.path; |
| 91 } catch (exception) { | 90 // } |
| 92 // If we can't read the file, or if it isn't valid YAML, then ignore it. | 91 // } |
| 93 } | 92 // } |
| 94 } | 93 // } catch (exception) { |
| 94 // // If we can't read the file, or if it isn't valid YAML, then ignore i
t. |
| 95 // } |
| 96 // } |
| 95 Folder pluginFolder = packageFolder | 97 Folder pluginFolder = packageFolder |
| 96 .getChildAssumingFolder(toolsFolderName) | 98 .getChildAssumingFolder(toolsFolderName) |
| 97 .getChildAssumingFolder(defaultPluginFolderName); | 99 .getChildAssumingFolder(defaultPluginFolderName); |
| 98 if (pluginFolder.exists) { | 100 if (pluginFolder.exists) { |
| 99 return pluginFolder.path; | 101 return pluginFolder.path; |
| 100 } | 102 } |
| 101 return null; | 103 return null; |
| 102 } | 104 } |
| 103 } | 105 } |
| OLD | NEW |