Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(697)

Side by Side Diff: utils/pub/pubspec.dart

Issue 12211097: Added support for 'description' in pubspec.yaml. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | utils/tests/pub/pubspec_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 '../../pkg/yaml/lib/yaml.dart'; 7 import '../../pkg/yaml/lib/yaml.dart';
8 import '../../pkg/path/lib/path.dart' as path; 8 import '../../pkg/path/lib/path.dart' as path;
9 9
10 import 'io.dart'; 10 import 'io.dart';
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 // the server: 125 // the server:
126 // TODO(rnystrom): We should split this validation into separate layers: 126 // TODO(rnystrom): We should split this validation into separate layers:
127 // 1. Stuff that is required in any pubspec to perform any command. Things 127 // 1. Stuff that is required in any pubspec to perform any command. Things
128 // like "must have a name". That should go here. 128 // like "must have a name". That should go here.
129 // 2. Stuff that is required to upload a package. Things like "homepage 129 // 2. Stuff that is required to upload a package. Things like "homepage
130 // must use a valid scheme". That should go elsewhere. pub upload should 130 // must use a valid scheme". That should go elsewhere. pub upload should
131 // call it, and we should provide a separate command to show the user, 131 // call it, and we should provide a separate command to show the user,
132 // and also expose it to the editor in some way. 132 // and also expose it to the editor in some way.
133 133
134 if (parsedPubspec.containsKey('homepage')) { 134 if (parsedPubspec.containsKey('homepage')) {
135 var homepage = parsedPubspec['homepage']; 135 _validateFieldUrl(parsedPubspec['homepage'], 'homepage');
136 136 }
137 if (homepage is! String) { 137 if (parsedPubspec.containsKey('documentation')) {
138 throw new FormatException( 138 _validateFieldUrl(parsedPubspec['documentation'], 'documentation');
139 'The "homepage" field should be a string, but was "$homepage".');
140 }
141
142 var goodScheme = new RegExp(r'^https?:');
143 if (!goodScheme.hasMatch(homepage)) {
144 throw new FormatException(
145 'The "homepage" field should be an "http:" or "https:" URL, but '
146 'was "$homepage".');
147 }
148 } 139 }
149 140
150 if (parsedPubspec.containsKey('author') && 141 if (parsedPubspec.containsKey('author') &&
151 parsedPubspec['author'] is! String) { 142 parsedPubspec['author'] is! String) {
152 throw new FormatException( 143 throw new FormatException(
153 'The "author" field should be a string, but was ' 144 'The "author" field should be a string, but was '
154 '${parsedPubspec["author"]}.'); 145 '${parsedPubspec["author"]}.');
155 } 146 }
156 147
157 if (parsedPubspec.containsKey('authors')) { 148 if (parsedPubspec.containsKey('authors')) {
(...skipping 12 matching lines...) Expand all
170 if (parsedPubspec.containsKey('author')) { 161 if (parsedPubspec.containsKey('author')) {
171 throw new FormatException('A pubspec should not have both an "author" ' 162 throw new FormatException('A pubspec should not have both an "author" '
172 'and an "authors" field.'); 163 'and an "authors" field.');
173 } 164 }
174 } 165 }
175 166
176 return new Pubspec(name, version, dependencies, environment, parsedPubspec); 167 return new Pubspec(name, version, dependencies, environment, parsedPubspec);
177 } 168 }
178 } 169 }
179 170
171 /**
172 * Evaluates whether the given [url] for [field] is valid.
173 *
174 * Throws [FormatException] on an invalid url.
175 */
176 void _validateFieldUrl(url, String field) {
177 if (url is! String) {
178 throw new FormatException(
179 'The "$field" field should be a string, but was "$url".');
180 }
181
182 var goodScheme = new RegExp(r'^https?:');
183 if (!goodScheme.hasMatch(url)) {
184 throw new FormatException(
185 'The "$field" field should be an "http:" or "https:" URL, but '
186 'was "$url".');
187 }
188 }
189
180 List<PackageRef> _parseDependencies(SourceRegistry sources, yaml) { 190 List<PackageRef> _parseDependencies(SourceRegistry sources, yaml) {
181 var dependencies = <PackageRef>[]; 191 var dependencies = <PackageRef>[];
182 192
183 // Allow an empty dependencies key. 193 // Allow an empty dependencies key.
184 if (yaml == null) return dependencies; 194 if (yaml == null) return dependencies;
185 195
186 if (yaml is! Map || yaml.keys.any((e) => e is! String)) { 196 if (yaml is! Map || yaml.keys.any((e) => e is! String)) {
187 throw new FormatException( 197 throw new FormatException(
188 'The pubspec dependencies should be a map of package names, but ' 198 'The pubspec dependencies should be a map of package names, but '
189 'was ${yaml}.'); 199 'was ${yaml}.');
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 /// The environment-related metadata in the pubspec. Corresponds to the data 245 /// The environment-related metadata in the pubspec. Corresponds to the data
236 /// under the "environment:" key in the pubspec. 246 /// under the "environment:" key in the pubspec.
237 class PubspecEnvironment { 247 class PubspecEnvironment {
238 /// The version constraint specifying which SDK versions this package works 248 /// The version constraint specifying which SDK versions this package works
239 /// with. 249 /// with.
240 final VersionConstraint sdkVersion; 250 final VersionConstraint sdkVersion;
241 251
242 PubspecEnvironment([VersionConstraint sdk]) 252 PubspecEnvironment([VersionConstraint sdk])
243 : sdkVersion = sdk != null ? sdk : VersionConstraint.any; 253 : sdkVersion = sdk != null ? sdk : VersionConstraint.any;
244 } 254 }
OLDNEW
« no previous file with comments | « no previous file | utils/tests/pub/pubspec_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698