| 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 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:collection'; | 6 import 'dart:collection'; |
| 7 import 'dart:io' show Platform; | 7 import 'dart:convert'; |
| 8 import 'dart:io' show Platform, Process, ProcessResult; |
| 8 | 9 |
| 9 import 'package:analysis_server/src/plugin/notification_manager.dart'; | 10 import 'package:analysis_server/src/plugin/notification_manager.dart'; |
| 10 import 'package:analyzer/context/context_root.dart' as analyzer; | 11 import 'package:analyzer/context/context_root.dart' as analyzer; |
| 11 import 'package:analyzer/file_system/file_system.dart'; | 12 import 'package:analyzer/file_system/file_system.dart'; |
| 12 import 'package:analyzer/instrumentation/instrumentation.dart'; | 13 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| 13 import 'package:analyzer/src/generated/bazel.dart'; | 14 import 'package:analyzer/src/generated/bazel.dart'; |
| 14 import 'package:analyzer/src/generated/gn.dart'; | 15 import 'package:analyzer/src/generated/gn.dart'; |
| 15 import 'package:analyzer/src/util/glob.dart'; | 16 import 'package:analyzer/src/util/glob.dart'; |
| 16 import 'package:analyzer_plugin/channel/channel.dart'; | 17 import 'package:analyzer_plugin/channel/channel.dart'; |
| 17 import 'package:analyzer_plugin/protocol/protocol.dart'; | 18 import 'package:analyzer_plugin/protocol/protocol.dart'; |
| 18 import 'package:analyzer_plugin/protocol/protocol_common.dart'; | 19 import 'package:analyzer_plugin/protocol/protocol_common.dart'; |
| 19 import 'package:analyzer_plugin/protocol/protocol_constants.dart'; | 20 import 'package:analyzer_plugin/protocol/protocol_constants.dart'; |
| 20 import 'package:analyzer_plugin/protocol/protocol_generated.dart'; | 21 import 'package:analyzer_plugin/protocol/protocol_generated.dart'; |
| 21 import 'package:analyzer_plugin/src/channel/isolate_channel.dart'; | 22 import 'package:analyzer_plugin/src/channel/isolate_channel.dart'; |
| 22 import 'package:analyzer_plugin/src/protocol/protocol_internal.dart'; | 23 import 'package:analyzer_plugin/src/protocol/protocol_internal.dart'; |
| 23 import 'package:convert/convert.dart'; | 24 import 'package:convert/convert.dart'; |
| 24 import 'package:crypto/crypto.dart'; | 25 import 'package:crypto/crypto.dart'; |
| 25 import 'package:meta/meta.dart'; | 26 import 'package:meta/meta.dart'; |
| 27 import 'package:path/path.dart' as path; |
| 26 import 'package:watcher/watcher.dart' as watcher; | 28 import 'package:watcher/watcher.dart' as watcher; |
| 27 | 29 |
| 28 /** | 30 /** |
| 29 * Information about a plugin that is built-in. | 31 * Information about a plugin that is built-in. |
| 30 */ | 32 */ |
| 31 class BuiltInPluginInfo extends PluginInfo { | 33 class BuiltInPluginInfo extends PluginInfo { |
| 32 /** | 34 /** |
| 33 * The entry point function that will be executed in the plugin's isolate. | 35 * The entry point function that will be executed in the plugin's isolate. |
| 34 */ | 36 */ |
| 35 final EntryPoint entryPoint; | 37 final EntryPoint entryPoint; |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 */ | 328 */ |
| 327 Future<Null> addPluginToContextRoot( | 329 Future<Null> addPluginToContextRoot( |
| 328 analyzer.ContextRoot contextRoot, String path) async { | 330 analyzer.ContextRoot contextRoot, String path) async { |
| 329 if (!_isWhitelisted(path)) { | 331 if (!_isWhitelisted(path)) { |
| 330 return; | 332 return; |
| 331 } | 333 } |
| 332 PluginInfo plugin = _pluginMap[path]; | 334 PluginInfo plugin = _pluginMap[path]; |
| 333 bool isNew = plugin == null; | 335 bool isNew = plugin == null; |
| 334 if (isNew) { | 336 if (isNew) { |
| 335 List<String> pluginPaths = _pathsFor(path); | 337 List<String> pluginPaths = _pathsFor(path); |
| 336 if (pluginPaths == null) { | 338 if (pluginPaths == null || pluginPaths[1] == null) { |
| 337 return; | 339 return; |
| 338 } | 340 } |
| 339 plugin = new DiscoveredPluginInfo(path, pluginPaths[0], pluginPaths[1], | 341 plugin = new DiscoveredPluginInfo(path, pluginPaths[0], pluginPaths[1], |
| 340 notificationManager, instrumentationService); | 342 notificationManager, instrumentationService); |
| 341 _pluginMap[path] = plugin; | 343 _pluginMap[path] = plugin; |
| 342 if (pluginPaths[0] != null) { | 344 if (pluginPaths[0] != null) { |
| 343 PluginSession session = await plugin.start(byteStorePath, sdkPath); | 345 PluginSession session = await plugin.start(byteStorePath, sdkPath); |
| 344 session?.onDone?.then((_) { | 346 session?.onDone?.then((_) { |
| 345 _pluginMap.remove(path); | 347 _pluginMap.remove(path); |
| 346 }); | 348 }); |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 List<String> computePaths(Folder pluginFolder, {bool runPub: false}) { | 573 List<String> computePaths(Folder pluginFolder, {bool runPub: false}) { |
| 572 File pluginFile = pluginFolder | 574 File pluginFile = pluginFolder |
| 573 .getChildAssumingFolder('bin') | 575 .getChildAssumingFolder('bin') |
| 574 .getChildAssumingFile('plugin.dart'); | 576 .getChildAssumingFile('plugin.dart'); |
| 575 if (!pluginFile.exists) { | 577 if (!pluginFile.exists) { |
| 576 return null; | 578 return null; |
| 577 } | 579 } |
| 578 File packagesFile = pluginFolder.getChildAssumingFile('.packages'); | 580 File packagesFile = pluginFolder.getChildAssumingFile('.packages'); |
| 579 if (!packagesFile.exists) { | 581 if (!packagesFile.exists) { |
| 580 if (runPub) { | 582 if (runPub) { |
| 581 // TODO(brianwilkerson) Run pub in the pluginFolder. | 583 String vmPath = Platform.executable; |
| 584 String pubPath = path.join(path.dirname(vmPath), 'pub'); |
| 585 ProcessResult result = Process.runSync(pubPath, <String>['get'], |
| 586 stderrEncoding: UTF8, |
| 587 stdoutEncoding: UTF8, |
| 588 workingDirectory: pluginFolder.path); |
| 589 if (result.exitCode != 0) { |
| 590 StringBuffer buffer = new StringBuffer(); |
| 591 buffer.writeln('Failed to run pub get'); |
| 592 buffer.writeln(' pluginFolder = ${pluginFolder.path}'); |
| 593 buffer.writeln(' exitCode = ${result.exitCode}'); |
| 594 buffer.writeln(' stdout = ${result.stdout}'); |
| 595 buffer.writeln(' stderr = ${result.stderr}'); |
| 596 instrumentationService.logError(buffer.toString()); |
| 597 } |
| 582 if (!packagesFile.exists) { | 598 if (!packagesFile.exists) { |
| 583 packagesFile = null; | 599 packagesFile = null; |
| 584 } | 600 } |
| 585 } else { | 601 } else { |
| 586 packagesFile = null; | 602 packagesFile = null; |
| 587 } | 603 } |
| 588 } | 604 } |
| 589 return <String>[pluginFile.path, packagesFile?.path]; | 605 return <String>[pluginFile.path, packagesFile?.path]; |
| 590 } | 606 } |
| 591 | 607 |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 * The completer that will be used to complete the future when the response is | 896 * The completer that will be used to complete the future when the response is |
| 881 * received from the plugin. | 897 * received from the plugin. |
| 882 */ | 898 */ |
| 883 final Completer<Response> completer; | 899 final Completer<Response> completer; |
| 884 | 900 |
| 885 /** | 901 /** |
| 886 * Initialize a pending request. | 902 * Initialize a pending request. |
| 887 */ | 903 */ |
| 888 _PendingRequest(this.method, this.requestTime, this.completer); | 904 _PendingRequest(this.method, this.requestTime, this.completer); |
| 889 } | 905 } |
| OLD | NEW |