| 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/constants.dart'; | |
| 11 import 'package:analysis_server/src/protocol.dart'; | 10 import 'package:analysis_server/src/protocol.dart'; |
| 12 | 11 |
| 13 /** | 12 /** |
| 14 * [AnalysisManager] is used to launch and manage an analysis server | 13 * [AnalysisManager] is used to launch and manage an analysis server |
| 15 * running in a separate process using either the [start] or [connect] methods. | 14 * running in a separate process using either the [start] or [connect] methods. |
| 16 */ | 15 */ |
| 17 class AnalysisManager { | 16 class AnalysisManager { |
| 18 // TODO dynamically allocate port and/or allow client to specify port | 17 // TODO dynamically allocate port and/or allow client to specify port |
| 19 static const int PORT = 3333; | 18 static const int PORT = 3333; |
| 20 | 19 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 * | 113 * |
| 115 * Returns `true` if the signal is successfully sent and process terminates. | 114 * Returns `true` if the signal is successfully sent and process terminates. |
| 116 * Otherwise there was no attached process or the signal could not be sent, | 115 * Otherwise there was no attached process or the signal could not be sent, |
| 117 * usually meaning that the process is already dead. | 116 * usually meaning that the process is already dead. |
| 118 */ | 117 */ |
| 119 Future<bool> stop() { | 118 Future<bool> stop() { |
| 120 if (process == null) { | 119 if (process == null) { |
| 121 return channel.close().then((_) => false); | 120 return channel.close().then((_) => false); |
| 122 } | 121 } |
| 123 return channel | 122 return channel |
| 124 .sendRequest(new Request('0', SERVER_SHUTDOWN)) | 123 .sendRequest(new ServerShutdownParams().toRequest('0')) |
| 125 .timeout(new Duration(seconds: 2), onTimeout: () { | 124 .timeout(new Duration(seconds: 2), onTimeout: () { |
| 126 print('Expected shutdown response'); | 125 print('Expected shutdown response'); |
| 127 }) | 126 }) |
| 128 .then((Response response) { | 127 .then((Response response) { |
| 129 return channel.close().then((_) => process.exitCode); | 128 return channel.close().then((_) => process.exitCode); |
| 130 }) | 129 }) |
| 131 .timeout(new Duration(seconds: 2), onTimeout: () { | 130 .timeout(new Duration(seconds: 2), onTimeout: () { |
| 132 print('Expected server to shutdown'); | 131 print('Expected server to shutdown'); |
| 133 process.kill(); | 132 process.kill(); |
| 134 }) | 133 }) |
| 135 .then((int result) { | 134 .then((int result) { |
| 136 if (result != null && result != 0) { | 135 if (result != null && result != 0) { |
| 137 exitCode = result; | 136 exitCode = result; |
| 138 } | 137 } |
| 139 return true; | 138 return true; |
| 140 }); | 139 }); |
| 141 } | 140 } |
| 142 } | 141 } |
| OLD | NEW |