| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 serialization.elements; | 5 library serialization.elements; |
| 6 | 6 |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 | 8 |
| 9 import 'package:analyzer/src/generated/source.dart'; | 9 import 'package:analyzer/src/generated/source.dart'; |
| 10 import 'package:analyzer/src/summary/format.dart'; | 10 import 'package:analyzer/src/summary/format.dart'; |
| 11 import 'package:analyzer/src/summary/idl.dart'; | 11 import 'package:analyzer/src/summary/idl.dart'; |
| 12 import 'package:analyzer/src/summary/package_bundle_reader.dart'; | |
| 13 import 'package:convert/convert.dart'; | 12 import 'package:convert/convert.dart'; |
| 14 import 'package:crypto/crypto.dart'; | 13 import 'package:crypto/crypto.dart'; |
| 15 import 'package:front_end/src/base/api_signature.dart'; | 14 import 'package:front_end/src/base/api_signature.dart'; |
| 16 | 15 |
| 17 /** | 16 /** |
| 18 * Object that gathers information uses it to assemble a new | 17 * Object that gathers information uses it to assemble a new |
| 19 * [PackageBundleBuilder]. | 18 * [PackageBundleBuilder]. |
| 20 */ | 19 */ |
| 21 class PackageBundleAssembler { | 20 class PackageBundleAssembler { |
| 22 /** | 21 /** |
| (...skipping 13 matching lines...) Expand all Loading... |
| 36 */ | 35 */ |
| 37 static const int currentMinorVersion = 0; | 36 static const int currentMinorVersion = 0; |
| 38 | 37 |
| 39 final List<String> _linkedLibraryUris = <String>[]; | 38 final List<String> _linkedLibraryUris = <String>[]; |
| 40 final List<LinkedLibraryBuilder> _linkedLibraries = <LinkedLibraryBuilder>[]; | 39 final List<LinkedLibraryBuilder> _linkedLibraries = <LinkedLibraryBuilder>[]; |
| 41 final List<String> _unlinkedUnitUris = <String>[]; | 40 final List<String> _unlinkedUnitUris = <String>[]; |
| 42 final List<UnlinkedUnitBuilder> _unlinkedUnits = <UnlinkedUnitBuilder>[]; | 41 final List<UnlinkedUnitBuilder> _unlinkedUnits = <UnlinkedUnitBuilder>[]; |
| 43 final Map<String, UnlinkedUnitBuilder> _unlinkedUnitMap = | 42 final Map<String, UnlinkedUnitBuilder> _unlinkedUnitMap = |
| 44 <String, UnlinkedUnitBuilder>{}; | 43 <String, UnlinkedUnitBuilder>{}; |
| 45 final List<String> _unlinkedUnitHashes; | 44 final List<String> _unlinkedUnitHashes; |
| 46 final List<PackageDependencyInfoBuilder> _dependencies = | |
| 47 <PackageDependencyInfoBuilder>[]; | |
| 48 final bool _excludeHashes; | 45 final bool _excludeHashes; |
| 49 | 46 |
| 50 /** | 47 /** |
| 51 * Create a [PackageBundleAssembler]. If [excludeHashes] is `true`, hash | 48 * Create a [PackageBundleAssembler]. If [excludeHashes] is `true`, hash |
| 52 * computation will be skipped. | 49 * computation will be skipped. |
| 53 */ | 50 */ |
| 54 PackageBundleAssembler({bool excludeHashes: false}) | 51 PackageBundleAssembler({bool excludeHashes: false}) |
| 55 : _excludeHashes = excludeHashes, | 52 : _excludeHashes = excludeHashes, |
| 56 _unlinkedUnitHashes = excludeHashes ? null : <String>[]; | 53 _unlinkedUnitHashes = excludeHashes ? null : <String>[]; |
| 57 | 54 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 78 */ | 75 */ |
| 79 PackageBundleBuilder assemble() { | 76 PackageBundleBuilder assemble() { |
| 80 return new PackageBundleBuilder( | 77 return new PackageBundleBuilder( |
| 81 linkedLibraryUris: _linkedLibraryUris, | 78 linkedLibraryUris: _linkedLibraryUris, |
| 82 linkedLibraries: _linkedLibraries, | 79 linkedLibraries: _linkedLibraries, |
| 83 unlinkedUnitUris: _unlinkedUnitUris, | 80 unlinkedUnitUris: _unlinkedUnitUris, |
| 84 unlinkedUnits: _unlinkedUnits, | 81 unlinkedUnits: _unlinkedUnits, |
| 85 unlinkedUnitHashes: _unlinkedUnitHashes, | 82 unlinkedUnitHashes: _unlinkedUnitHashes, |
| 86 majorVersion: currentMajorVersion, | 83 majorVersion: currentMajorVersion, |
| 87 minorVersion: currentMinorVersion, | 84 minorVersion: currentMinorVersion, |
| 88 dependencies: _dependencies, | |
| 89 apiSignature: _computeApiSignature()); | 85 apiSignature: _computeApiSignature()); |
| 90 } | 86 } |
| 91 | 87 |
| 92 /** | 88 /** |
| 93 * Use the dependency information in [summaryDataStore] to populate the | |
| 94 * dependencies in the package bundle being assembled. | |
| 95 */ | |
| 96 void recordDependencies(SummaryDataStore summaryDataStore) { | |
| 97 _dependencies.addAll(summaryDataStore.dependencies); | |
| 98 } | |
| 99 | |
| 100 /** | |
| 101 * Compute the API signature for this package bundle. | 89 * Compute the API signature for this package bundle. |
| 102 */ | 90 */ |
| 103 String _computeApiSignature() { | 91 String _computeApiSignature() { |
| 104 ApiSignature apiSignature = new ApiSignature(); | 92 ApiSignature apiSignature = new ApiSignature(); |
| 105 for (String unitUri in _unlinkedUnitMap.keys.toList()..sort()) { | 93 for (String unitUri in _unlinkedUnitMap.keys.toList()..sort()) { |
| 106 apiSignature.addString(unitUri); | 94 apiSignature.addString(unitUri); |
| 107 _unlinkedUnitMap[unitUri].collectApiSignature(apiSignature); | 95 _unlinkedUnitMap[unitUri].collectApiSignature(apiSignature); |
| 108 } | 96 } |
| 109 return apiSignature.toHex(); | 97 return apiSignature.toHex(); |
| 110 } | 98 } |
| 111 | 99 |
| 112 /** | 100 /** |
| 113 * Compute a hash of the given file contents. | 101 * Compute a hash of the given file contents. |
| 114 */ | 102 */ |
| 115 String _hash(String contents) { | 103 String _hash(String contents) { |
| 116 return hex.encode(md5.convert(UTF8.encode(contents)).bytes); | 104 return hex.encode(md5.convert(UTF8.encode(contents)).bytes); |
| 117 } | 105 } |
| 118 } | 106 } |
| OLD | NEW |