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

Side by Side Diff: pkg/analysis_server/lib/driver.dart

Issue 751353002: An option to enable 'print' to send output to the console. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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
« no previous file with comments | « editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/DartCoreDebug.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 static const String HELP_OPTION = "help"; 44 static const String HELP_OPTION = "help";
45 45
46 /** 46 /**
47 * The name of the option used to specify the log file to which 47 * The name of the option used to specify the log file to which
48 * instrumentation data is to be written. 48 * instrumentation data is to be written.
49 */ 49 */
50 static const String INSTRUMENTATION_LOG_FILE_OPTION = 50 static const String INSTRUMENTATION_LOG_FILE_OPTION =
51 "instrumentation-log-file"; 51 "instrumentation-log-file";
52 52
53 /** 53 /**
54 * The name of the option used to specify if [print] should print to the
55 * console instead of being intercepted.
56 */
57 static const String INTERNAL_PRINT_TO_CONSOLE =
58 "internal-print-to-console";
59
60 /**
54 * The name of the option used to specify the port to which the server will 61 * The name of the option used to specify the port to which the server will
55 * connect. 62 * connect.
56 */ 63 */
57 static const String PORT_OPTION = "port"; 64 static const String PORT_OPTION = "port";
58 65
59 /** 66 /**
60 * The path to the SDK. 67 * The path to the SDK.
61 * TODO(paulberry): get rid of this once the 'analysis.updateSdks' request is 68 * TODO(paulberry): get rid of this once the 'analysis.updateSdks' request is
62 * operational. 69 * operational.
63 */ 70 */
(...skipping 27 matching lines...) Expand all
91 defaultsTo: false, 98 defaultsTo: false,
92 negatable: false); 99 negatable: false);
93 parser.addFlag( 100 parser.addFlag(
94 HELP_OPTION, 101 HELP_OPTION,
95 help: "print this help message without starting a server", 102 help: "print this help message without starting a server",
96 defaultsTo: false, 103 defaultsTo: false,
97 negatable: false); 104 negatable: false);
98 parser.addOption( 105 parser.addOption(
99 INSTRUMENTATION_LOG_FILE_OPTION, 106 INSTRUMENTATION_LOG_FILE_OPTION,
100 help: "[path] the file to which instrumentation data will be logged"); 107 help: "[path] the file to which instrumentation data will be logged");
108 parser.addFlag(
109 INTERNAL_PRINT_TO_CONSOLE,
110 help: "enable sending `print` output to the console",
111 defaultsTo: false,
112 negatable: false);
101 parser.addOption( 113 parser.addOption(
102 PORT_OPTION, 114 PORT_OPTION,
103 help: "[port] the port on which the server will listen"); 115 help: "[port] the port on which the server will listen");
104 parser.addOption(SDK_OPTION, help: "[path] the path to the sdk"); 116 parser.addOption(SDK_OPTION, help: "[path] the path to the sdk");
105 parser.addFlag( 117 parser.addFlag(
106 NO_ERROR_NOTIFICATION, 118 NO_ERROR_NOTIFICATION,
107 help: 119 help:
108 "disable sending all analysis error notifications to the server (not yet implemented)", 120 "disable sending all analysis error notifications to the server (not yet implemented)",
109 defaultsTo: false, 121 defaultsTo: false,
110 negatable: false); 122 negatable: false);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 defaultSdk = DirectoryBasedDartSdk.defaultSdk; 164 defaultSdk = DirectoryBasedDartSdk.defaultSdk;
153 } 165 }
154 166
155 socketServer = new SocketServer(analysisServerOptions, defaultSdk); 167 socketServer = new SocketServer(analysisServerOptions, defaultSdk);
156 httpServer = new HttpAnalysisServer(socketServer); 168 httpServer = new HttpAnalysisServer(socketServer);
157 stdioServer = new StdioAnalysisServer(socketServer); 169 stdioServer = new StdioAnalysisServer(socketServer);
158 170
159 if (serve_http) { 171 if (serve_http) {
160 httpServer.serveHttp(port); 172 httpServer.serveHttp(port);
161 } 173 }
162 _capturePrints(() { 174
175 if (results[INTERNAL_PRINT_TO_CONSOLE]) {
163 stdioServer.serveStdio().then((_) { 176 stdioServer.serveStdio().then((_) {
164 if (serve_http) { 177 if (serve_http) {
165 httpServer.close(); 178 httpServer.close();
166 } 179 }
167 exit(0); 180 exit(0);
168 }); 181 });
169 }, httpServer.recordPrint); 182 } else {
183 _capturePrints(() {
184 stdioServer.serveStdio().then((_) {
185 if (serve_http) {
186 httpServer.close();
187 }
188 exit(0);
189 });
190 }, httpServer.recordPrint);
191 }
170 } 192 }
171 193
172 /** 194 /**
173 * Execute [callback], capturing any data it prints out and redirecting it to 195 * Execute [callback], capturing any data it prints out and redirecting it to
174 * the function [printHandler]. 196 * the function [printHandler].
175 */ 197 */
176 dynamic _capturePrints(dynamic callback(), void printHandler(String line)) { 198 dynamic _capturePrints(dynamic callback(), void printHandler(String line)) {
177 ZoneSpecification zoneSpecification = new ZoneSpecification( 199 ZoneSpecification zoneSpecification = new ZoneSpecification(
178 print: (Zone self, ZoneDelegate parent, Zone zone, String line) { 200 print: (Zone self, ZoneDelegate parent, Zone zone, String line) {
179 printHandler(line); 201 printHandler(line);
180 // Note: we don't pass the line on to stdout, because that is reserved 202 // Note: we don't pass the line on to stdout, because that is reserved
181 // for communication to the client. 203 // for communication to the client.
182 }); 204 });
183 return runZoned(callback, zoneSpecification: zoneSpecification); 205 return runZoned(callback, zoneSpecification: zoneSpecification);
184 } 206 }
185 207
186 /** 208 /**
187 * Print information about how to use the server. 209 * Print information about how to use the server.
188 */ 210 */
189 void _printUsage(ArgParser parser) { 211 void _printUsage(ArgParser parser) {
190 print('Usage: $BINARY_NAME [flags]'); 212 print('Usage: $BINARY_NAME [flags]');
191 print(''); 213 print('');
192 print('Supported flags are:'); 214 print('Supported flags are:');
193 print(parser.usage); 215 print(parser.usage);
194 } 216 }
195 } 217 }
OLDNEW
« no previous file with comments | « editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/DartCoreDebug.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698