Remove SdkExtUriResolver.
R=brianwilkerson@google.com Change-Id: If0d7bb91e9b1c42e15935b315288fa8e3a000c6d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/128770 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
committed by
commit-bot@chromium.org
parent
c13ab9dce2
commit
7ef8822c2a
@@ -26,7 +26,6 @@ import 'package:analyzer/src/manifest/manifest_validator.dart';
|
||||
import 'package:analyzer/src/pubspec/pubspec_validator.dart';
|
||||
import 'package:analyzer/src/source/package_map_resolver.dart';
|
||||
import 'package:analyzer/src/source/path_filter.dart';
|
||||
import 'package:analyzer/src/source/sdk_ext.dart';
|
||||
import 'package:analyzer/src/task/options.dart';
|
||||
import 'package:analyzer/src/util/glob.dart';
|
||||
import 'package:analyzer/src/util/uri.dart';
|
||||
@@ -1778,10 +1777,7 @@ class PackageMapDisposition extends FolderDisposition {
|
||||
@override
|
||||
Iterable<UriResolver> createPackageUriResolvers(
|
||||
ResourceProvider resourceProvider) =>
|
||||
<UriResolver>[
|
||||
new SdkExtUriResolver(packageMap),
|
||||
new PackageMapUriResolver(resourceProvider, packageMap)
|
||||
];
|
||||
<UriResolver>[new PackageMapUriResolver(resourceProvider, packageMap)];
|
||||
|
||||
@override
|
||||
EmbedderYamlLocator getEmbedderLocator(ResourceProvider resourceProvider) {
|
||||
@@ -1829,9 +1825,10 @@ class PackagesFileDisposition extends FolderDisposition {
|
||||
Iterable<UriResolver> createPackageUriResolvers(
|
||||
ResourceProvider resourceProvider) {
|
||||
if (packages != null) {
|
||||
// Construct package map for the SdkExtUriResolver.
|
||||
Map<String, List<Folder>> packageMap = buildPackageMap(resourceProvider);
|
||||
return <UriResolver>[new SdkExtUriResolver(packageMap)];
|
||||
return <UriResolver>[
|
||||
new PackageMapUriResolver(resourceProvider, packageMap),
|
||||
];
|
||||
} else {
|
||||
return const <UriResolver>[];
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ import 'package:analyzer/src/lint/linter.dart';
|
||||
import 'package:analyzer/src/lint/registry.dart';
|
||||
import 'package:analyzer/src/services/lint.dart';
|
||||
import 'package:analyzer/src/source/package_map_resolver.dart';
|
||||
import 'package:analyzer/src/source/sdk_ext.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
final String kCustomCss = '''
|
||||
@@ -643,10 +642,6 @@ class ContextsPage extends DiagnosticPageWithNav {
|
||||
buf.write(')');
|
||||
}
|
||||
buf.write(')');
|
||||
} else if (resolver is SdkExtUriResolver) {
|
||||
buf.write(' (map = ');
|
||||
writeMap(resolver.urlMappings);
|
||||
buf.write(')');
|
||||
} else if (resolver is PackageMapUriResolver) {
|
||||
writeMap(resolver.packageMap);
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
@deprecated
|
||||
library analyzer.source.sdk_ext;
|
||||
|
||||
export 'package:analyzer/src/source/sdk_ext.dart';
|
||||
@@ -1,204 +0,0 @@
|
||||
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:core';
|
||||
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
import 'package:analyzer/src/generated/java_io.dart' show JavaFile;
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer/src/generated/source_io.dart' show FileBasedSource;
|
||||
import 'package:analyzer/src/source/package_map_provider.dart'
|
||||
show PackageMapProvider;
|
||||
import 'package:path/path.dart' as pathos;
|
||||
|
||||
/// Given a packageMap (see [PackageMapProvider]), check in each package's lib
|
||||
/// directory for the existence of a `_sdkext` file. This file must contain a
|
||||
/// JSON encoded map. Each key in the map is a `dart:` library name. Each value
|
||||
/// is a path (relative to the directory containing `_sdkext`) to a dart script
|
||||
/// for the given library. For example:
|
||||
/// {
|
||||
/// "dart:sky": "../sdk_ext/dart_sky.dart"
|
||||
/// }
|
||||
///
|
||||
/// If a key doesn't begin with `dart:` it is ignored.
|
||||
class SdkExtUriResolver extends UriResolver {
|
||||
static const String SDK_EXT_NAME = '_sdkext';
|
||||
static const String DART_COLON_PREFIX = 'dart:';
|
||||
|
||||
final Map<String, String> _urlMappings = <String, String>{};
|
||||
|
||||
/**
|
||||
* The absolute paths of the extension files that contributed to the
|
||||
* [_urlMappings].
|
||||
*/
|
||||
final List<String> extensionFilePaths = <String>[];
|
||||
|
||||
/// Construct a [SdkExtUriResolver] from a package map
|
||||
/// (see [PackageMapProvider]).
|
||||
SdkExtUriResolver(Map<String, List<Folder>> packageMap) {
|
||||
if (packageMap == null) {
|
||||
return;
|
||||
}
|
||||
packageMap.forEach(_processPackage);
|
||||
}
|
||||
|
||||
/// Number of sdk extensions.
|
||||
int get length => _urlMappings.length;
|
||||
|
||||
/**
|
||||
* Return a table mapping the names of extensions to the paths where those
|
||||
* extensions can be found.
|
||||
*/
|
||||
Map<String, String> get urlMappings => Map<String, String>.from(_urlMappings);
|
||||
|
||||
/// Return the path mapping for [libName] or null if there is none.
|
||||
String operator [](String libName) => _urlMappings[libName];
|
||||
|
||||
/// Programmatically add a new SDK extension given a JSON description
|
||||
/// ([sdkExtJSON]) and a lib directory ([libDir]).
|
||||
void addSdkExt(String sdkExtJSON, Folder libDir) {
|
||||
_processSdkExt(sdkExtJSON, libDir);
|
||||
}
|
||||
|
||||
@override
|
||||
Source resolveAbsolute(Uri importUri, [Uri actualUri]) {
|
||||
String libraryName = _libraryName(importUri);
|
||||
String partPath = _partPath(importUri);
|
||||
// Lookup library name in mappings.
|
||||
String mapping = _urlMappings[libraryName];
|
||||
if (mapping == null) {
|
||||
// Not found.
|
||||
return null;
|
||||
}
|
||||
// This mapping points to the main entry file of the sdk extension.
|
||||
Uri libraryEntry = Uri.file(mapping);
|
||||
if (!libraryEntry.isAbsolute) {
|
||||
// We expect an absolute path.
|
||||
return null;
|
||||
}
|
||||
|
||||
if (partPath != null) {
|
||||
return _resolvePart(libraryEntry, partPath, importUri);
|
||||
} else {
|
||||
return _resolveEntry(libraryEntry, importUri);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Uri restoreAbsolute(Source source) {
|
||||
String extensionName = _findExtensionNameFor(source.fullName);
|
||||
if (extensionName != null) {
|
||||
return Uri.parse(extensionName);
|
||||
}
|
||||
// TODO(johnmccutchan): Handle restoring parts.
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Return the extension name for [fullName] or `null`.
|
||||
String _findExtensionNameFor(String fullName) {
|
||||
var result;
|
||||
_urlMappings.forEach((extensionName, pathMapping) {
|
||||
if (pathMapping == fullName) {
|
||||
result = extensionName;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Return the library name of [importUri].
|
||||
String _libraryName(Uri importUri) {
|
||||
var uri = importUri.toString();
|
||||
int index = uri.indexOf('/');
|
||||
if (index >= 0) {
|
||||
return uri.substring(0, index);
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
/// Return the part path of [importUri].
|
||||
String _partPath(Uri importUri) {
|
||||
var uri = importUri.toString();
|
||||
int index = uri.indexOf('/');
|
||||
if (index >= 0) {
|
||||
return uri.substring(index + 1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Given a package [name] and a list of folders ([libDirs]),
|
||||
/// add any found sdk extensions.
|
||||
void _processPackage(String name, List<Folder> libDirs) {
|
||||
for (var libDir in libDirs) {
|
||||
var sdkExt = _readDotSdkExt(libDir);
|
||||
if (sdkExt != null) {
|
||||
_processSdkExt(sdkExt, libDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Given the JSON for an SDK extension ([sdkExtJSON]) and a folder
|
||||
/// ([libDir]), setup the uri mapping.
|
||||
void _processSdkExt(String sdkExtJSON, Folder libDir) {
|
||||
var sdkExt;
|
||||
try {
|
||||
sdkExt = json.decode(sdkExtJSON);
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
if ((sdkExt == null) || (sdkExt is! Map)) {
|
||||
return;
|
||||
}
|
||||
bool contributed = false;
|
||||
sdkExt.forEach((k, v) {
|
||||
if (_processSdkExtension(k, v, libDir)) {
|
||||
contributed = true;
|
||||
}
|
||||
});
|
||||
if (contributed) {
|
||||
extensionFilePaths.add(libDir.getChild(SDK_EXT_NAME).path);
|
||||
}
|
||||
}
|
||||
|
||||
/// Install the mapping from [name] to [libDir]/[file].
|
||||
bool _processSdkExtension(String name, String file, Folder libDir) {
|
||||
if (!name.startsWith(DART_COLON_PREFIX)) {
|
||||
// SDK extensions must begin with 'dart:'.
|
||||
return false;
|
||||
}
|
||||
var key = name;
|
||||
var value = libDir.canonicalizePath(file);
|
||||
_urlMappings[key] = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Read the contents of [libDir]/[SDK_EXT_NAME] as a string.
|
||||
/// Returns null if the file doesn't exist.
|
||||
String _readDotSdkExt(Folder libDir) {
|
||||
File file = libDir.getChild(SDK_EXT_NAME);
|
||||
try {
|
||||
return file.readAsStringSync();
|
||||
} on FileSystemException {
|
||||
// File can't be read.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolve an import of an sdk extension.
|
||||
Source _resolveEntry(Uri libraryEntry, Uri importUri) {
|
||||
// Library entry.
|
||||
JavaFile javaFile = JavaFile.fromUri(libraryEntry);
|
||||
return FileBasedSource(javaFile, importUri);
|
||||
}
|
||||
|
||||
/// Resolve a 'part' statement inside an sdk extension.
|
||||
Source _resolvePart(Uri libraryEntry, String partPath, Uri importUri) {
|
||||
// Library part.
|
||||
var directory = pathos.dirname(libraryEntry.path);
|
||||
var partUri = Uri.file(pathos.join(directory, partPath));
|
||||
assert(partUri.isAbsolute);
|
||||
JavaFile javaFile = JavaFile.fromUri(partUri);
|
||||
return FileBasedSource(javaFile, importUri);
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
import 'package:analyzer/src/source/sdk_ext.dart';
|
||||
import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(SdkExtUriResolverTest);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class SdkExtUriResolverTest with ResourceProviderMixin {
|
||||
void setUp() {
|
||||
String joinAndEscape(List<String> components) {
|
||||
return resourceProvider.pathContext
|
||||
.joinAll(components)
|
||||
.replaceAll(r'\', r'\\');
|
||||
}
|
||||
|
||||
newFolder('/empty');
|
||||
newFolder('/tmp');
|
||||
newFile('/tmp/_sdkext', content: '''
|
||||
{
|
||||
"dart:fox": "slippy.dart",
|
||||
"dart:bear": "grizzly.dart",
|
||||
"dart:relative": "${joinAndEscape(['..', 'relative.dart'])}",
|
||||
"dart:deep": "${joinAndEscape(['deep', 'directory', 'file.dart'])}",
|
||||
"fart:loudly": "nomatter.dart"
|
||||
}''');
|
||||
}
|
||||
|
||||
test_create_badJSON() {
|
||||
var resolver = SdkExtUriResolver(null);
|
||||
resolver.addSdkExt(r'''{{{,{{}}},}}''', null);
|
||||
expect(resolver.length, 0);
|
||||
}
|
||||
|
||||
test_create_noSdkExtPackageMap() {
|
||||
var resolver = SdkExtUriResolver({
|
||||
'fox': <Folder>[getFolder('/empty')]
|
||||
});
|
||||
expect(resolver.length, 0);
|
||||
}
|
||||
|
||||
test_create_nullPackageMap() {
|
||||
var resolver = SdkExtUriResolver(null);
|
||||
expect(resolver.length, 0);
|
||||
}
|
||||
|
||||
test_create_sdkExtPackageMap() {
|
||||
var resolver = SdkExtUriResolver({
|
||||
'fox': <Folder>[newFolder('/tmp')]
|
||||
});
|
||||
// We have four mappings.
|
||||
expect(resolver.length, 4);
|
||||
// Check that they map to the correct paths.
|
||||
expect(resolver['dart:fox'], convertPath('/tmp/slippy.dart'));
|
||||
expect(resolver['dart:bear'], convertPath('/tmp/grizzly.dart'));
|
||||
expect(resolver['dart:relative'], convertPath('/relative.dart'));
|
||||
expect(resolver['dart:deep'], convertPath('/tmp/deep/directory/file.dart'));
|
||||
}
|
||||
|
||||
test_restoreAbsolute() {
|
||||
var resolver = SdkExtUriResolver({
|
||||
'fox': <Folder>[newFolder('/tmp')]
|
||||
});
|
||||
var source = resolver.resolveAbsolute(Uri.parse('dart:fox'));
|
||||
expect(source, isNotNull);
|
||||
// Restore source's uri.
|
||||
var restoreUri = resolver.restoreAbsolute(source);
|
||||
expect(restoreUri, isNotNull);
|
||||
// Verify that it is 'dart:fox'.
|
||||
expect(restoreUri.toString(), 'dart:fox');
|
||||
expect(restoreUri.scheme, 'dart');
|
||||
expect(restoreUri.path, 'fox');
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,6 @@ import 'embedder_test.dart' // ignore: deprecated_member_use_from_same_package
|
||||
import 'error_processor_test.dart' as error_processor_test;
|
||||
import 'package_map_resolver_test.dart' as package_map_resolver_test;
|
||||
import 'path_filter_test.dart' as path_filter_test;
|
||||
import 'sdk_ext_test.dart' as sdk_ext_test;
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
@@ -19,6 +18,5 @@ main() {
|
||||
error_processor_test.main();
|
||||
package_map_resolver_test.main();
|
||||
path_filter_test.main();
|
||||
sdk_ext_test.main();
|
||||
}, name: 'source');
|
||||
}
|
||||
|
||||
@@ -6,11 +6,11 @@ import 'dart:async';
|
||||
import 'dart:io' as io;
|
||||
import 'dart:isolate';
|
||||
|
||||
import 'package:analyzer/src/context/context_root.dart';
|
||||
import 'package:analyzer/error/error.dart';
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
import 'package:analyzer/file_system/physical_file_system.dart';
|
||||
import 'package:analyzer/src/context/builder.dart';
|
||||
import 'package:analyzer/src/context/context_root.dart';
|
||||
import 'package:analyzer/src/dart/analysis/byte_store.dart';
|
||||
import 'package:analyzer/src/dart/analysis/driver.dart';
|
||||
import 'package:analyzer/src/dart/analysis/file_state.dart';
|
||||
@@ -29,7 +29,6 @@ import 'package:analyzer/src/manifest/manifest_validator.dart';
|
||||
import 'package:analyzer/src/pubspec/pubspec_validator.dart';
|
||||
import 'package:analyzer/src/source/package_map_resolver.dart';
|
||||
import 'package:analyzer/src/source/path_filter.dart';
|
||||
import 'package:analyzer/src/source/sdk_ext.dart';
|
||||
import 'package:analyzer/src/summary/idl.dart';
|
||||
import 'package:analyzer/src/summary/package_bundle_reader.dart';
|
||||
import 'package:analyzer/src/summary/summary_file_builder.dart';
|
||||
@@ -460,11 +459,6 @@ class Driver with HasContextMixin implements CommandLineStarter {
|
||||
}
|
||||
}
|
||||
|
||||
// Next SdkExts.
|
||||
if (packageInfo.packageMap != null) {
|
||||
resolvers.add(new SdkExtUriResolver(packageInfo.packageMap));
|
||||
}
|
||||
|
||||
// Then package URIs from summaries.
|
||||
resolvers.add(new InSummaryUriResolver(resourceProvider, summaryDataStore));
|
||||
|
||||
@@ -768,12 +762,12 @@ class _PackageInfo {
|
||||
_PackageInfo(this.packages, this.packageMap);
|
||||
}
|
||||
|
||||
/// [SdkExtUriResolver] needs a Map from package name to folder. In the case
|
||||
/// that the analyzer is invoked with a --package-root option, we need to
|
||||
/// manually create this mapping. Given [packageRootPath],
|
||||
/// [_PackageRootPackageMapBuilder] creates a simple mapping from package name
|
||||
/// to full path on disk (resolving any symbolic links).
|
||||
class _PackageRootPackageMapBuilder {
|
||||
/// In the case that the analyzer is invoked with a --package-root option, we
|
||||
/// need to manually create the mapping from package name to folder.
|
||||
///
|
||||
/// Given [packageRootPath], creates a simple mapping from package name
|
||||
/// to full path on disk (resolving any symbolic links).
|
||||
static Map<String, List<Folder>> buildPackageMap(String packageRootPath) {
|
||||
var packageRoot = new io.Directory(packageRootPath);
|
||||
if (!packageRoot.existsSync()) {
|
||||
|
||||
Reference in New Issue
Block a user