| 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:io' as io; | 6 import 'dart:io' as io; |
| 7 | 7 |
| 8 import 'package:analysis_server/src/plugin/notification_manager.dart'; | 8 import 'package:analysis_server/src/plugin/notification_manager.dart'; |
| 9 import 'package:analysis_server/src/plugin/plugin_manager.dart'; | 9 import 'package:analysis_server/src/plugin/plugin_manager.dart'; |
| 10 import 'package:analyzer/context/context_root.dart'; | 10 import 'package:analyzer/context/context_root.dart'; |
| 11 import 'package:analyzer/file_system/file_system.dart'; |
| 11 import 'package:analyzer/file_system/memory_file_system.dart'; | 12 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 12 import 'package:analyzer/file_system/physical_file_system.dart'; | 13 import 'package:analyzer/file_system/physical_file_system.dart'; |
| 13 import 'package:analyzer/instrumentation/instrumentation.dart'; | 14 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| 14 import 'package:analyzer_plugin/channel/channel.dart'; | 15 import 'package:analyzer_plugin/channel/channel.dart'; |
| 15 import 'package:analyzer_plugin/protocol/protocol.dart'; | 16 import 'package:analyzer_plugin/protocol/protocol.dart'; |
| 16 import 'package:analyzer_plugin/protocol/protocol_common.dart'; | 17 import 'package:analyzer_plugin/protocol/protocol_common.dart'; |
| 17 import 'package:analyzer_plugin/protocol/protocol_generated.dart' | 18 import 'package:analyzer_plugin/protocol/protocol_generated.dart' |
| 18 hide ContextRoot; | 19 hide ContextRoot; |
| 19 import 'package:path/path.dart' as path; | 20 import 'package:path/path.dart' as path; |
| 20 import 'package:test/test.dart'; | 21 import 'package:test/test.dart'; |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 io.Directory pkg1Dir = io.Directory.systemTemp.createTempSync('pkg1'); | 205 io.Directory pkg1Dir = io.Directory.systemTemp.createTempSync('pkg1'); |
| 205 String pkgPath = pkg1Dir.resolveSymbolicLinksSync(); | 206 String pkgPath = pkg1Dir.resolveSymbolicLinksSync(); |
| 206 await withPlugin(test: (String pluginPath) async { | 207 await withPlugin(test: (String pluginPath) async { |
| 207 ContextRoot contextRoot = new ContextRoot(pkgPath, []); | 208 ContextRoot contextRoot = new ContextRoot(pkgPath, []); |
| 208 await manager.addPluginToContextRoot(contextRoot, pluginPath); | 209 await manager.addPluginToContextRoot(contextRoot, pluginPath); |
| 209 await manager.stopAll(); | 210 await manager.stopAll(); |
| 210 }); | 211 }); |
| 211 pkg1Dir.deleteSync(recursive: true); | 212 pkg1Dir.deleteSync(recursive: true); |
| 212 } | 213 } |
| 213 | 214 |
| 215 @failingTest |
| 216 test_addPluginToContextRoot_pubspec() async { |
| 217 // We can't successfully run pub until after the analyzer_plugin package has |
| 218 // been published. |
| 219 io.Directory pkg1Dir = io.Directory.systemTemp.createTempSync('pkg1'); |
| 220 String pkgPath = pkg1Dir.resolveSymbolicLinksSync(); |
| 221 await withPubspecPlugin(test: (String pluginPath) async { |
| 222 ContextRoot contextRoot = new ContextRoot(pkgPath, []); |
| 223 await manager.addPluginToContextRoot(contextRoot, pluginPath); |
| 224 String packagesPath = |
| 225 resourceProvider.pathContext.join(pluginPath, '.packages'); |
| 226 File packagesFile = resourceProvider.getFile(packagesPath); |
| 227 bool exists = packagesFile.exists; |
| 228 await manager.stopAll(); |
| 229 expect(exists, isTrue, reason: '.packages file was not created'); |
| 230 }); |
| 231 pkg1Dir.deleteSync(recursive: true); |
| 232 } |
| 233 |
| 214 test_broadcastRequest_many() async { | 234 test_broadcastRequest_many() async { |
| 215 io.Directory pkg1Dir = io.Directory.systemTemp.createTempSync('pkg1'); | 235 io.Directory pkg1Dir = io.Directory.systemTemp.createTempSync('pkg1'); |
| 216 String pkgPath = pkg1Dir.resolveSymbolicLinksSync(); | 236 String pkgPath = pkg1Dir.resolveSymbolicLinksSync(); |
| 217 await withPlugin( | 237 await withPlugin( |
| 218 pluginName: 'plugin1', | 238 pluginName: 'plugin1', |
| 219 test: (String plugin1Path) async { | 239 test: (String plugin1Path) async { |
| 220 await withPlugin( | 240 await withPlugin( |
| 221 pluginName: 'plugin2', | 241 pluginName: 'plugin2', |
| 222 test: (String plugin2Path) async { | 242 test: (String plugin2Path) async { |
| 223 ContextRoot contextRoot = new ContextRoot(pkgPath, []); | 243 ContextRoot contextRoot = new ContextRoot(pkgPath, []); |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 // | 592 // |
| 573 // Run the actual test code. | 593 // Run the actual test code. |
| 574 // | 594 // |
| 575 await test(pluginPath); | 595 await test(pluginPath); |
| 576 } finally { | 596 } finally { |
| 577 tempDirectory.deleteSync(recursive: true); | 597 tempDirectory.deleteSync(recursive: true); |
| 578 } | 598 } |
| 579 } | 599 } |
| 580 | 600 |
| 581 /** | 601 /** |
| 602 * Create a directory structure representing a plugin on disk, run the given |
| 603 * [test] function, and then remove the directory. The directory will have the |
| 604 * following structure: |
| 605 * ``` |
| 606 * pluginDirectory |
| 607 * pubspec.yaml |
| 608 * bin |
| 609 * plugin.dart |
| 610 * ``` |
| 611 * The name of the plugin directory will be the [pluginName], if one is |
| 612 * provided (in order to allow more than one plugin to be created by a single |
| 613 * test). The 'plugin.dart' file will contain the given [content], or default |
| 614 * content that implements a minimal plugin if the contents are not given. The |
| 615 * [test] function will be passed the path of the directory that was created. |
| 616 */ |
| 617 Future<Null> withPubspecPlugin( |
| 618 {String content, |
| 619 String pluginName, |
| 620 Future<Null> test(String pluginPath)}) async { |
| 621 io.Directory tempDirectory = |
| 622 io.Directory.systemTemp.createTempSync(pluginName ?? 'test_plugin'); |
| 623 try { |
| 624 String pluginPath = tempDirectory.resolveSymbolicLinksSync(); |
| 625 // |
| 626 // Create a pubspec.yaml file. |
| 627 // |
| 628 io.File pubspecFile = new io.File(path.join(pluginPath, 'pubspec.yaml')); |
| 629 pubspecFile.writeAsStringSync(_getPubspecFileContent()); |
| 630 // |
| 631 // Create the 'bin' directory. |
| 632 // |
| 633 String binPath = path.join(pluginPath, 'bin'); |
| 634 new io.Directory(binPath).createSync(); |
| 635 // |
| 636 // Create the 'plugin.dart' file. |
| 637 // |
| 638 io.File pluginFile = new io.File(path.join(binPath, 'plugin.dart')); |
| 639 pluginFile.writeAsStringSync(content ?? _defaultPluginContent()); |
| 640 // |
| 641 // Run the actual test code. |
| 642 // |
| 643 await test(pluginPath); |
| 644 } finally { |
| 645 tempDirectory.deleteSync(recursive: true); |
| 646 } |
| 647 } |
| 648 |
| 649 /** |
| 582 * Convert the [sdkPackageMap] into a plugin-specific map by applying the | 650 * Convert the [sdkPackageMap] into a plugin-specific map by applying the |
| 583 * given relative path [delta] to each line. | 651 * given relative path [delta] to each line. |
| 584 */ | 652 */ |
| 585 String _convertPackageMap(String sdkDirPath, List<String> sdkPackageMap) { | 653 String _convertPackageMap(String sdkDirPath, List<String> sdkPackageMap) { |
| 586 StringBuffer buffer = new StringBuffer(); | 654 StringBuffer buffer = new StringBuffer(); |
| 587 for (String line in sdkPackageMap) { | 655 for (String line in sdkPackageMap) { |
| 588 if (!line.startsWith('#')) { | 656 if (!line.startsWith('#')) { |
| 589 int index = line.indexOf(':'); | 657 int index = line.indexOf(':'); |
| 590 String packageName = line.substring(0, index + 1); | 658 String packageName = line.substring(0, index + 1); |
| 591 String relativePath = line.substring(index + 1); | 659 String relativePath = line.substring(index + 1); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 if (_packagesFileContent == null) { | 714 if (_packagesFileContent == null) { |
| 647 io.File sdkPackagesFile = new io.File(_sdkPackagesPath()); | 715 io.File sdkPackagesFile = new io.File(_sdkPackagesPath()); |
| 648 List<String> sdkPackageMap = sdkPackagesFile.readAsLinesSync(); | 716 List<String> sdkPackageMap = sdkPackagesFile.readAsLinesSync(); |
| 649 _packagesFileContent = | 717 _packagesFileContent = |
| 650 _convertPackageMap(path.dirname(sdkPackagesFile.path), sdkPackageMap); | 718 _convertPackageMap(path.dirname(sdkPackagesFile.path), sdkPackageMap); |
| 651 } | 719 } |
| 652 return _packagesFileContent; | 720 return _packagesFileContent; |
| 653 } | 721 } |
| 654 | 722 |
| 655 /** | 723 /** |
| 724 * Return the content to be used for the 'pubspec.yaml' file. |
| 725 */ |
| 726 String _getPubspecFileContent() { |
| 727 return ''' |
| 728 name: 'test' |
| 729 dependencies: |
| 730 analyzer: any |
| 731 analyzer_plugin: any |
| 732 '''; |
| 733 } |
| 734 |
| 735 /** |
| 656 * Return the path to the '.packages' file in the root of the SDK checkout. | 736 * Return the path to the '.packages' file in the root of the SDK checkout. |
| 657 */ | 737 */ |
| 658 String _sdkPackagesPath() { | 738 String _sdkPackagesPath() { |
| 659 String packagesPath = io.Platform.script.toFilePath(); | 739 String packagesPath = io.Platform.script.toFilePath(); |
| 660 while (packagesPath.isNotEmpty && | 740 while (packagesPath.isNotEmpty && |
| 661 path.basename(packagesPath) != 'analysis_server') { | 741 path.basename(packagesPath) != 'analysis_server') { |
| 662 packagesPath = path.dirname(packagesPath); | 742 packagesPath = path.dirname(packagesPath); |
| 663 } | 743 } |
| 664 packagesPath = path.dirname(packagesPath); | 744 packagesPath = path.dirname(packagesPath); |
| 665 packagesPath = path.dirname(packagesPath); | 745 packagesPath = path.dirname(packagesPath); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 } | 787 } |
| 708 | 788 |
| 709 @override | 789 @override |
| 710 void sendRequest(Request request) { | 790 void sendRequest(Request request) { |
| 711 sentRequests.add(request); | 791 sentRequests.add(request); |
| 712 if (request.method == 'plugin.shutdown') { | 792 if (request.method == 'plugin.shutdown') { |
| 713 session.handleOnDone(); | 793 session.handleOnDone(); |
| 714 } | 794 } |
| 715 } | 795 } |
| 716 } | 796 } |
| OLD | NEW |