Chromium Code Reviews| 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 | |
| 17 /// comment to append at start of lock file | |
| 18 static final comment = "# Generated by pub. See: http://pub.dartlang.org/doc/g lossary.html#lockfile"; | |
|
Bob Nystrom
2013/01/31 22:17:44
It's probably not worth making a constant for this
keertip
2013/01/31 22:40:41
Done.
| |
| 19 | |
| 16 /// The packages this lockfile pins. | 20 /// The packages this lockfile pins. |
| 17 Map<String, PackageId> packages; | 21 Map<String, PackageId> packages; |
| 18 | 22 |
| 19 LockFile._(this.packages); | 23 LockFile._(this.packages); |
| 20 | 24 |
| 21 LockFile.empty() | 25 LockFile.empty() |
| 22 : packages = <String, PackageId>{}; | 26 : packages = <String, PackageId>{}; |
| 23 | 27 |
| 24 /// Parses the lockfile whose text is [contents]. | 28 /// Parses the lockfile whose text is [contents]. |
| 25 factory LockFile.parse(String contents, SourceRegistry sources) { | 29 factory LockFile.parse(String contents, SourceRegistry sources) { |
| 26 var packages = <String, PackageId>{}; | 30 var packages = <String, PackageId>{}; |
| 27 | 31 |
| 28 if (contents.trim() == '') return new LockFile.empty(); | 32 if (contents.trim() == '') return new LockFile.empty(); |
| 29 | 33 // remove comment before parsing |
| 30 var parsed = loadYaml(contents); | 34 var parsed = loadYaml(contents.replaceAll(comment, '')); |
|
Bob Nystrom
2013/01/31 22:17:44
This shouldn't be necessary. YAML supports comment
keertip
2013/01/31 22:40:41
Removed.
On 2013/01/31 22:17:44, Bob Nystrom wrot
| |
| 31 | 35 |
| 32 if (parsed.containsKey('packages')) { | 36 if (parsed.containsKey('packages')) { |
| 33 var packageEntries = parsed['packages']; | 37 var packageEntries = parsed['packages']; |
| 34 | 38 |
| 35 packageEntries.forEach((name, spec) { | 39 packageEntries.forEach((name, spec) { |
| 36 // Parse the version. | 40 // Parse the version. |
| 37 if (!spec.containsKey('version')) { | 41 if (!spec.containsKey('version')) { |
| 38 throw new FormatException('Package $name is missing a version.'); | 42 throw new FormatException('Package $name is missing a version.'); |
| 39 } | 43 } |
| 40 var version = new Version.parse(spec['version']); | 44 var version = new Version.parse(spec['version']); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 packages.forEach((name, id) { | 82 packages.forEach((name, id) { |
| 79 packagesObj[name] = { | 83 packagesObj[name] = { |
| 80 'version': id.version.toString(), | 84 'version': id.version.toString(), |
| 81 'source': id.source.name, | 85 'source': id.source.name, |
| 82 'description': id.description | 86 'description': id.description |
| 83 }; | 87 }; |
| 84 }); | 88 }); |
| 85 | 89 |
| 86 // TODO(nweiz): Serialize using the YAML library once it supports | 90 // TODO(nweiz): Serialize using the YAML library once it supports |
| 87 // serialization. For now, we use JSON, since it's a subset of YAML anyway. | 91 // serialization. For now, we use JSON, since it's a subset of YAML anyway. |
| 88 return json.stringify({'packages': packagesObj}); | 92 var lockFileString = json.stringify({'packages': packagesObj}); |
| 93 return '$comment $lockFileString'; | |
|
Bob Nystrom
2013/01/31 22:17:44
I'd use a multiline string here:
return '''
# Gen
keertip
2013/01/31 22:40:41
Done.
| |
| 89 } | 94 } |
| 90 } | 95 } |
| OLD | NEW |