Index: pkg/analyzer_cli/lib/src/build_mode.dart |
diff --git a/pkg/analyzer_cli/lib/src/build_mode.dart b/pkg/analyzer_cli/lib/src/build_mode.dart |
index b69669db2f17e405125c73366cf69cc8d4f83462..025e620a77d6e443aa623f8b70d8a8349dc5db8d 100644 |
--- a/pkg/analyzer_cli/lib/src/build_mode.dart |
+++ b/pkg/analyzer_cli/lib/src/build_mode.dart |
@@ -13,10 +13,10 @@ import 'package:analyzer/file_system/file_system.dart'; |
import 'package:analyzer/src/dart/sdk/sdk.dart'; |
import 'package:analyzer/src/generated/engine.dart'; |
import 'package:analyzer/src/generated/error.dart'; |
-import 'package:analyzer/src/generated/java_io.dart'; |
import 'package:analyzer/src/generated/sdk.dart'; |
import 'package:analyzer/src/generated/source.dart'; |
import 'package:analyzer/src/generated/source_io.dart'; |
+import 'package:analyzer/src/source/source_resource.dart'; |
import 'package:analyzer/src/summary/format.dart'; |
import 'package:analyzer/src/summary/idl.dart'; |
import 'package:analyzer/src/summary/link.dart'; |
@@ -131,7 +131,7 @@ class BuildMode { |
SummaryDataStore summaryDataStore; |
InternalAnalysisContext context; |
- Map<Uri, JavaFile> uriToFileMap; |
+ Map<Uri, File> uriToFileMap; |
final List<Source> explicitSources = <Source>[]; |
PackageBundleAssembler assembler; |
@@ -167,13 +167,13 @@ class BuildMode { |
// Add sources. |
ChangeSet changeSet = new ChangeSet(); |
for (Uri uri in uriToFileMap.keys) { |
- JavaFile file = uriToFileMap[uri]; |
- if (!file.exists()) { |
- errorSink.writeln('File not found: ${file.getPath()}'); |
+ File file = uriToFileMap[uri]; |
+ if (!file.exists) { |
+ errorSink.writeln('File not found: ${file.path}'); |
io.exitCode = ErrorSeverity.ERROR.ordinal; |
return ErrorSeverity.ERROR; |
} |
- Source source = new FileBasedSource(file, uri); |
+ Source source = new FileSource(file, uri); |
explicitSources.add(source); |
changeSet.addedSource(source); |
} |
@@ -291,7 +291,7 @@ class BuildMode { |
context = AnalysisEngine.instance.createAnalysisContext(); |
context.sourceFactory = new SourceFactory(<UriResolver>[ |
new DartUriResolver(sdk), |
- new InSummaryPackageUriResolver(summaryDataStore), |
+ new InSummaryUriResolver(resourceProvider, summaryDataStore), |
new ExplicitSourceResolver(uriToFileMap) |
]); |
@@ -312,6 +312,28 @@ class BuildMode { |
} |
/** |
+ * Convert [sourceEntities] (a list of file specifications of the form |
+ * "$uri|$path") to a map from URI to path. If an error occurs, report the |
+ * error and return null. |
+ */ |
+ Map<Uri, File> _createUriToFileMap(List<String> sourceEntities) { |
+ Map<Uri, File> uriToFileMap = <Uri, File>{}; |
+ for (String sourceFile in sourceEntities) { |
+ int pipeIndex = sourceFile.indexOf('|'); |
+ if (pipeIndex == -1) { |
+ // TODO(paulberry): add the ability to guess the URI from the path. |
+ errorSink.writeln( |
+ 'Illegal input file (must be "\$uri|\$path"): $sourceFile'); |
+ return null; |
+ } |
+ Uri uri = Uri.parse(sourceFile.substring(0, pipeIndex)); |
+ String path = sourceFile.substring(pipeIndex + 1); |
+ uriToFileMap[uri] = resourceProvider.getFile(path); |
+ } |
+ return uriToFileMap; |
+ } |
+ |
+ /** |
* Print errors for all explicit sources. If [outputPath] is supplied, output |
* is sent to a new file at that path. |
*/ |
@@ -377,26 +399,48 @@ class BuildMode { |
link(sourceUris, _getDependency, _getUnit, options.strongMode); |
linkResult.forEach(assembler.addLinkedLibrary); |
} |
+} |
+ |
+/** |
+ * Instances of the class [ExplicitSourceResolver] map URIs to files on disk |
+ * using a fixed mapping provided at construction time. |
+ */ |
+class ExplicitSourceResolver extends UriResolver { |
+ final Map<Uri, File> uriToFileMap; |
+ final Map<String, Uri> pathToUriMap; |
/** |
- * Convert [sourceEntities] (a list of file specifications of the form |
- * "$uri|$path") to a map from URI to path. If an error occurs, report the |
- * error and return null. |
+ * Construct an [ExplicitSourceResolver] based on the given [uriToFileMap]. |
*/ |
- static Map<Uri, JavaFile> _createUriToFileMap(List<String> sourceEntities) { |
- Map<Uri, JavaFile> uriToFileMap = <Uri, JavaFile>{}; |
- for (String sourceFile in sourceEntities) { |
- int pipeIndex = sourceFile.indexOf('|'); |
- if (pipeIndex == -1) { |
- // TODO(paulberry): add the ability to guess the URI from the path. |
- errorSink.writeln( |
- 'Illegal input file (must be "\$uri|\$path"): $sourceFile'); |
- return null; |
- } |
- Uri uri = Uri.parse(sourceFile.substring(0, pipeIndex)); |
- String path = sourceFile.substring(pipeIndex + 1); |
- uriToFileMap[uri] = new JavaFile(path); |
+ ExplicitSourceResolver(Map<Uri, File> uriToFileMap) |
+ : uriToFileMap = uriToFileMap, |
+ pathToUriMap = _computePathToUriMap(uriToFileMap); |
+ |
+ @override |
+ Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
+ File file = uriToFileMap[uri]; |
+ actualUri ??= uri; |
+ if (file == null) { |
+ return new NonExistingSource( |
+ uri.toString(), actualUri, UriKind.fromScheme(actualUri.scheme)); |
+ } else { |
+ return new FileSource(file, actualUri); |
} |
- return uriToFileMap; |
+ } |
+ |
+ @override |
+ Uri restoreAbsolute(Source source) { |
+ return pathToUriMap[source.fullName]; |
+ } |
+ |
+ /** |
+ * Build the inverse mapping of [uriToSourceMap]. |
+ */ |
+ static Map<String, Uri> _computePathToUriMap(Map<Uri, File> uriToSourceMap) { |
+ Map<String, Uri> pathToUriMap = <String, Uri>{}; |
+ uriToSourceMap.forEach((Uri uri, File file) { |
+ pathToUriMap[file.path] = uri; |
+ }); |
+ return pathToUriMap; |
} |
} |