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' as json; | 7 import 'dart:json' as json; |
8 import 'package.dart'; | 8 import 'package.dart'; |
9 import 'source_registry.dart'; | 9 import 'source_registry.dart'; |
10 import 'utils.dart'; | 10 import 'utils.dart'; |
11 import 'version.dart'; | 11 import 'version.dart'; |
12 import '../../pkg/yaml/lib/yaml.dart'; | 12 import '../../pkg/yaml/lib/yaml.dart'; |
13 | 13 |
14 /// A parsed and validated `pubspec.lock` file. | 14 /// A parsed and validated `pubspec.lock` file. |
15 class LockFile { | 15 class LockFile { |
16 /// The packages this lockfile pins. | 16 /// The packages this lockfile pins. |
17 Map<String, PackageId> packages; | 17 Map<String, PackageId> packages; |
18 | 18 |
19 LockFile._(this.packages); | 19 LockFile._(this.packages); |
20 | 20 |
21 LockFile.empty() | 21 LockFile.empty() |
22 : packages = <String, PackageId>{}; | 22 : packages = <String, PackageId>{}; |
23 | 23 |
24 /// Parses the lockfile whose text is [contents]. | 24 /// Parses the lockfile whose text is [contents]. |
25 factory LockFile.parse(String contents, SourceRegistry sources) { | 25 factory LockFile.parse(String filePath, String contents, |
| 26 SourceRegistry sources) { |
26 var packages = <String, PackageId>{}; | 27 var packages = <String, PackageId>{}; |
27 | 28 |
28 if (contents.trim() == '') return new LockFile.empty(); | 29 if (contents.trim() == '') return new LockFile.empty(); |
29 var parsed = loadYaml(contents); | 30 var parsed = loadYaml(contents); |
30 | 31 |
31 if (parsed.containsKey('packages')) { | 32 if (parsed.containsKey('packages')) { |
32 var packageEntries = parsed['packages']; | 33 var packageEntries = parsed['packages']; |
33 | 34 |
34 packageEntries.forEach((name, spec) { | 35 packageEntries.forEach((name, spec) { |
35 // Parse the version. | 36 // Parse the version. |
(...skipping 11 matching lines...) Expand all Loading... |
47 throw new FormatException( | 48 throw new FormatException( |
48 'Could not find a source named $sourceName.'); | 49 'Could not find a source named $sourceName.'); |
49 } | 50 } |
50 var source = sources[sourceName]; | 51 var source = sources[sourceName]; |
51 | 52 |
52 // Parse the description. | 53 // Parse the description. |
53 if (!spec.containsKey('description')) { | 54 if (!spec.containsKey('description')) { |
54 throw new FormatException('Package $name is missing a description.'); | 55 throw new FormatException('Package $name is missing a description.'); |
55 } | 56 } |
56 var description = spec['description']; | 57 var description = spec['description']; |
57 source.validateDescription(description, fromLockFile: true); | 58 description = source.parseDescription(filePath, description, |
| 59 fromLockFile: true); |
58 | 60 |
59 var id = new PackageId(name, source, version, description); | 61 var id = new PackageId(name, source, version, description); |
60 | 62 |
61 // Validate the name. | 63 // Validate the name. |
62 if (name != id.name) { | 64 if (name != id.name) { |
63 throw new FormatException( | 65 throw new FormatException( |
64 "Package name $name doesn't match ${id.name}."); | 66 "Package name $name doesn't match ${id.name}."); |
65 } | 67 } |
66 | 68 |
67 packages[name] = id; | 69 packages[name] = id; |
(...skipping 15 matching lines...) Expand all Loading... |
83 }); | 85 }); |
84 | 86 |
85 // TODO(nweiz): Serialize using the YAML library once it supports | 87 // TODO(nweiz): Serialize using the YAML library once it supports |
86 // serialization. For now, we use JSON, since it's a subset of YAML anyway. | 88 // serialization. For now, we use JSON, since it's a subset of YAML anyway. |
87 return ''' | 89 return ''' |
88 # Generated by pub. See: http://pub.dartlang.org/doc/glossary.html#lockf
ile | 90 # Generated by pub. See: http://pub.dartlang.org/doc/glossary.html#lockf
ile |
89 ${json.stringify({'packages': packagesObj})} | 91 ${json.stringify({'packages': packagesObj})} |
90 '''; | 92 '''; |
91 } | 93 } |
92 } | 94 } |
OLD | NEW |