| 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; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 * Identifiers that are numeric are converted to numbers. | 180 * Identifiers that are numeric are converted to numbers. |
| 181 */ | 181 */ |
| 182 List _splitParts(String text) { | 182 List _splitParts(String text) { |
| 183 return text.split('.').mappedBy((part) { | 183 return text.split('.').mappedBy((part) { |
| 184 try { | 184 try { |
| 185 return int.parse(part); | 185 return int.parse(part); |
| 186 } on FormatException catch (ex) { | 186 } on FormatException catch (ex) { |
| 187 // Not a number. | 187 // Not a number. |
| 188 return part; | 188 return part; |
| 189 } | 189 } |
| 190 }); | 190 }).toList(); |
| 191 } | 191 } |
| 192 } | 192 } |
| 193 | 193 |
| 194 /** | 194 /** |
| 195 * A [VersionConstraint] is a predicate that can determine whether a given | 195 * A [VersionConstraint] is a predicate that can determine whether a given |
| 196 * version is valid or not. For example, a ">= 2.0.0" constraint allows any | 196 * version is valid or not. For example, a ">= 2.0.0" constraint allows any |
| 197 * version that is "2.0.0" or greater. Version objects themselves implement | 197 * version that is "2.0.0" or greater. Version objects themselves implement |
| 198 * this to match a specific version. | 198 * this to match a specific version. |
| 199 */ | 199 */ |
| 200 interface VersionConstraint default _VersionConstraintFactory { | 200 interface VersionConstraint default _VersionConstraintFactory { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 219 * >2.0.4 <=2.4.6 | 219 * >2.0.4 <=2.4.6 |
| 220 */ | 220 */ |
| 221 VersionConstraint.parse(String text); | 221 VersionConstraint.parse(String text); |
| 222 | 222 |
| 223 /** | 223 /** |
| 224 * Creates a new version constraint that is the intersection of [constraints]. | 224 * Creates a new version constraint that is the intersection of [constraints]. |
| 225 * It will only allow versions that all of those constraints allow. If | 225 * It will only allow versions that all of those constraints allow. If |
| 226 * constraints is empty, then it returns a VersionConstraint that allows all | 226 * constraints is empty, then it returns a VersionConstraint that allows all |
| 227 * versions. | 227 * versions. |
| 228 */ | 228 */ |
| 229 VersionConstraint.intersect(Collection<VersionConstraint> constraints); | 229 VersionConstraint.intersect(Iterable<VersionConstraint> constraints); |
| 230 | 230 |
| 231 /** | 231 /** |
| 232 * Returns `true` if this constraint allows no versions. | 232 * Returns `true` if this constraint allows no versions. |
| 233 */ | 233 */ |
| 234 bool get isEmpty; | 234 bool get isEmpty; |
| 235 | 235 |
| 236 /** | 236 /** |
| 237 * Returns `true` if this constraint allows [version]. | 237 * Returns `true` if this constraint allows [version]. |
| 238 */ | 238 */ |
| 239 bool allows(Version version); | 239 bool allows(Version version); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 // Split it into space-separated parts. | 386 // Split it into space-separated parts. |
| 387 var constraints = <VersionConstraint>[]; | 387 var constraints = <VersionConstraint>[]; |
| 388 for (var part in text.split(' ')) { | 388 for (var part in text.split(' ')) { |
| 389 constraints.add(parseSingleConstraint(part)); | 389 constraints.add(parseSingleConstraint(part)); |
| 390 } | 390 } |
| 391 | 391 |
| 392 return new VersionConstraint.intersect(constraints); | 392 return new VersionConstraint.intersect(constraints); |
| 393 } | 393 } |
| 394 | 394 |
| 395 factory VersionConstraint.intersect( | 395 factory VersionConstraint.intersect( |
| 396 Collection<VersionConstraint> constraints) { | 396 Iterable<VersionConstraint> constraints) { |
| 397 var constraint = new VersionRange(); | 397 var constraint = new VersionRange(); |
| 398 for (var other in constraints) { | 398 for (var other in constraints) { |
| 399 constraint = constraint.intersect(other); | 399 constraint = constraint.intersect(other); |
| 400 } | 400 } |
| 401 return constraint; | 401 return constraint; |
| 402 } | 402 } |
| 403 | 403 |
| 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(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 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 |