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