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

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: address comments 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 String pluginFilePath = context.join(pluginDirPath, 'bin', 'plugin.dart');
405 resourceProvider.newFile(pluginFilePath, '');
406 String packagesFilePath = context.join(pluginDirPath, '.packages');
407 resourceProvider.newFile(packagesFilePath, '');
408 //
409 // Test path computation.
410 //
411 List<String> paths = manager.pathsFor(pluginDirPath);
412 expect(paths, hasLength(2));
413 expect(paths[0], pluginFilePath);
414 expect(paths[1], packagesFilePath);
415 }
416
417 void test_pathsFor_withPubspec_inBazelWorkspace() {
418 path.Context context = resourceProvider.pathContext;
419 //
420 // Build a Bazel workspace containing four packages, including the plugin.
421 //
422 String rootPath = resourceProvider.convertPath('/workspaceRoot');
423 resourceProvider.newFile(context.join(rootPath, 'WORKSPACE'), '');
424 resourceProvider.newFolder(context.join(rootPath, 'bazel-bin'));
425 resourceProvider.newFolder(context.join(rootPath, 'bazel-genfiles'));
426
427 String newPackage(String packageName, [List<String> dependencies]) {
428 String packageRoot =
429 context.join(rootPath, 'third_party', 'dart', packageName);
430 resourceProvider.newFile(
431 context.join(packageRoot, 'lib', packageName + '.dart'), '');
432 StringBuffer buffer = new StringBuffer();
433 if (dependencies != null) {
434 buffer.writeln('dependencies:');
435 for (String dependency in dependencies) {
436 buffer.writeln(' $dependency: any');
437 }
438 }
439 resourceProvider.newFile(
440 context.join(packageRoot, 'pubspec.yaml'), buffer.toString());
441 return packageRoot;
442 }
443
444 String pluginDirPath = newPackage('plugin', ['b', 'c']);
445 newPackage('b', ['d']);
446 newPackage('c', ['d']);
447 newPackage('d');
448 String pluginFilePath = context.join(pluginDirPath, 'bin', 'plugin.dart');
449 resourceProvider.newFile(pluginFilePath, '');
450 //
451 // Test path computation.
452 //
453 List<String> paths = manager.pathsFor(pluginDirPath);
454 expect(paths, hasLength(2));
455 expect(paths[0], pluginFilePath);
456 File packagesFile = resourceProvider.getFile(paths[1]);
457 expect(packagesFile.exists, isTrue);
458 String content = packagesFile.readAsStringSync();
459 List<String> lines = content.split('\n');
460 expect(
461 lines,
462 unorderedEquals([
463 'plugin:file:///workspaceRoot/third_party/dart/plugin/lib',
464 'b:file:///workspaceRoot/third_party/dart/b/lib',
465 'c:file:///workspaceRoot/third_party/dart/c/lib',
466 'd:file:///workspaceRoot/third_party/dart/d/lib',
467 ''
468 ]));
469 }
470
397 void test_pluginsForContextRoot_none() { 471 void test_pluginsForContextRoot_none() {
398 ContextRoot contextRoot = new ContextRoot('/pkg1', []); 472 ContextRoot contextRoot = new ContextRoot('/pkg1', []);
399 expect(manager.pluginsForContextRoot(contextRoot), isEmpty); 473 expect(manager.pluginsForContextRoot(contextRoot), isEmpty);
400 } 474 }
401 475
402 void test_stopAll_none() { 476 void test_stopAll_none() {
403 manager.stopAll(); 477 manager.stopAll();
404 } 478 }
405 } 479 }
406 480
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 } 871 }
798 872
799 @override 873 @override
800 void sendRequest(Request request) { 874 void sendRequest(Request request) {
801 sentRequests.add(request); 875 sentRequests.add(request);
802 if (request.method == 'plugin.shutdown') { 876 if (request.method == 'plugin.shutdown') {
803 session.handleOnDone(); 877 session.handleOnDone();
804 } 878 }
805 } 879 }
806 } 880 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698