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

Side by Side Diff: pkg/analysis_server/test/src/plugin/plugin_manager_test.dart

Issue 2988673002: Add support for creating a .packages file when the plugin is in a Bazel workspace (Closed)
Patch Set: Created 3 years, 5 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 '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';
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 expect(responses, hasLength(0)); 387 expect(responses, hasLength(0));
388 } 388 }
389 389
390 void test_creation() { 390 void test_creation() {
391 expect(manager.resourceProvider, resourceProvider); 391 expect(manager.resourceProvider, resourceProvider);
392 expect(manager.byteStorePath, byteStorePath); 392 expect(manager.byteStorePath, byteStorePath);
393 expect(manager.sdkPath, sdkPath); 393 expect(manager.sdkPath, sdkPath);
394 expect(manager.notificationManager, notificationManager); 394 expect(manager.notificationManager, notificationManager);
395 } 395 }
396 396
397 void test_pathsFor_withPackagesFile() {
398 path.Context context = resourceProvider.pathContext;
399 //
400 // Build the minimal directory structure for a plugin package that includes
401 // a .packages file.
402 //
403 String pluginDirPath = resourceProvider.convertPath('/plugin');
404 resourceProvider.newFolder(pluginDirPath);
405 String binPath = context.join(pluginDirPath, 'bin');
406 resourceProvider.newFolder(binPath);
407 String pluginFilePath = context.join(binPath, 'plugin.dart');
408 resourceProvider.newFile(pluginFilePath, '');
scheglov 2017/07/24 15:35:34 MemoryResourceProvider.newFile() creates all enclo
Brian Wilkerson 2017/07/24 15:57:42 Done
409 String packagesFilePath = context.join(pluginDirPath, '.packages');
410 resourceProvider.newFile(packagesFilePath, '');
411 //
412 // Test path computation.
413 //
414 List<String> paths = manager.pathsFor(pluginDirPath);
415 expect(paths, hasLength(2));
416 expect(paths[0], pluginFilePath);
417 expect(paths[1], packagesFilePath);
418 }
419
420 void test_pathsFor_withPubspec_inBazelWorkspace() {
421 path.Context context = resourceProvider.pathContext;
422 //
423 // Build a Bazel workspace containing four packages, including the plugin.
424 //
425 String rootPath = resourceProvider.convertPath('/workspaceRoot');
426 resourceProvider.newFolder(rootPath);
427 resourceProvider.newFile(context.join(rootPath, 'WORKSPACE'), '');
428 resourceProvider.newFolder(context.join(rootPath, 'bazel-bin'));
429 resourceProvider.newFolder(context.join(rootPath, 'bazel-genfiles'));
430
431 String newPackage(String packageName, [List<String> dependencies]) {
432 String packageRoot =
433 context.join(rootPath, 'third_party', 'dart', packageName);
434 resourceProvider.newFile(
435 context.join(packageRoot, 'lib', packageName + '.dart'), '');
436 StringBuffer buffer = new StringBuffer();
437 if (dependencies != null) {
438 buffer.writeln('dependencies:');
439 for (String dependency in dependencies) {
440 buffer.writeln(' $dependency: any');
441 }
442 }
443 resourceProvider.newFile(
444 context.join(packageRoot, 'pubspec.yaml'), buffer.toString());
445 return packageRoot;
446 }
447
448 String pluginDirPath = newPackage('plugin', ['b', 'c']);
449 newPackage('b', ['d']);
450 newPackage('c', ['d']);
451 newPackage('d');
452 String binPath = context.join(pluginDirPath, 'bin');
453 resourceProvider.newFolder(binPath);
454 String pluginFilePath = context.join(binPath, 'plugin.dart');
455 resourceProvider.newFile(pluginFilePath, '');
456 //
457 // Test path computation.
458 //
459 List<String> paths = manager.pathsFor(pluginDirPath);
460 expect(paths, hasLength(2));
461 expect(paths[0], pluginFilePath);
462 File packagesFile = resourceProvider.getFile(paths[1]);
463 expect(packagesFile.exists, isTrue);
464 String content = packagesFile.readAsStringSync();
465 List<String> lines = content.split('\n');
466 expect(
467 lines,
468 unorderedEquals([
469 'plugin:file:///workspaceRoot/third_party/dart/plugin/lib',
470 'b:file:///workspaceRoot/third_party/dart/b/lib',
471 'c:file:///workspaceRoot/third_party/dart/c/lib',
472 'd:file:///workspaceRoot/third_party/dart/d/lib',
473 ''
474 ]));
475 }
476
397 void test_pluginsForContextRoot_none() { 477 void test_pluginsForContextRoot_none() {
398 ContextRoot contextRoot = new ContextRoot('/pkg1', []); 478 ContextRoot contextRoot = new ContextRoot('/pkg1', []);
399 expect(manager.pluginsForContextRoot(contextRoot), isEmpty); 479 expect(manager.pluginsForContextRoot(contextRoot), isEmpty);
400 } 480 }
401 481
402 void test_stopAll_none() { 482 void test_stopAll_none() {
403 manager.stopAll(); 483 manager.stopAll();
404 } 484 }
405 } 485 }
406 486
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 } 877 }
798 878
799 @override 879 @override
800 void sendRequest(Request request) { 880 void sendRequest(Request request) {
801 sentRequests.add(request); 881 sentRequests.add(request);
802 if (request.method == 'plugin.shutdown') { 882 if (request.method == 'plugin.shutdown') {
803 session.handleOnDone(); 883 session.handleOnDone();
804 } 884 }
805 } 885 }
806 } 886 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698