| OLD | NEW |
| 1 #!/usr/bin/env dart | 1 #!/usr/bin/env dart |
| 2 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 2 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
| 4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 /** The entry point for the analyzer. */ | 6 /** The entry point for the analyzer. */ |
| 7 library analyzer; | 7 library analyzer; |
| 8 | 8 |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 import 'dart:convert'; | 10 import 'dart:convert'; |
| 11 import 'dart:io'; | 11 import 'dart:io'; |
| 12 | 12 |
| 13 import 'package:analyzer/options.dart'; | 13 import 'package:analyzer/options.dart'; |
| 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/interner.dart'; | 17 import 'package:analyzer/src/generated/interner.dart'; |
| 18 import 'package:analyzer/src/generated/java_core.dart' show JavaSystem; | 18 import 'package:analyzer/src/generated/java_core.dart' show JavaSystem; |
| 19 import 'package:analyzer/src/generated/java_engine.dart'; | 19 import 'package:analyzer/src/generated/java_engine.dart'; |
| 20 import 'package:analyzer/src/generated/utilities_general.dart'; | 20 import 'package:analyzer/src/generated/utilities_general.dart'; |
| 21 | 21 |
| 22 void main(List<String> args) { | 22 void main(List<String> args) { |
| 23 StringUtilities.INTERNER = new MappedInterner(); | 23 StringUtilities.INTERNER = new MappedInterner(); |
| 24 CommandLineOptions options = CommandLineOptions.parse(args); | 24 CommandLineOptions options = CommandLineOptions.parse(args); |
| 25 if (options.shouldBatch) { | 25 if (options.shouldBatch) { |
| 26 BatchRunner.runAsBatch(args, (List<String> args) { | 26 BatchRunner.runAsBatch(args, (List<String> args) { |
| 27 CommandLineOptions options = CommandLineOptions.parse(args); | 27 CommandLineOptions options = CommandLineOptions.parse(args); |
| 28 return _analyzeAll(options); | 28 return _analyzeAll(options, true); |
| 29 }); | 29 }); |
| 30 } else { | 30 } else { |
| 31 _analyzeAll(options); | 31 _analyzeAll(options, false); |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 | 34 |
| 35 _analyzeAll(CommandLineOptions options) { | 35 _analyzeAll(CommandLineOptions options, bool isBatch) { |
| 36 if (!options.machineFormat) { | 36 if (!options.machineFormat) { |
| 37 stdout.writeln("Analyzing ${options.sourceFiles}..."); | 37 stdout.writeln("Analyzing ${options.sourceFiles}..."); |
| 38 } | 38 } |
| 39 ErrorSeverity allResult = ErrorSeverity.NONE; | 39 ErrorSeverity allResult = ErrorSeverity.NONE; |
| 40 for (String sourcePath in options.sourceFiles) { | 40 for (String sourcePath in options.sourceFiles) { |
| 41 sourcePath = sourcePath.trim(); | 41 sourcePath = sourcePath.trim(); |
| 42 // check that file exists | 42 // check that file exists |
| 43 if (!new File(sourcePath).existsSync()) { | 43 if (!new File(sourcePath).existsSync()) { |
| 44 print('File not found: $sourcePath'); | 44 print('File not found: $sourcePath'); |
| 45 exitCode = ErrorSeverity.ERROR.ordinal; | 45 exitCode = ErrorSeverity.ERROR.ordinal; |
| 46 // fail fast; don't analyze more files | 46 // fail fast; don't analyze more files |
| 47 return ErrorSeverity.ERROR; | 47 return ErrorSeverity.ERROR; |
| 48 } | 48 } |
| 49 // check that file is Dart file | 49 // check that file is Dart file |
| 50 if (!AnalysisEngine.isDartFileName(sourcePath)) { | 50 if (!AnalysisEngine.isDartFileName(sourcePath)) { |
| 51 print('$sourcePath is not a Dart file'); | 51 print('$sourcePath is not a Dart file'); |
| 52 exitCode = ErrorSeverity.ERROR.ordinal; | 52 exitCode = ErrorSeverity.ERROR.ordinal; |
| 53 // fail fast; don't analyze more files | 53 // fail fast; don't analyze more files |
| 54 return ErrorSeverity.ERROR; | 54 return ErrorSeverity.ERROR; |
| 55 } | 55 } |
| 56 ErrorSeverity status = _runAnalyzer(options, sourcePath); | 56 ErrorSeverity status = _runAnalyzer(options, sourcePath, isBatch); |
| 57 allResult = allResult.max(status); | 57 allResult = allResult.max(status); |
| 58 } | 58 } |
| 59 return allResult; | 59 return allResult; |
| 60 } | 60 } |
| 61 | 61 |
| 62 _runAnalyzer(CommandLineOptions options, String sourcePath) { | 62 _runAnalyzer(CommandLineOptions options, String sourcePath, bool isBatch) { |
| 63 if (options.warmPerf) { | 63 if (options.warmPerf) { |
| 64 int startTime = JavaSystem.currentTimeMillis(); | 64 int startTime = JavaSystem.currentTimeMillis(); |
| 65 AnalyzerImpl analyzer = new AnalyzerImpl(sourcePath, options, startTime); | 65 AnalyzerImpl analyzer = |
| 66 new AnalyzerImpl(sourcePath, options, startTime, isBatch); |
| 66 analyzer.analyzeSync(printMode: 2); | 67 analyzer.analyzeSync(printMode: 2); |
| 67 | 68 |
| 68 for (int i = 0; i < 8; i++) { | 69 for (int i = 0; i < 8; i++) { |
| 69 startTime = JavaSystem.currentTimeMillis(); | 70 startTime = JavaSystem.currentTimeMillis(); |
| 70 analyzer = new AnalyzerImpl(sourcePath, options, startTime); | 71 analyzer = new AnalyzerImpl(sourcePath, options, startTime, isBatch); |
| 71 analyzer.analyzeSync(printMode: 0); | 72 analyzer.analyzeSync(printMode: 0); |
| 72 } | 73 } |
| 73 | 74 |
| 74 PerformanceTag.reset(); | 75 PerformanceTag.reset(); |
| 75 startTime = JavaSystem.currentTimeMillis(); | 76 startTime = JavaSystem.currentTimeMillis(); |
| 76 analyzer = new AnalyzerImpl(sourcePath, options, startTime); | 77 analyzer = new AnalyzerImpl(sourcePath, options, startTime, isBatch); |
| 77 return analyzer.analyzeSync(); | 78 return analyzer.analyzeSync(); |
| 78 } | 79 } |
| 79 int startTime = JavaSystem.currentTimeMillis(); | 80 int startTime = JavaSystem.currentTimeMillis(); |
| 80 AnalyzerImpl analyzer = new AnalyzerImpl(sourcePath, options, startTime); | 81 AnalyzerImpl analyzer = |
| 82 new AnalyzerImpl(sourcePath, options, startTime, isBatch); |
| 81 var errorSeverity = analyzer.analyzeSync(); | 83 var errorSeverity = analyzer.analyzeSync(); |
| 82 if (errorSeverity == ErrorSeverity.ERROR) { | 84 if (errorSeverity == ErrorSeverity.ERROR) { |
| 83 exitCode = errorSeverity.ordinal; | 85 exitCode = errorSeverity.ordinal; |
| 84 } | 86 } |
| 85 if (options.warningsAreFatal && errorSeverity == ErrorSeverity.WARNING) { | 87 if (options.warningsAreFatal && errorSeverity == ErrorSeverity.WARNING) { |
| 86 exitCode = errorSeverity.ordinal; | 88 exitCode = errorSeverity.ordinal; |
| 87 } | 89 } |
| 88 return errorSeverity; | 90 return errorSeverity; |
| 89 } | 91 } |
| 90 | 92 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 '>>> TEST $resultPassString ${stopwatch.elapsedMilliseconds}ms'); | 142 '>>> TEST $resultPassString ${stopwatch.elapsedMilliseconds}ms'); |
| 141 } catch (e, stackTrace) { | 143 } catch (e, stackTrace) { |
| 142 stderr.writeln(e); | 144 stderr.writeln(e); |
| 143 stderr.writeln(stackTrace); | 145 stderr.writeln(stackTrace); |
| 144 stderr.writeln('>>> EOF STDERR'); | 146 stderr.writeln('>>> EOF STDERR'); |
| 145 stdout.writeln('>>> TEST CRASH'); | 147 stdout.writeln('>>> TEST CRASH'); |
| 146 } | 148 } |
| 147 }); | 149 }); |
| 148 } | 150 } |
| 149 } | 151 } |
| OLD | NEW |