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 import 'dart:collection'; | 5 import 'dart:collection'; |
6 | 6 |
7 import 'package:path/path.dart' as p; | 7 import 'package:path/path.dart' as p; |
8 import 'package:package_config/packages_file.dart' as packages_file; | 8 import 'package:package_config/packages_file.dart' as packages_file; |
9 import 'package:pub_semver/pub_semver.dart'; | 9 import 'package:pub_semver/pub_semver.dart'; |
10 import 'package:source_span/source_span.dart'; | 10 import 'package:source_span/source_span.dart'; |
11 import 'package:yaml/yaml.dart'; | 11 import 'package:yaml/yaml.dart'; |
12 | 12 |
13 import 'io.dart'; | 13 import 'io.dart'; |
14 import 'package.dart'; | 14 import 'package.dart'; |
15 import 'source_registry.dart'; | 15 import 'source_registry.dart'; |
| 16 import 'system_cache.dart'; |
16 import 'utils.dart'; | 17 import 'utils.dart'; |
17 | 18 |
18 /// A parsed and validated `pubspec.lock` file. | 19 /// A parsed and validated `pubspec.lock` file. |
19 class LockFile { | 20 class LockFile { |
20 /// The source registry with which the lock file's IDs are interpreted. | 21 /// The source registry with which the lock file's IDs are interpreted. |
21 final SourceRegistry _sources; | 22 final SourceRegistry _sources; |
22 | 23 |
23 /// The packages this lockfile pins. | 24 /// The packages this lockfile pins. |
24 final Map<String, PackageId> packages; | 25 final Map<String, PackageId> packages; |
25 | 26 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 | 169 |
169 var packages = new Map.from(this.packages); | 170 var packages = new Map.from(this.packages); |
170 packages.remove(name); | 171 packages.remove(name); |
171 return new LockFile._(packages, sdkConstraint, _sources); | 172 return new LockFile._(packages, sdkConstraint, _sources); |
172 } | 173 } |
173 | 174 |
174 /// Returns the contents of the `.packages` file generated from this lockfile. | 175 /// Returns the contents of the `.packages` file generated from this lockfile. |
175 /// | 176 /// |
176 /// If [entrypoint] is passed, a relative entry is added for its "lib/" | 177 /// If [entrypoint] is passed, a relative entry is added for its "lib/" |
177 /// directory. | 178 /// directory. |
178 String packagesFile([String entrypoint]) { | 179 String packagesFile(SystemCache cache, [String entrypoint]) { |
179 var header = "Generated by pub on ${new DateTime.now()}."; | 180 var header = "Generated by pub on ${new DateTime.now()}."; |
180 | 181 |
181 var map = new Map.fromIterable(ordered(packages.keys), value: (name) { | 182 var map = new Map.fromIterable(ordered(packages.keys), value: (name) { |
182 var id = packages[name]; | 183 var id = packages[name]; |
183 var source = _sources[id.source]; | 184 var source = cache.source(id.source); |
184 return p.toUri(p.join(source.getDirectory(id), "lib")); | 185 return p.toUri(p.join(source.getDirectory(id), "lib")); |
185 }); | 186 }); |
186 | 187 |
187 if (entrypoint != null) map[entrypoint] = Uri.parse("lib/"); | 188 if (entrypoint != null) map[entrypoint] = Uri.parse("lib/"); |
188 | 189 |
189 var text = new StringBuffer(); | 190 var text = new StringBuffer(); |
190 packages_file.write(text, map, comment: header); | 191 packages_file.write(text, map, comment: header); |
191 return text.toString(); | 192 return text.toString(); |
192 } | 193 } |
193 | 194 |
(...skipping 16 matching lines...) Expand all Loading... |
210 }); | 211 }); |
211 | 212 |
212 var data = {'sdk': sdkConstraint.toString(), 'packages': packageMap}; | 213 var data = {'sdk': sdkConstraint.toString(), 'packages': packageMap}; |
213 return """ | 214 return """ |
214 # Generated by pub | 215 # Generated by pub |
215 # See http://pub.dartlang.org/doc/glossary.html#lockfile | 216 # See http://pub.dartlang.org/doc/glossary.html#lockfile |
216 ${yamlToString(data)} | 217 ${yamlToString(data)} |
217 """; | 218 """; |
218 } | 219 } |
219 } | 220 } |
OLD | NEW |