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 /** | 5 /** |
6 * Handles version numbers, following the [Semantic Versioning][semver] spec. | 6 * Handles version numbers, following the [Semantic Versioning][semver] spec. |
7 * | 7 * |
8 * [semver]: http://semver.org/ | 8 * [semver]: http://semver.org/ |
9 */ | 9 */ |
10 library version; | 10 library version; |
11 | 11 |
12 import 'dart:math'; | 12 import 'dart:math'; |
13 | 13 |
14 import 'utils.dart'; | 14 import 'utils.dart'; |
15 | 15 |
16 /** A parsed semantic version number. */ | 16 /** A parsed semantic version number. */ |
17 class Version implements Comparable, VersionConstraint { | 17 class Version implements Comparable, VersionConstraint { |
18 /** No released version: i.e. "0.0.0". */ | 18 /** No released version: i.e. "0.0.0". */ |
19 static Version get none => new Version(0, 0, 0); | 19 static Version get none => new Version(0, 0, 0); |
20 | 20 |
21 static final _PARSE_REGEX = new RegExp( | 21 static const _PARSE_REGEX = const RegExp( |
22 r'^' // Start at beginning. | 22 r'^' // Start at beginning. |
23 r'(\d+).(\d+).(\d+)' // Version number. | 23 r'(\d+).(\d+).(\d+)' // Version number. |
24 r'(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?' // Pre-release. | 24 r'(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?' // Pre-release. |
25 r'(\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?' // Build. | 25 r'(\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?' // Build. |
26 r'$'); // Consume entire string. | 26 r'$'); // Consume entire string. |
27 | 27 |
28 /** The major version number: "1" in "1.2.3". */ | 28 /** The major version number: "1" in "1.2.3". */ |
29 final int major; | 29 final int major; |
30 | 30 |
31 /** The minor version number: "2" in "1.2.3". */ | 31 /** The minor version number: "2" in "1.2.3". */ |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 static VersionConstraint parseSingleConstraint(String text) { | 404 static VersionConstraint parseSingleConstraint(String text) { |
405 if (text == 'any') { | 405 if (text == 'any') { |
406 return new VersionRange(); | 406 return new VersionRange(); |
407 } | 407 } |
408 | 408 |
409 // TODO(rnystrom): Consider other syntaxes for version constraints. This | 409 // TODO(rnystrom): Consider other syntaxes for version constraints. This |
410 // one is whitespace sensitive (you can't do "< 1.2.3") and "<" is | 410 // one is whitespace sensitive (you can't do "< 1.2.3") and "<" is |
411 // unfortunately meaningful in YAML, requiring it to be quoted in a | 411 // unfortunately meaningful in YAML, requiring it to be quoted in a |
412 // pubspec. | 412 // pubspec. |
413 // See if it's a comparison operator followed by a version, like ">1.2.3". | 413 // See if it's a comparison operator followed by a version, like ">1.2.3". |
414 var match = new RegExp(r"^([<>]=?)?(.*)$").firstMatch(text); | 414 var match = const RegExp(r"^([<>]=?)?(.*)$").firstMatch(text); |
415 if (match != null) { | 415 if (match != null) { |
416 var comparison = match[1]; | 416 var comparison = match[1]; |
417 var version = new Version.parse(match[2]); | 417 var version = new Version.parse(match[2]); |
418 switch (match[1]) { | 418 switch (match[1]) { |
419 case '<=': return new VersionRange(max: version, includeMax: true); | 419 case '<=': return new VersionRange(max: version, includeMax: true); |
420 case '<': return new VersionRange(max: version, includeMax: false); | 420 case '<': return new VersionRange(max: version, includeMax: false); |
421 case '>=': return new VersionRange(min: version, includeMin: true); | 421 case '>=': return new VersionRange(min: version, includeMin: true); |
422 case '>': return new VersionRange(min: version, includeMin: false); | 422 case '>': return new VersionRange(min: version, includeMin: false); |
423 } | 423 } |
424 } | 424 } |
425 | 425 |
426 // Otherwise, it must be an explicit version. | 426 // Otherwise, it must be an explicit version. |
427 return new Version.parse(text); | 427 return new Version.parse(text); |
428 } | 428 } |
429 } | 429 } |
OLD | NEW |