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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:io' as io; | 6 import 'dart:io' as io; |
7 | 7 |
8 import 'package:analyzer/error/error.dart'; | 8 import 'package:analyzer/error/error.dart'; |
9 import 'package:analyzer/file_system/file_system.dart' as file_system; | 9 import 'package:analyzer/file_system/file_system.dart' as file_system; |
10 import 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 StringUtilities.INTERNER = new MappedInterner(); | 123 StringUtilities.INTERNER = new MappedInterner(); |
124 | 124 |
125 _processPlugins(); | 125 _processPlugins(); |
126 | 126 |
127 // Parse commandline options. | 127 // Parse commandline options. |
128 CommandLineOptions options = CommandLineOptions.parse(args); | 128 CommandLineOptions options = CommandLineOptions.parse(args); |
129 | 129 |
130 // Do analysis. | 130 // Do analysis. |
131 if (options.buildMode) { | 131 if (options.buildMode) { |
132 ErrorSeverity severity = _buildModeAnalyze(options); | 132 ErrorSeverity severity = _buildModeAnalyze(options); |
133 // In case of error propagate exit code. | 133 // Propagate issues to the exit code. |
134 if (severity == ErrorSeverity.ERROR) { | 134 if (_shouldBeFatal(severity, options)) { |
135 io.exitCode = severity.ordinal; | 135 io.exitCode = severity.ordinal; |
136 } | 136 } |
137 } else if (options.shouldBatch) { | 137 } else if (options.shouldBatch) { |
138 BatchRunner batchRunner = new BatchRunner(outSink, errorSink); | 138 BatchRunner batchRunner = new BatchRunner(outSink, errorSink); |
139 batchRunner.runAsBatch(args, (List<String> args) async { | 139 batchRunner.runAsBatch(args, (List<String> args) async { |
140 CommandLineOptions options = CommandLineOptions.parse(args); | 140 CommandLineOptions options = CommandLineOptions.parse(args); |
141 return await _analyzeAll(options); | 141 return await _analyzeAll(options); |
142 }); | 142 }); |
143 } else { | 143 } else { |
144 ErrorSeverity severity = await _analyzeAll(options); | 144 ErrorSeverity severity = await _analyzeAll(options); |
145 // In case of error propagate exit code. | 145 // Propagate issues to the exit code. |
146 if (severity == ErrorSeverity.ERROR) { | 146 if (_shouldBeFatal(severity, options)) { |
147 io.exitCode = severity.ordinal; | 147 io.exitCode = severity.ordinal; |
148 } | 148 } |
149 } | 149 } |
150 | 150 |
151 if (_context != null) { | 151 if (_context != null) { |
152 _analyzedFileCount += _context.sources.length; | 152 _analyzedFileCount += _context.sources.length; |
153 } | 153 } |
154 | 154 |
155 if (options.perfReport != null) { | 155 if (options.perfReport != null) { |
156 String json = makePerfReport( | 156 String json = makePerfReport( |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 plugins.addAll(AnalysisEngine.instance.requiredPlugins); | 706 plugins.addAll(AnalysisEngine.instance.requiredPlugins); |
707 plugins.addAll(_userDefinedPlugins); | 707 plugins.addAll(_userDefinedPlugins); |
708 | 708 |
709 ExtensionManager manager = new ExtensionManager(); | 709 ExtensionManager manager = new ExtensionManager(); |
710 manager.processPlugins(plugins); | 710 manager.processPlugins(plugins); |
711 | 711 |
712 linter.registerLintRules(); | 712 linter.registerLintRules(); |
713 } | 713 } |
714 | 714 |
715 /// Analyze a single source. | 715 /// Analyze a single source. |
716 Future<ErrorSeverity> _runAnalyzer(Source source, CommandLineOptions options, | 716 Future<ErrorSeverity> _runAnalyzer( |
717 ErrorFormatter formatter) async { | 717 Source source, CommandLineOptions options, ErrorFormatter formatter) { |
718 int startTime = currentTimeMillis; | 718 int startTime = currentTimeMillis; |
719 AnalyzerImpl analyzer = new AnalyzerImpl(_context.analysisOptions, _context, | 719 AnalyzerImpl analyzer = new AnalyzerImpl(_context.analysisOptions, _context, |
720 analysisDriver, source, options, stats, startTime); | 720 analysisDriver, source, options, stats, startTime); |
721 ErrorSeverity errorSeverity = await analyzer.analyze(formatter); | 721 return analyzer.analyze(formatter); |
722 if (errorSeverity == ErrorSeverity.ERROR) { | |
723 io.exitCode = errorSeverity.ordinal; | |
724 } | |
725 if (options.warningsAreFatal && errorSeverity == ErrorSeverity.WARNING) { | |
726 io.exitCode = errorSeverity.ordinal; | |
727 } | |
728 return errorSeverity; | |
729 } | 722 } |
730 | 723 |
731 void _setupSdk(CommandLineOptions options, bool useSummaries, | 724 void _setupSdk(CommandLineOptions options, bool useSummaries, |
732 AnalysisOptions analysisOptions) { | 725 AnalysisOptions analysisOptions) { |
733 if (sdk == null) { | 726 if (sdk == null) { |
734 if (options.dartSdkSummaryPath != null) { | 727 if (options.dartSdkSummaryPath != null) { |
735 sdk = new SummaryBasedDartSdk( | 728 sdk = new SummaryBasedDartSdk( |
736 options.dartSdkSummaryPath, options.strongMode); | 729 options.dartSdkSummaryPath, options.strongMode); |
737 } else { | 730 } else { |
738 String dartSdkPath = options.dartSdkPath; | 731 String dartSdkPath = options.dartSdkPath; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 if (!m2.containsKey(key) || m1[key] != m2[key]) { | 837 if (!m2.containsKey(key) || m1[key] != m2[key]) { |
845 return false; | 838 return false; |
846 } | 839 } |
847 } | 840 } |
848 return true; | 841 return true; |
849 } | 842 } |
850 | 843 |
851 /// Convert [sourcePath] into an absolute path. | 844 /// Convert [sourcePath] into an absolute path. |
852 static String _normalizeSourcePath(String sourcePath) => | 845 static String _normalizeSourcePath(String sourcePath) => |
853 path.normalize(new io.File(sourcePath).absolute.path); | 846 path.normalize(new io.File(sourcePath).absolute.path); |
| 847 |
| 848 bool _shouldBeFatal(ErrorSeverity severity, CommandLineOptions options) { |
| 849 if (severity == ErrorSeverity.ERROR) { |
| 850 return true; |
| 851 } else if (severity == ErrorSeverity.WARNING && |
| 852 (options.warningsAreFatal || options.hintsAreFatal)) { |
| 853 return true; |
| 854 } else if (severity == ErrorSeverity.INFO && options.hintsAreFatal) { |
| 855 return true; |
| 856 } else { |
| 857 return false; |
| 858 } |
| 859 } |
854 } | 860 } |
855 | 861 |
856 class _DriverError implements Exception { | 862 class _DriverError implements Exception { |
857 String msg; | 863 String msg; |
858 _DriverError(this.msg); | 864 _DriverError(this.msg); |
859 } | 865 } |
860 | 866 |
861 class _PackageInfo { | 867 class _PackageInfo { |
862 Packages packages; | 868 Packages packages; |
863 Map<String, List<file_system.Folder>> packageMap; | 869 Map<String, List<file_system.Folder>> packageMap; |
(...skipping 18 matching lines...) Expand all Loading... |
882 for (var package in packages) { | 888 for (var package in packages) { |
883 var packageName = path.basename(package.path); | 889 var packageName = path.basename(package.path); |
884 var realPath = package.resolveSymbolicLinksSync(); | 890 var realPath = package.resolveSymbolicLinksSync(); |
885 result[packageName] = [ | 891 result[packageName] = [ |
886 PhysicalResourceProvider.INSTANCE.getFolder(realPath) | 892 PhysicalResourceProvider.INSTANCE.getFolder(realPath) |
887 ]; | 893 ]; |
888 } | 894 } |
889 return result; | 895 return result; |
890 } | 896 } |
891 } | 897 } |
OLD | NEW |