| 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 24 matching lines...) Expand all Loading... |
| 35 * Parses the pubspec whose text is [contents]. If the pubspec doesn't define | 35 * Parses the pubspec whose text is [contents]. If the pubspec doesn't define |
| 36 * version for itself, it defaults to [Version.none]. | 36 * version for itself, it defaults to [Version.none]. |
| 37 */ | 37 */ |
| 38 factory Pubspec.parse(String contents, SourceRegistry sources) { | 38 factory Pubspec.parse(String contents, SourceRegistry sources) { |
| 39 var version = Version.none; | 39 var version = Version.none; |
| 40 var dependencies = <PackageRef>[]; | 40 var dependencies = <PackageRef>[]; |
| 41 | 41 |
| 42 if (contents.trim() == '') return new Pubspec.empty(); | 42 if (contents.trim() == '') return new Pubspec.empty(); |
| 43 | 43 |
| 44 var parsedPubspec = loadYaml(contents); | 44 var parsedPubspec = loadYaml(contents); |
| 45 if (parsedPubspec == null) return new Pubspec.empty(); |
| 46 |
| 45 if (parsedPubspec is! Map) { | 47 if (parsedPubspec is! Map) { |
| 46 throw new FormatException('The pubspec must be a YAML mapping.'); | 48 throw new FormatException('The pubspec must be a YAML mapping.'); |
| 47 } | 49 } |
| 48 | 50 |
| 49 if (parsedPubspec.containsKey('version')) { | 51 if (parsedPubspec.containsKey('version')) { |
| 50 version = new Version.parse(parsedPubspec['version']); | 52 version = new Version.parse(parsedPubspec['version']); |
| 51 } | 53 } |
| 52 | 54 |
| 53 if (parsedPubspec.containsKey('dependencies')) { | 55 if (parsedPubspec.containsKey('dependencies')) { |
| 54 var dependencyEntries = parsedPubspec['dependencies']; | 56 var dependencyEntries = parsedPubspec['dependencies']; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 source.validateDescription(description); | 98 source.validateDescription(description); |
| 97 | 99 |
| 98 dependencies.add(new PackageRef( | 100 dependencies.add(new PackageRef( |
| 99 source, versionConstraint, description)); | 101 source, versionConstraint, description)); |
| 100 }); | 102 }); |
| 101 } | 103 } |
| 102 | 104 |
| 103 return new Pubspec(version, dependencies); | 105 return new Pubspec(version, dependencies); |
| 104 } | 106 } |
| 105 } | 107 } |
| OLD | NEW |