| 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'); | |
| 8 #import('package.dart'); | 7 #import('package.dart'); |
| 9 #import('source_registry.dart'); | 8 #import('source_registry.dart'); |
| 10 #import('utils.dart'); | 9 #import('utils.dart'); |
| 11 #import('version.dart'); | 10 #import('version.dart'); |
| 12 #import('yaml/yaml.dart'); | 11 #import('yaml/yaml.dart'); |
| 13 | 12 |
| 14 /** | 13 /** |
| 15 * A parsed and validated `pubspec.lock` file. | 14 * A parsed and validated `pubspec.lock` file. |
| 16 */ | 15 */ |
| 17 class LockFile { | 16 class LockFile { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 throw new FormatException( | 53 throw new FormatException( |
| 55 'Could not find a source named $sourceName.'); | 54 'Could not find a source named $sourceName.'); |
| 56 } | 55 } |
| 57 var source = sources[sourceName]; | 56 var source = sources[sourceName]; |
| 58 | 57 |
| 59 // Parse the description. | 58 // Parse the description. |
| 60 if (!spec.containsKey('description')) { | 59 if (!spec.containsKey('description')) { |
| 61 throw new FormatException('Package $name is missing a description.'); | 60 throw new FormatException('Package $name is missing a description.'); |
| 62 } | 61 } |
| 63 var description = spec['description']; | 62 var description = spec['description']; |
| 64 source.validateDescription(description, fromLockFile: true); | 63 source.validateDescription(description); |
| 65 | 64 |
| 66 var id = new PackageId(source, version, description); | 65 var id = new PackageId(source, version, description); |
| 67 | 66 |
| 68 // Validate the name. | 67 // Validate the name. |
| 69 if (name != id.name) { | 68 if (name != id.name) { |
| 70 throw new FormatException( | 69 throw new FormatException( |
| 71 "Package name $name doesn't match ${id.name}."); | 70 "Package name $name doesn't match ${id.name}."); |
| 72 } | 71 } |
| 73 | 72 |
| 74 packages[name] = id; | 73 packages[name] = id; |
| 75 }); | 74 }); |
| 76 } | 75 } |
| 77 | 76 |
| 78 return new LockFile._(packages); | 77 return new LockFile._(packages); |
| 79 } | 78 } |
| 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 } | |
| 98 } | 79 } |
| OLD | NEW |