 Chromium Code Reviews
 Chromium Code Reviews Issue 10542015:
  Start adding support for lock files.  (Closed) 
  Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
    
  
    Issue 10542015:
  Start adding support for lock files.  (Closed) 
  Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart| OLD | NEW | 
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 #library('lock_file'); | |
| 6 | |
| 7 #import('package.dart'); | |
| 8 #import('source_registry.dart'); | |
| 9 #import('utils.dart'); | |
| 10 #import('version.dart'); | |
| 11 #import('yaml/yaml.dart'); | |
| 12 | |
| 13 /** | |
| 14 * A parsed and validated `pubspec.lock` file. | |
| 15 */ | |
| 16 class LockFile { | |
| 17 /** | |
| 18 * The packages this lockfile pins. | |
| 19 */ | |
| 20 Map<String, PackageId> packages; | |
| 21 | |
| 22 LockFile._(this.packages); | |
| 23 | |
| 24 LockFile.empty() | |
| 25 : packages = <PackageId>{}; | |
| 26 | |
| 27 /** | |
| 28 * Parses the lockfile whose text is [contents]. | |
| 29 */ | |
| 30 factory LockFile.parse(String contents, SourceRegistry sources) { | |
| 31 var packages = <PackageId>{}; | |
| 32 | |
| 33 if (contents.trim() == '') return new LockFile.empty(); | |
| 34 | |
| 35 var parsed = loadYaml(contents); | |
| 36 | |
| 37 if (parsed.containsKey('packages')) { | |
| 38 var packageEntries = parsed['packages']; | |
| 39 | |
| 40 packageEntries.forEach((name, spec) { | |
| 41 // Parse the version. | |
| 42 if (!spec.containsKey('version')) { | |
| 43 throw new FormatException('Package $name is missing a version.'); | |
| 44 } | |
| 45 var version = new Version.parse(spec['version']); | |
| 46 | |
| 47 // Parse the source. | |
| 48 if (!spec.containsKey('source')) { | |
| 49 throw new FormatException('Package $name is missing a source.'); | |
| 50 } | |
| 51 var sourceName = spec['source']; | |
| 52 if (!sources.contains(sourceName)) { | |
| 53 throw new FormatException( | |
| 54 'Could not find a source named $sourceName.'); | |
| 55 } | |
| 56 var source = sources[sourceName]; | |
| 57 | |
| 58 // Parse the description. | |
| 59 if (!spec.containsKey('description')) { | |
| 60 throw new FormatException('Package $name is missing a description.'); | |
| 61 } | |
| 62 var description = spec['description']; | |
| 63 source.validateDescription(description); | |
| 64 | |
| 65 var id = new PackageId(source, version, description); | |
| 66 | |
| 67 // Validate the name. | |
| 68 if (name != id.name) { | |
| 
Jennifer Messerly
2012/06/06 00:23:52
How could this happen? It sounds like this means d
 
Bob Nystrom
2012/06/06 20:44:48
Exactly right. This shouldn't occur in practice, b
 | |
| 69 throw new FormatException( | |
| 70 "Package name $name doesn't match ${id.name}."); | |
| 71 } | |
| 72 | |
| 73 packages[name] = id; | |
| 74 }); | |
| 75 } | |
| 76 | |
| 77 return new LockFile._(packages); | |
| 78 } | |
| 79 } | |
| OLD | NEW |