Chromium Code Reviews| Index: pkg/analyzer_cli/lib/src/driver.dart |
| diff --git a/pkg/analyzer_cli/lib/src/driver.dart b/pkg/analyzer_cli/lib/src/driver.dart |
| index dc40c0d6f3fe3927b1173258deaf65a83f8eccc9..bca565b631bce03d862c928c9ff38f37d02edd00 100644 |
| --- a/pkg/analyzer_cli/lib/src/driver.dart |
| +++ b/pkg/analyzer_cli/lib/src/driver.dart |
| @@ -33,6 +33,7 @@ import 'package:analyzer/src/generated/utilities_general.dart' |
| import 'package:analyzer/src/services/lint.dart'; |
| import 'package:analyzer/src/task/options.dart'; |
| import 'package:analyzer_cli/src/analyzer_impl.dart'; |
| +import 'package:analyzer_cli/src/error_formatter.dart'; |
| import 'package:analyzer_cli/src/options.dart'; |
| import 'package:analyzer_cli/src/package_analyzer.dart'; |
| import 'package:analyzer_cli/src/perf_report.dart'; |
| @@ -89,6 +90,9 @@ class Driver implements CommandLineStarter { |
| @override |
| ResolverProvider packageResolverProvider; |
| + /// Collected analysis statistics. |
| + final AnalysisStats stats = new AnalysisStats(); |
| + |
| /// This Driver's current analysis context. |
| /// |
| /// *Visible for testing.* |
| @@ -96,7 +100,7 @@ class Driver implements CommandLineStarter { |
| @override |
| void set userDefinedPlugins(List<Plugin> plugins) { |
| - _userDefinedPlugins = plugins == null ? <Plugin>[] : plugins; |
| + _userDefinedPlugins = plugins ?? <Plugin>[]; |
| } |
| @override |
| @@ -162,32 +166,32 @@ class Driver implements CommandLineStarter { |
| // Add all the files to be analyzed en masse to the context. Skip any |
| // files that were added earlier (whether explicitly or implicitly) to |
| // avoid causing those files to be unnecessarily re-read. |
| - Set<Source> knownSources = _context.sources.toSet(); |
| + Set<Source> knownSources = context.sources.toSet(); |
| List<Source> sourcesToAnalyze = <Source>[]; |
| ChangeSet changeSet = new ChangeSet(); |
| for (String sourcePath in options.sourceFiles) { |
| sourcePath = sourcePath.trim(); |
| - // Check that file exists. |
| - if (!new File(sourcePath).existsSync()) { |
| - errorSink.writeln('File not found: $sourcePath'); |
| - exitCode = ErrorSeverity.ERROR.ordinal; |
| - //Fail fast; don't analyze more files |
| - return ErrorSeverity.ERROR; |
| - } |
| - // Check that file is Dart file. |
| - if (!AnalysisEngine.isDartFileName(sourcePath)) { |
| - errorSink.writeln('$sourcePath is not a Dart file'); |
| + |
| + // Collect files for analysis. |
| + // Note that these files will all be analyzed in the same context. |
| + // This should be updated when the ContextManager re-work is complete |
| + // (See: https://github.com/dart-lang/sdk/issues/24133) |
| + Iterable<File> files = _collectFiles(sourcePath); |
| + if (files.isEmpty) { |
| + errorSink.writeln('No dart files found at: $sourcePath'); |
| exitCode = ErrorSeverity.ERROR.ordinal; |
| - // Fail fast; don't analyze more files. |
| return ErrorSeverity.ERROR; |
| } |
| - Source source = _computeLibrarySource(sourcePath); |
| - if (!knownSources.contains(source)) { |
| - changeSet.addedSource(source); |
| + |
| + for (File file in files) { |
| + Source source = _computeLibrarySource(file.absolute.path); |
| + if (!knownSources.contains(source)) { |
| + changeSet.addedSource(source); |
| + } |
| + sourcesToAnalyze.add(source); |
|
pquitslund
2016/03/17 18:55:55
FYI: here's the change. The previous version had
|
| } |
| - sourcesToAnalyze.add(source); |
| } |
| - _context.applyChanges(changeSet); |
| + context.applyChanges(changeSet); |
| // Analyze the libraries. |
| ErrorSeverity allResult = ErrorSeverity.NONE; |
| @@ -219,13 +223,17 @@ class Driver implements CommandLineStarter { |
| } |
| } |
| + if (!options.machineFormat) { |
| + stats.print(outSink); |
| + } |
| + |
| return allResult; |
| } |
| /// Perform package analysis according to the given [options]. |
| ErrorSeverity _analyzePackage(CommandLineOptions options) { |
| return _analyzeAllTag.makeCurrentWhile(() { |
| - return new PackageAnalyzer(options).analyze(); |
| + return new PackageAnalyzer(options, stats).analyze(); |
| }); |
| } |
| @@ -451,6 +459,29 @@ class Driver implements CommandLineStarter { |
| return new SourceFactory(resolvers, packages); |
| } |
| + /// Collect all analyzable files at [filePath], recursively if it's a |
| + /// directory, ignoring links. |
| + Iterable<File> _collectFiles(String filePath) { |
| + List<File> files = <File>[]; |
| + File file = new File(filePath); |
| + if (file.existsSync()) { |
| + files.add(file); |
| + } else { |
| + Directory directory = new Directory(filePath); |
| + if (directory.existsSync()) { |
| + for (FileSystemEntity entry |
| + in directory.listSync(recursive: true, followLinks: false)) { |
| + String relative = path.relative(entry.path, from: directory.path); |
| + if (AnalysisEngine.isDartFileName(entry.path) && |
| + !_isInHiddenDir(relative)) { |
| + files.add(entry); |
| + } |
| + } |
| + } |
| + } |
| + return files; |
| + } |
| + |
| /// Convert the given [sourcePath] (which may be relative to the current |
| /// working directory) to a [Source] object that can be fed to the analysis |
| /// context. |
| @@ -525,6 +556,10 @@ class Driver implements CommandLineStarter { |
| return folderMap; |
| } |
| + /// Returns `true` if this relative path is a hidden directory. |
| + bool _isInHiddenDir(String relative) => |
| + path.split(relative).any((part) => part.startsWith(".")); |
| + |
| void _processPlugins() { |
| List<Plugin> plugins = <Plugin>[]; |
| plugins.addAll(AnalysisEngine.instance.requiredPlugins); |
| @@ -541,7 +576,7 @@ class Driver implements CommandLineStarter { |
| ErrorSeverity _runAnalyzer(Source source, CommandLineOptions options) { |
| int startTime = currentTimeMillis(); |
| AnalyzerImpl analyzer = |
| - new AnalyzerImpl(_context, source, options, startTime); |
| + new AnalyzerImpl(_context, source, options, stats, startTime); |
| var errorSeverity = analyzer.analyzeSync(); |
| if (errorSeverity == ErrorSeverity.ERROR) { |
| exitCode = errorSeverity.ordinal; |
| @@ -685,7 +720,7 @@ class _BatchRunner { |
| '>>> BATCH END (${totalTests - testsFailed}/$totalTests) ${time}ms'); |
| exitCode = batchResult.ordinal; |
| } |
| - // Prepare aruments. |
| + // Prepare arguments. |
| var args; |
| { |
| var lineArgs = line.split(new RegExp('\\s+')); |