Split out options from ContextBuilder

R=scheglov@google.com

Review URL: https://codereview.chromium.org/2425423009 .
This commit is contained in:
Brian Wilkerson 2016-10-20 11:03:11 -07:00
parent 59ec5d4f60
commit 96750cd5cb
8 changed files with 145 additions and 101 deletions

View file

@ -1645,16 +1645,18 @@ class ServerContextManagerCallbacks extends ContextManagerCallbacks {
} }
} }
ContextBuilderOptions builderOptions = new ContextBuilderOptions();
builderOptions.defaultOptions = options;
builderOptions.defaultPackageFilePath = defaultPackageFilePath;
builderOptions.defaultPackagesDirectoryPath = defaultPackagesDirectoryPath;
if (analysisServer.options.enablePubSummaryManager) {
builderOptions.pubSummaryManager = analysisServer.pubSummaryManager;
}
ContextBuilder builder = new ContextBuilder(resourceProvider, ContextBuilder builder = new ContextBuilder(resourceProvider,
analysisServer.sdkManager, analysisServer.overlayState); analysisServer.sdkManager, analysisServer.overlayState,
builder.defaultOptions = options; options: builderOptions);
builder.fileResolverProvider = analysisServer.fileResolverProvider; builder.fileResolverProvider = analysisServer.fileResolverProvider;
builder.packageResolverProvider = analysisServer.packageResolverProvider; builder.packageResolverProvider = analysisServer.packageResolverProvider;
builder.defaultPackageFilePath = defaultPackageFilePath;
builder.defaultPackagesDirectoryPath = defaultPackagesDirectoryPath;
if (analysisServer.options.enablePubSummaryManager) {
builder.pubSummaryManager = analysisServer.pubSummaryManager;
}
return builder; return builder;
} }

View file

