mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 08:24:39 +00:00
Create summary files in MockSdk classes
Review URL: https://codereview.chromium.org/2542853003 .
This commit is contained in:
parent
47bfb02f36
commit
e17e359faa
|
@ -121,20 +121,19 @@ import "../foo/foo.dart";
|
|||
});
|
||||
}
|
||||
|
||||
void processRequiredPlugins() {
|
||||
void processRequiredPlugins(ServerPlugin serverPlugin) {
|
||||
List<Plugin> plugins = <Plugin>[];
|
||||
plugins.addAll(AnalysisEngine.instance.requiredPlugins);
|
||||
plugins.add(AnalysisEngine.instance.optionsPlugin);
|
||||
plugins.add(server.serverPlugin);
|
||||
plugins.add(serverPlugin);
|
||||
|
||||
ExtensionManager manager = new ExtensionManager();
|
||||
manager.processPlugins(plugins);
|
||||
}
|
||||
|
||||
void setUp() {
|
||||
ExtensionManager manager = new ExtensionManager();
|
||||
ServerPlugin plugin = new ServerPlugin();
|
||||
manager.processPlugins([plugin]);
|
||||
ServerPlugin serverPlugin = new ServerPlugin();
|
||||
processRequiredPlugins(serverPlugin);
|
||||
channel = new MockServerChannel();
|
||||
resourceProvider = new MemoryResourceProvider();
|
||||
// Create an SDK in the mock file system.
|
||||
|
@ -145,12 +144,11 @@ import "../foo/foo.dart";
|
|||
resourceProvider,
|
||||
packageMapProvider,
|
||||
null,
|
||||
plugin,
|
||||
serverPlugin,
|
||||
new AnalysisServerOptions(),
|
||||
new DartSdkManager('/', false),
|
||||
InstrumentationService.NULL_SERVICE,
|
||||
rethrowExceptions: true);
|
||||
processRequiredPlugins();
|
||||
}
|
||||
|
||||
Future test_contextDisposed() {
|
||||
|
|
|
@ -13,8 +13,10 @@ import 'package:analysis_server/src/domain_analysis.dart';
|
|||
import 'package:analysis_server/src/plugin/server_plugin.dart';
|
||||
import 'package:analyzer/file_system/memory_file_system.dart';
|
||||
import 'package:analyzer/instrumentation/instrumentation.dart';
|
||||
import 'package:analyzer/src/generated/engine.dart';
|
||||
import 'package:analyzer/src/generated/sdk.dart';
|
||||
import 'package:plugin/manager.dart';
|
||||
import 'package:plugin/plugin.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
|
@ -33,12 +35,21 @@ main() {
|
|||
AnalysisServer server;
|
||||
AnalysisDomainHandler handler;
|
||||
|
||||
void processRequiredPlugins(ServerPlugin serverPlugin) {
|
||||
List<Plugin> plugins = <Plugin>[];
|
||||
plugins.addAll(AnalysisEngine.instance.requiredPlugins);
|
||||
plugins.add(AnalysisEngine.instance.optionsPlugin);
|
||||
plugins.add(serverPlugin);
|
||||
|
||||
ExtensionManager manager = new ExtensionManager();
|
||||
manager.processPlugins(plugins);
|
||||
}
|
||||
|
||||
setUp(() {
|
||||
serverChannel = new MockServerChannel();
|
||||
resourceProvider = new MemoryResourceProvider();
|
||||
ExtensionManager manager = new ExtensionManager();
|
||||
ServerPlugin serverPlugin = new ServerPlugin();
|
||||
manager.processPlugins([serverPlugin]);
|
||||
processRequiredPlugins(serverPlugin);
|
||||
// Create an SDK in the mock file system.
|
||||
new MockSdk(resourceProvider: resourceProvider);
|
||||
server = new AnalysisServer(
|
||||
|
@ -429,11 +440,10 @@ class AnalysisTestHelper {
|
|||
String testCode;
|
||||
|
||||
AnalysisTestHelper() {
|
||||
ServerPlugin serverPlugin = new ServerPlugin();
|
||||
processRequiredPlugins(serverPlugin);
|
||||
serverChannel = new MockServerChannel();
|
||||
resourceProvider = new MemoryResourceProvider();
|
||||
ExtensionManager manager = new ExtensionManager();
|
||||
ServerPlugin serverPlugin = new ServerPlugin();
|
||||
manager.processPlugins([serverPlugin]);
|
||||
// Create an SDK in the mock file system.
|
||||
new MockSdk(resourceProvider: resourceProvider);
|
||||
server = new AnalysisServer(
|
||||
|
@ -597,6 +607,16 @@ class AnalysisTestHelper {
|
|||
expect(response, isResponseSuccess('0'));
|
||||
}
|
||||
|
||||
void processRequiredPlugins(ServerPlugin serverPlugin) {
|
||||
List<Plugin> plugins = <Plugin>[];
|
||||
plugins.addAll(AnalysisEngine.instance.requiredPlugins);
|
||||
plugins.add(AnalysisEngine.instance.optionsPlugin);
|
||||
plugins.add(serverPlugin);
|
||||
|
||||
ExtensionManager manager = new ExtensionManager();
|
||||
manager.processPlugins(plugins);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an `updateContent` request for [testFile].
|
||||
*/
|
||||
|
|
|
@ -24,21 +24,20 @@ main() {
|
|||
DiagnosticDomainHandler handler;
|
||||
MemoryResourceProvider resourceProvider;
|
||||
|
||||
setUp(() {
|
||||
//
|
||||
// Collect plugins
|
||||
//
|
||||
ServerPlugin serverPlugin = new ServerPlugin();
|
||||
void processRequiredPlugins(ServerPlugin serverPlugin) {
|
||||
List<Plugin> plugins = <Plugin>[];
|
||||
plugins.addAll(AnalysisEngine.instance.requiredPlugins);
|
||||
plugins.add(AnalysisEngine.instance.commandLinePlugin);
|
||||
plugins.add(AnalysisEngine.instance.optionsPlugin);
|
||||
plugins.add(serverPlugin);
|
||||
//
|
||||
// Process plugins
|
||||
//
|
||||
|
||||
ExtensionManager manager = new ExtensionManager();
|
||||
manager.processPlugins(plugins);
|
||||
}
|
||||
|
||||
setUp(() {
|
||||
ServerPlugin serverPlugin = new ServerPlugin();
|
||||
processRequiredPlugins(serverPlugin);
|
||||
//
|
||||
// Create the server
|
||||
//
|
||||
|
|
|
@ -274,8 +274,15 @@ const Map<String, LibraryInfo> libraries = const {
|
|||
LIBRARIES.forEach((SdkLibrary library) {
|
||||
provider.newFile(library.path, (library as MockSdkLibrary).content);
|
||||
});
|
||||
provider.newFile('/lib/_internal/sdk_library_metadata/lib/libraries.dart',
|
||||
provider.newFile(
|
||||
provider.convertPath(
|
||||
'/lib/_internal/sdk_library_metadata/lib/libraries.dart'),
|
||||
librariesContent);
|
||||
List<int> bytes = _computeLinkedBundleBytes();
|
||||
provider.newFileWithBytes(
|
||||
provider.convertPath('/lib/_internal/spec.sum'), bytes);
|
||||
provider.newFileWithBytes(
|
||||
provider.convertPath('/lib/_internal/strong.sum'), bytes);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -341,13 +348,7 @@ const Map<String, LibraryInfo> libraries = const {
|
|||
@override
|
||||
PackageBundle getLinkedBundle() {
|
||||
if (_bundle == null) {
|
||||
List<Source> librarySources = sdkLibraries
|
||||
.map((SdkLibrary library) => mapDartUri(library.shortName))
|
||||
.toList();
|
||||
List<int> bytes = new SummaryBuilder(
|
||||
librarySources, context, context.analysisOptions.strongMode)
|
||||
.build();
|
||||
_bundle = new PackageBundle.fromBuffer(bytes);
|
||||
_bundle = new PackageBundle.fromBuffer(_computeLinkedBundleBytes());
|
||||
}
|
||||
return _bundle;
|
||||
}
|
||||
|
@ -383,6 +384,18 @@ const Map<String, LibraryInfo> libraries = const {
|
|||
// table above.
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the bytes of the linked bundle associated with this SDK.
|
||||
*/
|
||||
List<int> _computeLinkedBundleBytes() {
|
||||
List<Source> librarySources = sdkLibraries
|
||||
.map((SdkLibrary library) => mapDartUri(library.shortName))
|
||||
.toList();
|
||||
return new SummaryBuilder(
|
||||
librarySources, context, context.analysisOptions.strongMode)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
class MockSdkLibrary implements SdkLibrary {
|
||||
|
|
|
@ -351,7 +351,9 @@ class MockSdk implements DartSdk {
|
|||
PackageBundle _bundle;
|
||||
|
||||
MockSdk(
|
||||
{bool dartAsync: true, resource.MemoryResourceProvider resourceProvider})
|
||||
{bool buildSummaries: true,
|
||||
bool dartAsync: true,
|
||||
resource.MemoryResourceProvider resourceProvider})
|
||||
: provider = resourceProvider ?? new resource.MemoryResourceProvider(),
|
||||
sdkLibraries = dartAsync ? _LIBRARIES : [_LIB_CORE],
|
||||
uriMap = dartAsync ? FULL_URI_MAP : NO_ASYNC_URI_MAP {
|
||||
|
@ -365,6 +367,13 @@ class MockSdk implements DartSdk {
|
|||
provider.convertPath(
|
||||
'$sdkRoot/lib/_internal/sdk_library_metadata/lib/libraries.dart'),
|
||||
librariesContent);
|
||||
if (buildSummaries) {
|
||||
List<int> bytes = _computeLinkedBundleBytes();
|
||||
provider.newFileWithBytes(
|
||||
provider.convertPath('/lib/_internal/spec.sum'), bytes);
|
||||
provider.newFileWithBytes(
|
||||
provider.convertPath('/lib/_internal/strong.sum'), bytes);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -422,13 +431,7 @@ class MockSdk implements DartSdk {
|
|||
@override
|
||||
PackageBundle getLinkedBundle() {
|
||||
if (_bundle == null) {
|
||||
List<Source> librarySources = sdkLibraries
|
||||
.map((SdkLibrary library) => mapDartUri(library.shortName))
|
||||
.toList();
|
||||
List<int> bytes = new SummaryBuilder(
|
||||
librarySources, context, context.analysisOptions.strongMode)
|
||||
.build();
|
||||
_bundle = new PackageBundle.fromBuffer(bytes);
|
||||
_bundle = new PackageBundle.fromBuffer(_computeLinkedBundleBytes());
|
||||
}
|
||||
return _bundle;
|
||||
}
|
||||
|
@ -467,6 +470,18 @@ class MockSdk implements DartSdk {
|
|||
String newContent = updateContent(content);
|
||||
provider.updateFile(path, newContent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the bytes of the linked bundle associated with this SDK.
|
||||
*/
|
||||
List<int> _computeLinkedBundleBytes() {
|
||||
List<Source> librarySources = sdkLibraries
|
||||
.map((SdkLibrary library) => mapDartUri(library.shortName))
|
||||
.toList();
|
||||
return new SummaryBuilder(
|
||||
librarySources, context, context.analysisOptions.strongMode)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
class _MockSdkLibrary implements SdkLibrary {
|
||||
|
|
|
@ -254,7 +254,8 @@ A b;
|
|||
// Use DartSdk with a different API signature.
|
||||
// Different linked bundles should be created.
|
||||
{
|
||||
MockSdk sdk = new MockSdk(resourceProvider: resourceProvider);
|
||||
MockSdk sdk = new MockSdk(
|
||||
buildSummaries: false, resourceProvider: resourceProvider);
|
||||
sdk.updateUriFile('dart:math', (String content) {
|
||||
return content + ' class NewMathClass {}';
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue