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 'package:args/args.dart' show ArgParser, ArgResults; | 5 import 'package:args/args.dart' show ArgParser, ArgResults; |
6 import 'package:analyzer/src/command_line/arguments.dart'; | 6 import 'package:analyzer/src/command_line/arguments.dart'; |
7 import 'package:analyzer/file_system/file_system.dart' | 7 import 'package:analyzer/file_system/file_system.dart' |
8 show ResourceProvider, ResourceUriResolver; | 8 show ResourceProvider, ResourceUriResolver; |
9 import 'package:analyzer/file_system/physical_file_system.dart' | 9 import 'package:analyzer/file_system/physical_file_system.dart' |
10 show PhysicalResourceProvider; | 10 show PhysicalResourceProvider; |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 /// Custom URI mappings, such as "dart:foo" -> "path/to/foo.dart" | 26 /// Custom URI mappings, such as "dart:foo" -> "path/to/foo.dart" |
27 final Map<String, String> customUrlMappings; | 27 final Map<String, String> customUrlMappings; |
28 | 28 |
29 /// Package root when resolving 'package:' urls the standard way. | 29 /// Package root when resolving 'package:' urls the standard way. |
30 String get packageRoot => contextBuilderOptions.defaultPackagesDirectoryPath; | 30 String get packageRoot => contextBuilderOptions.defaultPackagesDirectoryPath; |
31 | 31 |
32 /// List of summary file paths. | 32 /// List of summary file paths. |
33 final List<String> summaryPaths; | 33 final List<String> summaryPaths; |
34 | 34 |
| 35 final Map<String, String> customSummaryModules = {}; |
| 36 |
35 /// Path to the dart-sdk, or `null` if the path couldn't be determined. | 37 /// Path to the dart-sdk, or `null` if the path couldn't be determined. |
36 final String dartSdkPath; | 38 final String dartSdkPath; |
37 | 39 |
38 /// Path to the dart-sdk summary. If this is set, it will be used in favor | 40 /// Path to the dart-sdk summary. If this is set, it will be used in favor |
39 /// of the unsummarized one. | 41 /// of the unsummarized one. |
40 String get dartSdkSummaryPath => contextBuilderOptions.dartSdkSummaryPath; | 42 String get dartSdkSummaryPath => contextBuilderOptions.dartSdkSummaryPath; |
41 | 43 |
42 /// Defined variables used by `bool.fromEnvironment` etc. | 44 /// Defined variables used by `bool.fromEnvironment` etc. |
43 Map<String, String> get declaredVariables => | 45 Map<String, String> get declaredVariables => |
44 contextBuilderOptions.declaredVariables; | 46 contextBuilderOptions.declaredVariables; |
45 | 47 |
46 AnalyzerOptions._( | 48 AnalyzerOptions._( |
47 {this.contextBuilderOptions, | 49 {this.contextBuilderOptions, |
48 List<String> summaryPaths, | 50 List<String> summaryPaths, |
49 String dartSdkPath, | 51 String dartSdkPath, |
50 this.customUrlMappings: const {}}) | 52 this.customUrlMappings: const {}}) |
51 : dartSdkPath = dartSdkPath ?? getSdkDir().path, | 53 : dartSdkPath = dartSdkPath ?? getSdkDir().path, |
52 summaryPaths = summaryPaths ?? const [] { | 54 summaryPaths = summaryPaths ?? const [] { |
53 contextBuilderOptions.declaredVariables ??= const {}; | 55 contextBuilderOptions.declaredVariables ??= const {}; |
| 56 _parseCustomSummaryModules(); |
54 } | 57 } |
55 | 58 |
56 factory AnalyzerOptions.basic( | 59 factory AnalyzerOptions.basic( |
57 {String dartSdkPath, | 60 {String dartSdkPath, |
58 String dartSdkSummaryPath, | 61 String dartSdkSummaryPath, |
59 List<String> summaryPaths}) { | 62 List<String> summaryPaths}) { |
60 var contextBuilderOptions = new ContextBuilderOptions() | 63 var contextBuilderOptions = new ContextBuilderOptions() |
61 ..defaultOptions = (new AnalysisOptionsImpl()..strongMode = true) | 64 ..defaultOptions = (new AnalysisOptionsImpl()..strongMode = true) |
62 ..dartSdkSummaryPath = dartSdkSummaryPath; | 65 ..dartSdkSummaryPath = dartSdkSummaryPath; |
63 | 66 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 static Map<String, String> _parseUrlMappings(Iterable argument) { | 105 static Map<String, String> _parseUrlMappings(Iterable argument) { |
103 var mappings = <String, String>{}; | 106 var mappings = <String, String>{}; |
104 for (var mapping in argument) { | 107 for (var mapping in argument) { |
105 var splitMapping = mapping.split(','); | 108 var splitMapping = mapping.split(','); |
106 if (splitMapping.length >= 2) { | 109 if (splitMapping.length >= 2) { |
107 mappings[splitMapping[0]] = path.absolute(splitMapping[1]); | 110 mappings[splitMapping[0]] = path.absolute(splitMapping[1]); |
108 } | 111 } |
109 } | 112 } |
110 return mappings; | 113 return mappings; |
111 } | 114 } |
| 115 |
| 116 /// A summary path can contain ":" followed by an explicit module name to |
| 117 /// allow working with summaries whose physical location is outside of the |
| 118 /// module root directory. |
| 119 /// |
| 120 /// Removes any explicit module names from [summaryPaths] and populates with |
| 121 /// [customSummaryModules] with them. |
| 122 void _parseCustomSummaryModules() { |
| 123 for (var i = 0; i < summaryPaths.length; i++) { |
| 124 var summaryPath = summaryPaths[i]; |
| 125 var comma = summaryPath.indexOf(":"); |
| 126 if (comma != -1) { |
| 127 summaryPaths[i] = summaryPath.substring(0, comma); |
| 128 customSummaryModules[summaryPaths[i]] = |
| 129 summaryPath.substring(comma + 1); |
| 130 } |
| 131 } |
| 132 } |
112 } | 133 } |
113 | 134 |
114 /// Creates a SourceFactory configured by the [options]. | 135 /// Creates a SourceFactory configured by the [options]. |
115 /// | 136 /// |
116 /// If supplied, [fileResolvers] will override the default `file:` and | 137 /// If supplied, [fileResolvers] will override the default `file:` and |
117 /// `package:` URI resolvers. | 138 /// `package:` URI resolvers. |
118 SourceFactory createSourceFactory(AnalyzerOptions options, | 139 SourceFactory createSourceFactory(AnalyzerOptions options, |
119 {DartUriResolver sdkResolver, | 140 {DartUriResolver sdkResolver, |
120 List<UriResolver> fileResolvers, | 141 List<UriResolver> fileResolvers, |
121 SummaryDataStore summaryData, | 142 SummaryDataStore summaryData, |
(...skipping 25 matching lines...) Expand all Loading... |
147 builderOptions.defaultPackagesDirectoryPath = options.packageRoot; | 168 builderOptions.defaultPackagesDirectoryPath = options.packageRoot; |
148 } | 169 } |
149 ContextBuilder builder = new ContextBuilder(resourceProvider, null, null, | 170 ContextBuilder builder = new ContextBuilder(resourceProvider, null, null, |
150 options: builderOptions); | 171 options: builderOptions); |
151 return new PackageMapUriResolver(resourceProvider, | 172 return new PackageMapUriResolver(resourceProvider, |
152 builder.convertPackagesToMap(builder.createPackageMap(''))); | 173 builder.convertPackagesToMap(builder.createPackageMap(''))); |
153 } | 174 } |
154 | 175 |
155 return [new ResourceUriResolver(resourceProvider), packageResolver()]; | 176 return [new ResourceUriResolver(resourceProvider), packageResolver()]; |
156 } | 177 } |
OLD | NEW |