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 | |
|
Bob Nystrom
2013/01/31 22:42:31
Can you remove this empty line?
keertip
2013/01/31 22:53:05
Done.
| |
| 16 /// The packages this lockfile pins. | 17 /// The packages this lockfile pins. |
| 17 Map<String, PackageId> packages; | 18 Map<String, PackageId> packages; |
| 18 | 19 |
| 19 LockFile._(this.packages); | 20 LockFile._(this.packages); |
| 20 | 21 |
| 21 LockFile.empty() | 22 LockFile.empty() |
| 22 : packages = <String, PackageId>{}; | 23 : packages = <String, PackageId>{}; |
| 23 | 24 |
| 24 /// Parses the lockfile whose text is [contents]. | 25 /// Parses the lockfile whose text is [contents]. |
| 25 factory LockFile.parse(String contents, SourceRegistry sources) { | 26 factory LockFile.parse(String contents, 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 | |
| 30 var parsed = loadYaml(contents); | 30 var parsed = loadYaml(contents); |
| 31 | 31 |
| 32 if (parsed.containsKey('packages')) { | 32 if (parsed.containsKey('packages')) { |
| 33 var packageEntries = parsed['packages']; | 33 var packageEntries = parsed['packages']; |
| 34 | 34 |
| 35 packageEntries.forEach((name, spec) { | 35 packageEntries.forEach((name, spec) { |
| 36 // Parse the version. | 36 // Parse the version. |
| 37 if (!spec.containsKey('version')) { | 37 if (!spec.containsKey('version')) { |
| 38 throw new FormatException('Package $name is missing a version.'); | 38 throw new FormatException('Package $name is missing a version.'); |
| 39 } | 39 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 packages.forEach((name, id) { | 78 packages.forEach((name, id) { |
| 79 packagesObj[name] = { | 79 packagesObj[name] = { |
| 80 'version': id.version.toString(), | 80 'version': id.version.toString(), |
| 81 'source': id.source.name, | 81 'source': id.source.name, |
| 82 'description': id.description | 82 'description': id.description |
| 83 }; | 83 }; |
| 84 }); | 84 }); |
| 85 | 85 |
| 86 // TODO(nweiz): Serialize using the YAML library once it supports | 86 // 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. | 87 // serialization. For now, we use JSON, since it's a subset of YAML anyway. |
| 88 return json.stringify({'packages': packagesObj}); | 88 return ''' |
| 89 # Generated by pub. See: http://pub.dartlang.org/doc/glossary.html#lockf ile | |
| 90 ${json.stringify({'packages': packagesObj})} | |
| 91 '''; | |
| 89 } | 92 } |
| 90 } | 93 } |
| OLD | NEW |