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 41 matching lines...) Loading... |
52 | 52 |
53 if (parsedPubspec.containsKey('dependencies')) { | 53 if (parsedPubspec.containsKey('dependencies')) { |
54 var dependencyEntries = parsedPubspec['dependencies']; | 54 var dependencyEntries = parsedPubspec['dependencies']; |
55 if (dependencyEntries is! Map || | 55 if (dependencyEntries is! Map || |
56 dependencyEntries.getKeys().some((e) => e is! String)) { | 56 dependencyEntries.getKeys().some((e) => e is! String)) { |
57 throw new FormatException( | 57 throw new FormatException( |
58 'The pubspec dependencies must be a map of package names.'); | 58 'The pubspec dependencies must be a map of package names.'); |
59 } | 59 } |
60 | 60 |
61 dependencyEntries.forEach((name, spec) { | 61 dependencyEntries.forEach((name, spec) { |
62 var description, source; | 62 var description, source, versionConstraint; |
63 if (spec == null) { | 63 if (spec == null) { |
64 description = name; | 64 description = name; |
65 source = sources.defaultSource; | 65 source = sources.defaultSource; |
66 } else if (spec is String) { | 66 } else if (spec is String) { |
67 description = name; | 67 description = name; |
68 source = sources.defaultSource; | 68 source = sources.defaultSource; |
69 // TODO(rnystrom): Support parsing version constraints like | 69 versionConstraint = new VersionConstraint.parse(spec); |
70 // ">= 2.0.0 < 3.1.3". | |
71 version = new Version.parse(spec); | |
72 } else if (spec is Map) { | 70 } else if (spec is Map) { |
73 if (spec.containsKey('version')) { | 71 if (spec.containsKey('version')) { |
74 // TODO(rnystrom): Support parsing version constraints like | 72 versionConstraint = new VersionConstraint.parse( |
75 // ">= 2.0.0 < 3.1.3". | 73 spec.remove('version')); |
76 version = new Version.parse(spec.remove('version')); | |
77 } | 74 } |
78 | 75 |
79 var sourceNames = spec.getKeys(); | 76 var sourceNames = spec.getKeys(); |
80 if (sourceNames.length > 1) { | 77 if (sourceNames.length > 1) { |
81 throw new FormatException( | 78 throw new FormatException( |
82 'Dependency $name may only have one source: $sourceNames.'); | 79 'Dependency $name may only have one source: $sourceNames.'); |
83 } | 80 } |
84 | 81 |
85 var sourceName = only(sourceNames); | 82 var sourceName = only(sourceNames); |
86 if (sourceName is! String) { | 83 if (sourceName is! String) { |
87 throw new FormatException( | 84 throw new FormatException( |
88 'Source name $sourceName must be a string.'); | 85 'Source name $sourceName must be a string.'); |
89 } | 86 } |
90 | 87 |
91 source = sources[sourceName]; | 88 source = sources[sourceName]; |
92 description = spec[sourceName]; | 89 description = spec[sourceName]; |
93 } else { | 90 } else { |
94 throw new FormatException( | 91 throw new FormatException( |
95 'Dependency specification $spec must be a string or a mapping.'); | 92 'Dependency specification $spec must be a string or a mapping.'); |
96 } | 93 } |
97 | 94 |
98 source.validateDescription(description); | 95 source.validateDescription(description); |
99 | 96 |
100 dependencies.add(new PackageRef( | 97 dependencies.add(new PackageRef( |
101 name, source, Version.none, description)); | 98 name, source, versionConstraint, description)); |
102 }); | 99 }); |
103 } | 100 } |
104 | 101 |
105 return new Pubspec._(version, dependencies); | 102 return new Pubspec._(version, dependencies); |
106 } | 103 } |
107 } | 104 } |
OLD | NEW |