@ -2707,9 +2707,11 @@ class TestContextManagerCallbacks extends ContextManagerCallbacks {
@override @override
ContextBuilder createContextBuilder(Folder folder, AnalysisOptions options) { ContextBuilder createContextBuilder(Folder folder, AnalysisOptions options) {
DartSdkManager sdkManager = new DartSdkManager('/', false); DartSdkManager sdkManager = new DartSdkManager('/', false);
ContextBuilder builder = ContextBuilderOptions builderOptions = new ContextBuilderOptions();
new ContextBuilder(resourceProvider, sdkManager, new ContentCache()); builderOptions.defaultOptions = options;
builder.defaultOptions = options; ContextBuilder builder = new ContextBuilder(
resourceProvider, sdkManager, new ContentCache(),
options: builderOptions);
return builder; return builder;
} }

View file

@ -68,6 +68,11 @@ class ContextBuilder {
*/ */
final ContentCache contentCache; final ContentCache contentCache;
/**
* The options used by the context builder.
*/
final ContextBuilderOptions builderOptions;
/** /**
* The resolver provider used to create a package: URI resolver, or `null` if * The resolver provider used to create a package: URI resolver, or `null` if
* the normal (Package Specification DEP) lookup mechanism is to be used. * the normal (Package Specification DEP) lookup mechanism is to be used.
@ -82,57 +87,13 @@ class ContextBuilder {
@deprecated @deprecated
ResolverProvider fileResolverProvider; ResolverProvider fileResolverProvider;
/**
* The file path of the .packages file that should be used in place of any
* file found using the normal (Package Specification DEP) lookup mechanism,
* or `null` if the normal lookup mechanism should be used.
*/
String defaultPackageFilePath;
/**
* The file path of the packages directory that should be used in place of any
* file found using the normal (Package Specification DEP) lookup mechanism,
* or `null` if the normal lookup mechanism should be used.
*/
String defaultPackagesDirectoryPath;
/**
* The file path of the file containing the summary of the SDK that should be
* used to "analyze" the SDK. This option should only be specified by
* command-line tools such as 'dartanalyzer' or 'ddc'.
*/
String dartSdkSummaryPath;
/**
* The file path of the analysis options file that should be used in place of
* any file in the root directory or a parent of the root directory, or `null`
* if the normal lookup mechanism should be used.
*/
String defaultAnalysisOptionsFilePath;
/**
* The default analysis options that should be used unless some or all of them
* are overridden in the analysis options file, or `null` if the default
* defaults should be used.
*/
AnalysisOptions defaultOptions;
/**
* A table mapping variable names to values for the declared variables, or
* `null` if no additional variables should be declared.
*/
Map<String, String> declaredVariables;
/**
* The manager of pub package summaries.
*/
PubSummaryManager pubSummaryManager;
/** /**
* Initialize a newly created builder to be ready to build a context rooted in * Initialize a newly created builder to be ready to build a context rooted in
* the directory with the given [rootDirectoryPath]. * the directory with the given [rootDirectoryPath].
*/ */
ContextBuilder(this.resourceProvider, this.sdkManager, this.contentCache); ContextBuilder(this.resourceProvider, this.sdkManager, this.contentCache,
{ContextBuilderOptions options})
: builderOptions = options ?? new ContextBuilderOptions();
/** /**
* Return an analysis context that is configured correctly to analyze code in * Return an analysis context that is configured correctly to analyze code in
@ -158,9 +119,9 @@ class ContextBuilder {
* Configure the context to make use of summaries. * Configure the context to make use of summaries.
*/ */
void configureSummaries(InternalAnalysisContext context) { void configureSummaries(InternalAnalysisContext context) {
if (pubSummaryManager != null) { PubSummaryManager manager = builderOptions.pubSummaryManager;
List<LinkedPubPackage> linkedBundles = if (manager != null) {
pubSummaryManager.getLinkedBundles(context); List<LinkedPubPackage> linkedBundles = manager.getLinkedBundles(context);
if (linkedBundles.isNotEmpty) { if (linkedBundles.isNotEmpty) {
SummaryDataStore store = new SummaryDataStore([]); SummaryDataStore store = new SummaryDataStore([]);
for (LinkedPubPackage package in linkedBundles) { for (LinkedPubPackage package in linkedBundles) {
@ -211,6 +172,7 @@ class ContextBuilder {
* Return an analysis options object containing the default option values. * Return an analysis options object containing the default option values.
*/ */
AnalysisOptions createDefaultOptions() { AnalysisOptions createDefaultOptions() {
AnalysisOptions defaultOptions = builderOptions.defaultOptions;
if (defaultOptions == null) { if (defaultOptions == null) {
return new AnalysisOptionsImpl(); return new AnalysisOptionsImpl();
} }
@ -218,14 +180,17 @@ class ContextBuilder {
} }
Packages createPackageMap(String rootDirectoryPath) { Packages createPackageMap(String rootDirectoryPath) {
if (defaultPackageFilePath != null) { String filePath = builderOptions.defaultPackageFilePath;
File configFile = resourceProvider.getFile(defaultPackageFilePath); if (filePath != null) {
File configFile = resourceProvider.getFile(filePath);
List<int> bytes = configFile.readAsBytesSync(); List<int> bytes = configFile.readAsBytesSync();
Map<String, Uri> map = parse(bytes, configFile.toUri()); Map<String, Uri> map = parse(bytes, configFile.toUri());
resolveSymbolicLinks(map); resolveSymbolicLinks(map);
return new MapPackages(map); return new MapPackages(map);
} else if (defaultPackagesDirectoryPath != null) { }
Folder folder = resourceProvider.getFolder(defaultPackagesDirectoryPath); String directoryPath = builderOptions.defaultPackagesDirectoryPath;
if (directoryPath != null) {
Folder folder = resourceProvider.getFolder(directoryPath);
return getPackagesFromFolder(folder); return getPackagesFromFolder(folder);
} }
return findPackagesFromFile(rootDirectoryPath); return findPackagesFromFile(rootDirectoryPath);
@ -258,9 +223,10 @@ class ContextBuilder {
* given [context]. * given [context].
*/ */
void declareVariables(InternalAnalysisContext context) { void declareVariables(InternalAnalysisContext context) {
if (declaredVariables != null && declaredVariables.isNotEmpty) { Map<String, String> variables = builderOptions.declaredVariables;
if (variables != null && variables.isNotEmpty) {
DeclaredVariables contextVariables = context.declaredVariables; DeclaredVariables contextVariables = context.declaredVariables;
declaredVariables.forEach((String variableName, String value) { variables.forEach((String variableName, String value) {
contextVariables.define(variableName, value); contextVariables.define(variableName, value);
}); });
} }
@ -292,12 +258,13 @@ class ContextBuilder {
/** /**
* Return the SDK that should be used to analyze code. Use the given * Return the SDK that should be used to analyze code. Use the given
* [packageMap] and [options] to locate the SDK. * [packageMap] and [analysisOptions] to locate the SDK.
*/ */
DartSdk findSdk( DartSdk findSdk(
Map<String, List<Folder>> packageMap, AnalysisOptions options) { Map<String, List<Folder>> packageMap, AnalysisOptions analysisOptions) {
if (dartSdkSummaryPath != null) { String summaryPath = builderOptions.dartSdkSummaryPath;
return new SummaryBasedDartSdk(dartSdkSummaryPath, options.strongMode); if (summaryPath != null) {
return new SummaryBasedDartSdk(summaryPath, analysisOptions.strongMode);
} else if (packageMap != null) { } else if (packageMap != null) {
SdkExtensionFinder extFinder = new SdkExtensionFinder(packageMap); SdkExtensionFinder extFinder = new SdkExtensionFinder(packageMap);
List<String> extFilePaths = extFinder.extensionFilePaths; List<String> extFilePaths = extFinder.extensionFilePaths;
@ -317,12 +284,12 @@ class ContextBuilder {
.path); .path);
} }
paths.addAll(extFilePaths); paths.addAll(extFilePaths);
SdkDescription description = new SdkDescription(paths, options); SdkDescription description = new SdkDescription(paths, analysisOptions);
DartSdk dartSdk = sdkManager.getSdk(description, () { DartSdk dartSdk = sdkManager.getSdk(description, () {
if (extFilePaths.isNotEmpty) { if (extFilePaths.isNotEmpty) {
embedderSdk.addExtensions(extFinder.urlMappings); embedderSdk.addExtensions(extFinder.urlMappings);
} }
embedderSdk.analysisOptions = options; embedderSdk.analysisOptions = analysisOptions;
embedderSdk.useSummary = sdkManager.canUseSummaries; embedderSdk.useSummary = sdkManager.canUseSummaries;
return embedderSdk; return embedderSdk;
}); });
@ -334,25 +301,26 @@ class ContextBuilder {
String sdkPath = sdkManager.defaultSdkDirectory; String sdkPath = sdkManager.defaultSdkDirectory;
List<String> paths = <String>[sdkPath]; List<String> paths = <String>[sdkPath];
paths.addAll(extFilePaths); paths.addAll(extFilePaths);
SdkDescription description = new SdkDescription(paths, options); SdkDescription description = new SdkDescription(paths, analysisOptions);
return sdkManager.getSdk(description, () { return sdkManager.getSdk(description, () {
FolderBasedDartSdk sdk = new FolderBasedDartSdk( FolderBasedDartSdk sdk = new FolderBasedDartSdk(
resourceProvider, resourceProvider.getFolder(sdkPath)); resourceProvider, resourceProvider.getFolder(sdkPath));
if (extFilePaths.isNotEmpty) { if (extFilePaths.isNotEmpty) {
sdk.addExtensions(extFinder.urlMappings); sdk.addExtensions(extFinder.urlMappings);
} }
sdk.analysisOptions = options; sdk.analysisOptions = analysisOptions;
sdk.useSummary = sdkManager.canUseSummaries; sdk.useSummary = sdkManager.canUseSummaries;
return sdk; return sdk;
}); });
} }
} }
String sdkPath = sdkManager.defaultSdkDirectory; String sdkPath = sdkManager.defaultSdkDirectory;
SdkDescription description = new SdkDescription(<String>[sdkPath], options); SdkDescription description =
new SdkDescription(<String>[sdkPath], analysisOptions);
return sdkManager.getSdk(description, () { return sdkManager.getSdk(description, () {
FolderBasedDartSdk sdk = new FolderBasedDartSdk(resourceProvider, FolderBasedDartSdk sdk = new FolderBasedDartSdk(resourceProvider,
resourceProvider.getFolder(sdkPath), options.strongMode); resourceProvider.getFolder(sdkPath), analysisOptions.strongMode);
sdk.analysisOptions = options; sdk.analysisOptions = analysisOptions;
sdk.useSummary = sdkManager.canUseSummaries; sdk.useSummary = sdkManager.canUseSummaries;
return sdk; return sdk;
}); });
@ -386,8 +354,9 @@ class ContextBuilder {
* the directory with the given [path]. * the directory with the given [path].
*/ */
File getOptionsFile(String path) { File getOptionsFile(String path) {
if (defaultAnalysisOptionsFilePath != null) { String filePath = builderOptions.defaultAnalysisOptionsFilePath;
return resourceProvider.getFile(defaultAnalysisOptionsFilePath); if (filePath != null) {
return resourceProvider.getFile(filePath);
} }
Folder root = resourceProvider.getFolder(path); Folder root = resourceProvider.getFolder(path);
for (Folder folder = root; folder != null; folder = folder.parent) { for (Folder folder = root; folder != null; folder = folder.parent) {
@ -503,6 +472,62 @@ class ContextBuilder {
} }
} }
/**
* Options used by a [ContextBuilder].
*/
class ContextBuilderOptions {
/**
* The file path of the file containing the summary of the SDK that should be
* used to "analyze" the SDK. This option should only be specified by
* command-line tools such as 'dartanalyzer' or 'ddc'.
*/
String dartSdkSummaryPath;
/**
* The file path of the analysis options file that should be used in place of
* any file in the root directory or a parent of the root directory, or `null`
* if the normal lookup mechanism should be used.
*/
String defaultAnalysisOptionsFilePath;
/**
* A table mapping variable names to values for the declared variables, or
* `null` if no additional variables should be declared.
*/
Map<String, String> declaredVariables;
/**
* The default analysis options that should be used unless some or all of them
* are overridden in the analysis options file, or `null` if the default
* defaults should be used.
*/
AnalysisOptions defaultOptions;
/**
* The file path of the .packages file that should be used in place of any
* file found using the normal (Package Specification DEP) lookup mechanism,
* or `null` if the normal lookup mechanism should be used.
*/
String defaultPackageFilePath;
/**
* The file path of the packages directory that should be used in place of any
* file found using the normal (Package Specification DEP) lookup mechanism,
* or `null` if the normal lookup mechanism should be used.
*/
String defaultPackagesDirectoryPath;
/**
* The manager of pub package summaries.
*/
PubSummaryManager pubSummaryManager;
/**
* Initialize a newly created set of options
*/
ContextBuilderOptions();
}
/** /**
* Given a package map, check in each package's lib directory for the existence * Given a package map, check in each package's lib directory for the existence
* of an `_embedder.yaml` file. If the file contains a top level YamlMap, it * of an `_embedder.yaml` file. If the file contains a top level YamlMap, it

View file

@ -54,6 +54,11 @@ class ContextBuilderTest extends EngineTestCase {
*/ */
ContentCache contentCache; ContentCache contentCache;
/**
* The options passed to the context builder.
*/
ContextBuilderOptions builderOptions = new ContextBuilderOptions();
/** /**
* The context builder to be used in the test. * The context builder to be used in the test.
*/ */
@ -83,7 +88,8 @@ const Map<String, LibraryInfo> libraries = const {
}; };
'''); ''');
sdkManager = new DartSdkManager(defaultSdkPath, false); sdkManager = new DartSdkManager(defaultSdkPath, false);
builder = new ContextBuilder(resourceProvider, sdkManager, contentCache); builder = new ContextBuilder(resourceProvider, sdkManager, contentCache,
options: builderOptions);
} }
void createFile(String path, String content) { void createFile(String path, String content) {
@ -98,7 +104,8 @@ const Map<String, LibraryInfo> libraries = const {
sdkManager = sdkManager =
new DartSdkManager(resourceProvider.convertPath('/sdk'), false); new DartSdkManager(resourceProvider.convertPath('/sdk'), false);
contentCache = new ContentCache(); contentCache = new ContentCache();
builder = new ContextBuilder(resourceProvider, sdkManager, contentCache); builder = new ContextBuilder(resourceProvider, sdkManager, contentCache,
options: builderOptions);
} }
@failingTest @failingTest
@ -142,7 +149,7 @@ const Map<String, LibraryInfo> libraries = const {
defaultOptions.enableStrictCallChecks = defaultOptions.enableStrictCallChecks =
!defaultOptions.enableStrictCallChecks; !defaultOptions.enableStrictCallChecks;
defaultOptions.enableSuperMixins = !defaultOptions.enableSuperMixins; defaultOptions.enableSuperMixins = !defaultOptions.enableSuperMixins;
builder.defaultOptions = defaultOptions; builderOptions.defaultOptions = defaultOptions;
AnalysisOptions options = builder.createDefaultOptions(); AnalysisOptions options = builder.createDefaultOptions();
_expectEqualOptions(options, defaultOptions); _expectEqualOptions(options, defaultOptions);
} }
@ -165,7 +172,7 @@ const Map<String, LibraryInfo> libraries = const {
resourceProvider.newFolder(fooPath); resourceProvider.newFolder(fooPath);
resourceProvider.newFolder(barPath); resourceProvider.newFolder(barPath);
builder.defaultPackagesDirectoryPath = packageDirPath; builderOptions.defaultPackagesDirectoryPath = packageDirPath;
Packages packages = builder.createPackageMap(projectPath); Packages packages = builder.createPackageMap(projectPath);
expect(packages, isNotNull); expect(packages, isNotNull);
@ -209,7 +216,7 @@ foo:$fooUri
bar:$barUri bar:$barUri
'''); ''');
builder.defaultPackageFilePath = packageFilePath; builderOptions.defaultPackageFilePath = packageFilePath;
Packages packages = builder.createPackageMap(projectPath); Packages packages = builder.createPackageMap(projectPath);
expect(packages, isNotNull); expect(packages, isNotNull);
Map<String, Uri> map = packages.asMap(); Map<String, Uri> map = packages.asMap();
@ -410,7 +417,7 @@ b:${pathContext.toUri(packageB)}
void test_declareVariables_emptyMap() { void test_declareVariables_emptyMap() {
AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); AnalysisContext context = AnalysisEngine.instance.createAnalysisContext();
Iterable<String> expected = context.declaredVariables.variableNames; Iterable<String> expected = context.declaredVariables.variableNames;
builder.declaredVariables = <String, String>{}; builderOptions.declaredVariables = <String, String>{};
builder.declareVariables(context); builder.declareVariables(context);
expect(context.declaredVariables.variableNames, unorderedEquals(expected)); expect(context.declaredVariables.variableNames, unorderedEquals(expected));
@ -422,7 +429,7 @@ b:${pathContext.toUri(packageB)}
expect(expected, isNot(contains('a'))); expect(expected, isNot(contains('a')));
expect(expected, isNot(contains('b'))); expect(expected, isNot(contains('b')));
expected.addAll(['a', 'b']); expected.addAll(['a', 'b']);
builder.declaredVariables = <String, String>{'a': 'a', 'b': 'b'}; builderOptions.declaredVariables = <String, String>{'a': 'a', 'b': 'b'};
builder.declareVariables(context); builder.declareVariables(context);
expect(context.declaredVariables.variableNames, unorderedEquals(expected)); expect(context.declaredVariables.variableNames, unorderedEquals(expected));
@ -491,7 +498,7 @@ b:${pathContext.toUri(packageB)}
void test_getAnalysisOptions_default_noOverrides() { void test_getAnalysisOptions_default_noOverrides() {
AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl();
defaultOptions.enableGenericMethods = true; defaultOptions.enableGenericMethods = true;
builder.defaultOptions = defaultOptions; builderOptions.defaultOptions = defaultOptions;
AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); AnalysisOptionsImpl expected = new AnalysisOptionsImpl();
expected.enableGenericMethods = true; expected.enableGenericMethods = true;
String path = resourceProvider.convertPath('/some/directory/path'); String path = resourceProvider.convertPath('/some/directory/path');
@ -513,7 +520,7 @@ linter:
void test_getAnalysisOptions_default_overrides() { void test_getAnalysisOptions_default_overrides() {
AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl();
defaultOptions.enableGenericMethods = true; defaultOptions.enableGenericMethods = true;
builder.defaultOptions = defaultOptions; builderOptions.defaultOptions = defaultOptions;
AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); AnalysisOptionsImpl expected = new AnalysisOptionsImpl();
expected.enableSuperMixins = true; expected.enableSuperMixins = true;
expected.enableGenericMethods = true; expected.enableGenericMethods = true;
@ -611,7 +618,7 @@ analyzer:
String filePath = resourceProvider.convertPath('/options/analysis.yaml'); String filePath = resourceProvider.convertPath('/options/analysis.yaml');
resourceProvider.newFile(filePath, ''); resourceProvider.newFile(filePath, '');
builder.defaultAnalysisOptionsFilePath = filePath; builderOptions.defaultAnalysisOptionsFilePath = filePath;
File result = builder.getOptionsFile(path); File result = builder.getOptionsFile(path);
expect(result, isNotNull); expect(result, isNotNull);
expect(result.path, filePath); expect(result.path, filePath);

View file

@ -246,9 +246,11 @@ class StressTest {
FolderBasedDartSdk.defaultSdkDirectory(resourceProvider); FolderBasedDartSdk.defaultSdkDirectory(resourceProvider);
sdkManager = new DartSdkManager(sdkDirectory.path, false); sdkManager = new DartSdkManager(sdkDirectory.path, false);
contentCache = new ContentCache(); contentCache = new ContentCache();
ContextBuilder builder = ContextBuilderOptions builderOptions = new ContextBuilderOptions();
new ContextBuilder(resourceProvider, sdkManager, contentCache); builderOptions.defaultOptions = new AnalysisOptionsImpl();
builder.defaultOptions = new AnalysisOptionsImpl(); ContextBuilder builder = new ContextBuilder(
resourceProvider, sdkManager, contentCache,
options: builderOptions);
expectedContext = builder.buildContext(folderPath); expectedContext = builder.buildContext(folderPath);
actualContext = builder.buildContext(folderPath); actualContext = builder.buildContext(folderPath);
expectedContext.analysisOptions = expectedContext.analysisOptions =

View file

@ -154,17 +154,19 @@ ${generateGraphData()}
DartSdk sdk = new FolderBasedDartSdk(resourceProvider, DartSdk sdk = new FolderBasedDartSdk(resourceProvider,
FolderBasedDartSdk.defaultSdkDirectory(resourceProvider)); FolderBasedDartSdk.defaultSdkDirectory(resourceProvider));
context = AnalysisEngine.instance.createAnalysisContext(); context = AnalysisEngine.instance.createAnalysisContext();
ContextBuilder builder = new ContextBuilder(resourceProvider, null, null); ContextBuilderOptions builderOptions = new ContextBuilderOptions();
if (Platform.packageRoot != null) { if (Platform.packageRoot != null) {
builder.defaultPackagesDirectoryPath = builderOptions.defaultPackagesDirectoryPath =
Uri.parse(Platform.packageRoot).toFilePath(); Uri.parse(Platform.packageRoot).toFilePath();
} else if (Platform.packageConfig != null) { } else if (Platform.packageConfig != null) {
builder.defaultPackageFilePath = builderOptions.defaultPackageFilePath =
Uri.parse(Platform.packageConfig).toFilePath(); Uri.parse(Platform.packageConfig).toFilePath();
} else { } else {
// Let the context builder use the default algorithm for package // Let the context builder use the default algorithm for package
// resolution. // resolution.
} }
ContextBuilder builder = new ContextBuilder(resourceProvider, null, null,
options: builderOptions);
List<UriResolver> uriResolvers = [ List<UriResolver> uriResolvers = [
new DartUriResolver(sdk), new DartUriResolver(sdk),
new PackageMapUriResolver(resourceProvider, new PackageMapUriResolver(resourceProvider,

View file

@ -373,8 +373,10 @@ class Driver implements CommandLineStarter {
UriResolver packageUriResolver; UriResolver packageUriResolver;
if (options.packageRootPath != null) { if (options.packageRootPath != null) {
ContextBuilder builder = new ContextBuilder(resourceProvider, null, null); ContextBuilderOptions builderOptions = new ContextBuilderOptions();
builder.defaultPackagesDirectoryPath = options.packageRootPath; builderOptions.defaultPackagesDirectoryPath = options.packageRootPath;
ContextBuilder builder = new ContextBuilder(resourceProvider, null, null,
options: builderOptions);
packageUriResolver = new PackageMapUriResolver(resourceProvider, packageUriResolver = new PackageMapUriResolver(resourceProvider,
builder.convertPackagesToMap(builder.createPackageMap(''))); builder.convertPackagesToMap(builder.createPackageMap('')));
} else if (options.packageConfigPath == null) { } else if (options.packageConfigPath == null) {

View file

@ -139,10 +139,12 @@ List<UriResolver> createFileResolvers(AnalyzerOptions options,
{ResourceProvider resourceProvider}) { {ResourceProvider resourceProvider}) {
resourceProvider ??= PhysicalResourceProvider.INSTANCE; resourceProvider ??= PhysicalResourceProvider.INSTANCE;
UriResolver packageResolver() { UriResolver packageResolver() {
ContextBuilder builder = new ContextBuilder(resourceProvider, null, null); ContextBuilderOptions builderOptions = new ContextBuilderOptions();
if (options.packageRoot != null) { if (options.packageRoot != null) {
builder.defaultPackagesDirectoryPath = options.packageRoot; builderOptions.defaultPackagesDirectoryPath = options.packageRoot;
} }
ContextBuilder builder = new ContextBuilder(resourceProvider, null, null,
options: builderOptions);
return new PackageMapUriResolver(resourceProvider, return new PackageMapUriResolver(resourceProvider,
builder.convertPackagesToMap(builder.createPackageMap(''))); builder.convertPackagesToMap(builder.createPackageMap('')));
} }