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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 Set<Source> knownSources = context.sources.toSet(); | 204 Set<Source> knownSources = context.sources.toSet(); |
205 Set<Source> sourcesToAnalyze = new Set<Source>(); | 205 Set<Source> sourcesToAnalyze = new Set<Source>(); |
206 ChangeSet changeSet = new ChangeSet(); | 206 ChangeSet changeSet = new ChangeSet(); |
207 for (String sourcePath in options.sourceFiles) { | 207 for (String sourcePath in options.sourceFiles) { |
208 sourcePath = sourcePath.trim(); | 208 sourcePath = sourcePath.trim(); |
209 | 209 |
210 // Collect files for analysis. | 210 // Collect files for analysis. |
211 // Note that these files will all be analyzed in the same context. | 211 // Note that these files will all be analyzed in the same context. |
212 // This should be updated when the ContextManager re-work is complete | 212 // This should be updated when the ContextManager re-work is complete |
213 // (See: https://github.com/dart-lang/sdk/issues/24133) | 213 // (See: https://github.com/dart-lang/sdk/issues/24133) |
214 Iterable<io.File> files = _collectFiles(sourcePath); | 214 Iterable<io.File> files = |
| 215 _collectFiles(sourcePath, context.analysisOptions); |
215 if (files.isEmpty) { | 216 if (files.isEmpty) { |
216 errorSink.writeln('No dart files found at: $sourcePath'); | 217 errorSink.writeln('No dart files found at: $sourcePath'); |
217 io.exitCode = ErrorSeverity.ERROR.ordinal; | 218 io.exitCode = ErrorSeverity.ERROR.ordinal; |
218 return ErrorSeverity.ERROR; | 219 return ErrorSeverity.ERROR; |
219 } | 220 } |
220 | 221 |
221 for (io.File file in files) { | 222 for (io.File file in files) { |
222 Source source = _computeLibrarySource(file.absolute.path); | 223 Source source = _computeLibrarySource(file.absolute.path); |
223 if (!knownSources.contains(source)) { | 224 if (!knownSources.contains(source)) { |
224 changeSet.addedSource(source); | 225 changeSet.addedSource(source); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 } | 440 } |
440 | 441 |
441 // Finally files. | 442 // Finally files. |
442 resolvers.add(new file_system.ResourceUriResolver(resourceProvider)); | 443 resolvers.add(new file_system.ResourceUriResolver(resourceProvider)); |
443 | 444 |
444 return new SourceFactory(resolvers, packageInfo.packages); | 445 return new SourceFactory(resolvers, packageInfo.packages); |
445 } | 446 } |
446 | 447 |
447 /// Collect all analyzable files at [filePath], recursively if it's a | 448 /// Collect all analyzable files at [filePath], recursively if it's a |
448 /// directory, ignoring links. | 449 /// directory, ignoring links. |
449 Iterable<io.File> _collectFiles(String filePath) { | 450 Iterable<io.File> _collectFiles(String filePath, AnalysisOptions options) { |
450 // TODO(devoncarew): This needs to respect analysis_options excludes. | 451 List<String> excludedPaths = options.excludePatterns; |
| 452 |
| 453 /** |
| 454 * Returns `true` if the given [path] is excluded by [excludedPaths]. |
| 455 */ |
| 456 bool _isExcluded(String path) { |
| 457 return excludedPaths.any((excludedPath) { |
| 458 if (resourceProvider.absolutePathContext.isWithin(excludedPath, path)) { |
| 459 return true; |
| 460 } |
| 461 return path == excludedPath; |
| 462 }); |
| 463 } |
| 464 |
451 List<io.File> files = <io.File>[]; | 465 List<io.File> files = <io.File>[]; |
452 io.File file = new io.File(filePath); | 466 io.File file = new io.File(filePath); |
453 if (file.existsSync()) { | 467 if (file.existsSync() && !_isExcluded(filePath)) { |
454 files.add(file); | 468 files.add(file); |
455 } else { | 469 } else { |
456 io.Directory directory = new io.Directory(filePath); | 470 io.Directory directory = new io.Directory(filePath); |
457 if (directory.existsSync()) { | 471 if (directory.existsSync()) { |
458 for (io.FileSystemEntity entry | 472 for (io.FileSystemEntity entry |
459 in directory.listSync(recursive: true, followLinks: false)) { | 473 in directory.listSync(recursive: true, followLinks: false)) { |
460 String relative = path.relative(entry.path, from: directory.path); | 474 String relative = path.relative(entry.path, from: directory.path); |
461 if (AnalysisEngine.isDartFileName(entry.path) && | 475 if (AnalysisEngine.isDartFileName(entry.path) && |
| 476 !_isExcluded(relative) && |
462 !_isInHiddenDir(relative)) { | 477 !_isInHiddenDir(relative)) { |
463 files.add(entry); | 478 files.add(entry); |
464 } | 479 } |
465 } | 480 } |
466 } | 481 } |
467 } | 482 } |
468 return files; | 483 return files; |
469 } | 484 } |
470 | 485 |
471 /// Convert the given [sourcePath] (which may be relative to the current | 486 /// Convert the given [sourcePath] (which may be relative to the current |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
932 for (var package in packages) { | 947 for (var package in packages) { |
933 var packageName = path.basename(package.path); | 948 var packageName = path.basename(package.path); |
934 var realPath = package.resolveSymbolicLinksSync(); | 949 var realPath = package.resolveSymbolicLinksSync(); |
935 result[packageName] = [ | 950 result[packageName] = [ |
936 PhysicalResourceProvider.INSTANCE.getFolder(realPath) | 951 PhysicalResourceProvider.INSTANCE.getFolder(realPath) |
937 ]; | 952 ]; |
938 } | 953 } |
939 return result; | 954 return result; |
940 } | 955 } |
941 } | 956 } |
OLD | NEW |