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) { | |
nweiz
2012/07/16 19:34:02
Nit: we usually do single-line if statements when
| |
46 // content just yaml comments | |
47 return new Pubspec.empty(); | |
48 } | |
45 if (parsedPubspec is! Map) { | 49 if (parsedPubspec is! Map) { |
46 throw new FormatException('The pubspec must be a YAML mapping.'); | 50 throw new FormatException('The pubspec must be a YAML mapping.'); |
47 } | 51 } |
48 | 52 |
49 if (parsedPubspec.containsKey('version')) { | 53 if (parsedPubspec.containsKey('version')) { |
50 version = new Version.parse(parsedPubspec['version']); | 54 version = new Version.parse(parsedPubspec['version']); |
51 } | 55 } |
52 | 56 |
53 if (parsedPubspec.containsKey('dependencies')) { | 57 if (parsedPubspec.containsKey('dependencies')) { |
54 var dependencyEntries = parsedPubspec['dependencies']; | 58 var dependencyEntries = parsedPubspec['dependencies']; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 source.validateDescription(description); | 102 source.validateDescription(description); |
99 | 103 |
100 dependencies.add(new PackageRef( | 104 dependencies.add(new PackageRef( |
101 name, source, Version.none, description)); | 105 name, source, Version.none, description)); |
102 }); | 106 }); |
103 } | 107 } |
104 | 108 |
105 return new Pubspec._(version, dependencies); | 109 return new Pubspec._(version, dependencies); |
106 } | 110 } |
107 } | 111 } |
OLD | NEW |