Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(616)

Unified Diff: pkg/analysis_server/lib/src/analysis_manager.dart

Issue 725143004: Format and sort analyzer and analysis_server packages. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analysis_server/lib/src/analysis_logger.dart ('k') | pkg/analysis_server/lib/src/analysis_server.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/analysis_manager.dart
diff --git a/pkg/analysis_server/lib/src/analysis_manager.dart b/pkg/analysis_server/lib/src/analysis_manager.dart
index 22892b82abddd47df9f976b87123b8464566f839..d9c009264e9b3fb8b02903e79b92a6029cd8496c 100644
--- a/pkg/analysis_server/lib/src/analysis_manager.dart
+++ b/pkg/analysis_server/lib/src/analysis_manager.dart
@@ -30,19 +30,31 @@ class AnalysisManager {
ClientCommunicationChannel channel;
/**
- * Launch analysis server in a separate process
- * and return a future with a manager for that analysis server.
- */
- static Future<AnalysisManager> start(String serverPath) {
- return new AnalysisManager()._launchServer(serverPath);
- }
-
- /**
- * Open a connection to a running analysis server
- * and return a future with a manager for that analysis server.
+ * Stop the analysis server.
+ *
+ * Returns `true` if the signal is successfully sent and process terminates.
+ * Otherwise there was no attached process or the signal could not be sent,
+ * usually meaning that the process is already dead.
*/
- static Future<AnalysisManager> connect(String serverUrl) {
- return new AnalysisManager()._openConnection(serverUrl);
+ Future<bool> stop() {
+ if (process == null) {
+ return channel.close().then((_) => false);
+ }
+ return channel.sendRequest(
+ new ServerShutdownParams().toRequest(
+ '0')).timeout(new Duration(seconds: 2), onTimeout: () {
+ print('Expected shutdown response');
+ }).then((Response response) {
+ return channel.close().then((_) => process.exitCode);
+ }).timeout(new Duration(seconds: 2), onTimeout: () {
+ print('Expected server to shutdown');
+ process.kill();
+ }).then((int result) {
+ if (result != null && result != 0) {
+ exitCode = result;
+ }
+ return true;
+ });
}
/**
@@ -51,12 +63,10 @@ class AnalysisManager {
Future<AnalysisManager> _launchServer(String pathToServer) {
// TODO dynamically allocate port and/or allow client to specify port
List<String> serverArgs = [pathToServer, '--port', PORT.toString()];
- return Process.start(Platform.executable, serverArgs)
- .catchError((error) {
- exitCode = 1;
- throw 'Failed to launch analysis server: $error';
- })
- .then(_listenForPort);
+ return Process.start(Platform.executable, serverArgs).catchError((error) {
+ exitCode = 1;
+ throw 'Failed to launch analysis server: $error';
+ }).then(_listenForPort);
}
/**
@@ -72,18 +82,18 @@ class AnalysisManager {
// Listen for port from server
const String pattern = 'Listening on port ';
- return out.firstWhere((String line) => line.startsWith(pattern))
- .timeout(new Duration(seconds: 10))
- .catchError((error) {
- exitCode = 1;
- process.kill();
- throw 'Expected port from analysis server';
- })
- .then((String line) {
- String port = line.substring(pattern.length).trim();
- String url = 'ws://${InternetAddress.LOOPBACK_IP_V4.address}:$port/';
- return _openConnection(url);
- });
+ return out.firstWhere(
+ (String line) =>
+ line.startsWith(
+ pattern)).timeout(new Duration(seconds: 10)).catchError((error) {
+ exitCode = 1;
+ process.kill();
+ throw 'Expected port from analysis server';
+ }).then((String line) {
+ String port = line.substring(pattern.length).trim();
+ String url = 'ws://${InternetAddress.LOOPBACK_IP_V4.address}:$port/';
+ return _openConnection(url);
+ });
}
/**
@@ -98,45 +108,29 @@ class AnalysisManager {
throw 'Failed to connect to analysis server at $serverUrl\n $error';
};
try {
- return WebSocket.connect(serverUrl)
- .catchError(onError)
- .then((WebSocket socket) {
- this.channel = new WebSocketClientChannel(socket);
- return this;
- });
+ return WebSocket.connect(
+ serverUrl).catchError(onError).then((WebSocket socket) {
+ this.channel = new WebSocketClientChannel(socket);
+ return this;
+ });
} catch (error) {
onError(error);
}
}
/**
- * Stop the analysis server.
- *
- * Returns `true` if the signal is successfully sent and process terminates.
- * Otherwise there was no attached process or the signal could not be sent,
- * usually meaning that the process is already dead.
+ * Open a connection to a running analysis server
+ * and return a future with a manager for that analysis server.
*/
- Future<bool> stop() {
- if (process == null) {
- return channel.close().then((_) => false);
- }
- return channel
- .sendRequest(new ServerShutdownParams().toRequest('0'))
- .timeout(new Duration(seconds: 2), onTimeout: () {
- print('Expected shutdown response');
- })
- .then((Response response) {
- return channel.close().then((_) => process.exitCode);
- })
- .timeout(new Duration(seconds: 2), onTimeout: () {
- print('Expected server to shutdown');
- process.kill();
- })
- .then((int result) {
- if (result != null && result != 0) {
- exitCode = result;
- }
- return true;
- });
+ static Future<AnalysisManager> connect(String serverUrl) {
+ return new AnalysisManager()._openConnection(serverUrl);
+ }
+
+ /**
+ * Launch analysis server in a separate process
+ * and return a future with a manager for that analysis server.
+ */
+ static Future<AnalysisManager> start(String serverPath) {
+ return new AnalysisManager()._launchServer(serverPath);
}
}
« no previous file with comments | « pkg/analysis_server/lib/src/analysis_logger.dart ('k') | pkg/analysis_server/lib/src/analysis_server.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698