Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2206)

Unified Diff: pkg/analyzer_cli/lib/src/analyzer_driver.dart

Issue 2840703002: Refactoring analyzer_cli for code hygiene. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer_cli/lib/src/analyzer_driver.dart
diff --git a/pkg/analyzer_cli/lib/src/driver.dart b/pkg/analyzer_cli/lib/src/analyzer_driver.dart
similarity index 93%
rename from pkg/analyzer_cli/lib/src/driver.dart
rename to pkg/analyzer_cli/lib/src/analyzer_driver.dart
index d3dc92e76f2cc379487bded60f0640f98baa4ffa..c84d32a8268424d25261f0d11715291911c971fd 100644
--- a/pkg/analyzer_cli/lib/src/driver.dart
+++ b/pkg/analyzer_cli/lib/src/analyzer_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,10 +33,11 @@ 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/analyzer_options.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';
-import 'package:analyzer_cli/src/options.dart';
import 'package:analyzer_cli/src/perf_report.dart';
import 'package:analyzer_cli/starter.dart' show CommandLineStarter;
import 'package:linter/src/rules.dart' as linter;
@@ -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);
« no previous file with comments | « no previous file | pkg/analyzer_cli/lib/src/analyzer_impl.dart » ('j') | pkg/analyzer_cli/lib/src/analyzer_options.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698