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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 if (parsedPubspec.containsKey('version')) { | 69 if (parsedPubspec.containsKey('version')) { |
70 version = new Version.parse(parsedPubspec['version']); | 70 version = new Version.parse(parsedPubspec['version']); |
71 } | 71 } |
72 | 72 |
73 var dependencies = _parseDependencies(sources, | 73 var dependencies = _parseDependencies(sources, |
74 parsedPubspec['dependencies']); | 74 parsedPubspec['dependencies']); |
75 | 75 |
76 // Even though the pub app itself doesn't use these fields, we validate | 76 // Even though the pub app itself doesn't use these fields, we validate |
77 // them here so that users find errors early before they try to upload to | 77 // them here so that users find errors early before they try to upload to |
78 // the server: | 78 // the server: |
| 79 // TODO(rnystrom): We should split this validation into separate layers: |
| 80 // 1. Stuff that is required in any pubspec to perform any command. Things |
| 81 // like "must have a name". That should go here. |
| 82 // 2. Stuff that is required to upload a package. Things like "homepage |
| 83 // must use a valid scheme". That should go elsewhere. pub upload should |
| 84 // call it, and we should provide a separate command to show the user, |
| 85 // and also expose it to the editor in some way. |
79 | 86 |
80 if (parsedPubspec.containsKey('homepage') && | 87 if (parsedPubspec.containsKey('homepage')) { |
81 parsedPubspec['homepage'] is! String) { | 88 var homepage = parsedPubspec['homepage']; |
82 throw new FormatException( | 89 |
83 'The "homepage" field should be a string, but was ' | 90 if (homepage is! String) { |
84 '${parsedPubspec["homepage"]}.'); | 91 throw new FormatException( |
| 92 'The "homepage" field should be a string, but was "$homepage".'); |
| 93 } |
| 94 |
| 95 var goodScheme = new RegExp(r'^https?:'); |
| 96 if (!goodScheme.hasMatch(homepage)) { |
| 97 throw new FormatException( |
| 98 'The "homepage" field should be an "http:" or "https:" URL, but ' |
| 99 'was "$homepage".'); |
| 100 } |
85 } | 101 } |
86 | 102 |
87 if (parsedPubspec.containsKey('author') && | 103 if (parsedPubspec.containsKey('author') && |
88 parsedPubspec['author'] is! String) { | 104 parsedPubspec['author'] is! String) { |
89 throw new FormatException( | 105 throw new FormatException( |
90 'The "author" field should be a string, but was ' | 106 'The "author" field should be a string, but was ' |
91 '${parsedPubspec["author"]}.'); | 107 '${parsedPubspec["author"]}.'); |
92 } | 108 } |
93 | 109 |
94 if (parsedPubspec.containsKey('authors')) { | 110 if (parsedPubspec.containsKey('authors')) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 } | 177 } |
162 | 178 |
163 source.validateDescription(description, fromLockFile: false); | 179 source.validateDescription(description, fromLockFile: false); |
164 | 180 |
165 dependencies.add(new PackageRef( | 181 dependencies.add(new PackageRef( |
166 name, source, versionConstraint, description)); | 182 name, source, versionConstraint, description)); |
167 }); | 183 }); |
168 | 184 |
169 return dependencies; | 185 return dependencies; |
170 } | 186 } |
OLD | NEW |