OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library testing.mock_sdk; | 5 library testing.mock_sdk; |
6 | 6 |
7 import 'package:analyzer/file_system/file_system.dart' as resource; | 7 import 'package:analyzer/file_system/file_system.dart' as resource; |
8 import 'package:analyzer/file_system/memory_file_system.dart' as resource; | 8 import 'package:analyzer/file_system/memory_file_system.dart' as resource; |
9 import 'package:analyzer/src/context/context.dart'; | 9 import 'package:analyzer/src/context/context.dart'; |
10 import 'package:analyzer/src/generated/engine.dart'; | 10 import 'package:analyzer/src/generated/engine.dart'; |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 /** | 262 /** |
263 * The [AnalysisContext] which is used for all of the sources. | 263 * The [AnalysisContext] which is used for all of the sources. |
264 */ | 264 */ |
265 InternalAnalysisContext _analysisContext; | 265 InternalAnalysisContext _analysisContext; |
266 | 266 |
267 /** | 267 /** |
268 * The cached linked bundle of the SDK. | 268 * The cached linked bundle of the SDK. |
269 */ | 269 */ |
270 PackageBundle _bundle; | 270 PackageBundle _bundle; |
271 | 271 |
272 MockSdk({resource.ResourceProvider resourceProvider}) | 272 MockSdk( |
| 273 {bool generateSummaryFiles: false, |
| 274 resource.ResourceProvider resourceProvider}) |
273 : provider = resourceProvider ?? new resource.MemoryResourceProvider() { | 275 : provider = resourceProvider ?? new resource.MemoryResourceProvider() { |
274 LIBRARIES.forEach((SdkLibrary library) { | 276 LIBRARIES.forEach((SdkLibrary library) { |
275 provider.newFile(library.path, (library as MockSdkLibrary).content); | 277 provider.newFile(library.path, (library as MockSdkLibrary).content); |
276 }); | 278 }); |
277 provider.newFile( | 279 provider.newFile( |
278 provider.convertPath( | 280 provider.convertPath( |
279 '/lib/_internal/sdk_library_metadata/lib/libraries.dart'), | 281 '/lib/_internal/sdk_library_metadata/lib/libraries.dart'), |
280 librariesContent); | 282 librariesContent); |
281 List<int> bytes = _computeLinkedBundleBytes(); | 283 if (generateSummaryFiles) { |
282 provider.newFileWithBytes( | 284 List<int> bytes = _computeLinkedBundleBytes(); |
283 provider.convertPath('/lib/_internal/spec.sum'), bytes); | 285 provider.newFileWithBytes( |
284 provider.newFileWithBytes( | 286 provider.convertPath('/lib/_internal/spec.sum'), bytes); |
285 provider.convertPath('/lib/_internal/strong.sum'), bytes); | 287 provider.newFileWithBytes( |
| 288 provider.convertPath('/lib/_internal/strong.sum'), bytes); |
| 289 } |
286 } | 290 } |
287 | 291 |
288 @override | 292 @override |
289 AnalysisContext get context { | 293 AnalysisContext get context { |
290 if (_analysisContext == null) { | 294 if (_analysisContext == null) { |
291 _analysisContext = new SdkAnalysisContext(null); | 295 _analysisContext = new SdkAnalysisContext(null); |
292 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); | 296 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); |
293 _analysisContext.sourceFactory = factory; | 297 _analysisContext.sourceFactory = factory; |
294 } | 298 } |
295 return _analysisContext; | 299 return _analysisContext; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 return null; | 345 return null; |
342 } | 346 } |
343 } | 347 } |
344 } | 348 } |
345 return null; | 349 return null; |
346 } | 350 } |
347 | 351 |
348 @override | 352 @override |
349 PackageBundle getLinkedBundle() { | 353 PackageBundle getLinkedBundle() { |
350 if (_bundle == null) { | 354 if (_bundle == null) { |
351 _bundle = new PackageBundle.fromBuffer(_computeLinkedBundleBytes()); | 355 resource.File summaryFile = |
| 356 provider.getFile(provider.convertPath('/lib/_internal/spec.sum')); |
| 357 List<int> bytes; |
| 358 if (summaryFile.exists) { |
| 359 bytes = summaryFile.readAsBytesSync(); |
| 360 } else { |
| 361 bytes = _computeLinkedBundleBytes(); |
| 362 } |
| 363 _bundle = new PackageBundle.fromBuffer(bytes); |
352 } | 364 } |
353 return _bundle; | 365 return _bundle; |
354 } | 366 } |
355 | 367 |
356 @override | 368 @override |
357 SdkLibrary getSdkLibrary(String dartUri) { | 369 SdkLibrary getSdkLibrary(String dartUri) { |
358 // getSdkLibrary() is only used to determine whether a library is internal | 370 // getSdkLibrary() is only used to determine whether a library is internal |
359 // to the SDK. The mock SDK doesn't have any internals, so it's safe to | 371 // to the SDK. The mock SDK doesn't have any internals, so it's safe to |
360 // return null. | 372 // return null. |
361 return null; | 373 return null; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 bool get isShared => throw unimplemented; | 436 bool get isShared => throw unimplemented; |
425 | 437 |
426 @override | 438 @override |
427 bool get isVmLibrary => throw unimplemented; | 439 bool get isVmLibrary => throw unimplemented; |
428 | 440 |
429 UnimplementedError get unimplemented => new UnimplementedError(); | 441 UnimplementedError get unimplemented => new UnimplementedError(); |
430 | 442 |
431 @override | 443 @override |
432 List<String> getPatches(int platform) => const <String>[]; | 444 List<String> getPatches(int platform) => const <String>[]; |
433 } | 445 } |
OLD | NEW |