| 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/src/channel.dart'; | 9 import 'package:analysis_server/src/channel.dart'; |
| 10 import 'package:analysis_server/src/domain_server.dart'; | 10 import 'package:analysis_server/src/domain_server.dart'; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 */ | 43 */ |
| 44 static Future<AnalysisManager> connect(String serverUrl) { | 44 static Future<AnalysisManager> connect(String serverUrl) { |
| 45 return new AnalysisManager()._openConnection(serverUrl); | 45 return new AnalysisManager()._openConnection(serverUrl); |
| 46 } | 46 } |
| 47 | 47 |
| 48 /** | 48 /** |
| 49 * Launch an analysis server and open a connection to that server. | 49 * Launch an analysis server and open a connection to that server. |
| 50 */ | 50 */ |
| 51 Future<AnalysisManager> _launchServer(String pathToServer) { | 51 Future<AnalysisManager> _launchServer(String pathToServer) { |
| 52 // TODO dynamically allocate port and/or allow client to specify port | 52 // TODO dynamically allocate port and/or allow client to specify port |
| 53 var serverArgs = [pathToServer, '--port', PORT.toString()]; | 53 List<String> serverArgs = [pathToServer, '--port', PORT.toString()]; |
| 54 return Process.start(Platform.executable, serverArgs) | 54 return Process.start(Platform.executable, serverArgs) |
| 55 .catchError((error) { | 55 .catchError((error) { |
| 56 exitCode = 1; | 56 exitCode = 1; |
| 57 throw 'Failed to launch analysis server: $error'; | 57 throw 'Failed to launch analysis server: $error'; |
| 58 }) | 58 }) |
| 59 .then(_listenForPort); | 59 .then(_listenForPort); |
| 60 } | 60 } |
| 61 | 61 |
| 62 /** | 62 /** |
| 63 * Listen for a port from the given analysis server process. | 63 * Listen for a port from the given analysis server process. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 74 const String pattern = 'Listening on port '; | 74 const String pattern = 'Listening on port '; |
| 75 return out.firstWhere((String line) => line.startsWith(pattern)) | 75 return out.firstWhere((String line) => line.startsWith(pattern)) |
| 76 .timeout(new Duration(seconds: 10)) | 76 .timeout(new Duration(seconds: 10)) |
| 77 .catchError((error) { | 77 .catchError((error) { |
| 78 exitCode = 1; | 78 exitCode = 1; |
| 79 process.kill(); | 79 process.kill(); |
| 80 throw 'Expected port from analysis server'; | 80 throw 'Expected port from analysis server'; |
| 81 }) | 81 }) |
| 82 .then((String line) { | 82 .then((String line) { |
| 83 String port = line.substring(pattern.length).trim(); | 83 String port = line.substring(pattern.length).trim(); |
| 84 var url = 'ws://${InternetAddress.LOOPBACK_IP_V4.address}:$port/'; | 84 String url = 'ws://${InternetAddress.LOOPBACK_IP_V4.address}:$port/'; |
| 85 return _openConnection(url); | 85 return _openConnection(url); |
| 86 }); | 86 }); |
| 87 } | 87 } |
| 88 | 88 |
| 89 /** | 89 /** |
| 90 * Open a connection to the analysis server using the given URL. | 90 * Open a connection to the analysis server using the given URL. |
| 91 */ | 91 */ |
| 92 Future<AnalysisManager> _openConnection(String serverUrl) { | 92 Future<AnalysisManager> _openConnection(String serverUrl) { |
| 93 var onError = (error) { | 93 Function onError = (error) { |
| 94 exitCode = 1; | 94 exitCode = 1; |
| 95 if (process != null) { | 95 if (process != null) { |
| 96 process.kill(); | 96 process.kill(); |
| 97 } | 97 } |
| 98 throw 'Failed to connect to analysis server at $serverUrl\n $error'; | 98 throw 'Failed to connect to analysis server at $serverUrl\n $error'; |
| 99 }; | 99 }; |
| 100 try { | 100 try { |
| 101 return WebSocket.connect(serverUrl) | 101 return WebSocket.connect(serverUrl) |
| 102 .catchError(onError) | 102 .catchError(onError) |
| 103 .then((WebSocket socket) { | 103 .then((WebSocket socket) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 133 process.kill(); | 133 process.kill(); |
| 134 }) | 134 }) |
| 135 .then((int result) { | 135 .then((int result) { |
| 136 if (result != null && result != 0) { | 136 if (result != null && result != 0) { |
| 137 exitCode = result; | 137 exitCode = result; |
| 138 } | 138 } |
| 139 return true; | 139 return true; |
| 140 }); | 140 }); |
| 141 } | 141 } |
| 142 } | 142 } |
| OLD | NEW |