| 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 library driver; | 5 library driver; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'package:analysis_server/http_server.dart'; | 10 import 'package:analysis_server/http_server.dart'; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 * server application. It is responsible for parsing command line options | 50 * server application. It is responsible for parsing command line options |
| 51 * and starting the HTTP and/or stdio servers. | 51 * and starting the HTTP and/or stdio servers. |
| 52 */ | 52 */ |
| 53 class Driver { | 53 class Driver { |
| 54 /** | 54 /** |
| 55 * The name of the application that is used to start a server. | 55 * The name of the application that is used to start a server. |
| 56 */ | 56 */ |
| 57 static const BINARY_NAME = "server"; | 57 static const BINARY_NAME = "server"; |
| 58 | 58 |
| 59 /** | 59 /** |
| 60 * The name of the option used to set the identifier for the client. |
| 61 */ |
| 62 static const String CLIENT_ID = "client-id"; |
| 63 |
| 64 /** |
| 60 * The name of the option used to enable incremental resolution. | 65 * The name of the option used to enable incremental resolution. |
| 61 */ | 66 */ |
| 62 static const String ENABLE_INCREMENTAL_RESOLUTION = | 67 static const String ENABLE_INCREMENTAL_RESOLUTION = |
| 63 "enable-incremental-resolution"; | 68 "enable-incremental-resolution"; |
| 64 | 69 |
| 65 /** | 70 /** |
| 66 * The name of the option used to enable incremental resolution of API | 71 * The name of the option used to enable incremental resolution of API |
| 67 * changes. | 72 * changes. |
| 68 */ | 73 */ |
| 69 static const String ENABLE_INCREMENTAL_RESOLUTION_API = | 74 static const String ENABLE_INCREMENTAL_RESOLUTION_API = |
| 70 "enable-incremental-resolution-api"; | 75 "enable-incremental-resolution-api"; |
| 71 | 76 |
| 72 /** | 77 /** |
| 73 * The name of the option used to describe the incremental resolution logger. | 78 * The name of the option used to describe the incremental resolution logger. |
| 74 */ | 79 */ |
| 75 static const String INCREMENTAL_RESOLUTION_LOG = "incremental-resolution-log"; | 80 static const String INCREMENTAL_RESOLUTION_LOG = "incremental-resolution-log"; |
| 76 | 81 |
| 77 /** | 82 /** |
| 78 * The name of the option used to enable instrumentation. | 83 * The name of the option used to enable instrumentation. |
| 79 */ | 84 */ |
| 80 static const String ENABLE_INSTRUMENTATION_OPTION = "enable-instrumentation"; | 85 static const String ENABLE_INSTRUMENTATION_OPTION = "enable-instrumentation"; |
| 81 | 86 |
| 82 /** | 87 /** |
| 83 * The name of the option used to print usage information. | 88 * The name of the option used to print usage information. |
| 84 */ | 89 */ |
| 85 static const String HELP_OPTION = "help"; | 90 static const String HELP_OPTION = "help"; |
| 86 | 91 |
| 87 /** | 92 /** |
| 88 * The name of the option used to specify the log file to which | |
| 89 * instrumentation data is to be written. | |
| 90 */ | |
| 91 static const String INSTRUMENTATION_LOG_FILE_OPTION = | |
| 92 "instrumentation-log-file"; | |
| 93 | |
| 94 /** | |
| 95 * The name of the option used to specify if [print] should print to the | 93 * The name of the option used to specify if [print] should print to the |
| 96 * console instead of being intercepted. | 94 * console instead of being intercepted. |
| 97 */ | 95 */ |
| 98 static const String INTERNAL_PRINT_TO_CONSOLE = "internal-print-to-console"; | 96 static const String INTERNAL_PRINT_TO_CONSOLE = "internal-print-to-console"; |
| 99 | 97 |
| 100 /** | 98 /** |
| 101 * The name of the option used to specify the port to which the server will | 99 * The name of the option used to specify the port to which the server will |
| 102 * connect. | 100 * connect. |
| 103 */ | 101 */ |
| 104 static const String PORT_OPTION = "port"; | 102 static const String PORT_OPTION = "port"; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 125 HttpAnalysisServer httpServer; | 123 HttpAnalysisServer httpServer; |
| 126 | 124 |
| 127 StdioAnalysisServer stdioServer; | 125 StdioAnalysisServer stdioServer; |
| 128 | 126 |
| 129 Driver(); | 127 Driver(); |
| 130 /** | 128 /** |
| 131 * Use the given command-line arguments to start this server. | 129 * Use the given command-line arguments to start this server. |
| 132 */ | 130 */ |
| 133 void start(List<String> args) { | 131 void start(List<String> args) { |
| 134 ArgParser parser = new ArgParser(); | 132 ArgParser parser = new ArgParser(); |
| 133 parser.addOption( |
| 134 CLIENT_ID, |
| 135 help: "an identifier used to identify the client"); |
| 135 parser.addFlag( | 136 parser.addFlag( |
| 136 ENABLE_INCREMENTAL_RESOLUTION, | 137 ENABLE_INCREMENTAL_RESOLUTION, |
| 137 help: "enable using incremental resolution", | 138 help: "enable using incremental resolution", |
| 138 defaultsTo: false, | 139 defaultsTo: false, |
| 139 negatable: false); | 140 negatable: false); |
| 140 parser.addFlag( | 141 parser.addFlag( |
| 141 ENABLE_INCREMENTAL_RESOLUTION_API, | 142 ENABLE_INCREMENTAL_RESOLUTION_API, |
| 142 help: "enable using incremental resolution for API changes", | 143 help: "enable using incremental resolution for API changes", |
| 143 defaultsTo: false, | 144 defaultsTo: false, |
| 144 negatable: false); | 145 negatable: false); |
| 145 parser.addFlag( | 146 parser.addFlag( |
| 146 ENABLE_INSTRUMENTATION_OPTION, | 147 ENABLE_INSTRUMENTATION_OPTION, |
| 147 help: "enable sending instrumentation information to a server", | 148 help: "enable sending instrumentation information to a server", |
| 148 defaultsTo: false, | 149 defaultsTo: false, |
| 149 negatable: false); | 150 negatable: false); |
| 150 parser.addFlag( | 151 parser.addFlag( |
| 151 HELP_OPTION, | 152 HELP_OPTION, |
| 152 help: "print this help message without starting a server", | 153 help: "print this help message without starting a server", |
| 153 defaultsTo: false, | 154 defaultsTo: false, |
| 154 negatable: false); | 155 negatable: false); |
| 155 parser.addOption( | 156 parser.addOption( |
| 156 INCREMENTAL_RESOLUTION_LOG, | 157 INCREMENTAL_RESOLUTION_LOG, |
| 157 help: "the description of the incremental resolotion log"); | 158 help: "the description of the incremental resolotion log"); |
| 158 parser.addOption( | |
| 159 INSTRUMENTATION_LOG_FILE_OPTION, | |
| 160 help: "[path] the file to which instrumentation data will be logged"); | |
| 161 parser.addFlag( | 159 parser.addFlag( |
| 162 INTERNAL_PRINT_TO_CONSOLE, | 160 INTERNAL_PRINT_TO_CONSOLE, |
| 163 help: "enable sending `print` output to the console", | 161 help: "enable sending `print` output to the console", |
| 164 defaultsTo: false, | 162 defaultsTo: false, |
| 165 negatable: false); | 163 negatable: false); |
| 166 parser.addOption( | 164 parser.addOption( |
| 167 PORT_OPTION, | 165 PORT_OPTION, |
| 168 help: "[port] the port on which the server will listen"); | 166 help: "[port] the port on which the server will listen"); |
| 169 parser.addOption(SDK_OPTION, help: "[path] the path to the sdk"); | 167 parser.addOption(SDK_OPTION, help: "[path] the path to the sdk"); |
| 170 parser.addFlag( | 168 parser.addFlag( |
| 171 NO_ERROR_NOTIFICATION, | 169 NO_ERROR_NOTIFICATION, |
| 172 help: | 170 help: |
| 173 "disable sending all analysis error notifications to the server (not
yet implemented)", | 171 "disable sending all analysis error notifications to the server (not
yet implemented)", |
| 174 defaultsTo: false, | 172 defaultsTo: false, |
| 175 negatable: false); | 173 negatable: false); |
| 176 | 174 |
| 177 ArgResults results = parser.parse(args); | 175 ArgResults results = parser.parse(args); |
| 178 if (results[HELP_OPTION]) { | 176 if (results[HELP_OPTION]) { |
| 179 _printUsage(parser); | 177 _printUsage(parser); |
| 180 return; | 178 return; |
| 181 } | 179 } |
| 182 | 180 |
| 183 // TODO(brianwilkerson) Enable this after it is possible for an | 181 // TODO(brianwilkerson) Enable this after it is possible for an |
| 184 // instrumentation server to be provided. | 182 // instrumentation server to be provided. |
| 185 // if (results[ENABLE_INSTRUMENTATION_OPTION]) { | 183 // if (results[ENABLE_INSTRUMENTATION_OPTION]) { |
| 186 //// if (results[INSTRUMENTATION_LOG_FILE_OPTION] != null) { | |
| 187 //// // TODO(brianwilkerson) Initialize the instrumentation server with | |
| 188 //// // logging. | |
| 189 //// } else { | |
| 190 //// // TODO(brianwilkerson) Initialize the instrumentation server withou
t | |
| 191 //// // logging. | |
| 192 //// } | |
| 193 // if (instrumentationServer == null) { | 184 // if (instrumentationServer == null) { |
| 194 // print('Exiting server: enabled instrumentation without providing an in
strumentation server'); | 185 // print('Exiting server: enabled instrumentation without providing an in
strumentation server'); |
| 195 // print(''); | 186 // print(''); |
| 196 // _printUsage(parser); | 187 // _printUsage(parser); |
| 197 // return; | 188 // return; |
| 198 // } | 189 // } |
| 199 // } else { | 190 // } else { |
| 200 // if (instrumentationServer != null) { | 191 // if (instrumentationServer != null) { |
| 201 // print('Exiting server: providing an instrumentation server without ena
bling instrumentation'); | 192 // print('Exiting server: providing an instrumentation server without ena
bling instrumentation'); |
| 202 // print(''); | 193 // print(''); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 232 if (results[SDK_OPTION] != null) { | 223 if (results[SDK_OPTION] != null) { |
| 233 defaultSdk = new DirectoryBasedDartSdk(new JavaFile(results[SDK_OPTION])); | 224 defaultSdk = new DirectoryBasedDartSdk(new JavaFile(results[SDK_OPTION])); |
| 234 } else { | 225 } else { |
| 235 // No path to the SDK provided; use DirectoryBasedDartSdk.defaultSdk, | 226 // No path to the SDK provided; use DirectoryBasedDartSdk.defaultSdk, |
| 236 // which will make a guess. | 227 // which will make a guess. |
| 237 defaultSdk = DirectoryBasedDartSdk.defaultSdk; | 228 defaultSdk = DirectoryBasedDartSdk.defaultSdk; |
| 238 } | 229 } |
| 239 | 230 |
| 240 InstrumentationService service = | 231 InstrumentationService service = |
| 241 new InstrumentationService(instrumentationServer); | 232 new InstrumentationService(instrumentationServer); |
| 242 // service.logVersion(defaultSdk.sdkVersion); | 233 // service.logVersion(results[CLIENT_ID], defaultSdk.sdkVersion); |
| 243 | 234 |
| 244 socketServer = new SocketServer(analysisServerOptions, defaultSdk, service); | 235 socketServer = new SocketServer(analysisServerOptions, defaultSdk, service); |
| 245 httpServer = new HttpAnalysisServer(socketServer); | 236 httpServer = new HttpAnalysisServer(socketServer); |
| 246 stdioServer = new StdioAnalysisServer(socketServer); | 237 stdioServer = new StdioAnalysisServer(socketServer); |
| 247 | 238 |
| 248 if (serve_http) { | 239 if (serve_http) { |
| 249 httpServer.serveHttp(port); | 240 httpServer.serveHttp(port); |
| 250 } | 241 } |
| 251 | 242 |
| 252 if (results[INTERNAL_PRINT_TO_CONSOLE]) { | 243 if (results[INTERNAL_PRINT_TO_CONSOLE]) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 /** | 276 /** |
| 286 * Print information about how to use the server. | 277 * Print information about how to use the server. |
| 287 */ | 278 */ |
| 288 void _printUsage(ArgParser parser) { | 279 void _printUsage(ArgParser parser) { |
| 289 print('Usage: $BINARY_NAME [flags]'); | 280 print('Usage: $BINARY_NAME [flags]'); |
| 290 print(''); | 281 print(''); |
| 291 print('Supported flags are:'); | 282 print('Supported flags are:'); |
| 292 print(parser.usage); | 283 print(parser.usage); |
| 293 } | 284 } |
| 294 } | 285 } |
| OLD | NEW |