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'; | 9 import 'dart:io'; |
10 | 10 |
11 import 'package:analyzer/file_system/file_system.dart' as fileSystem; | 11 import 'package:analyzer/file_system/file_system.dart' as fileSystem; |
12 import 'package:analyzer/file_system/physical_file_system.dart'; | 12 import 'package:analyzer/file_system/physical_file_system.dart'; |
13 import 'package:analyzer/plugin/options.dart'; | 13 import 'package:analyzer/plugin/options.dart'; |
14 import 'package:analyzer/source/analysis_options_provider.dart'; | 14 import 'package:analyzer/source/analysis_options_provider.dart'; |
15 import 'package:analyzer/source/package_map_provider.dart'; | 15 import 'package:analyzer/source/package_map_provider.dart'; |
16 import 'package:analyzer/source/package_map_resolver.dart'; | 16 import 'package:analyzer/source/package_map_resolver.dart'; |
17 import 'package:analyzer/source/pub_package_map_provider.dart'; | 17 import 'package:analyzer/source/pub_package_map_provider.dart'; |
18 import 'package:analyzer/source/sdk_ext.dart'; | 18 import 'package:analyzer/source/sdk_ext.dart'; |
19 import 'package:analyzer/src/generated/constant.dart'; | 19 import 'package:analyzer/src/generated/constant.dart'; |
20 import 'package:analyzer/src/generated/engine.dart'; | 20 import 'package:analyzer/src/generated/engine.dart'; |
21 import 'package:analyzer/src/generated/error.dart'; | 21 import 'package:analyzer/src/generated/error.dart'; |
22 import 'package:analyzer/src/generated/interner.dart'; | 22 import 'package:analyzer/src/generated/interner.dart'; |
23 import 'package:analyzer/src/generated/java_engine.dart'; | 23 import 'package:analyzer/src/generated/java_engine.dart'; |
24 import 'package:analyzer/src/generated/java_io.dart'; | 24 import 'package:analyzer/src/generated/java_io.dart'; |
25 import 'package:analyzer/src/generated/sdk_io.dart'; | 25 import 'package:analyzer/src/generated/sdk_io.dart'; |
26 import 'package:analyzer/src/generated/source.dart'; | 26 import 'package:analyzer/src/generated/source.dart'; |
27 import 'package:analyzer/src/generated/source_io.dart'; | 27 import 'package:analyzer/src/generated/source_io.dart'; |
28 import 'package:analyzer/src/services/lint.dart'; | 28 import 'package:analyzer/src/services/lint.dart'; |
| 29 import 'package:analyzer/src/task/options.dart'; |
29 import 'package:analyzer_cli/src/analyzer_impl.dart'; | 30 import 'package:analyzer_cli/src/analyzer_impl.dart'; |
30 import 'package:analyzer_cli/src/options.dart'; | 31 import 'package:analyzer_cli/src/options.dart'; |
31 import 'package:linter/src/plugin/linter_plugin.dart'; | 32 import 'package:linter/src/plugin/linter_plugin.dart'; |
32 import 'package:package_config/discovery.dart' as pkgDiscovery; | 33 import 'package:package_config/discovery.dart' as pkgDiscovery; |
33 import 'package:package_config/packages.dart' show Packages; | 34 import 'package:package_config/packages.dart' show Packages; |
34 import 'package:package_config/packages_file.dart' as pkgfile show parse; | 35 import 'package:package_config/packages_file.dart' as pkgfile show parse; |
35 import 'package:package_config/src/packages_impl.dart' show MapPackages; | 36 import 'package:package_config/src/packages_impl.dart' show MapPackages; |
36 import 'package:path/path.dart' as path; | 37 import 'package:path/path.dart' as path; |
37 import 'package:plugin/plugin.dart'; | 38 import 'package:plugin/plugin.dart'; |
38 import 'package:yaml/yaml.dart'; | 39 import 'package:yaml/yaml.dart'; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 // Add all the files to be analyzed en masse to the context. Skip any | 129 // Add all the files to be analyzed en masse to the context. Skip any |
129 // files that were added earlier (whether explicitly or implicitly) to | 130 // files that were added earlier (whether explicitly or implicitly) to |
130 // avoid causing those files to be unnecessarily re-read. | 131 // avoid causing those files to be unnecessarily re-read. |
131 Set<Source> knownSources = _context.sources.toSet(); | 132 Set<Source> knownSources = _context.sources.toSet(); |
132 List<Source> sourcesToAnalyze = <Source>[]; | 133 List<Source> sourcesToAnalyze = <Source>[]; |
133 ChangeSet changeSet = new ChangeSet(); | 134 ChangeSet changeSet = new ChangeSet(); |
134 for (String sourcePath in options.sourceFiles) { | 135 for (String sourcePath in options.sourceFiles) { |
135 sourcePath = sourcePath.trim(); | 136 sourcePath = sourcePath.trim(); |
136 // Check that file exists. | 137 // Check that file exists. |
137 if (!new File(sourcePath).existsSync()) { | 138 if (!new File(sourcePath).existsSync()) { |
138 stderr.writeln('File not found: $sourcePath'); | 139 errorSink.writeln('File not found: $sourcePath'); |
139 exitCode = ErrorSeverity.ERROR.ordinal; | 140 exitCode = ErrorSeverity.ERROR.ordinal; |
140 //Fail fast; don't analyze more files | 141 //Fail fast; don't analyze more files |
141 return ErrorSeverity.ERROR; | 142 return ErrorSeverity.ERROR; |
142 } | 143 } |
143 // Check that file is Dart file. | 144 // Check that file is Dart file. |
144 if (!AnalysisEngine.isDartFileName(sourcePath)) { | 145 if (!AnalysisEngine.isDartFileName(sourcePath)) { |
145 stderr.writeln('$sourcePath is not a Dart file'); | 146 errorSink.writeln('$sourcePath is not a Dart file'); |
146 exitCode = ErrorSeverity.ERROR.ordinal; | 147 exitCode = ErrorSeverity.ERROR.ordinal; |
147 // Fail fast; don't analyze more files. | 148 // Fail fast; don't analyze more files. |
148 return ErrorSeverity.ERROR; | 149 return ErrorSeverity.ERROR; |
149 } | 150 } |
150 Source source = _computeLibrarySource(sourcePath); | 151 Source source = _computeLibrarySource(sourcePath); |
151 if (!knownSources.contains(source)) { | 152 if (!knownSources.contains(source)) { |
152 changeSet.addedSource(source); | 153 changeSet.addedSource(source); |
153 } | 154 } |
154 sourcesToAnalyze.add(source); | 155 sourcesToAnalyze.add(source); |
155 } | 156 } |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 Map<String, YamlNode> optionMap = | 486 Map<String, YamlNode> optionMap = |
486 analysisOptionsProvider.getOptionsFromFile(file); | 487 analysisOptionsProvider.getOptionsFromFile(file); |
487 optionsProcessors.forEach( | 488 optionsProcessors.forEach( |
488 (OptionsProcessor p) => p.optionsProcessed(context, optionMap)); | 489 (OptionsProcessor p) => p.optionsProcessed(context, optionMap)); |
489 | 490 |
490 // Fill in lint rule defaults in case lints are enabled and rules are | 491 // Fill in lint rule defaults in case lints are enabled and rules are |
491 // not specified in an options file. | 492 // not specified in an options file. |
492 if (options.lints && !containsLintRuleEntry(optionMap)) { | 493 if (options.lints && !containsLintRuleEntry(optionMap)) { |
493 setLints(context, linterPlugin.contributedRules); | 494 setLints(context, linterPlugin.contributedRules); |
494 } | 495 } |
| 496 |
| 497 // Ask engine to further process options. |
| 498 if (optionMap != null) { |
| 499 configureContextOptions(context, optionMap); |
| 500 } |
495 } on Exception catch (e) { | 501 } on Exception catch (e) { |
496 optionsProcessors.forEach((OptionsProcessor p) => p.onError(e)); | 502 optionsProcessors.forEach((OptionsProcessor p) => p.onError(e)); |
497 } | 503 } |
498 } | 504 } |
499 | 505 |
500 void _processPlugins() { | 506 void _processPlugins() { |
501 List<Plugin> plugins = <Plugin>[]; | 507 List<Plugin> plugins = <Plugin>[]; |
502 plugins.add(linterPlugin); | 508 plugins.add(linterPlugin); |
503 plugins.addAll(_userDefinedPlugins); | 509 plugins.addAll(_userDefinedPlugins); |
504 AnalysisEngine.instance.userDefinedPlugins = plugins; | 510 AnalysisEngine.instance.userDefinedPlugins = plugins; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 for (var package in packages) { | 637 for (var package in packages) { |
632 var packageName = path.basename(package.path); | 638 var packageName = path.basename(package.path); |
633 var realPath = package.resolveSymbolicLinksSync(); | 639 var realPath = package.resolveSymbolicLinksSync(); |
634 result[packageName] = [ | 640 result[packageName] = [ |
635 PhysicalResourceProvider.INSTANCE.getFolder(realPath) | 641 PhysicalResourceProvider.INSTANCE.getFolder(realPath) |
636 ]; | 642 ]; |
637 } | 643 } |
638 return result; | 644 return result; |
639 } | 645 } |
640 } | 646 } |
OLD | NEW |