OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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('lock_file'); | 5 #library('lock_file'); |
6 | 6 |
| 7 #import('dart:json'); |
7 #import('package.dart'); | 8 #import('package.dart'); |
8 #import('source_registry.dart'); | 9 #import('source_registry.dart'); |
9 #import('utils.dart'); | 10 #import('utils.dart'); |
10 #import('version.dart'); | 11 #import('version.dart'); |
11 #import('yaml/yaml.dart'); | 12 #import('yaml/yaml.dart'); |
12 | 13 |
13 /** | 14 /** |
14 * A parsed and validated `pubspec.lock` file. | 15 * A parsed and validated `pubspec.lock` file. |
15 */ | 16 */ |
16 class LockFile { | 17 class LockFile { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 throw new FormatException( | 54 throw new FormatException( |
54 'Could not find a source named $sourceName.'); | 55 'Could not find a source named $sourceName.'); |
55 } | 56 } |
56 var source = sources[sourceName]; | 57 var source = sources[sourceName]; |
57 | 58 |
58 // Parse the description. | 59 // Parse the description. |
59 if (!spec.containsKey('description')) { | 60 if (!spec.containsKey('description')) { |
60 throw new FormatException('Package $name is missing a description.'); | 61 throw new FormatException('Package $name is missing a description.'); |
61 } | 62 } |
62 var description = spec['description']; | 63 var description = spec['description']; |
63 source.validateDescription(description); | 64 source.validateDescription(description, fromLockFile: true); |
64 | 65 |
65 var id = new PackageId(source, version, description); | 66 var id = new PackageId(source, version, description); |
66 | 67 |
67 // Validate the name. | 68 // Validate the name. |
68 if (name != id.name) { | 69 if (name != id.name) { |
69 throw new FormatException( | 70 throw new FormatException( |
70 "Package name $name doesn't match ${id.name}."); | 71 "Package name $name doesn't match ${id.name}."); |
71 } | 72 } |
72 | 73 |
73 packages[name] = id; | 74 packages[name] = id; |
74 }); | 75 }); |
75 } | 76 } |
76 | 77 |
77 return new LockFile._(packages); | 78 return new LockFile._(packages); |
78 } | 79 } |
| 80 |
| 81 /** |
| 82 * Returns the serialized YAML text of the lock file. |
| 83 */ |
| 84 String serialize() { |
| 85 var packagesObj = <Map>{}; |
| 86 packages.forEach((name, id) { |
| 87 packagesObj[name] = { |
| 88 'version': id.version.toString(), |
| 89 'source': id.source.name, |
| 90 'description': id.description |
| 91 }; |
| 92 }); |
| 93 |
| 94 // TODO(nweiz): Serialize using the YAML library once it supports |
| 95 // serialization. For now, we use JSON, since it's a subset of YAML anyway. |
| 96 return JSON.stringify({'packages': packagesObj}); |
| 97 } |
79 } | 98 } |
OLD | NEW |