| 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.driver; | 5 library analyzer_cli.src.driver; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:io' as io; | 9 import 'dart:io' as io; |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 import 'package:analyzer/src/generated/source_io.dart'; | 31 import 'package:analyzer/src/generated/source_io.dart'; |
| 32 import 'package:analyzer/src/generated/utilities_general.dart' | 32 import 'package:analyzer/src/generated/utilities_general.dart' |
| 33 show PerformanceTag; | 33 show PerformanceTag; |
| 34 import 'package:analyzer/src/source/source_resource.dart'; | 34 import 'package:analyzer/src/source/source_resource.dart'; |
| 35 import 'package:analyzer/src/summary/idl.dart'; | 35 import 'package:analyzer/src/summary/idl.dart'; |
| 36 import 'package:analyzer/src/summary/package_bundle_reader.dart'; | 36 import 'package:analyzer/src/summary/package_bundle_reader.dart'; |
| 37 import 'package:analyzer/src/summary/summary_sdk.dart' show SummaryBasedDartSdk; | 37 import 'package:analyzer/src/summary/summary_sdk.dart' show SummaryBasedDartSdk; |
| 38 import 'package:analyzer_cli/src/analyzer_impl.dart'; | 38 import 'package:analyzer_cli/src/analyzer_impl.dart'; |
| 39 import 'package:analyzer_cli/src/build_mode.dart'; | 39 import 'package:analyzer_cli/src/build_mode.dart'; |
| 40 import 'package:analyzer_cli/src/error_formatter.dart'; | 40 import 'package:analyzer_cli/src/error_formatter.dart'; |
| 41 import 'package:analyzer_cli/src/error_severity.dart'; |
| 41 import 'package:analyzer_cli/src/options.dart'; | 42 import 'package:analyzer_cli/src/options.dart'; |
| 42 import 'package:analyzer_cli/src/perf_report.dart'; | 43 import 'package:analyzer_cli/src/perf_report.dart'; |
| 43 import 'package:analyzer_cli/starter.dart' show CommandLineStarter; | 44 import 'package:analyzer_cli/starter.dart' show CommandLineStarter; |
| 44 import 'package:linter/src/rules.dart' as linter; | 45 import 'package:linter/src/rules.dart' as linter; |
| 45 import 'package:package_config/discovery.dart' as pkg_discovery; | 46 import 'package:package_config/discovery.dart' as pkg_discovery; |
| 46 import 'package:package_config/packages.dart' show Packages; | 47 import 'package:package_config/packages.dart' show Packages; |
| 47 import 'package:package_config/packages_file.dart' as pkgfile show parse; | 48 import 'package:package_config/packages_file.dart' as pkgfile show parse; |
| 48 import 'package:package_config/src/packages_impl.dart' show MapPackages; | 49 import 'package:package_config/src/packages_impl.dart' show MapPackages; |
| 49 import 'package:path/path.dart' as path; | 50 import 'package:path/path.dart' as path; |
| 50 import 'package:plugin/manager.dart'; | 51 import 'package:plugin/manager.dart'; |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 if (analysisDriver == null) { | 226 if (analysisDriver == null) { |
| 226 context.applyChanges(changeSet); | 227 context.applyChanges(changeSet); |
| 227 } | 228 } |
| 228 } | 229 } |
| 229 | 230 |
| 230 // Analyze the libraries. | 231 // Analyze the libraries. |
| 231 ErrorSeverity allResult = ErrorSeverity.NONE; | 232 ErrorSeverity allResult = ErrorSeverity.NONE; |
| 232 List<Uri> libUris = <Uri>[]; | 233 List<Uri> libUris = <Uri>[]; |
| 233 Set<Source> partSources = new Set<Source>(); | 234 Set<Source> partSources = new Set<Source>(); |
| 234 | 235 |
| 236 SeverityProcessor defaultSeverityProcessor = (AnalysisError error) { |
| 237 return determineProcessedSeverity( |
| 238 error, options, _context.analysisOptions); |
| 239 }; |
| 240 |
| 241 // We currently print out to stderr to ensure that when in batch mode we |
| 242 // print to stderr, this is because the prints from batch are made to |
| 243 // stderr. The reason that options.shouldBatch isn't used is because when |
| 244 // the argument flags are constructed in BatchRunner and passed in from |
| 245 // batch mode which removes the batch flag to prevent the "cannot have the |
| 246 // batch flag and source file" error message. |
| 247 ErrorFormatter formatter; |
| 248 if (options.machineFormat) { |
| 249 formatter = new MachineErrorFormatter(errorSink, options, stats, |
| 250 severityProcessor: defaultSeverityProcessor); |
| 251 } else { |
| 252 formatter = new HumanErrorFormatter(outSink, options, stats, |
| 253 severityProcessor: defaultSeverityProcessor); |
| 254 } |
| 255 |
| 235 for (Source source in sourcesToAnalyze) { | 256 for (Source source in sourcesToAnalyze) { |
| 236 SourceKind sourceKind = analysisDriver != null | 257 SourceKind sourceKind = analysisDriver != null |
| 237 ? await analysisDriver.getSourceKind(source.fullName) | 258 ? await analysisDriver.getSourceKind(source.fullName) |
| 238 : context.computeKindOf(source); | 259 : context.computeKindOf(source); |
| 239 if (sourceKind == SourceKind.PART) { | 260 if (sourceKind == SourceKind.PART) { |
| 240 partSources.add(source); | 261 partSources.add(source); |
| 241 continue; | 262 continue; |
| 242 } | 263 } |
| 243 // TODO(devoncarew): Analyzing each source individually causes errors to | 264 ErrorSeverity status = await _runAnalyzer(source, options, formatter); |
| 244 // be reported multiple times (#25697). | |
| 245 ErrorSeverity status = await _runAnalyzer(source, options); | |
| 246 allResult = allResult.max(status); | 265 allResult = allResult.max(status); |
| 247 libUris.add(source.uri); | 266 libUris.add(source.uri); |
| 248 } | 267 } |
| 249 | 268 |
| 269 formatter.flush(); |
| 270 |
| 250 // Check that each part has a corresponding source in the input list. | 271 // Check that each part has a corresponding source in the input list. |
| 251 for (Source partSource in partSources) { | 272 for (Source partSource in partSources) { |
| 252 bool found = false; | 273 bool found = false; |
| 253 if (analysisDriver != null) { | 274 if (analysisDriver != null) { |
| 254 var partFile = | 275 var partFile = |
| 255 analysisDriver.fsState.getFileForPath(partSource.fullName); | 276 analysisDriver.fsState.getFileForPath(partSource.fullName); |
| 256 if (libUris.contains(partFile.library?.uri)) { | 277 if (libUris.contains(partFile.library?.uri)) { |
| 257 found = true; | 278 found = true; |
| 258 } | 279 } |
| 259 } else { | 280 } else { |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 plugins.addAll(AnalysisEngine.instance.requiredPlugins); | 709 plugins.addAll(AnalysisEngine.instance.requiredPlugins); |
| 689 plugins.addAll(_userDefinedPlugins); | 710 plugins.addAll(_userDefinedPlugins); |
| 690 | 711 |
| 691 ExtensionManager manager = new ExtensionManager(); | 712 ExtensionManager manager = new ExtensionManager(); |
| 692 manager.processPlugins(plugins); | 713 manager.processPlugins(plugins); |
| 693 | 714 |
| 694 linter.registerLintRules(); | 715 linter.registerLintRules(); |
| 695 } | 716 } |
| 696 | 717 |
| 697 /// Analyze a single source. | 718 /// Analyze a single source. |
| 698 Future<ErrorSeverity> _runAnalyzer( | 719 Future<ErrorSeverity> _runAnalyzer(Source source, CommandLineOptions options, |
| 699 Source source, CommandLineOptions options) async { | 720 ErrorFormatter formatter) async { |
| 700 int startTime = currentTimeMillis; | 721 int startTime = currentTimeMillis; |
| 701 AnalyzerImpl analyzer = new AnalyzerImpl(_context.analysisOptions, _context, | 722 AnalyzerImpl analyzer = new AnalyzerImpl(_context.analysisOptions, _context, |
| 702 analysisDriver, source, options, stats, startTime); | 723 analysisDriver, source, options, stats, startTime); |
| 703 ErrorSeverity errorSeverity = await analyzer.analyze(); | 724 ErrorSeverity errorSeverity = await analyzer.analyze(formatter); |
| 704 if (errorSeverity == ErrorSeverity.ERROR) { | 725 if (errorSeverity == ErrorSeverity.ERROR) { |
| 705 io.exitCode = errorSeverity.ordinal; | 726 io.exitCode = errorSeverity.ordinal; |
| 706 } | 727 } |
| 707 if (options.warningsAreFatal && errorSeverity == ErrorSeverity.WARNING) { | 728 if (options.warningsAreFatal && errorSeverity == ErrorSeverity.WARNING) { |
| 708 io.exitCode = errorSeverity.ordinal; | 729 io.exitCode = errorSeverity.ordinal; |
| 709 } | 730 } |
| 710 return errorSeverity; | 731 return errorSeverity; |
| 711 } | 732 } |
| 712 | 733 |
| 713 void _setupSdk(CommandLineOptions options, bool useSummaries, | 734 void _setupSdk(CommandLineOptions options, bool useSummaries, |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 for (var package in packages) { | 938 for (var package in packages) { |
| 918 var packageName = path.basename(package.path); | 939 var packageName = path.basename(package.path); |
| 919 var realPath = package.resolveSymbolicLinksSync(); | 940 var realPath = package.resolveSymbolicLinksSync(); |
| 920 result[packageName] = [ | 941 result[packageName] = [ |
| 921 PhysicalResourceProvider.INSTANCE.getFolder(realPath) | 942 PhysicalResourceProvider.INSTANCE.getFolder(realPath) |
| 922 ]; | 943 ]; |
| 923 } | 944 } |
| 924 return result; | 945 return result; |
| 925 } | 946 } |
| 926 } | 947 } |
| OLD | NEW |