Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: utils/pub/lock_file.dart

Issue 12133002: add a comment to the generated lock file (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 contents, SourceRegistry sources) {
26 var packages = <String, PackageId>{}; 26 var packages = <String, PackageId>{};
27 27
28 if (contents.trim() == '') return new LockFile.empty(); 28 if (contents.trim() == '') return new LockFile.empty();
29
30 var parsed = loadYaml(contents); 29 var parsed = loadYaml(contents);
31 30
32 if (parsed.containsKey('packages')) { 31 if (parsed.containsKey('packages')) {
33 var packageEntries = parsed['packages']; 32 var packageEntries = parsed['packages'];
34 33
35 packageEntries.forEach((name, spec) { 34 packageEntries.forEach((name, spec) {
36 // Parse the version. 35 // Parse the version.
37 if (!spec.containsKey('version')) { 36 if (!spec.containsKey('version')) {
38 throw new FormatException('Package $name is missing a version.'); 37 throw new FormatException('Package $name is missing a version.');
39 } 38 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 packages.forEach((name, id) { 77 packages.forEach((name, id) {
79 packagesObj[name] = { 78 packagesObj[name] = {
80 'version': id.version.toString(), 79 'version': id.version.toString(),
81 'source': id.source.name, 80 'source': id.source.name,
82 'description': id.description 81 'description': id.description
83 }; 82 };
84 }); 83 });
85 84
86 // TODO(nweiz): Serialize using the YAML library once it supports 85 // 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. 86 // serialization. For now, we use JSON, since it's a subset of YAML anyway.
88 return json.stringify({'packages': packagesObj}); 87 return '''
88 # Generated by pub. See: http://pub.dartlang.org/doc/glossary.html#lockf ile
89 ${json.stringify({'packages': packagesObj})}
90 ''';
89 } 91 }
90 } 92 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698