| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:convert'; | 6 import 'dart:convert'; |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| 10 import 'package:analysis_server/src/channel/channel.dart'; | 10 import 'package:analysis_server/src/channel/channel.dart'; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 if (result != null && result != 0) { | 53 if (result != null && result != 0) { |
| 54 exitCode = result; | 54 exitCode = result; |
| 55 } | 55 } |
| 56 return true; | 56 return true; |
| 57 }); | 57 }); |
| 58 } | 58 } |
| 59 | 59 |
| 60 /** | 60 /** |
| 61 * Launch an analysis server and open a connection to that server. | 61 * Launch an analysis server and open a connection to that server. |
| 62 */ | 62 */ |
| 63 Future<AnalysisManager> _launchServer(String pathToServer) { | 63 Future<AnalysisManager> _launchServer(String pathToServer) async { |
| 64 // TODO dynamically allocate port and/or allow client to specify port | 64 try { |
| 65 List<String> serverArgs = [pathToServer, '--port', PORT.toString()]; | 65 // TODO dynamically allocate port and/or allow client to specify port |
| 66 return Process.start(Platform.executable, serverArgs).catchError((error) { | 66 List<String> serverArgs = [pathToServer, '--port', PORT.toString()]; |
| 67 Process process = await Process.start(Platform.executable, serverArgs); |
| 68 return _listenForPort(process); |
| 69 } catch (error) { |
| 67 exitCode = 1; | 70 exitCode = 1; |
| 68 throw 'Failed to launch analysis server: $error'; | 71 throw 'Failed to launch analysis server: $error'; |
| 69 }).then(_listenForPort); | 72 } |
| 70 } | 73 } |
| 71 | 74 |
| 72 /** | 75 /** |
| 73 * Listen for a port from the given analysis server process. | 76 * Listen for a port from the given analysis server process. |
| 74 */ | 77 */ |
| 75 Future<AnalysisManager> _listenForPort(Process process) { | 78 Future<AnalysisManager> _listenForPort(Process process) { |
| 76 this.process = process; | 79 this.process = process; |
| 77 | 80 |
| 78 // Echo stdout and stderr | 81 // Echo stdout and stderr |
| 79 Stream out = process.stdout.transform(UTF8.decoder).asBroadcastStream(); | 82 Stream out = process.stdout.transform(UTF8.decoder).asBroadcastStream(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 } | 132 } |
| 130 | 133 |
| 131 /** | 134 /** |
| 132 * Launch analysis server in a separate process | 135 * Launch analysis server in a separate process |
| 133 * and return a future with a manager for that analysis server. | 136 * and return a future with a manager for that analysis server. |
| 134 */ | 137 */ |
| 135 static Future<AnalysisManager> start(String serverPath) { | 138 static Future<AnalysisManager> start(String serverPath) { |
| 136 return new AnalysisManager()._launchServer(serverPath); | 139 return new AnalysisManager()._launchServer(serverPath); |
| 137 } | 140 } |
| 138 } | 141 } |
| OLD | NEW |