| 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 | 9 |
| 10 import 'package:analysis_server/http_server.dart'; | 10 import 'package:analysis_server/http_server.dart'; |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 AnalysisEngine.instance.instrumentationService = service; | 222 AnalysisEngine.instance.instrumentationService = service; |
| 223 | 223 |
| 224 socketServer = new SocketServer(analysisServerOptions, defaultSdk, service); | 224 socketServer = new SocketServer(analysisServerOptions, defaultSdk, service); |
| 225 httpServer = new HttpAnalysisServer(socketServer); | 225 httpServer = new HttpAnalysisServer(socketServer); |
| 226 stdioServer = new StdioAnalysisServer(socketServer); | 226 stdioServer = new StdioAnalysisServer(socketServer); |
| 227 | 227 |
| 228 if (serve_http) { | 228 if (serve_http) { |
| 229 httpServer.serveHttp(port); | 229 httpServer.serveHttp(port); |
| 230 } | 230 } |
| 231 | 231 |
| 232 _captureExceptions(() { | 232 _captureExceptions(service, () { |
| 233 stdioServer.serveStdio().then((_) { | 233 stdioServer.serveStdio().then((_) { |
| 234 if (serve_http) { | 234 if (serve_http) { |
| 235 httpServer.close(); | 235 httpServer.close(); |
| 236 } | 236 } |
| 237 service.shutdown(); | 237 service.shutdown(); |
| 238 exit(0); | 238 exit(0); |
| 239 }); | 239 }); |
| 240 }, | 240 }, |
| 241 print: results[INTERNAL_PRINT_TO_CONSOLE] ? null : httpServer.recordPrin
t); | 241 print: results[INTERNAL_PRINT_TO_CONSOLE] ? null : httpServer.recordPrin
t); |
| 242 } | 242 } |
| 243 | 243 |
| 244 /** | 244 /** |
| 245 * Execute the given [callback], capturing any unhandled exceptions and | 245 * Execute the given [callback] within a zone that will capture any unhandled |
| 246 * reporting them to the client. If a [print] function is provided, then also | 246 * exceptions and both report them to the client and send them to the given |
| 247 * instrumentation [service]. If a [print] function is provided, then also |
| 247 * capture any data printed by the callback and redirect it to the function. | 248 * capture any data printed by the callback and redirect it to the function. |
| 248 */ | 249 */ |
| 249 dynamic _captureExceptions(dynamic callback(), {void print(String line)}) { | 250 dynamic _captureExceptions(InstrumentationService service, dynamic callback(), |
| 250 ZoneSpecification zoneSpecification = new ZoneSpecification( | 251 {void print(String line)}) { |
| 251 handleUncaughtError: (Zone self, ZoneDelegate parent, Zone zone, | 252 Function errorFunction = |
| 252 dynamic exception, StackTrace stackTrace) { | 253 (Zone self, ZoneDelegate parent, Zone zone, dynamic exception, |
| 254 StackTrace stackTrace) { |
| 255 service.logException(exception, stackTrace); |
| 253 socketServer.analysisServer.reportException(exception, stackTrace); | 256 socketServer.analysisServer.reportException(exception, stackTrace); |
| 254 throw exception; | 257 throw exception; |
| 255 }, | 258 }; |
| 256 print: print == null ? | 259 Function printFunction = print == null ? |
| 257 null : | 260 null : |
| 258 (Zone self, ZoneDelegate parent, Zone zone, String line) { | 261 (Zone self, ZoneDelegate parent, Zone zone, String line) { |
| 259 // Note: we don't pass the line on to stdout, because that is reserved | 262 // Note: we don't pass the line on to stdout, because that is reserved |
| 260 // for communication to the client. | 263 // for communication to the client. |
| 261 print(line); | 264 print(line); |
| 262 }); | 265 }; |
| 266 ZoneSpecification zoneSpecification = new ZoneSpecification( |
| 267 handleUncaughtError: errorFunction, |
| 268 print: printFunction); |
| 263 return runZoned(callback, zoneSpecification: zoneSpecification); | 269 return runZoned(callback, zoneSpecification: zoneSpecification); |
| 264 } | 270 } |
| 265 | 271 |
| 266 /** | 272 /** |
| 267 * Print information about how to use the server. | 273 * Print information about how to use the server. |
| 268 */ | 274 */ |
| 269 void _printUsage(ArgParser parser) { | 275 void _printUsage(ArgParser parser) { |
| 270 print('Usage: $BINARY_NAME [flags]'); | 276 print('Usage: $BINARY_NAME [flags]'); |
| 271 print(''); | 277 print(''); |
| 272 print('Supported flags are:'); | 278 print('Supported flags are:'); |
| 273 print(parser.usage); | 279 print(parser.usage); |
| 274 } | 280 } |
| 275 } | 281 } |
| OLD | NEW |