| 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:io'; | 8 import 'dart:io'; |
| 8 | 9 |
| 9 import 'package:analysis_server/http_server.dart'; | 10 import 'package:analysis_server/http_server.dart'; |
| 10 import 'package:analysis_server/src/socket_server.dart'; | 11 import 'package:analysis_server/src/socket_server.dart'; |
| 11 import 'package:analysis_server/stdio_server.dart'; | 12 import 'package:analysis_server/stdio_server.dart'; |
| 12 import 'package:analyzer/src/generated/java_io.dart'; | 13 import 'package:analyzer/src/generated/java_io.dart'; |
| 13 import 'package:analyzer/src/generated/sdk.dart'; | 14 import 'package:analyzer/src/generated/sdk.dart'; |
| 14 import 'package:analyzer/src/generated/sdk_io.dart'; | 15 import 'package:analyzer/src/generated/sdk_io.dart'; |
| 15 import 'package:args/args.dart'; | 16 import 'package:args/args.dart'; |
| 16 | 17 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 defaultSdk = DirectoryBasedDartSdk.defaultSdk; | 119 defaultSdk = DirectoryBasedDartSdk.defaultSdk; |
| 119 } | 120 } |
| 120 | 121 |
| 121 socketServer = new SocketServer(defaultSdk); | 122 socketServer = new SocketServer(defaultSdk); |
| 122 httpServer = new HttpAnalysisServer(socketServer); | 123 httpServer = new HttpAnalysisServer(socketServer); |
| 123 stdioServer = new StdioAnalysisServer(socketServer); | 124 stdioServer = new StdioAnalysisServer(socketServer); |
| 124 | 125 |
| 125 if (serve_http) { | 126 if (serve_http) { |
| 126 httpServer.serveHttp(port); | 127 httpServer.serveHttp(port); |
| 127 } | 128 } |
| 128 stdioServer.serveStdio().then((_) { | 129 _capturePrints(() { |
| 129 if (serve_http) { | 130 stdioServer.serveStdio().then((_) { |
| 130 httpServer.close(); | 131 if (serve_http) { |
| 131 } | 132 httpServer.close(); |
| 132 exit(0); | 133 } |
| 133 }); | 134 exit(0); |
| 135 }); |
| 136 }, httpServer.recordPrint); |
| 134 } | 137 } |
| 135 | 138 |
| 136 /** | 139 /** |
| 140 * Execute [callback], capturing any data it prints out and redirecting it to |
| 141 * the function [printHandler]. |
| 142 */ |
| 143 dynamic _capturePrints(dynamic callback(), void printHandler(String line)) { |
| 144 ZoneSpecification zoneSpecification = new ZoneSpecification(print: |
| 145 (Zone self, ZoneDelegate parent, Zone zone, String line) { |
| 146 printHandler(line); |
| 147 // Note: we don't pass the line on to stdout, because that is reserved |
| 148 // for communication to the client. |
| 149 }); |
| 150 return runZoned(callback, zoneSpecification: zoneSpecification); |
| 151 } |
| 152 |
| 153 /** |
| 137 * Print information about how to use the server. | 154 * Print information about how to use the server. |
| 138 */ | 155 */ |
| 139 void _printUsage(ArgParser parser) { | 156 void _printUsage(ArgParser parser) { |
| 140 print('Usage: $BINARY_NAME [flags]'); | 157 print('Usage: $BINARY_NAME [flags]'); |
| 141 print(''); | 158 print(''); |
| 142 print('Supported flags are:'); | 159 print('Supported flags are:'); |
| 143 print(parser.usage); | 160 print(parser.usage); |
| 144 } | 161 } |
| 145 } | 162 } |
| OLD | NEW |