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

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

Issue 10874051: Support self-referential package: imports with Pub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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
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('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');
11 #import('version.dart'); 11 #import('version.dart');
12 #import('yaml/yaml.dart'); 12 #import('yaml/yaml.dart');
13 13
14 /** 14 /**
15 * The parsed and validated contents of a pubspec file. 15 * The parsed and validated contents of a pubspec file.
16 */ 16 */
17 class Pubspec { 17 class Pubspec {
18 /** 18 /**
19 * This package's name.
20 */
21 final String name;
22
23 /**
19 * This package's version. 24 * This package's version.
20 */ 25 */
21 final Version version; 26 final Version version;
22 27
23 /** 28 /**
24 * The packages this package depends on. 29 * The packages this package depends on.
25 */ 30 */
26 List<PackageRef> dependencies; 31 List<PackageRef> dependencies;
27 32
28 Pubspec(this.version, this.dependencies); 33 Pubspec(this.name, this.version, this.dependencies);
29 34
30 Pubspec.empty() 35 Pubspec.empty()
31 : version = Version.none, 36 : name = null,
37 version = Version.none,
32 dependencies = <PackageRef>[]; 38 dependencies = <PackageRef>[];
33 39
40 /** Whether or not the pubspec has no contents. */
41 bool get isEmpty() =>
42 name == null && version == Version.none && dependencies.isEmpty();
43
34 /** 44 /**
35 * Parses the pubspec whose text is [contents]. If the pubspec doesn't define 45 * Parses the pubspec whose text is [contents]. If the pubspec doesn't define
36 * version for itself, it defaults to [Version.none]. 46 * version for itself, it defaults to [Version.none].
37 */ 47 */
38 factory Pubspec.parse(String contents, SourceRegistry sources) { 48 factory Pubspec.parse(String contents, SourceRegistry sources) {
49 var name = null;
39 var version = Version.none; 50 var version = Version.none;
40 var dependencies = <PackageRef>[]; 51 var dependencies = <PackageRef>[];
41 52
42 if (contents.trim() == '') return new Pubspec.empty(); 53 if (contents.trim() == '') return new Pubspec.empty();
43 54
44 var parsedPubspec = loadYaml(contents); 55 var parsedPubspec = loadYaml(contents);
45 if (parsedPubspec == null) return new Pubspec.empty(); 56 if (parsedPubspec == null) return new Pubspec.empty();
46 57
47 if (parsedPubspec is! Map) { 58 if (parsedPubspec is! Map) {
48 throw new FormatException('The pubspec must be a YAML mapping.'); 59 throw new FormatException('The pubspec must be a YAML mapping.');
49 } 60 }
50 61
62 if (parsedPubspec.containsKey('name')) name = parsedPubspec['name'];
63
51 if (parsedPubspec.containsKey('version')) { 64 if (parsedPubspec.containsKey('version')) {
52 version = new Version.parse(parsedPubspec['version']); 65 version = new Version.parse(parsedPubspec['version']);
53 } 66 }
54 67
55 if (parsedPubspec.containsKey('dependencies')) { 68 if (parsedPubspec.containsKey('dependencies')) {
56 var dependencyEntries = parsedPubspec['dependencies']; 69 var dependencyEntries = parsedPubspec['dependencies'];
57 if (dependencyEntries is! Map || 70 if (dependencyEntries is! Map ||
58 dependencyEntries.getKeys().some((e) => e is! String)) { 71 dependencyEntries.getKeys().some((e) => e is! String)) {
59 throw new FormatException( 72 throw new FormatException(
60 'The pubspec dependencies must be a map of package names.'); 73 'The pubspec dependencies must be a map of package names.');
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 'Dependency specification $spec must be a string or a mapping.'); 108 'Dependency specification $spec must be a string or a mapping.');
96 } 109 }
97 110
98 source.validateDescription(description, fromLockFile: false); 111 source.validateDescription(description, fromLockFile: false);
99 112
100 dependencies.add(new PackageRef( 113 dependencies.add(new PackageRef(
101 source, versionConstraint, description)); 114 source, versionConstraint, description));
102 }); 115 });
103 } 116 }
104 117
105 return new Pubspec(version, dependencies); 118 return new Pubspec(name, version, dependencies);
106 } 119 }
107 } 120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698