| OLD | NEW |
| 1 #!/usr/bin/env dart | 1 #!/usr/bin/env dart |
| 2 | 2 |
| 3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 4 // for details. All rights reserved. Use of this source code is governed by a | 4 // for details. All rights reserved. Use of this source code is governed by a |
| 5 // BSD-style license that can be found in the LICENSE file. | 5 // BSD-style license that can be found in the LICENSE file. |
| 6 | 6 |
| 7 /** The entry point for the analyzer. */ | 7 /** The entry point for the analyzer. */ |
| 8 library analyzer; | 8 library analyzer; |
| 9 | 9 |
| 10 import 'dart:async'; | 10 import 'dart:async'; |
| 11 import 'dart:convert'; | 11 import 'dart:convert'; |
| 12 import 'dart:io'; | 12 import 'dart:io'; |
| 13 | 13 |
| 14 import 'package:analyzer/src/analyzer_impl.dart'; | 14 import 'package:analyzer/src/analyzer_impl.dart'; |
| 15 import 'package:analyzer/src/generated/engine.dart'; | 15 import 'package:analyzer/src/generated/engine.dart'; |
| 16 import 'package:analyzer/src/generated/error.dart'; | 16 import 'package:analyzer/src/generated/error.dart'; |
| 17 import 'package:analyzer/src/generated/java_core.dart' show JavaSystem; | 17 import 'package:analyzer/src/generated/java_core.dart' show JavaSystem; |
| 18 import 'package:analyzer/options.dart'; | 18 import 'package:analyzer/options.dart'; |
| 19 | 19 |
| 20 void main(args) { | 20 void main(args) { |
| 21 CommandLineOptions options = CommandLineOptions.parse(args); | 21 CommandLineOptions options = CommandLineOptions.parse(args); |
| 22 if (options.shouldBatch) { | 22 if (options.shouldBatch) { |
| 23 BatchRunner.runAsBatch(args, (List<String> args) { | 23 BatchRunner.runAsBatch(args, (List<String> args) { |
| 24 CommandLineOptions options = CommandLineOptions.parse(args); | 24 CommandLineOptions options = CommandLineOptions.parse(args); |
| 25 _runAnalyzer(options); | 25 return _runAnalyzer(options, false); |
| 26 }); | 26 }); |
| 27 } else { | 27 } else { |
| 28 _runAnalyzer(options); | 28 _runAnalyzer(options); |
| 29 } | 29 } |
| 30 } | 30 } |
| 31 | 31 |
| 32 void _runAnalyzer(CommandLineOptions options) { | 32 _runAnalyzer(CommandLineOptions options, [bool async = true]) { |
| 33 int startTime = JavaSystem.currentTimeMillis(); | 33 int startTime = JavaSystem.currentTimeMillis(); |
| 34 if (!options.machineFormat) { | 34 if (!options.machineFormat) { |
| 35 stdout.writeln("Analyzing ${options.sourceFiles}..."); | 35 stdout.writeln("Analyzing ${options.sourceFiles}..."); |
| 36 } | 36 } |
| 37 ErrorSeverity allResult = ErrorSeverity.NONE; | 37 ErrorSeverity allResult = ErrorSeverity.NONE; |
| 38 String sourcePath = options.sourceFiles[0]; | 38 String sourcePath = options.sourceFiles[0]; |
| 39 sourcePath = sourcePath.trim(); | 39 sourcePath = sourcePath.trim(); |
| 40 // check that file exists | 40 // check that file exists |
| 41 if (!new File(sourcePath).existsSync()) { | 41 if (!new File(sourcePath).existsSync()) { |
| 42 print('File not found: $sourcePath'); | 42 print('File not found: $sourcePath'); |
| 43 exitCode = ErrorSeverity.ERROR.ordinal; | 43 exitCode = ErrorSeverity.ERROR.ordinal; |
| 44 return; | 44 return ErrorSeverity.ERROR; |
| 45 } | 45 } |
| 46 // check that file is Dart file | 46 // check that file is Dart file |
| 47 if (!AnalysisEngine.isDartFileName(sourcePath)) { | 47 if (!AnalysisEngine.isDartFileName(sourcePath)) { |
| 48 print('$sourcePath is not a Dart file'); | 48 print('$sourcePath is not a Dart file'); |
| 49 exitCode = ErrorSeverity.ERROR.ordinal; | 49 exitCode = ErrorSeverity.ERROR.ordinal; |
| 50 return; | 50 return ErrorSeverity.ERROR; |
| 51 } | 51 } |
| 52 // do analyze | 52 // do analyze |
| 53 AnalyzerImpl analyzer = new AnalyzerImpl(sourcePath, options, startTime); | 53 AnalyzerImpl analyzer = new AnalyzerImpl(sourcePath, options, startTime); |
| 54 analyzer.analyze(); | 54 if (async) { |
| 55 return analyzer.analyzeAsync(); |
| 56 } else { |
| 57 return analyzer.analyzeSync(); |
| 58 } |
| 55 } | 59 } |
| 56 | 60 |
| 57 typedef ErrorSeverity BatchRunnerHandler(List<String> args); | 61 typedef ErrorSeverity BatchRunnerHandler(List<String> args); |
| 58 | 62 |
| 59 /// Provides a framework to read command line options from stdin and feed them t
o a callback. | 63 /// Provides a framework to read command line options from stdin and feed them t
o a callback. |
| 60 class BatchRunner { | 64 class BatchRunner { |
| 61 /** | 65 /** |
| 62 * Run the tool in 'batch' mode, receiving command lines through stdin and ret
urning pass/fail | 66 * Run the tool in 'batch' mode, receiving command lines through stdin and ret
urning pass/fail |
| 63 * status through stdout. This feature is intended for use in unit testing. | 67 * status through stdout. This feature is intended for use in unit testing. |
| 64 */ | 68 */ |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 stdout.writeln('>>> TEST $resultPassString ${stopwatch.elapsedMillisecon
ds}ms'); | 111 stdout.writeln('>>> TEST $resultPassString ${stopwatch.elapsedMillisecon
ds}ms'); |
| 108 } catch (e, stackTrace) { | 112 } catch (e, stackTrace) { |
| 109 stderr.writeln(e); | 113 stderr.writeln(e); |
| 110 stderr.writeln(stackTrace); | 114 stderr.writeln(stackTrace); |
| 111 stderr.writeln('>>> EOF STDERR'); | 115 stderr.writeln('>>> EOF STDERR'); |
| 112 stdout.writeln('>>> TEST CRASH'); | 116 stdout.writeln('>>> TEST CRASH'); |
| 113 } | 117 } |
| 114 }); | 118 }); |
| 115 } | 119 } |
| 116 } | 120 } |
| OLD | NEW |