| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 | 69 |
| 70 if (parsedPubspec.containsKey('version')) { | 70 if (parsedPubspec.containsKey('version')) { |
| 71 version = new Version.parse(parsedPubspec['version']); | 71 version = new Version.parse(parsedPubspec['version']); |
| 72 } | 72 } |
| 73 | 73 |
| 74 if (parsedPubspec.containsKey('dependencies')) { | 74 if (parsedPubspec.containsKey('dependencies')) { |
| 75 var dependencyEntries = parsedPubspec['dependencies']; | 75 var dependencyEntries = parsedPubspec['dependencies']; |
| 76 if (dependencyEntries is! Map || | 76 if (dependencyEntries is! Map || |
| 77 dependencyEntries.getKeys().some((e) => e is! String)) { | 77 dependencyEntries.keys.some((e) => e is! String)) { |
| 78 throw new FormatException( | 78 throw new FormatException( |
| 79 'The pubspec dependencies should be a map of package names, but ' | 79 'The pubspec dependencies should be a map of package names, but ' |
| 80 'was ${dependencyEntries}.'); | 80 'was ${dependencyEntries}.'); |
| 81 } | 81 } |
| 82 | 82 |
| 83 dependencyEntries.forEach((name, spec) { | 83 dependencyEntries.forEach((name, spec) { |
| 84 var description, source; | 84 var description, source; |
| 85 var versionConstraint = new VersionRange(); | 85 var versionConstraint = new VersionRange(); |
| 86 if (spec == null) { | 86 if (spec == null) { |
| 87 description = name; | 87 description = name; |
| 88 source = sources.defaultSource; | 88 source = sources.defaultSource; |
| 89 } else if (spec is String) { | 89 } else if (spec is String) { |
| 90 description = name; | 90 description = name; |
| 91 source = sources.defaultSource; | 91 source = sources.defaultSource; |
| 92 versionConstraint = new VersionConstraint.parse(spec); | 92 versionConstraint = new VersionConstraint.parse(spec); |
| 93 } else if (spec is Map) { | 93 } else if (spec is Map) { |
| 94 if (spec.containsKey('version')) { | 94 if (spec.containsKey('version')) { |
| 95 versionConstraint = new VersionConstraint.parse( | 95 versionConstraint = new VersionConstraint.parse( |
| 96 spec.remove('version')); | 96 spec.remove('version')); |
| 97 } | 97 } |
| 98 | 98 |
| 99 var sourceNames = spec.getKeys(); | 99 var sourceNames = spec.keys; |
| 100 if (sourceNames.length > 1) { | 100 if (sourceNames.length > 1) { |
| 101 throw new FormatException( | 101 throw new FormatException( |
| 102 'Dependency $name may only have one source: $sourceNames.'); | 102 'Dependency $name may only have one source: $sourceNames.'); |
| 103 } | 103 } |
| 104 | 104 |
| 105 var sourceName = only(sourceNames); | 105 var sourceName = only(sourceNames); |
| 106 if (sourceName is! String) { | 106 if (sourceName is! String) { |
| 107 throw new FormatException( | 107 throw new FormatException( |
| 108 'Source name $sourceName should be a string.'); | 108 'Source name $sourceName should be a string.'); |
| 109 } | 109 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 156 |
| 157 if (parsedPubspec.containsKey('author')) { | 157 if (parsedPubspec.containsKey('author')) { |
| 158 throw new FormatException('A pubspec should not have both an "author" ' | 158 throw new FormatException('A pubspec should not have both an "author" ' |
| 159 'and an "authors" field.'); | 159 'and an "authors" field.'); |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 | 162 |
| 163 return new Pubspec(name, version, dependencies); | 163 return new Pubspec(name, version, dependencies); |
| 164 } | 164 } |
| 165 } | 165 } |
| OLD | NEW |