OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library driver; | 5 library driver; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 import 'dart:math'; | 9 import 'dart:math'; |
10 | 10 |
11 import 'package:analysis_server/src/analysis_server.dart'; | 11 import 'package:analysis_server/src/analysis_server.dart'; |
12 import 'package:analysis_server/src/plugin/server_plugin.dart'; | 12 import 'package:analysis_server/src/plugin/server_plugin.dart'; |
13 import 'package:analysis_server/src/provisional/completion/dart/completion_plugi
n.dart'; | 13 import 'package:analysis_server/src/provisional/completion/dart/completion_plugi
n.dart'; |
| 14 import 'package:analysis_server/src/server/diagnostic_server.dart'; |
14 import 'package:analysis_server/src/server/http_server.dart'; | 15 import 'package:analysis_server/src/server/http_server.dart'; |
15 import 'package:analysis_server/src/server/stdio_server.dart'; | 16 import 'package:analysis_server/src/server/stdio_server.dart'; |
16 import 'package:analysis_server/src/socket_server.dart'; | 17 import 'package:analysis_server/src/socket_server.dart'; |
17 import 'package:analysis_server/starter.dart'; | 18 import 'package:analysis_server/starter.dart'; |
18 import 'package:analyzer/file_system/physical_file_system.dart'; | 19 import 'package:analyzer/file_system/physical_file_system.dart'; |
19 import 'package:analyzer/instrumentation/file_instrumentation.dart'; | 20 import 'package:analyzer/instrumentation/file_instrumentation.dart'; |
20 import 'package:analyzer/instrumentation/instrumentation.dart'; | 21 import 'package:analyzer/instrumentation/instrumentation.dart'; |
21 import 'package:analyzer/plugin/resolver_provider.dart'; | 22 import 'package:analyzer/plugin/resolver_provider.dart'; |
22 import 'package:analyzer/src/dart/sdk/sdk.dart'; | 23 import 'package:analyzer/src/dart/sdk/sdk.dart'; |
23 import 'package:analyzer/src/generated/engine.dart'; | 24 import 'package:analyzer/src/generated/engine.dart'; |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 // TODO (danrubel) Remove this workaround | 365 // TODO (danrubel) Remove this workaround |
365 // once the underlying VM and dart:io issue has been fixed. | 366 // once the underlying VM and dart:io issue has been fixed. |
366 if (results[INTERNAL_DELAY_FREQUENCY] != null) { | 367 if (results[INTERNAL_DELAY_FREQUENCY] != null) { |
367 AnalysisServer.performOperationDelayFrequency = | 368 AnalysisServer.performOperationDelayFrequency = |
368 int.parse(results[INTERNAL_DELAY_FREQUENCY], onError: (_) => 0); | 369 int.parse(results[INTERNAL_DELAY_FREQUENCY], onError: (_) => 0); |
369 } | 370 } |
370 | 371 |
371 int port; | 372 int port; |
372 bool serve_http = false; | 373 bool serve_http = false; |
373 if (results[PORT_OPTION] != null) { | 374 if (results[PORT_OPTION] != null) { |
374 serve_http = true; | |
375 try { | 375 try { |
376 port = int.parse(results[PORT_OPTION]); | 376 port = int.parse(results[PORT_OPTION]); |
| 377 serve_http = true; |
377 } on FormatException { | 378 } on FormatException { |
378 print('Invalid port number: ${results[PORT_OPTION]}'); | 379 print('Invalid port number: ${results[PORT_OPTION]}'); |
379 print(''); | 380 print(''); |
380 _printUsage(parser.parser); | 381 _printUsage(parser.parser); |
381 exitCode = 1; | 382 exitCode = 1; |
382 return; | 383 return; |
383 } | 384 } |
384 } | 385 } |
385 | 386 |
386 AnalysisServerOptions analysisServerOptions = new AnalysisServerOptions(); | 387 AnalysisServerOptions analysisServerOptions = new AnalysisServerOptions(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 String logFilePath = results[INSTRUMENTATION_LOG_FILE]; | 438 String logFilePath = results[INSTRUMENTATION_LOG_FILE]; |
438 if (logFilePath != null) { | 439 if (logFilePath != null) { |
439 _rollLogFiles(logFilePath, 5); | 440 _rollLogFiles(logFilePath, 5); |
440 FileInstrumentationServer fileBasedServer = | 441 FileInstrumentationServer fileBasedServer = |
441 new FileInstrumentationServer(logFilePath); | 442 new FileInstrumentationServer(logFilePath); |
442 instrumentationServer = instrumentationServer != null | 443 instrumentationServer = instrumentationServer != null |
443 ? new MulticastInstrumentationServer( | 444 ? new MulticastInstrumentationServer( |
444 [instrumentationServer, fileBasedServer]) | 445 [instrumentationServer, fileBasedServer]) |
445 : fileBasedServer; | 446 : fileBasedServer; |
446 } | 447 } |
447 InstrumentationService service = | 448 InstrumentationService instrumentationService = |
448 new InstrumentationService(instrumentationServer); | 449 new InstrumentationService(instrumentationServer); |
449 service.logVersion(_readUuid(service), results[CLIENT_ID], | 450 instrumentationService.logVersion( |
450 results[CLIENT_VERSION], AnalysisServer.VERSION, defaultSdk.sdkVersion); | 451 _readUuid(instrumentationService), |
451 AnalysisEngine.instance.instrumentationService = service; | 452 results[CLIENT_ID], |
| 453 results[CLIENT_VERSION], |
| 454 AnalysisServer.VERSION, |
| 455 defaultSdk.sdkVersion); |
| 456 AnalysisEngine.instance.instrumentationService = instrumentationService; |
| 457 |
| 458 _DiagnosticServerImpl diagnosticServer = new _DiagnosticServerImpl(); |
| 459 |
452 // | 460 // |
453 // Create the sockets and start listening for requests. | 461 // Create the sockets and start listening for requests. |
454 // | 462 // |
455 socketServer = new SocketServer( | 463 socketServer = new SocketServer( |
456 analysisServerOptions, | 464 analysisServerOptions, |
457 new DartSdkManager(defaultSdkPath, useSummaries), | 465 new DartSdkManager(defaultSdkPath, useSummaries), |
458 defaultSdk, | 466 defaultSdk, |
459 service, | 467 instrumentationService, |
| 468 diagnosticServer, |
460 serverPlugin, | 469 serverPlugin, |
461 fileResolverProvider, | 470 fileResolverProvider, |
462 packageResolverProvider, | 471 packageResolverProvider, |
463 useSingleContextManager); | 472 useSingleContextManager); |
464 httpServer = new HttpAnalysisServer(socketServer); | 473 httpServer = new HttpAnalysisServer(socketServer); |
465 stdioServer = new StdioAnalysisServer(socketServer); | 474 stdioServer = new StdioAnalysisServer(socketServer); |
466 socketServer.userDefinedPlugins = _userDefinedPlugins; | 475 socketServer.userDefinedPlugins = _userDefinedPlugins; |
467 | 476 |
| 477 diagnosticServer.httpServer = httpServer; |
468 if (serve_http) { | 478 if (serve_http) { |
469 httpServer.serveHttp(port); | 479 diagnosticServer.startOnPort(port); |
470 } | 480 } |
471 | 481 |
472 _captureExceptions(service, () { | 482 _captureExceptions(instrumentationService, () { |
473 stdioServer.serveStdio().then((_) async { | 483 stdioServer.serveStdio().then((_) async { |
474 if (serve_http) { | 484 if (serve_http) { |
475 httpServer.close(); | 485 httpServer.close(); |
476 } | 486 } |
477 await service.shutdown(); | 487 await instrumentationService.shutdown(); |
478 exit(0); | 488 exit(0); |
479 }); | 489 }); |
480 }, | 490 }, |
481 print: | 491 print: |
482 results[INTERNAL_PRINT_TO_CONSOLE] ? null : httpServer.recordPrint); | 492 results[INTERNAL_PRINT_TO_CONSOLE] ? null : httpServer.recordPrint); |
483 } | 493 } |
484 | 494 |
485 /** | 495 /** |
486 * Execute the given [callback] within a zone that will capture any unhandled | 496 * Execute the given [callback] within a zone that will capture any unhandled |
487 * exceptions and both report them to the client and send them to the given | 497 * exceptions and both report them to the client and send them to the given |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 */ | 654 */ |
645 static void _rollLogFiles(String path, int numOld) { | 655 static void _rollLogFiles(String path, int numOld) { |
646 for (int i = numOld - 1; i >= 0; i--) { | 656 for (int i = numOld - 1; i >= 0; i--) { |
647 try { | 657 try { |
648 String oldPath = i == 0 ? path : '$path.$i'; | 658 String oldPath = i == 0 ? path : '$path.$i'; |
649 new File(oldPath).renameSync('$path.${i+1}'); | 659 new File(oldPath).renameSync('$path.${i+1}'); |
650 } catch (e) {} | 660 } catch (e) {} |
651 } | 661 } |
652 } | 662 } |
653 } | 663 } |
| 664 |
| 665 /** |
| 666 * Implements the [DiagnosticServer] class by wrapping an [HttpAnalysisServer]. |
| 667 */ |
| 668 class _DiagnosticServerImpl extends DiagnosticServer { |
| 669 HttpAnalysisServer httpServer; |
| 670 |
| 671 _DiagnosticServerImpl(); |
| 672 |
| 673 Future startOnPort(int port) { |
| 674 return httpServer.serveHttp(port); |
| 675 } |
| 676 |
| 677 @override |
| 678 Future<int> getServerPort() => httpServer.serveHttp(); |
| 679 } |
OLD | NEW |