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

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

Issue 10540151: First pass at version constraint solver. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Request all versions from the source, and not just the best. Created 8 years, 6 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 | « utils/pub/package.dart ('k') | utils/pub/source.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('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 version. 19 * This package's version.
20 */ 20 */
21 final Version version; 21 final Version version;
22 22
23 /** 23 /**
24 * The packages this package depends on. 24 * The packages this package depends on.
25 */ 25 */
26 List<PackageRef> dependencies; 26 List<PackageRef> dependencies;
27 27
28 Pubspec._(this.version, this.dependencies); 28 Pubspec(this.version, this.dependencies);
29 29
30 Pubspec.empty() 30 Pubspec.empty()
31 : version = Version.none, 31 : version = Version.none,
32 dependencies = <PackageRef>[]; 32 dependencies = <PackageRef>[];
33 33
34 /** 34 /**
35 * Parses the pubspec whose text is [contents]. If the pubspec doesn't define 35 * Parses the pubspec whose text is [contents]. If the pubspec doesn't define
36 * version for itself, it defaults to [Version.none]. 36 * version for itself, it defaults to [Version.none].
37 */ 37 */
38 factory Pubspec.parse(String contents, SourceRegistry sources) { 38 factory Pubspec.parse(String contents, SourceRegistry sources) {
(...skipping 13 matching lines...) Expand all
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 }
OLDNEW
« no previous file with comments | « utils/pub/package.dart ('k') | utils/pub/source.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698