OLD | NEW |
---|---|
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:convert' show UTF8; | 5 import 'dart:convert' show ChunkedConversionSink, UTF8; |
6 import 'dart:core' hide Resource; | 6 import 'dart:core' hide Resource; |
7 | 7 |
8 import 'package:analyzer/dart/element/element.dart'; | 8 import 'package:analyzer/dart/element/element.dart'; |
9 import 'package:analyzer/file_system/file_system.dart'; | 9 import 'package:analyzer/file_system/file_system.dart'; |
10 import 'package:analyzer/src/generated/engine.dart'; | 10 import 'package:analyzer/src/generated/engine.dart'; |
11 import 'package:analyzer/src/generated/source.dart'; | 11 import 'package:analyzer/src/generated/source.dart'; |
12 import 'package:analyzer/src/summary/format.dart'; | 12 import 'package:analyzer/src/summary/format.dart'; |
13 import 'package:analyzer/src/summary/idl.dart'; | 13 import 'package:analyzer/src/summary/idl.dart'; |
14 import 'package:analyzer/src/summary/summarize_elements.dart'; | 14 import 'package:analyzer/src/summary/summarize_elements.dart'; |
15 import 'package:convert/convert.dart'; | |
15 import 'package:crypto/crypto.dart'; | 16 import 'package:crypto/crypto.dart'; |
16 | 17 |
17 /** | 18 /** |
18 * Storage for cache data. | 19 * Storage for cache data. |
19 */ | 20 */ |
20 abstract class CacheStorage { | 21 abstract class CacheStorage { |
21 /** | 22 /** |
22 * Return bytes for the given [key], `null` if [key] is not in the storage. | 23 * Return bytes for the given [key], `null` if [key] is not in the storage. |
23 */ | 24 */ |
24 List<int> get(String key); | 25 List<int> get(String key); |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 _sourceContentMap[source] = content; | 236 _sourceContentMap[source] = content; |
236 } | 237 } |
237 return content; | 238 return content; |
238 } | 239 } |
239 | 240 |
240 /** | 241 /** |
241 * Return the key of the content based [source] information. | 242 * Return the key of the content based [source] information. |
242 */ | 243 */ |
243 String _getCacheSourceContentKey(Source source) { | 244 String _getCacheSourceContentKey(Source source) { |
244 List<int> hash = _getSourceContentHash(source); | 245 List<int> hash = _getSourceContentHash(source); |
245 String hashStr = CryptoUtils.bytesToHex(hash); | 246 String hashStr = hex.encode(hash); |
246 return '$hashStr.content'; | 247 return '$hashStr.content'; |
247 } | 248 } |
248 | 249 |
249 /** | 250 /** |
250 * Get the bundle for the given key. | 251 * Get the bundle for the given key. |
251 */ | 252 */ |
252 PackageBundle _getLibraryBundle(String key) { | 253 PackageBundle _getLibraryBundle(String key) { |
253 PackageBundle bundle = _bundleMap[key]; | 254 PackageBundle bundle = _bundleMap[key]; |
254 if (bundle == null) { | 255 if (bundle == null) { |
255 List<int> bytes = storage.get(key); | 256 List<int> bytes = storage.get(key); |
256 if (bytes == null) { | 257 if (bytes == null) { |
257 return null; | 258 return null; |
258 } | 259 } |
259 bundle = new PackageBundle.fromBuffer(bytes); | 260 bundle = new PackageBundle.fromBuffer(bytes); |
260 _bundleMap[key] = bundle; | 261 _bundleMap[key] = bundle; |
261 } | 262 } |
262 return bundle; | 263 return bundle; |
263 } | 264 } |
264 | 265 |
265 /** | 266 /** |
266 * Return the key of the bundle of the [librarySource]. | 267 * Return the key of the bundle of the [librarySource]. |
267 */ | 268 */ |
268 String _getLibraryBundleKey(Source librarySource) { | 269 String _getLibraryBundleKey(Source librarySource) { |
269 List<int> hash = _getLibraryClosureHash(librarySource); | 270 List<int> hash = _getLibraryClosureHash(librarySource); |
270 String hashStr = CryptoUtils.bytesToHex(hash); | 271 String hashStr = hex.encode(hash); |
271 return '$hashStr.summary'; | 272 return '$hashStr.summary'; |
272 } | 273 } |
273 | 274 |
274 /** | 275 /** |
275 * Return the whole source closure of the library with the given | 276 * Return the whole source closure of the library with the given |
276 * [librarySource]. It includes defining units and parts of the library and | 277 * [librarySource]. It includes defining units and parts of the library and |
277 * of all its directly or indirectly imported or exported libraries. | 278 * of all its directly or indirectly imported or exported libraries. |
278 */ | 279 */ |
279 List<Source> _getLibraryClosure(Source librarySource) { | 280 List<Source> _getLibraryClosure(Source librarySource) { |
280 return _libraryClosureMap.putIfAbsent(librarySource, () { | 281 return _libraryClosureMap.putIfAbsent(librarySource, () { |
281 Set<Source> closure = new Set<Source>(); | 282 Set<Source> closure = new Set<Source>(); |
282 _appendLibraryClosure(closure, librarySource); | 283 _appendLibraryClosure(closure, librarySource); |
283 return closure.toList(); | 284 return closure.toList(); |
284 }); | 285 }); |
285 } | 286 } |
286 | 287 |
287 /** | 288 /** |
288 * Return the [context]-specific hash of the closure of the library with | 289 * Return the [context]-specific hash of the closure of the library with |
289 * the given [librarySource]. | 290 * the given [librarySource]. |
290 */ | 291 */ |
291 List<int> _getLibraryClosureHash(Source librarySource) { | 292 List<int> _getLibraryClosureHash(Source librarySource) { |
292 return _libraryClosureHashMap.putIfAbsent(librarySource, () { | 293 return _libraryClosureHashMap.putIfAbsent(librarySource, () { |
293 List<Source> closure = _getLibraryClosure(librarySource); | 294 List<Source> closure = _getLibraryClosure(librarySource); |
294 MD5 md5 = new MD5(); | 295 |
296 var digestList = <int>[]; | |
297 | |
298 var sink = new ChunkedConversionSink<List<int>>.withCallback((value) { | |
299 digestList = value; | |
300 }); | |
301 | |
295 for (Source source in closure) { | 302 for (Source source in closure) { |
296 List<int> sourceHash = _getSourceContentHash(source); | 303 List<int> sourceHash = _getSourceContentHash(source); |
297 md5.add(sourceHash); | 304 sink.add(sourceHash); |
298 } | 305 } |
299 md5.add(configSalt); | 306 sink.add(configSalt); |
300 return md5.close(); | 307 return md5.convert(digestList).bytes; |
nweiz
2016/04/14 21:53:09
All you're doing here is a very roundabout way of
kevmoo
2016/04/14 23:13:35
Done.
| |
301 }); | 308 }); |
302 } | 309 } |
303 | 310 |
304 /** | 311 /** |
305 * Compute a hash of the given [source] contents. | 312 * Compute a hash of the given [source] contents. |
306 */ | 313 */ |
307 List<int> _getSourceContentHash(Source source) { | 314 List<int> _getSourceContentHash(Source source) { |
308 return _sourceContentHashMap.putIfAbsent(source, () { | 315 return _sourceContentHashMap.putIfAbsent(source, () { |
309 String sourceText = source.contents.data; | 316 String sourceText = source.contents.data; |
310 List<int> sourceBytes = UTF8.encode(sourceText); | 317 List<int> sourceBytes = UTF8.encode(sourceText); |
311 return (new MD5()..add(sourceBytes)).close(); | 318 return md5.convert(sourceBytes).bytes; |
312 }); | 319 }); |
313 } | 320 } |
314 | 321 |
315 /** | 322 /** |
316 * Return a source representing the URI that results from resolving the given | 323 * Return a source representing the URI that results from resolving the given |
317 * (possibly relative) [containedUri] against the URI associated with the | 324 * (possibly relative) [containedUri] against the URI associated with the |
318 * [containingSource], whether or not the resulting source exists, or `null` | 325 * [containingSource], whether or not the resulting source exists, or `null` |
319 * if either the [containedUri] is invalid or if it cannot be resolved against | 326 * if either the [containedUri] is invalid or if it cannot be resolved against |
320 * the [containingSource]'s URI. | 327 * the [containingSource]'s URI. |
321 */ | 328 */ |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 */ | 418 */ |
412 final String id; | 419 final String id; |
413 | 420 |
414 /** | 421 /** |
415 * The payload bundle. | 422 * The payload bundle. |
416 */ | 423 */ |
417 final PackageBundle bundle; | 424 final PackageBundle bundle; |
418 | 425 |
419 LibraryBundleWithId(this.source, this.id, this.bundle); | 426 LibraryBundleWithId(this.source, this.id, this.bundle); |
420 } | 427 } |
OLD | NEW |