| 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'; | |
| 11 import 'dart:convert'; | 10 import 'dart:convert'; |
| 12 import 'dart:io'; | 11 import 'dart:io'; |
| 13 | 12 |
| 14 import 'package:analyzer/src/analyzer_impl.dart'; | 13 import 'package:analyzer/src/analyzer_impl.dart'; |
| 15 import 'package:analyzer/src/generated/engine.dart'; | 14 import 'package:analyzer/src/generated/engine.dart'; |
| 16 import 'package:analyzer/src/generated/error.dart'; | 15 import 'package:analyzer/src/generated/error.dart'; |
| 17 import 'package:analyzer/src/generated/interner.dart'; | 16 import 'package:analyzer/src/generated/interner.dart'; |
| 18 import 'package:analyzer/src/generated/java_core.dart' show JavaSystem; | 17 import 'package:analyzer/src/generated/java_core.dart' show JavaSystem; |
| 19 import 'package:analyzer/src/generated/java_engine.dart'; | 18 import 'package:analyzer/src/generated/java_engine.dart'; |
| 20 import 'package:analyzer/options.dart'; | 19 import 'package:analyzer/options.dart'; |
| 21 | 20 |
| 22 void main(args) { | 21 void main(args) { |
| 23 StringUtilities.INTERNER = new MappedInterner(); | 22 StringUtilities.INTERNER = new MappedInterner(); |
| 24 CommandLineOptions options = CommandLineOptions.parse(args); | 23 CommandLineOptions options = CommandLineOptions.parse(args); |
| 25 if (options.shouldBatch) { | 24 if (options.shouldBatch) { |
| 26 BatchRunner.runAsBatch(args, (List<String> args) { | 25 BatchRunner.runAsBatch(args, (List<String> args) { |
| 27 CommandLineOptions options = CommandLineOptions.parse(args); | 26 CommandLineOptions options = CommandLineOptions.parse(args); |
| 28 return _runAnalyzer(options, false); | 27 return _analyzeAll(options); |
| 29 }); | 28 }); |
| 30 } else { | 29 } else { |
| 31 _runAnalyzer(options, false); | 30 _analyzeAll(options); |
| 32 } | 31 } |
| 33 } | 32 } |
| 34 | 33 |
| 35 _runAnalyzer(CommandLineOptions options, [bool async = true]) { | 34 _analyzeAll(CommandLineOptions options) { |
| 36 if (!options.machineFormat) { | 35 if (!options.machineFormat) { |
| 37 stdout.writeln("Analyzing ${options.sourceFiles}..."); | 36 stdout.writeln("Analyzing ${options.sourceFiles}..."); |
| 38 } | 37 } |
| 39 ErrorSeverity allResult = ErrorSeverity.NONE; | 38 ErrorSeverity allResult = ErrorSeverity.NONE; |
| 40 String sourcePath = options.sourceFiles[0]; | 39 for (String sourcePath in options.sourceFiles) { |
| 41 sourcePath = sourcePath.trim(); | 40 sourcePath = sourcePath.trim(); |
| 42 // check that file exists | 41 // check that file exists |
| 43 if (!new File(sourcePath).existsSync()) { | 42 if (!new File(sourcePath).existsSync()) { |
| 44 print('File not found: $sourcePath'); | 43 print('File not found: $sourcePath'); |
| 45 exitCode = ErrorSeverity.ERROR.ordinal; | 44 exitCode = ErrorSeverity.ERROR.ordinal; |
| 46 return ErrorSeverity.ERROR; | 45 // fail fast; don't analyze more files |
| 46 return ErrorSeverity.ERROR; |
| 47 } |
| 48 // check that file is Dart file |
| 49 if (!AnalysisEngine.isDartFileName(sourcePath)) { |
| 50 print('$sourcePath is not a Dart file'); |
| 51 exitCode = ErrorSeverity.ERROR.ordinal; |
| 52 // fail fast; don't analyze more files |
| 53 return ErrorSeverity.ERROR; |
| 54 } |
| 55 ErrorSeverity status = _runAnalyzer(options, sourcePath); |
| 56 allResult = allResult.max(status); |
| 47 } | 57 } |
| 48 // check that file is Dart file | 58 return allResult; |
| 49 if (!AnalysisEngine.isDartFileName(sourcePath)) { | 59 } |
| 50 print('$sourcePath is not a Dart file'); | 60 |
| 51 exitCode = ErrorSeverity.ERROR.ordinal; | 61 _runAnalyzer(CommandLineOptions options, String sourcePath) { |
| 52 return ErrorSeverity.ERROR; | |
| 53 } | |
| 54 // do analyze | |
| 55 if (options.warmPerf) { | 62 if (options.warmPerf) { |
| 56 int startTime = JavaSystem.currentTimeMillis(); | 63 int startTime = JavaSystem.currentTimeMillis(); |
| 57 AnalyzerImpl analyzer = new AnalyzerImpl(sourcePath, options, startTime); | 64 AnalyzerImpl analyzer = new AnalyzerImpl(sourcePath, options, startTime); |
| 58 analyzer.analyzeSync(printMode: 2); | 65 analyzer.analyzeSync(printMode: 2); |
| 59 | 66 |
| 60 for (int i = 0; i < 8; i++) { | 67 for (int i = 0; i < 8; i++) { |
| 61 startTime = JavaSystem.currentTimeMillis(); | 68 startTime = JavaSystem.currentTimeMillis(); |
| 62 analyzer = new AnalyzerImpl(sourcePath, options, startTime); | 69 analyzer = new AnalyzerImpl(sourcePath, options, startTime); |
| 63 analyzer.analyzeSync(printMode: 0); | 70 analyzer.analyzeSync(printMode: 0); |
| 64 } | 71 } |
| 65 | 72 |
| 66 PerformanceStatistics.reset(); | 73 PerformanceStatistics.reset(); |
| 67 startTime = JavaSystem.currentTimeMillis(); | 74 startTime = JavaSystem.currentTimeMillis(); |
| 68 analyzer = new AnalyzerImpl(sourcePath, options, startTime); | 75 analyzer = new AnalyzerImpl(sourcePath, options, startTime); |
| 69 return analyzer.analyzeSync(); | 76 return analyzer.analyzeSync(); |
| 70 } | 77 } |
| 71 int startTime = JavaSystem.currentTimeMillis(); | 78 int startTime = JavaSystem.currentTimeMillis(); |
| 72 AnalyzerImpl analyzer = new AnalyzerImpl(sourcePath, options, startTime); | 79 AnalyzerImpl analyzer = new AnalyzerImpl(sourcePath, options, startTime); |
| 73 if (async) { | 80 var errorSeverity = analyzer.analyzeSync(); |
| 74 return analyzer.analyzeAsync(); | 81 if (errorSeverity == ErrorSeverity.ERROR) { |
| 75 } else { | 82 exitCode = errorSeverity.ordinal; |
| 76 var errorSeverity = analyzer.analyzeSync(); | |
| 77 if (errorSeverity == ErrorSeverity.ERROR) { | |
| 78 exitCode = errorSeverity.ordinal; | |
| 79 } | |
| 80 if (options.warningsAreFatal && errorSeverity == ErrorSeverity.WARNING) { | |
| 81 exitCode = errorSeverity.ordinal; | |
| 82 } | |
| 83 return errorSeverity; | |
| 84 } | 83 } |
| 84 if (options.warningsAreFatal && errorSeverity == ErrorSeverity.WARNING) { |
| 85 exitCode = errorSeverity.ordinal; |
| 86 } |
| 87 return errorSeverity; |
| 85 } | 88 } |
| 86 | 89 |
| 87 typedef ErrorSeverity BatchRunnerHandler(List<String> args); | 90 typedef ErrorSeverity BatchRunnerHandler(List<String> args); |
| 88 | 91 |
| 89 /// Provides a framework to read command line options from stdin and feed them t
o a callback. | 92 /// Provides a framework to read command line options from stdin and feed them t
o a callback. |
| 90 class BatchRunner { | 93 class BatchRunner { |
| 91 /** | 94 /** |
| 92 * Run the tool in 'batch' mode, receiving command lines through stdin and ret
urning pass/fail | 95 * Run the tool in 'batch' mode, receiving command lines through stdin and ret
urning pass/fail |
| 93 * status through stdout. This feature is intended for use in unit testing. | 96 * status through stdout. This feature is intended for use in unit testing. |
| 94 */ | 97 */ |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 stdout.writeln('>>> TEST $resultPassString ${stopwatch.elapsedMillisecon
ds}ms'); | 138 stdout.writeln('>>> TEST $resultPassString ${stopwatch.elapsedMillisecon
ds}ms'); |
| 136 } catch (e, stackTrace) { | 139 } catch (e, stackTrace) { |
| 137 stderr.writeln(e); | 140 stderr.writeln(e); |
| 138 stderr.writeln(stackTrace); | 141 stderr.writeln(stackTrace); |
| 139 stderr.writeln('>>> EOF STDERR'); | 142 stderr.writeln('>>> EOF STDERR'); |
| 140 stdout.writeln('>>> TEST CRASH'); | 143 stdout.writeln('>>> TEST CRASH'); |
| 141 } | 144 } |
| 142 }); | 145 }); |
| 143 } | 146 } |
| 144 } | 147 } |
| OLD | NEW |