| 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'; |
| 11 import 'package:analysis_server/src/analysis_server.dart'; | 11 import 'package:analysis_server/src/analysis_server.dart'; |
| 12 import 'package:analysis_server/src/socket_server.dart'; | 12 import 'package:analysis_server/src/socket_server.dart'; |
| 13 import 'package:analysis_server/stdio_server.dart'; | 13 import 'package:analysis_server/stdio_server.dart'; |
| 14 import 'package:analyzer/src/generated/incremental_logger.dart'; |
| 14 import 'package:analyzer/src/generated/java_io.dart'; | 15 import 'package:analyzer/src/generated/java_io.dart'; |
| 15 import 'package:analyzer/src/generated/sdk.dart'; | 16 import 'package:analyzer/src/generated/sdk.dart'; |
| 16 import 'package:analyzer/src/generated/sdk_io.dart'; | 17 import 'package:analyzer/src/generated/sdk_io.dart'; |
| 17 import 'package:args/args.dart'; | 18 import 'package:args/args.dart'; |
| 18 | 19 |
| 20 |
| 21 /** |
| 22 * Initializes incremental logger. |
| 23 * |
| 24 * Supports following formats of [spec]: |
| 25 * |
| 26 * "console" - log to the console; |
| 27 * "file:/some/file/name" - log to the file, overwritten on start. |
| 28 */ |
| 29 void _initIncrementalLogger(String spec) { |
| 30 logger = new NullLogger(); |
| 31 if (spec == null) { |
| 32 return; |
| 33 } |
| 34 // create logger |
| 35 if (spec == 'console') { |
| 36 logger = new StringSinkLogger(console.log); |
| 37 } |
| 38 if (spec.startsWith('file:')) { |
| 39 String fileName = spec.substring('file:'.length); |
| 40 File file = new File(fileName); |
| 41 IOSink sink = file.openWrite(); |
| 42 logger = new StringSinkLogger(sink); |
| 43 } |
| 44 } |
| 45 |
| 46 |
| 19 /** | 47 /** |
| 20 * The [Driver] class represents a single running instance of the analysis | 48 * The [Driver] class represents a single running instance of the analysis |
| 21 * server application. It is responsible for parsing command line options | 49 * server application. It is responsible for parsing command line options |
| 22 * and starting the HTTP and/or stdio servers. | 50 * and starting the HTTP and/or stdio servers. |
| 23 */ | 51 */ |
| 24 class Driver { | 52 class Driver { |
| 25 /** | 53 /** |
| 26 * The name of the application that is used to start a server. | 54 * The name of the application that is used to start a server. |
| 27 */ | 55 */ |
| 28 static const BINARY_NAME = "server"; | 56 static const BINARY_NAME = "server"; |
| 29 | 57 |
| 30 /** | 58 /** |
| 31 * The name of the option used to enable incremental resolution. | 59 * The name of the option used to enable incremental resolution. |
| 32 */ | 60 */ |
| 33 static const String ENABLE_INCREMENTAL_RESOLUTION = | 61 static const String ENABLE_INCREMENTAL_RESOLUTION = |
| 34 "enable-incremental-resolution"; | 62 "enable-incremental-resolution"; |
| 35 | 63 |
| 36 /** | 64 /** |
| 65 * The name of the option used to describe the incremental resolution logger. |
| 66 */ |
| 67 static const String INCREMENTAL_RESOLUTION_LOG = "incremental-resolution-log"; |
| 68 |
| 69 /** |
| 37 * The name of the option used to enable instrumentation. | 70 * The name of the option used to enable instrumentation. |
| 38 */ | 71 */ |
| 39 static const String ENABLE_INSTRUMENTATION_OPTION = "enable-instrumentation"; | 72 static const String ENABLE_INSTRUMENTATION_OPTION = "enable-instrumentation"; |
| 40 | 73 |
| 41 /** | 74 /** |
| 42 * The name of the option used to print usage information. | 75 * The name of the option used to print usage information. |
| 43 */ | 76 */ |
| 44 static const String HELP_OPTION = "help"; | 77 static const String HELP_OPTION = "help"; |
| 45 | 78 |
| 46 /** | 79 /** |
| 47 * The name of the option used to specify the log file to which | 80 * The name of the option used to specify the log file to which |
| 48 * instrumentation data is to be written. | 81 * instrumentation data is to be written. |
| 49 */ | 82 */ |
| 50 static const String INSTRUMENTATION_LOG_FILE_OPTION = | 83 static const String INSTRUMENTATION_LOG_FILE_OPTION = |
| 51 "instrumentation-log-file"; | 84 "instrumentation-log-file"; |
| 52 | 85 |
| 53 /** | 86 /** |
| 54 * The name of the option used to specify if [print] should print to the | 87 * The name of the option used to specify if [print] should print to the |
| 55 * console instead of being intercepted. | 88 * console instead of being intercepted. |
| 56 */ | 89 */ |
| 57 static const String INTERNAL_PRINT_TO_CONSOLE = | 90 static const String INTERNAL_PRINT_TO_CONSOLE = "internal-print-to-console"; |
| 58 "internal-print-to-console"; | |
| 59 | 91 |
| 60 /** | 92 /** |
| 61 * The name of the option used to specify the port to which the server will | 93 * The name of the option used to specify the port to which the server will |
| 62 * connect. | 94 * connect. |
| 63 */ | 95 */ |
| 64 static const String PORT_OPTION = "port"; | 96 static const String PORT_OPTION = "port"; |
| 65 | 97 |
| 66 /** | 98 /** |
| 67 * The path to the SDK. | 99 * The path to the SDK. |
| 68 * TODO(paulberry): get rid of this once the 'analysis.updateSdks' request is | 100 * TODO(paulberry): get rid of this once the 'analysis.updateSdks' request is |
| (...skipping 27 matching lines...) Expand all Loading... |
| 96 ENABLE_INSTRUMENTATION_OPTION, | 128 ENABLE_INSTRUMENTATION_OPTION, |
| 97 help: "enable sending instrumentation information to a server", | 129 help: "enable sending instrumentation information to a server", |
| 98 defaultsTo: false, | 130 defaultsTo: false, |
| 99 negatable: false); | 131 negatable: false); |
| 100 parser.addFlag( | 132 parser.addFlag( |
| 101 HELP_OPTION, | 133 HELP_OPTION, |
| 102 help: "print this help message without starting a server", | 134 help: "print this help message without starting a server", |
| 103 defaultsTo: false, | 135 defaultsTo: false, |
| 104 negatable: false); | 136 negatable: false); |
| 105 parser.addOption( | 137 parser.addOption( |
| 138 INCREMENTAL_RESOLUTION_LOG, |
| 139 help: "the description of the incremental resolotion log"); |
| 140 parser.addOption( |
| 106 INSTRUMENTATION_LOG_FILE_OPTION, | 141 INSTRUMENTATION_LOG_FILE_OPTION, |
| 107 help: "[path] the file to which instrumentation data will be logged"); | 142 help: "[path] the file to which instrumentation data will be logged"); |
| 108 parser.addFlag( | 143 parser.addFlag( |
| 109 INTERNAL_PRINT_TO_CONSOLE, | 144 INTERNAL_PRINT_TO_CONSOLE, |
| 110 help: "enable sending `print` output to the console", | 145 help: "enable sending `print` output to the console", |
| 111 defaultsTo: false, | 146 defaultsTo: false, |
| 112 negatable: false); | 147 negatable: false); |
| 113 parser.addOption( | 148 parser.addOption( |
| 114 PORT_OPTION, | 149 PORT_OPTION, |
| 115 help: "[port] the port on which the server will listen"); | 150 help: "[port] the port on which the server will listen"); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 _printUsage(parser); | 183 _printUsage(parser); |
| 149 exitCode = 1; | 184 exitCode = 1; |
| 150 return; | 185 return; |
| 151 } | 186 } |
| 152 } | 187 } |
| 153 | 188 |
| 154 AnalysisServerOptions analysisServerOptions = new AnalysisServerOptions(); | 189 AnalysisServerOptions analysisServerOptions = new AnalysisServerOptions(); |
| 155 analysisServerOptions.enableIncrementalResolution = | 190 analysisServerOptions.enableIncrementalResolution = |
| 156 results[ENABLE_INCREMENTAL_RESOLUTION]; | 191 results[ENABLE_INCREMENTAL_RESOLUTION]; |
| 157 | 192 |
| 193 _initIncrementalLogger(results[INCREMENTAL_RESOLUTION_LOG]); |
| 194 |
| 158 DartSdk defaultSdk; | 195 DartSdk defaultSdk; |
| 159 if (results[SDK_OPTION] != null) { | 196 if (results[SDK_OPTION] != null) { |
| 160 defaultSdk = new DirectoryBasedDartSdk(new JavaFile(results[SDK_OPTION])); | 197 defaultSdk = new DirectoryBasedDartSdk(new JavaFile(results[SDK_OPTION])); |
| 161 } else { | 198 } else { |
| 162 // No path to the SDK provided; use DirectoryBasedDartSdk.defaultSdk, | 199 // No path to the SDK provided; use DirectoryBasedDartSdk.defaultSdk, |
| 163 // which will make a guess. | 200 // which will make a guess. |
| 164 defaultSdk = DirectoryBasedDartSdk.defaultSdk; | 201 defaultSdk = DirectoryBasedDartSdk.defaultSdk; |
| 165 } | 202 } |
| 166 | 203 |
| 167 socketServer = new SocketServer(analysisServerOptions, defaultSdk); | 204 socketServer = new SocketServer(analysisServerOptions, defaultSdk); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 /** | 245 /** |
| 209 * Print information about how to use the server. | 246 * Print information about how to use the server. |
| 210 */ | 247 */ |
| 211 void _printUsage(ArgParser parser) { | 248 void _printUsage(ArgParser parser) { |
| 212 print('Usage: $BINARY_NAME [flags]'); | 249 print('Usage: $BINARY_NAME [flags]'); |
| 213 print(''); | 250 print(''); |
| 214 print('Supported flags are:'); | 251 print('Supported flags are:'); |
| 215 print(parser.usage); | 252 print(parser.usage); |
| 216 } | 253 } |
| 217 } | 254 } |
| OLD | NEW |