public override async Task <Stream> GetStream(PackageIdentity identity, CancellationToken token) { Stream result = null; IPackage package = null; SemanticVersion version = SemanticVersion.Parse(identity.Version.ToString()); // attempt a normal lookup first if (!V2Client.TryFindPackage(identity.Id, version, out package)) { // skip further look ups for online repos DataServicePackageRepository v2Online = V2Client as DataServicePackageRepository; if (v2Online == null) { IVersionComparer versionComparer = VersionComparer.VersionRelease; // otherwise search further to find the package - this is needed for v2 non-normalized versions V2Client.FindPackagesById(identity.Id).Any(p => versionComparer.Equals(identity.Version, NuGetVersion.Parse(p.ToString()))); } } if (package != null) { result = package.GetStream(); } return(result); }
/// <summary> /// Checks if two version ranges are equivalent. This follows the rules of the version comparer /// when checking the bounds. /// </summary> public bool Equals(VersionRangeBase x, VersionRangeBase y) { // same object if (Object.ReferenceEquals(x, y)) { return(true); } // null checks if (Object.ReferenceEquals(y, null) || Object.ReferenceEquals(x, null)) { return(false); } return(x.IncludePrerelease == y.IncludePrerelease && x.IsMinInclusive == y.IsMinInclusive && y.IsMaxInclusive == x.IsMaxInclusive && _versionComparer.Equals(y.MinVersion, x.MinVersion) && _versionComparer.Equals(y.MaxVersion, x.MaxVersion)); }
private static bool EqualsOneWay(IVersionComparer comparer, string version1, string version2) { // Arrange var a = NuGetVersion.Parse(version1); var b = NuGetVersion.Parse(version2); SemanticVersion c = NuGetVersion.Parse(version1); SemanticVersion d = NuGetVersion.Parse(version2); // Act var match = Compare(comparer, version1, version2) == 0; match &= comparer.Equals(a, b); match &= comparer.Equals(a, d); match &= comparer.Equals(c, d); match &= comparer.Equals(c, b); return(match); }
/// <summary> /// Checks if two version ranges are equivalent. This follows the rules of the version comparer /// when checking the bounds. /// </summary> public bool Equals(VersionRangeBase x, VersionRangeBase y) { if (ReferenceEquals(x, y)) { return(true); } if (ReferenceEquals(y, null) || ReferenceEquals(x, null)) { return(false); } return(x.IsMinInclusive == y.IsMinInclusive && y.IsMaxInclusive == x.IsMaxInclusive && _versionComparer.Equals(y.MinVersion, x.MinVersion) && _versionComparer.Equals(y.MaxVersion, x.MaxVersion)); }
private static bool EqualsOneWayWithNuGetVersion(IVersionComparer comparer, string version1, string version2) { // Arrange var a = NuGetVersion.Parse(version1); var b = NuGetVersion.Parse(version2); // Act var match = comparer.Compare(a, b) == 0; match &= comparer.Equals(a, b); match &= comparer.GetHashCode(a) == comparer.GetHashCode(b); return(match); }
/// <summary> /// True if the package identities are the same when ignoring build metadata. /// </summary> public bool Equals(PackageIdentity x, PackageIdentity y) { if (Object.ReferenceEquals(x, y)) { return(true); } if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null)) { return(false); } return(_versionComparer.Equals(x.Version, y.Version) && StringComparer.OrdinalIgnoreCase.Equals(x.Id, y.Id)); }
public int Compare(ResolverPackage x, ResolverPackage y) { if (Object.ReferenceEquals(x, y)) { return(0); } Debug.Assert(string.Equals(x.Id, y.Id, StringComparison.OrdinalIgnoreCase)); // The absent package comes first in the sort order var isXAbsent = x.Absent; var isYAbsent = y.Absent; if (isXAbsent && !isYAbsent) { return(-1); } if (!isXAbsent && isYAbsent) { return(1); } if (isXAbsent && isYAbsent) { return(0); } if (_preferredVersions != null) { //Already installed packages come next in the sort order. var xInstalled = _preferredVersions.Contains(x, _identityComparer); var yInstalled = _preferredVersions.Contains(y, _identityComparer); if (xInstalled && !yInstalled) { return(-1); } if (!xInstalled && yInstalled) { return(1); } } //Prefer listed packages over unlisted if (x.Listed && !y.Listed) { return(-1); } if (!x.Listed && y.Listed) { return(1); } var xv = x.Version; var yv = y.Version; var packageBehavior = _dependencyBehavior; // for new packages use the highest version if (_targetIds.Contains(x.Id, StringComparer.OrdinalIgnoreCase)) { packageBehavior = DependencyBehavior.Highest; } // stay as close to the installed version as possible // Choose upgrades over downgrades // For downgrades choose the highest version // // Example: // 1.0.0 // 1.1.0 // 2.0.0 - installed // 2.1.0 // 3.0.0 // Order: 2.0.0, 2.1.0, 3.0.0, 1.1.0, 1.0.0 if (packageBehavior != DependencyBehavior.Highest && packageBehavior != DependencyBehavior.Ignore) { NuGetVersion installedVersion = null; if (_installedVersions.TryGetValue(x.Id, out installedVersion)) { var xvDowngrade = _versionComparer.Compare(xv, installedVersion) < 0; var yvDowngrade = _versionComparer.Compare(yv, installedVersion) < 0; // the upgrade is preferred over the downgrade if (xvDowngrade && !yvDowngrade) { return(1); } else if (!xvDowngrade && yvDowngrade) { return(-1); } else if (xvDowngrade && yvDowngrade) { // when both are downgrades prefer the highest return(-1 * _versionComparer.Compare(xv, yv)); } } } // Normal switch (packageBehavior) { case DependencyBehavior.Lowest: { return(_versionComparer.Compare(xv, yv)); } case DependencyBehavior.Ignore: case DependencyBehavior.Highest: return(-1 * _versionComparer.Compare(xv, yv)); case DependencyBehavior.HighestMinor: { if (_versionComparer.Equals(xv, yv)) { return(0); } // Take the lowest Major, then the Highest Minor and Patch return(new[] { x, y }.OrderBy(p => p.Version.Major) .ThenByDescending(p => p.Version.Minor) .ThenByDescending(p => p.Version.Patch).FirstOrDefault() == x ? -1 : 1); } case DependencyBehavior.HighestPatch: { if (_versionComparer.Equals(xv, yv)) { return(0); } // Take the lowest Major and Minor, then the Highest Patch return(new[] { x, y }.OrderBy(p => p.Version.Major) .ThenBy(p => p.Version.Minor) .ThenByDescending(p => p.Version.Patch).FirstOrDefault() == x ? -1 : 1); } default: return(_versionComparer.Compare(xv, yv)); } }
/// <summary> /// SubSet check /// </summary> public bool IsSubSetOrEqualTo(VersionRangeBase possibleSuperSet, IVersionComparer comparer) { VersionRangeComparer rangeComparer = new VersionRangeComparer(comparer); VersionRangeBase possibleSubSet = this; VersionRangeBase target = possibleSuperSet; if (rangeComparer.Equals(possibleSubSet, VersionRange.None)) { return(true); } if (rangeComparer.Equals(target, VersionRange.None)) { return(false); } if (target == null) { target = VersionRange.All; } if (possibleSubSet == null) { possibleSubSet = VersionRange.All; } bool result = true; if (possibleSubSet.IncludePrerelease && !target.IncludePrerelease) { result = false; } if (possibleSubSet.HasLowerBound) { // normal check if (!target.Satisfies(possibleSubSet.MinVersion)) { // it's possible we didn't need that version, do a special non inclusive check if (!possibleSubSet.IsMinInclusive && !target.IsMinInclusive) { result &= comparer.Equals(target.MinVersion, possibleSubSet.MinVersion); } else { result = false; } } } else { result &= !target.HasLowerBound; } if (possibleSubSet.HasUpperBound) { // normal check if (!target.Satisfies(possibleSubSet.MaxVersion)) { // it's possible we didn't need that version, do a special non inclusive check if (!possibleSubSet.IsMaxInclusive && !target.IsMaxInclusive) { result &= comparer.Equals(target.MaxVersion, possibleSubSet.MaxVersion); } else { result = false; } } } else { result &= !target.HasUpperBound; } return(result); }
private static bool EqualsOneWay(IVersionComparer comparer, string version1, string version2) { // Arrange var a = NuGetVersion.Parse(version1); var b = NuGetVersion.Parse(version2); SemanticVersion c = NuGetVersion.Parse(version1); SemanticVersion d = NuGetVersion.Parse(version2); // Act var match = Compare(comparer, version1, version2) == 0; match &= comparer.Equals(a, b); match &= comparer.Equals(a, d); match &= comparer.Equals(c, d); match &= comparer.Equals(c, b); return match; }