| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer_cli.src.build_mode; | 5 library analyzer_cli.src.build_mode; |
| 6 | 6 |
| 7 import 'dart:core'; | 7 import 'dart:core'; |
| 8 import 'dart:io' as io; | 8 import 'dart:io' as io; |
| 9 | 9 |
| 10 import 'package:analyzer/dart/ast/ast.dart' show CompilationUnit; | 10 import 'package:analyzer/dart/ast/ast.dart' show CompilationUnit; |
| 11 import 'package:analyzer/error/error.dart'; | 11 import 'package:analyzer/error/error.dart'; |
| 12 import 'package:analyzer/file_system/file_system.dart'; | 12 import 'package:analyzer/file_system/file_system.dart'; |
| 13 import 'package:analyzer/src/dart/sdk/sdk.dart'; | 13 import 'package:analyzer/src/dart/sdk/sdk.dart'; |
| 14 import 'package:analyzer/src/generated/engine.dart'; | 14 import 'package:analyzer/src/generated/engine.dart'; |
| 15 import 'package:analyzer/src/generated/sdk.dart'; | 15 import 'package:analyzer/src/generated/sdk.dart'; |
| 16 import 'package:analyzer/src/generated/source.dart'; | 16 import 'package:analyzer/src/generated/source.dart'; |
| 17 import 'package:analyzer/src/generated/source_io.dart'; | 17 import 'package:analyzer/src/generated/source_io.dart'; |
| 18 import 'package:analyzer/src/source/source_resource.dart'; | 18 import 'package:analyzer/src/source/source_resource.dart'; |
| 19 import 'package:analyzer/src/summary/format.dart'; | 19 import 'package:analyzer/src/summary/format.dart'; |
| 20 import 'package:analyzer/src/summary/idl.dart'; | 20 import 'package:analyzer/src/summary/idl.dart'; |
| 21 import 'package:analyzer/src/summary/link.dart'; | 21 import 'package:analyzer/src/summary/link.dart'; |
| 22 import 'package:analyzer/src/summary/package_bundle_reader.dart'; | 22 import 'package:analyzer/src/summary/package_bundle_reader.dart'; |
| 23 import 'package:analyzer/src/summary/summarize_ast.dart'; | 23 import 'package:analyzer/src/summary/summarize_ast.dart'; |
| 24 import 'package:analyzer/src/summary/summarize_elements.dart'; | 24 import 'package:analyzer/src/summary/summarize_elements.dart'; |
| 25 import 'package:analyzer/src/summary/summary_sdk.dart' show SummaryBasedDartSdk; | 25 import 'package:analyzer/src/summary/summary_sdk.dart' show SummaryBasedDartSdk; |
| 26 import 'package:analyzer/task/dart.dart'; | 26 import 'package:analyzer/task/dart.dart'; |
| 27 import 'package:analyzer_cli/src/analyzer_impl.dart'; | |
| 28 import 'package:analyzer_cli/src/driver.dart'; | |
| 29 import 'package:analyzer_cli/src/error_formatter.dart'; | |
| 30 import 'package:analyzer_cli/src/options.dart'; | |
| 31 import 'package:bazel_worker/bazel_worker.dart'; | 27 import 'package:bazel_worker/bazel_worker.dart'; |
| 32 | 28 |
| 29 import 'driver.dart'; |
| 30 import 'error_formatter.dart'; |
| 31 import 'error_severity.dart'; |
| 32 import 'options.dart'; |
| 33 |
| 33 /** | 34 /** |
| 34 * Persistent Bazel worker. | 35 * Persistent Bazel worker. |
| 35 */ | 36 */ |
| 36 class AnalyzerWorkerLoop extends SyncWorkerLoop { | 37 class AnalyzerWorkerLoop extends SyncWorkerLoop { |
| 37 final StringBuffer errorBuffer = new StringBuffer(); | 38 final StringBuffer errorBuffer = new StringBuffer(); |
| 38 final StringBuffer outBuffer = new StringBuffer(); | 39 final StringBuffer outBuffer = new StringBuffer(); |
| 39 | 40 |
| 40 final ResourceProvider resourceProvider; | 41 final ResourceProvider resourceProvider; |
| 41 final String dartSdkPath; | 42 final String dartSdkPath; |
| 42 | 43 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 bool get _shouldOutputSummary => | 143 bool get _shouldOutputSummary => |
| 143 options.buildSummaryOutput != null || | 144 options.buildSummaryOutput != null || |
| 144 options.buildSummaryOutputSemantic != null; | 145 options.buildSummaryOutputSemantic != null; |
| 145 | 146 |
| 146 /** | 147 /** |
| 147 * Perform package analysis according to the given [options]. | 148 * Perform package analysis according to the given [options]. |
| 148 */ | 149 */ |
| 149 ErrorSeverity analyze() { | 150 ErrorSeverity analyze() { |
| 150 // Write initial progress message. | 151 // Write initial progress message. |
| 151 if (!options.machineFormat) { | 152 if (!options.machineFormat) { |
| 152 outSink.writeln("Analyzing sources ${options.sourceFiles}..."); | 153 outSink.writeln("Analyzing ${options.sourceFiles.join(', ')}..."); |
| 153 } | 154 } |
| 154 | 155 |
| 155 // Create the URI to file map. | 156 // Create the URI to file map. |
| 156 uriToFileMap = _createUriToFileMap(options.sourceFiles); | 157 uriToFileMap = _createUriToFileMap(options.sourceFiles); |
| 157 if (uriToFileMap == null) { | 158 if (uriToFileMap == null) { |
| 158 io.exitCode = ErrorSeverity.ERROR.ordinal; | 159 io.exitCode = ErrorSeverity.ERROR.ordinal; |
| 159 return ErrorSeverity.ERROR; | 160 return ErrorSeverity.ERROR; |
| 160 } | 161 } |
| 161 | 162 |
| 162 // Prepare the analysis context. | 163 // Prepare the analysis context. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 return _computeMaxSeverity(); | 219 return _computeMaxSeverity(); |
| 219 } | 220 } |
| 220 } | 221 } |
| 221 | 222 |
| 222 ErrorSeverity _computeMaxSeverity() { | 223 ErrorSeverity _computeMaxSeverity() { |
| 223 ErrorSeverity maxSeverity = ErrorSeverity.NONE; | 224 ErrorSeverity maxSeverity = ErrorSeverity.NONE; |
| 224 if (!options.buildSuppressExitCode) { | 225 if (!options.buildSuppressExitCode) { |
| 225 for (Source source in explicitSources) { | 226 for (Source source in explicitSources) { |
| 226 AnalysisErrorInfo errorInfo = context.getErrors(source); | 227 AnalysisErrorInfo errorInfo = context.getErrors(source); |
| 227 for (AnalysisError error in errorInfo.errors) { | 228 for (AnalysisError error in errorInfo.errors) { |
| 228 ProcessedSeverity processedSeverity = AnalyzerImpl.processError( | 229 ProcessedSeverity processedSeverity = |
| 229 error, options, context.analysisOptions); | 230 processError(error, options, context.analysisOptions); |
| 230 if (processedSeverity != null) { | 231 if (processedSeverity != null) { |
| 231 maxSeverity = maxSeverity.max(processedSeverity.severity); | 232 maxSeverity = maxSeverity.max(processedSeverity.severity); |
| 232 } | 233 } |
| 233 } | 234 } |
| 234 } | 235 } |
| 235 } | 236 } |
| 236 return maxSeverity; | 237 return maxSeverity; |
| 237 } | 238 } |
| 238 | 239 |
| 239 void _createContext() { | 240 void _createContext() { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 * Print errors for all explicit sources. If [outputPath] is supplied, output | 313 * Print errors for all explicit sources. If [outputPath] is supplied, output |
| 313 * is sent to a new file at that path. | 314 * is sent to a new file at that path. |
| 314 */ | 315 */ |
| 315 void _printErrors({String outputPath}) { | 316 void _printErrors({String outputPath}) { |
| 316 StringBuffer buffer = new StringBuffer(); | 317 StringBuffer buffer = new StringBuffer(); |
| 317 ErrorFormatter formatter = new ErrorFormatter( | 318 ErrorFormatter formatter = new ErrorFormatter( |
| 318 buffer, | 319 buffer, |
| 319 options, | 320 options, |
| 320 stats, | 321 stats, |
| 321 (AnalysisError error) => | 322 (AnalysisError error) => |
| 322 AnalyzerImpl.processError(error, options, context.analysisOptions)); | 323 processError(error, options, context.analysisOptions)); |
| 323 for (Source source in explicitSources) { | 324 for (Source source in explicitSources) { |
| 324 AnalysisErrorInfo errorInfo = context.getErrors(source); | 325 AnalysisErrorInfo errorInfo = context.getErrors(source); |
| 325 formatter.formatErrors([errorInfo]); | 326 formatter.formatErrors([errorInfo]); |
| 326 } | 327 } |
| 327 if (!options.machineFormat) { | 328 if (!options.machineFormat) { |
| 328 stats.print(buffer); | 329 stats.print(buffer); |
| 329 } | 330 } |
| 330 if (outputPath == null) { | 331 if (outputPath == null) { |
| 331 StringSink sink = options.machineFormat ? errorSink : outSink; | 332 StringSink sink = options.machineFormat ? errorSink : outSink; |
| 332 sink.write(buffer); | 333 sink.write(buffer); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 * Build the inverse mapping of [uriToSourceMap]. | 417 * Build the inverse mapping of [uriToSourceMap]. |
| 417 */ | 418 */ |
| 418 static Map<String, Uri> _computePathToUriMap(Map<Uri, File> uriToSourceMap) { | 419 static Map<String, Uri> _computePathToUriMap(Map<Uri, File> uriToSourceMap) { |
| 419 Map<String, Uri> pathToUriMap = <String, Uri>{}; | 420 Map<String, Uri> pathToUriMap = <String, Uri>{}; |
| 420 uriToSourceMap.forEach((Uri uri, File file) { | 421 uriToSourceMap.forEach((Uri uri, File file) { |
| 421 pathToUriMap[file.path] = uri; | 422 pathToUriMap[file.path] = uri; |
| 422 }); | 423 }); |
| 423 return pathToUriMap; | 424 return pathToUriMap; |
| 424 } | 425 } |
| 425 } | 426 } |
| OLD | NEW |