| 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 pubspec; | 5 library pubspec; |
| 6 | 6 |
| 7 import 'package.dart'; | 7 import 'package.dart'; |
| 8 import 'source.dart'; | 8 import 'source.dart'; |
| 9 import 'source_registry.dart'; | 9 import 'source_registry.dart'; |
| 10 import 'utils.dart'; | 10 import 'utils.dart'; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 final String name; | 21 final String name; |
| 22 | 22 |
| 23 /** | 23 /** |
| 24 * This package's version. | 24 * This package's version. |
| 25 */ | 25 */ |
| 26 final Version version; | 26 final Version version; |
| 27 | 27 |
| 28 /** | 28 /** |
| 29 * The packages this package depends on. | 29 * The packages this package depends on. |
| 30 */ | 30 */ |
| 31 List<PackageRef> dependencies; | 31 final List<PackageRef> dependencies; |
| 32 | 32 |
| 33 Pubspec(this.name, this.version, this.dependencies); | 33 /// All pubspec fields. This includes the fields from which other properties |
| 34 /// are derived. |
| 35 final Map<String, Object> fields; |
| 36 |
| 37 Pubspec(this.name, this.version, this.dependencies, |
| 38 [Map<String, Object> fields]) |
| 39 : this.fields = fields == null ? {} : fields; |
| 34 | 40 |
| 35 Pubspec.empty() | 41 Pubspec.empty() |
| 36 : name = null, | 42 : name = null, |
| 37 version = Version.none, | 43 version = Version.none, |
| 38 dependencies = <PackageRef>[]; | 44 dependencies = <PackageRef>[], |
| 45 fields = {}; |
| 39 | 46 |
| 40 /** Whether or not the pubspec has no contents. */ | 47 /** Whether or not the pubspec has no contents. */ |
| 41 bool get isEmpty => | 48 bool get isEmpty => |
| 42 name == null && version == Version.none && dependencies.isEmpty; | 49 name == null && version == Version.none && dependencies.isEmpty; |
| 43 | 50 |
| 44 /** | 51 /** |
| 45 * Parses the pubspec whose text is [contents]. If the pubspec doesn't define | 52 * Parses the pubspec whose text is [contents]. If the pubspec doesn't define |
| 46 * version for itself, it defaults to [Version.none]. | 53 * version for itself, it defaults to [Version.none]. |
| 47 */ | 54 */ |
| 48 factory Pubspec.parse(String contents, SourceRegistry sources) { | 55 factory Pubspec.parse(String contents, SourceRegistry sources) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 throw new FormatException('The pubspec "authors" field should be a ' | 126 throw new FormatException('The pubspec "authors" field should be a ' |
| 120 'string or a list of strings, but was "$authors".'); | 127 'string or a list of strings, but was "$authors".'); |
| 121 } | 128 } |
| 122 | 129 |
| 123 if (parsedPubspec.containsKey('author')) { | 130 if (parsedPubspec.containsKey('author')) { |
| 124 throw new FormatException('A pubspec should not have both an "author" ' | 131 throw new FormatException('A pubspec should not have both an "author" ' |
| 125 'and an "authors" field.'); | 132 'and an "authors" field.'); |
| 126 } | 133 } |
| 127 } | 134 } |
| 128 | 135 |
| 129 return new Pubspec(name, version, dependencies); | 136 return new Pubspec(name, version, dependencies, parsedPubspec); |
| 130 } | 137 } |
| 131 } | 138 } |
| 132 | 139 |
| 133 List<PackageRef> _parseDependencies(SourceRegistry sources, yaml) { | 140 List<PackageRef> _parseDependencies(SourceRegistry sources, yaml) { |
| 134 var dependencies = <PackageRef>[]; | 141 var dependencies = <PackageRef>[]; |
| 135 | 142 |
| 136 // Allow an empty dependencies key. | 143 // Allow an empty dependencies key. |
| 137 if (yaml == null) return dependencies; | 144 if (yaml == null) return dependencies; |
| 138 | 145 |
| 139 if (yaml is! Map || yaml.keys.some((e) => e is! String)) { | 146 if (yaml is! Map || yaml.keys.some((e) => e is! String)) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 } | 184 } |
| 178 | 185 |
| 179 source.validateDescription(description, fromLockFile: false); | 186 source.validateDescription(description, fromLockFile: false); |
| 180 | 187 |
| 181 dependencies.add(new PackageRef( | 188 dependencies.add(new PackageRef( |
| 182 name, source, versionConstraint, description)); | 189 name, source, versionConstraint, description)); |
| 183 }); | 190 }); |
| 184 | 191 |
| 185 return dependencies; | 192 return dependencies; |
| 186 } | 193 } |
| OLD | NEW |