Index: pkg/analyzer_cli/lib/src/driver.dart |
diff --git a/pkg/analyzer_cli/lib/src/driver.dart b/pkg/analyzer_cli/lib/src/driver.dart |
index d3dc92e76f2cc379487bded60f0640f98baa4ffa..1a22de5803f31170953917c0d9b50570305f6efa 100644 |
--- a/pkg/analyzer_cli/lib/src/driver.dart |
+++ b/pkg/analyzer_cli/lib/src/driver.dart |
@@ -2,10 +2,7 @@ |
// for details. All rights reserved. Use of this source code is governed by a |
// BSD-style license that can be found in the LICENSE file. |
-library analyzer_cli.src.driver; |
- |
import 'dart:async'; |
-import 'dart:convert'; |
import 'dart:io' as io; |
import 'package:analyzer/error/error.dart'; |
@@ -36,6 +33,7 @@ import 'package:analyzer/src/summary/idl.dart'; |
import 'package:analyzer/src/summary/package_bundle_reader.dart'; |
import 'package:analyzer/src/summary/summary_sdk.dart' show SummaryBasedDartSdk; |
import 'package:analyzer_cli/src/analyzer_impl.dart'; |
+import 'package:analyzer_cli/src/batch_mode.dart'; |
import 'package:analyzer_cli/src/build_mode.dart'; |
import 'package:analyzer_cli/src/error_formatter.dart'; |
import 'package:analyzer_cli/src/error_severity.dart'; |
@@ -68,8 +66,6 @@ bool containsLintRuleEntry(Map<String, YamlNode> options) { |
return linterNode is YamlMap && linterNode.containsKey('rules'); |
} |
-typedef Future<ErrorSeverity> _BatchRunnerHandler(List<String> args); |
- |
class Driver implements CommandLineStarter { |
static final PerformanceTag _analyzeAllTag = |
new PerformanceTag("Driver._analyzeAll"); |
@@ -139,7 +135,8 @@ class Driver implements CommandLineStarter { |
io.exitCode = severity.ordinal; |
} |
} else if (options.shouldBatch) { |
- _BatchRunner.runAsBatch(args, (List<String> args) async { |
+ BatchRunner batchRunner = new BatchRunner(outSink, errorSink); |
+ batchRunner.runAsBatch(args, (List<String> args) async { |
CommandLineOptions options = CommandLineOptions.parse(args); |
return await _analyzeAll(options); |
}); |
@@ -854,61 +851,6 @@ class Driver implements CommandLineStarter { |
path.normalize(new io.File(sourcePath).absolute.path); |
} |
-/// Provides a framework to read command line options from stdin and feed them |
-/// to a callback. |
-class _BatchRunner { |
- /// Run the tool in 'batch' mode, receiving command lines through stdin and |
- /// returning pass/fail status through stdout. This feature is intended for |
- /// use in unit testing. |
- static void runAsBatch(List<String> sharedArgs, _BatchRunnerHandler handler) { |
- outSink.writeln('>>> BATCH START'); |
- Stopwatch stopwatch = new Stopwatch(); |
- stopwatch.start(); |
- int testsFailed = 0; |
- int totalTests = 0; |
- ErrorSeverity batchResult = ErrorSeverity.NONE; |
- // Read line from stdin. |
- Stream cmdLine = |
- io.stdin.transform(UTF8.decoder).transform(new LineSplitter()); |
- cmdLine.listen((String line) async { |
- // Maybe finish. |
- if (line.isEmpty) { |
- var time = stopwatch.elapsedMilliseconds; |
- outSink.writeln( |
- '>>> BATCH END (${totalTests - testsFailed}/$totalTests) ${time}ms'); |
- io.exitCode = batchResult.ordinal; |
- } |
- // Prepare arguments. |
- var lineArgs = line.split(new RegExp('\\s+')); |
- var args = new List<String>(); |
- args.addAll(sharedArgs); |
- args.addAll(lineArgs); |
- args.remove('-b'); |
- args.remove('--batch'); |
- // Analyze single set of arguments. |
- try { |
- totalTests++; |
- ErrorSeverity result = await handler(args); |
- bool resultPass = result != ErrorSeverity.ERROR; |
- if (!resultPass) { |
- testsFailed++; |
- } |
- batchResult = batchResult.max(result); |
- // Write stderr end token and flush. |
- errorSink.writeln('>>> EOF STDERR'); |
- String resultPassString = resultPass ? 'PASS' : 'FAIL'; |
- outSink.writeln( |
- '>>> TEST $resultPassString ${stopwatch.elapsedMilliseconds}ms'); |
- } catch (e, stackTrace) { |
- errorSink.writeln(e); |
- errorSink.writeln(stackTrace); |
- errorSink.writeln('>>> EOF STDERR'); |
- outSink.writeln('>>> TEST CRASH'); |
- } |
- }); |
- } |
-} |
- |
class _DriverError implements Exception { |
String msg; |
_DriverError(this.msg); |