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

Side by Side Diff: pkg/analysis_server/bin/dartdeps.dart

Issue 175183008: Analysis server connect fixes (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: add comment Created 6 years, 10 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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:io'; 6 import 'dart:io';
7 7
8 import 'package:args/args.dart'; 8 import 'package:args/args.dart';
9 import 'package:analysis_server/src/analysis_manager.dart'; 9 import 'package:analysis_server/src/analysis_manager.dart';
10 10
(...skipping 15 matching lines...) Expand all
26 * The name of the application that is used to start the analyzer. 26 * The name of the application that is used to start the analyzer.
27 */ 27 */
28 static const BINARY_NAME = 'dartdeps'; 28 static const BINARY_NAME = 'dartdeps';
29 29
30 /** 30 /**
31 * The name of the option used to print usage information. 31 * The name of the option used to print usage information.
32 */ 32 */
33 static const String HELP_OPTION = "help"; 33 static const String HELP_OPTION = "help";
34 34
35 /** 35 /**
36 * The name of the option used to specify an already running server.
37 */
38 static const String SERVER_OPTION = "server";
39
40 /**
36 * Parse the command line arguments to determine the application to be 41 * Parse the command line arguments to determine the application to be
37 * analyzed, then launch and manage an analysis server to do the work. 42 * analyzed, then launch and manage an analysis server to do the work.
38 * If there is a problem with the given arguments, then return a non zero 43 * If there is a problem with the given arguments, then return a non zero
39 * value, otherwise return zero. 44 * value, otherwise return zero.
40 */ 45 */
41 void start(List<String> args) { 46 void start(List<String> args) {
42 var parser = new ArgParser(); 47 var parser = new ArgParser();
43 parser.addFlag(HELP_OPTION, help: 48 parser.addFlag(HELP_OPTION,
44 "print this help message without starting analysis", defaultsTo: false, 49 help: "print this help message without starting analysis",
50 defaultsTo: false,
45 negatable: false); 51 negatable: false);
52 parser.addOption(
53 SERVER_OPTION,
54 help: "[serverUrl] use an analysis server thats already running");
46 55
47 // Parse arguments 56 // Parse arguments
48 ArgResults results = parser.parse(args); 57 ArgResults results;
58 try {
59 results = parser.parse(args);
60 } on FormatException catch(e) {
61 print(e.message);
62 print('');
63 printUsage(parser);
64 exitCode = 1;
65 return;
66 }
49 if (results[HELP_OPTION]) { 67 if (results[HELP_OPTION]) {
50 printUsage(parser); 68 printUsage(parser);
51 return; 69 return;
52 } 70 }
53 if (results.rest.length == 0) { 71 if (results.rest.length == 0) {
54 printUsage(parser); 72 printUsage(parser);
55 exitCode = 1; 73 exitCode = 1;
56 return; 74 return;
57 } 75 }
58 Directory appDir = new Directory(results.rest[0]); 76 Directory appDir = new Directory(results.rest[0]);
59 if (!appDir.existsSync()) { 77 if (!appDir.existsSync()) {
60 print('Specified application directory does not exist: $appDir'); 78 print('Specified application directory does not exist: $appDir');
61 print(''); 79 print('');
62 printUsage(parser); 80 printUsage(parser);
63 exitCode = 1; 81 exitCode = 1;
64 return; 82 return;
65 } 83 }
66 if (results.rest.length > 1) { 84 if (results.rest.length > 1) {
67 print('Unexpected arguments after $appDir'); 85 print('Unexpected arguments after $appDir');
68 print(''); 86 print('');
69 printUsage(parser); 87 printUsage(parser);
70 exitCode = 1; 88 exitCode = 1;
71 return; 89 return;
72 } 90 }
73 91
74 // Assume that the analysis server entry point is in the same directory 92 Future<AnalysisManager> future;
75 StringBuffer path = new StringBuffer(); 93 String serverUrl = results[SERVER_OPTION];
76 path.write(FileSystemEntity.parentOf(Platform.script.toFilePath())); 94 if (serverUrl != null) {
77 path.write(Platform.pathSeparator); 95 // Connect to an already running analysis server
78 path.write("server.dart"); 96 future = AnalysisManager.connect(serverUrl);
79 97
80 // Launch analysis server 98 } else {
81 AnalysisManager.start(path.toString()).then(analyze); 99 // Launch and connect to a new analysis server
100 // Assume that the analysis server entry point is in the same directory
101 StringBuffer path = new StringBuffer();
102 path.write(FileSystemEntity.parentOf(Platform.script.toFilePath()));
103 path.write(Platform.pathSeparator);
104 path.write("server.dart");
105 future = AnalysisManager.start(path.toString());
106 }
107 future.then(analyze);
82 } 108 }
83 109
84 void analyze(AnalysisManager mgr) { 110 void analyze(AnalysisManager mgr) {
85 print("Analyzing..."); 111 print("Analyzing...");
86 new Timer(new Duration(seconds: 5), () { 112 new Timer(new Duration(seconds: 5), () {
87 if (mgr.stop()) { 113 if (mgr.stop()) {
88 print("stopped"); 114 print("stopped");
89 } else { 115 } else {
90 print("already stopped"); 116 print("already stopped");
91 } 117 }
92 }); 118 });
93 } 119 }
94 120
95 /** 121 /**
96 * Print information about how to use the server. 122 * Print information about how to use the server.
97 */ 123 */
98 void printUsage(ArgParser parser) { 124 void printUsage(ArgParser parser) {
99 print('Usage: $BINARY_NAME [flags] <application_directory>'); 125 print('Usage: $BINARY_NAME [flags] <application_directory>');
100 print(''); 126 print('');
101 print('Supported flags are:'); 127 print('Supported flags are:');
102 print(parser.getUsage()); 128 print(parser.getUsage());
103 } 129 }
104 } 130 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/http_server.dart » ('j') | pkg/analysis_server/lib/src/analysis_manager.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698