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

Unified Diff: utils/pub/version.dart

Issue 11635060: Add a validator for dependency version constraints. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 8 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « utils/pub/validator/dependency.dart ('k') | utils/tests/pub/test_pub.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/version.dart
diff --git a/utils/pub/version.dart b/utils/pub/version.dart
index 50174cc40cb6f676821ea71c7f9778d1746b341e..346b372141f0064c1d6e1a6160843233acca0695 100644
--- a/utils/pub/version.dart
+++ b/utils/pub/version.dart
@@ -74,6 +74,20 @@ class Version implements Comparable, VersionConstraint {
}
}
+ /// Returns the primary version out of a list of candidates. This is the
+ /// highest-numbered stable (non-prerelease) version. If there are no stable
+ /// versions, it's just the highest-numbered version.
+ static Version primary(List<Version> versions) {
+ var primary;
+ for (var version in versions) {
+ if (primary == null || (!version.isPreRelease && primary.isPreRelease) ||
+ (version.isPreRelease == primary.isPreRelease && version > primary)) {
+ primary = version;
+ }
+ }
+ return primary;
+ }
+
bool operator ==(other) {
if (other is! Version) return false;
return compareTo(other) == 0;
@@ -84,8 +98,12 @@ class Version implements Comparable, VersionConstraint {
bool operator <=(Version other) => compareTo(other) <= 0;
bool operator >=(Version other) => compareTo(other) >= 0;
+ bool get isAny => false;
bool get isEmpty => false;
+ /// Whether or not this is a pre-release version.
+ bool get isPreRelease => preRelease != null;
+
/** Tests if [other] matches this version exactly. */
bool allows(Version other) => this == other;
@@ -252,6 +270,9 @@ abstract class VersionConstraint {
*/
bool get isEmpty;
+ /// Returns `true` if this constraint allows all versions.
+ bool get isAny;
+
/**
* Returns `true` if this constraint allows [version].
*/
@@ -321,6 +342,8 @@ class VersionRange implements VersionConstraint {
bool get isEmpty => false;
+ bool get isAny => !includeMin && !includeMax;
+
/** Tests if [other] matches falls within this version range. */
bool allows(Version other) {
if (min != null && other < min) return false;
@@ -415,6 +438,7 @@ class _EmptyVersion implements VersionConstraint {
const _EmptyVersion();
bool get isEmpty => true;
+ bool get isAny => false;
bool allows(Version other) => false;
VersionConstraint intersect(VersionConstraint other) => this;
String toString() => '<empty>';
« no previous file with comments | « utils/pub/validator/dependency.dart ('k') | utils/tests/pub/test_pub.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698