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

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

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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/validator/name.dart ('k') | utils/pub/version_solver.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 /// Handles version numbers, following the [Semantic Versioning][semver] spec. 5 /// Handles version numbers, following the [Semantic Versioning][semver] spec.
6 /// 6 ///
7 /// [semver]: http://semver.org/ 7 /// [semver]: http://semver.org/
8 library version; 8 library version;
9 9
10 import 'dart:math'; 10 import 'dart:math';
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 } 50 }
51 51
52 /// Creates a new [Version] by parsing [text]. 52 /// Creates a new [Version] by parsing [text].
53 factory Version.parse(String text) { 53 factory Version.parse(String text) {
54 final match = _PARSE_REGEX.firstMatch(text); 54 final match = _PARSE_REGEX.firstMatch(text);
55 if (match == null) { 55 if (match == null) {
56 throw new FormatException('Could not parse "$text".'); 56 throw new FormatException('Could not parse "$text".');
57 } 57 }
58 58
59 try { 59 try {
60 int major = parseInt(match[1]); 60 int major = int.parse(match[1]);
61 int minor = parseInt(match[2]); 61 int minor = int.parse(match[2]);
62 int patch = parseInt(match[3]); 62 int patch = int.parse(match[3]);
63 63
64 String preRelease = match[5]; 64 String preRelease = match[5];
65 String build = match[8]; 65 String build = match[8];
66 66
67 return new Version(major, minor, patch, pre: preRelease, build: build); 67 return new Version(major, minor, patch, pre: preRelease, build: build);
68 } on FormatException catch (ex) { 68 } on FormatException catch (ex) {
69 throw new FormatException('Could not parse "$text".'); 69 throw new FormatException('Could not parse "$text".');
70 } 70 }
71 } 71 }
72 72
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 return aPart.compareTo(bPart); 183 return aPart.compareTo(bPart);
184 } 184 }
185 } 185 }
186 } 186 }
187 } 187 }
188 } 188 }
189 189
190 /// Splits a string of dot-delimited identifiers into their component parts. 190 /// Splits a string of dot-delimited identifiers into their component parts.
191 /// Identifiers that are numeric are converted to numbers. 191 /// Identifiers that are numeric are converted to numbers.
192 List _splitParts(String text) { 192 List _splitParts(String text) {
193 return text.split('.').map((part) { 193 return text.split('.').mappedBy((part) {
194 try { 194 try {
195 return parseInt(part); 195 return int.parse(part);
196 } on FormatException catch (ex) { 196 } on FormatException catch (ex) {
197 // Not a number. 197 // Not a number.
198 return part; 198 return part;
199 } 199 }
200 }); 200 }).toList();
201 } 201 }
202 } 202 }
203 203
204 /// A [VersionConstraint] is a predicate that can determine whether a given 204 /// A [VersionConstraint] is a predicate that can determine whether a given
205 /// version is valid or not. For example, a ">= 2.0.0" constraint allows any 205 /// version is valid or not. For example, a ">= 2.0.0" constraint allows any
206 /// version that is "2.0.0" or greater. Version objects themselves implement 206 /// version that is "2.0.0" or greater. Version objects themselves implement
207 /// this to match a specific version. 207 /// this to match a specific version.
208 abstract class VersionConstraint { 208 abstract class VersionConstraint {
209 /// A [VersionConstraint] that allows no versions: i.e. the empty set. 209 /// A [VersionConstraint] that allows no versions: i.e. the empty set.
210 factory VersionConstraint.empty() => const _EmptyVersion(); 210 factory VersionConstraint.empty() => const _EmptyVersion();
(...skipping 23 matching lines...) Expand all
234 } 234 }
235 235
236 return new VersionConstraint.intersection(constraints); 236 return new VersionConstraint.intersection(constraints);
237 } 237 }
238 238
239 /// Creates a new version constraint that is the intersection of 239 /// Creates a new version constraint that is the intersection of
240 /// [constraints]. It will only allow versions that all of those constraints 240 /// [constraints]. It will only allow versions that all of those constraints
241 /// allow. If constraints is empty, then it returns a VersionConstraint that 241 /// allow. If constraints is empty, then it returns a VersionConstraint that
242 /// allows all versions. 242 /// allows all versions.
243 factory VersionConstraint.intersection( 243 factory VersionConstraint.intersection(
244 Collection<VersionConstraint> constraints) { 244 Iterable<VersionConstraint> constraints) {
245 var constraint = new VersionRange(); 245 var constraint = new VersionRange();
246 for (var other in constraints) { 246 for (var other in constraints) {
247 constraint = constraint.intersect(other); 247 constraint = constraint.intersect(other);
248 } 248 }
249 return constraint; 249 return constraint;
250 } 250 }
251 251
252 /// Returns `true` if this constraint allows no versions. 252 /// Returns `true` if this constraint allows no versions.
253 bool get isEmpty; 253 bool get isEmpty;
254 254
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 412
413 class _EmptyVersion implements VersionConstraint { 413 class _EmptyVersion implements VersionConstraint {
414 const _EmptyVersion(); 414 const _EmptyVersion();
415 415
416 bool get isEmpty => true; 416 bool get isEmpty => true;
417 bool get isAny => false; 417 bool get isAny => false;
418 bool allows(Version other) => false; 418 bool allows(Version other) => false;
419 VersionConstraint intersect(VersionConstraint other) => this; 419 VersionConstraint intersect(VersionConstraint other) => this;
420 String toString() => '<empty>'; 420 String toString() => '<empty>';
421 } 421 }
OLDNEW
« no previous file with comments | « utils/pub/validator/name.dart ('k') | utils/pub/version_solver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698