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

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

Issue 1903053003: Sort build_mode.dart. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer_cli/lib/src/build_mode.dart
diff --git a/pkg/analyzer_cli/lib/src/build_mode.dart b/pkg/analyzer_cli/lib/src/build_mode.dart
index 2d6d3da02bba622a59a47bcfd2e50cb68308ef3a..c165dbdb68c624b911c2963084be455d22bf9639 100644
--- a/pkg/analyzer_cli/lib/src/build_mode.dart
+++ b/pkg/analyzer_cli/lib/src/build_mode.dart
@@ -31,6 +31,92 @@ import 'package:analyzer_cli/src/options.dart';
import 'package:bazel_worker/bazel_worker.dart';
/**
+ * Persistent Bazel worker.
+ */
+class AnalyzerWorkerLoop extends SyncWorkerLoop {
+ final StringBuffer errorBuffer = new StringBuffer();
+ final StringBuffer outBuffer = new StringBuffer();
+
+ final String dartSdkPath;
+
+ AnalyzerWorkerLoop(SyncWorkerConnection connection, {this.dartSdkPath})
+ : super(connection: connection);
+
+ factory AnalyzerWorkerLoop.std(
+ {io.Stdin stdinStream, io.Stdout stdoutStream, String dartSdkPath}) {
+ SyncWorkerConnection connection = new StdSyncWorkerConnection(
+ stdinStream: stdinStream, stdoutStream: stdoutStream);
+ return new AnalyzerWorkerLoop(connection, dartSdkPath: dartSdkPath);
+ }
+
+ /**
+ * Performs analysis with given [options].
+ */
+ void analyze(CommandLineOptions options) {
+ new BuildMode(options, new AnalysisStats()).analyze();
+ AnalysisEngine.instance.clearCaches();
+ }
+
+ /**
+ * Perform a single loop step.
+ */
+ WorkResponse performRequest(WorkRequest request) {
+ errorBuffer.clear();
+ outBuffer.clear();
+ try {
+ // Add in the dart-sdk argument if `dartSdkPath` is not null, otherwise it
+ // will try to find the currently installed sdk.
+ var arguments = new List.from(request.arguments);
+ if (dartSdkPath != null &&
+ !arguments.any((arg) => arg.startsWith('--dart-sdk'))) {
+ arguments.add('--dart-sdk=$dartSdkPath');
+ }
+ // Prepare options.
+ CommandLineOptions options =
+ CommandLineOptions.parse(arguments, (String msg) {
+ throw new ArgumentError(msg);
+ });
+ // Analyze and respond.
+ analyze(options);
+ String msg = _getErrorOutputBuffersText();
+ return new WorkResponse()
+ ..exitCode = EXIT_CODE_OK
+ ..output = msg;
+ } catch (e, st) {
+ String msg = _getErrorOutputBuffersText();
+ msg += '$e\n$st';
+ return new WorkResponse()
+ ..exitCode = EXIT_CODE_ERROR
+ ..output = msg;
+ }
+ }
+
+ /**
+ * Run the worker loop.
+ */
+ @override
+ void run() {
+ errorSink = errorBuffer;
+ outSink = outBuffer;
+ exitHandler = (int exitCode) {
+ return throw new StateError('Exit called: $exitCode');
+ };
+ super.run();
+ }
+
+ String _getErrorOutputBuffersText() {
+ String msg = '';
+ if (errorBuffer.isNotEmpty) {
+ msg += errorBuffer.toString() + '\n';
+ }
+ if (outBuffer.isNotEmpty) {
+ msg += outBuffer.toString() + '\n';
+ }
+ return msg;
+ }
+}
+
+/**
* Analyzer used when the "--build-mode" option is supplied.
*/
class BuildMode {
@@ -272,89 +358,3 @@ class BuildMode {
return uriToFileMap;
}
}
-
-/**
- * Persistent Bazel worker.
- */
-class AnalyzerWorkerLoop extends SyncWorkerLoop {
- final StringBuffer errorBuffer = new StringBuffer();
- final StringBuffer outBuffer = new StringBuffer();
-
- final String dartSdkPath;
-
- AnalyzerWorkerLoop(SyncWorkerConnection connection, {this.dartSdkPath})
- : super(connection: connection);
-
- factory AnalyzerWorkerLoop.std(
- {io.Stdin stdinStream, io.Stdout stdoutStream, String dartSdkPath}) {
- SyncWorkerConnection connection = new StdSyncWorkerConnection(
- stdinStream: stdinStream, stdoutStream: stdoutStream);
- return new AnalyzerWorkerLoop(connection, dartSdkPath: dartSdkPath);
- }
-
- /**
- * Performs analysis with given [options].
- */
- void analyze(CommandLineOptions options) {
- new BuildMode(options, new AnalysisStats()).analyze();
- AnalysisEngine.instance.clearCaches();
- }
-
- /**
- * Perform a single loop step.
- */
- WorkResponse performRequest(WorkRequest request) {
- errorBuffer.clear();
- outBuffer.clear();
- try {
- // Add in the dart-sdk argument if `dartSdkPath` is not null, otherwise it
- // will try to find the currently installed sdk.
- var arguments = new List.from(request.arguments);
- if (dartSdkPath != null &&
- !arguments.any((arg) => arg.startsWith('--dart-sdk'))) {
- arguments.add('--dart-sdk=$dartSdkPath');
- }
- // Prepare options.
- CommandLineOptions options =
- CommandLineOptions.parse(arguments, (String msg) {
- throw new ArgumentError(msg);
- });
- // Analyze and respond.
- analyze(options);
- String msg = _getErrorOutputBuffersText();
- return new WorkResponse()
- ..exitCode = EXIT_CODE_OK
- ..output = msg;
- } catch (e, st) {
- String msg = _getErrorOutputBuffersText();
- msg += '$e\n$st';
- return new WorkResponse()
- ..exitCode = EXIT_CODE_ERROR
- ..output = msg;
- }
- }
-
- /**
- * Run the worker loop.
- */
- @override
- void run() {
- errorSink = errorBuffer;
- outSink = outBuffer;
- exitHandler = (int exitCode) {
- return throw new StateError('Exit called: $exitCode');
- };
- super.run();
- }
-
- String _getErrorOutputBuffersText() {
- String msg = '';
- if (errorBuffer.isNotEmpty) {
- msg += errorBuffer.toString() + '\n';
- }
- if (outBuffer.isNotEmpty) {
- msg += outBuffer.toString() + '\n';
- }
- return msg;
- }
-}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698