| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 input.transformer; | 5 library input.transformer; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 | 10 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 * to the target location of the source using during performance measurement. | 63 * to the target location of the source using during performance measurement. |
| 64 */ | 64 */ |
| 65 final Map<String, String> srcPathMap; | 65 final Map<String, String> srcPathMap; |
| 66 | 66 |
| 67 /** | 67 /** |
| 68 * The root directory for all source being modified | 68 * The root directory for all source being modified |
| 69 * during performance measurement. | 69 * during performance measurement. |
| 70 */ | 70 */ |
| 71 final String tmpSrcDirPath; | 71 final String tmpSrcDirPath; |
| 72 | 72 |
| 73 CommonInputConverter(this.tmpSrcDirPath, this.srcPathMap); | 73 /** |
| 74 * The diagnostic port for Analysis Server or `null` if none. |
| 75 */ |
| 76 final int diagnosticPort; |
| 77 |
| 78 CommonInputConverter(this.tmpSrcDirPath, this.srcPathMap, |
| 79 {this.diagnosticPort}); |
| 74 | 80 |
| 75 /** | 81 /** |
| 76 * Return an operation for the notification or `null` if none. | 82 * Return an operation for the notification or `null` if none. |
| 77 */ | 83 */ |
| 78 Operation convertNotification(Map<String, dynamic> json) { | 84 Operation convertNotification(Map<String, dynamic> json) { |
| 79 String event = json['event']; | 85 String event = json['event']; |
| 80 if (event == SERVER_STATUS) { | 86 if (event == SERVER_STATUS) { |
| 81 // {"event":"server.status","params":{"analysis":{"isAnalyzing":false}}} | 87 // {"event":"server.status","params":{"analysis":{"isAnalyzing":false}}} |
| 82 Map<String, dynamic> params = json['params']; | 88 Map<String, dynamic> params = json['params']; |
| 83 if (params != null) { | 89 if (params != null) { |
| 84 Map<String, dynamic> analysis = params['analysis']; | 90 Map<String, dynamic> analysis = params['analysis']; |
| 85 if (analysis != null && analysis['isAnalyzing'] == false) { | 91 if (analysis != null && analysis['isAnalyzing'] == false) { |
| 86 return new WaitForAnalysisCompleteOperation(); | 92 return new WaitForAnalysisCompleteOperation(); |
| 87 } | 93 } |
| 88 } | 94 } |
| 89 } | 95 } |
| 90 if (event == SERVER_CONNECTED) { | 96 if (event == SERVER_CONNECTED) { |
| 91 // {"event":"server.connected","params":{"version":"1.7.0"}} | 97 // {"event":"server.connected","params":{"version":"1.7.0"}} |
| 92 return new StartServerOperation(); | 98 return new StartServerOperation(diagnosticPort: diagnosticPort); |
| 93 } | 99 } |
| 94 if (eventsSeen.add(event)) { | 100 if (eventsSeen.add(event)) { |
| 95 logger.log(Level.INFO, 'Ignored notification: $event\n $json'); | 101 logger.log(Level.INFO, 'Ignored notification: $event\n $json'); |
| 96 } | 102 } |
| 97 return null; | 103 return null; |
| 98 } | 104 } |
| 99 | 105 |
| 100 /** | 106 /** |
| 101 * Return an operation for the request or `null` if none. | 107 * Return an operation for the request or `null` if none. |
| 102 */ | 108 */ |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 */ | 283 */ |
| 278 final Map<String, String> srcPathMap; | 284 final Map<String, String> srcPathMap; |
| 279 | 285 |
| 280 /** | 286 /** |
| 281 * The root directory for all source being modified | 287 * The root directory for all source being modified |
| 282 * during performance measurement. | 288 * during performance measurement. |
| 283 */ | 289 */ |
| 284 final String tmpSrcDirPath; | 290 final String tmpSrcDirPath; |
| 285 | 291 |
| 286 /** | 292 /** |
| 293 * The diagnostic port for Analysis Server or `null` if none. |
| 294 */ |
| 295 final int diagnosticPort; |
| 296 |
| 297 /** |
| 287 * The number of lines read before the underlying converter was determined | 298 * The number of lines read before the underlying converter was determined |
| 288 * or the end of file was reached. | 299 * or the end of file was reached. |
| 289 */ | 300 */ |
| 290 int headerLineCount = 0; | 301 int headerLineCount = 0; |
| 291 | 302 |
| 292 /** | 303 /** |
| 293 * The underlying converter used to translate lines into operations | 304 * The underlying converter used to translate lines into operations |
| 294 * or `null` if it has not yet been determined. | 305 * or `null` if it has not yet been determined. |
| 295 */ | 306 */ |
| 296 Converter<String, Operation> converter; | 307 Converter<String, Operation> converter; |
| 297 | 308 |
| 298 /** | 309 /** |
| 299 * [active] is `true` if converting lines to operations | 310 * [active] is `true` if converting lines to operations |
| 300 * or `false` if an exception has occurred. | 311 * or `false` if an exception has occurred. |
| 301 */ | 312 */ |
| 302 bool active = true; | 313 bool active = true; |
| 303 | 314 |
| 304 InputConverter(this.tmpSrcDirPath, this.srcPathMap); | 315 InputConverter(this.tmpSrcDirPath, this.srcPathMap, {this.diagnosticPort}); |
| 305 | 316 |
| 306 @override | 317 @override |
| 307 Operation convert(String line) { | 318 Operation convert(String line) { |
| 308 if (!active) { | 319 if (!active) { |
| 309 return null; | 320 return null; |
| 310 } | 321 } |
| 311 if (converter != null) { | 322 if (converter != null) { |
| 312 try { | 323 try { |
| 313 return converter.convert(line); | 324 return converter.convert(line); |
| 314 } catch (e) { | 325 } catch (e) { |
| 315 active = false; | 326 active = false; |
| 316 rethrow; | 327 rethrow; |
| 317 } | 328 } |
| 318 } | 329 } |
| 319 if (headerLineCount == 20) { | 330 if (headerLineCount == 20) { |
| 320 throw 'Failed to determine input file format'; | 331 throw 'Failed to determine input file format'; |
| 321 } | 332 } |
| 322 if (InstrumentationInputConverter.isFormat(line)) { | 333 if (InstrumentationInputConverter.isFormat(line)) { |
| 323 converter = new InstrumentationInputConverter(tmpSrcDirPath, srcPathMap); | 334 converter = new InstrumentationInputConverter(tmpSrcDirPath, srcPathMap, |
| 335 diagnosticPort: diagnosticPort); |
| 324 } else if (LogFileInputConverter.isFormat(line)) { | 336 } else if (LogFileInputConverter.isFormat(line)) { |
| 325 converter = new LogFileInputConverter(tmpSrcDirPath, srcPathMap); | 337 converter = new LogFileInputConverter(tmpSrcDirPath, srcPathMap, |
| 338 diagnosticPort: diagnosticPort); |
| 326 } | 339 } |
| 327 if (converter != null) { | 340 if (converter != null) { |
| 328 return converter.convert(line); | 341 return converter.convert(line); |
| 329 } | 342 } |
| 330 logger.log(Level.INFO, 'skipped input line: $line'); | 343 logger.log(Level.INFO, 'skipped input line: $line'); |
| 331 return null; | 344 return null; |
| 332 } | 345 } |
| 333 | 346 |
| 334 @override | 347 @override |
| 335 _InputSink startChunkedConversion(outSink) { | 348 _InputSink startChunkedConversion(outSink) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 349 if (op != null) { | 362 if (op != null) { |
| 350 outSink.add(op); | 363 outSink.add(op); |
| 351 } | 364 } |
| 352 } | 365 } |
| 353 | 366 |
| 354 @override | 367 @override |
| 355 void close() { | 368 void close() { |
| 356 outSink.close(); | 369 outSink.close(); |
| 357 } | 370 } |
| 358 } | 371 } |
| OLD | NEW |