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 'dart:collection'; |
8 | 9 |
9 import 'package:yaml/yaml.dart'; | 10 import 'package:yaml/yaml.dart'; |
10 | 11 |
11 import 'io.dart'; | 12 import 'io.dart'; |
12 import 'package.dart'; | 13 import 'package.dart'; |
13 import 'source_registry.dart'; | 14 import 'source_registry.dart'; |
14 import 'utils.dart'; | 15 import 'utils.dart'; |
15 import 'version.dart'; | 16 import 'version.dart'; |
16 | 17 |
17 /// A parsed and validated `pubspec.lock` file. | 18 /// A parsed and validated `pubspec.lock` file. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 82 |
82 packages[name] = id; | 83 packages[name] = id; |
83 }); | 84 }); |
84 } | 85 } |
85 | 86 |
86 return new LockFile._(packages); | 87 return new LockFile._(packages); |
87 } | 88 } |
88 | 89 |
89 /// Returns the serialized YAML text of the lock file. | 90 /// Returns the serialized YAML text of the lock file. |
90 String serialize() { | 91 String serialize() { |
91 var packagesObj = <String, Map>{}; | 92 var packagesObj = new LinkedHashMap<String, Map>(); |
92 packages.forEach((name, id) { | 93 |
| 94 // Sort the packages by name. |
| 95 var sortedKeys = packages.keys.toList(); |
| 96 sortedKeys.sort(); |
| 97 sortedKeys.forEach((name) { |
93 packagesObj[name] = { | 98 packagesObj[name] = { |
94 'version': id.version.toString(), | 99 'version': packages[name].version.toString(), |
95 'source': id.source.name, | 100 'source': packages[name].source.name, |
96 'description': id.description | 101 'description': packages[name].description |
97 }; | 102 }; |
98 }); | 103 }); |
99 | 104 |
100 // TODO(nweiz): Serialize using the YAML library once it supports | 105 // TODO(nweiz): Serialize using the YAML library once it supports |
101 // serialization. For now, we use JSON, since it's a subset of YAML anyway. | 106 // serialization. For now, we use JSON, since it's a subset of YAML anyway. |
102 return | 107 return |
103 '# Generated by pub\n' | 108 '# Generated by pub\n' |
104 '# See http://pub.dartlang.org/doc/glossary.html#lockfile\n' | 109 '# See http://pub.dartlang.org/doc/glossary.html#lockfile\n' |
105 '\n' | 110 '\n' |
106 '${json.stringify({'packages': packagesObj})}\n'; | 111 '${json.stringify({'packages': packagesObj})}\n'; |
107 } | 112 } |
108 } | 113 } |
OLD | NEW |