private static IEnumerable <Package> GetUpdates( IEnumerable <Package> packages, ILookup <string, Tuple <SemanticVersion, IVersionSpec> > versionLookup, IEnumerable <FrameworkName> targetFrameworkValues, bool includeAllVersions) { var updates = from p in packages.AsEnumerable() let version = SemanticVersion.Parse(p.Version) where versionLookup[p.PackageRegistration.Id] .Any(versionTuple => { SemanticVersion clientVersion = versionTuple.Item1; var supportedPackageFrameworks = p.SupportedFrameworks.Select(f => f.FrameworkName); IVersionSpec versionConstraint = versionTuple.Item2; return((version > clientVersion) && (targetFrameworkValues == null || targetFrameworkValues.Any(s => VersionUtility.IsCompatible(s, supportedPackageFrameworks))) && (versionConstraint == null || versionConstraint.Satisfies(version))); }) select p; if (!includeAllVersions) { updates = updates.GroupBy(p => p.PackageRegistration.Id) .Select(g => g.OrderByDescending(p => SemanticVersion.Parse(p.Version)).First()); } return(updates); }
public void SatisfiesReturnsExpectedValues(string verSpec, string semVer, bool expected) { // Arrange IVersionSpec spec = VersionUtility.ParseVersionSpec(verSpec); // Act/Assert Assert.Equal(expected, spec.Satisfies(new SemanticVersion(semVer))); }
private static bool IsVersionConstraintSatisfied(PackageItem item, IPackageRepository localRepository) { // honors the version constraint set in the allowedVersion attribute of packages.config file var constraintProvider = localRepository as IPackageConstraintProvider; if (constraintProvider != null) { IVersionSpec constraint = constraintProvider.GetConstraint(item.Id); if (constraint != null && !constraint.Satisfies(item.PackageIdentity.Version)) { return(false); } } return(true); }
public IPackage InstallPackage(PackageManager packageManager, bool updatePackages) { using (Trace.WithIndent().Verbose("Installing package {0}{1} from {2}", _packageId, _versionSpec == null ? string.Empty : " " + _versionSpec, packageManager.SourceRepository.Source)) { // Find the local package IPackage localPackage = packageManager.LocalRepository.FindPackage(_packageId); // Check if we're up to date if (localPackage != null && _versionSpec.Satisfies(localPackage.Version) && !updatePackages) { Trace.Verbose("Package {0}{1} is satisfied by version {2}, skipping", _packageId, _versionSpec == null ? string.Empty : " " + _versionSpec, localPackage.Version); return(localPackage); } // Find the source package IPackage sourcePackage = packageManager.SourceRepository .FindPackage(_packageId, _versionSpec, _allowPrereleaseVersions, _allowUnlisted); if (sourcePackage == null) { Trace.Warning("Package {0} {1} could not be found at {2}", _packageId, _versionSpec == null ? string.Empty : " " + _versionSpec, packageManager.SourceRepository.Source); return(null); } // Check if we're up to date if (localPackage != null && localPackage.Version >= sourcePackage.Version) { Trace.Verbose("Package {0}{1} is up to date with version {2}, skipping", _packageId, _versionSpec == null ? string.Empty : " " + _versionSpec, localPackage.Version); return(localPackage); } // Uninstall the old package if (localPackage != null) { packageManager.UninstallPackage(localPackage, true); Trace.Verbose("Uninstalled package {0} {1}", localPackage.Id, localPackage.Version); } // Install it packageManager.InstallPackage(sourcePackage, false, _allowPrereleaseVersions); Trace.Verbose("Installed package {0} {1}", sourcePackage.Id, sourcePackage.Version); return(sourcePackage); } }
private static IEnumerable <Package> GetUpdates( IEnumerable <Package> packages, Dictionary <string, Tuple <SemanticVersion, IVersionSpec> > versionLookup, IEnumerable <FrameworkName> targetFrameworkValues, bool includeAllVersions) { var updates = packages.AsEnumerable() .Where( p => { // For each package, if the version is higher than the client version and we satisty the target framework, return it. // TODO: We could optimize for the includeAllVersions case here by short circuiting the operation once we've encountered the highest version // for a given Id var version = SemanticVersion.Parse(p.Version); Tuple <SemanticVersion, IVersionSpec> versionTuple; if (versionLookup.TryGetValue(p.PackageRegistration.Id, out versionTuple)) { SemanticVersion clientVersion = versionTuple.Item1; var supportedPackageFrameworks = p.SupportedFrameworks.Select(f => f.FrameworkName); IVersionSpec versionConstraint = versionTuple.Item2; return((version > clientVersion) && (targetFrameworkValues == null || targetFrameworkValues.Any(s => VersionUtility.IsCompatible(s, supportedPackageFrameworks))) && (versionConstraint == null || versionConstraint.Satisfies(version))); } return(false); }); if (!includeAllVersions) { return(updates.GroupBy(p => p.PackageRegistration.Id) .Select(g => g.OrderByDescending(p => SemanticVersion.Parse(p.Version)).First())); } return(updates); }
public static bool IsSatisfiedBy(this IVersionSpec versionSpec, SemanticVersion version) { return(versionSpec.Satisfies(version)); }
public bool SatisfiesVersionSpec(IVersionSpec versionSpec) { return(versionSpec.Satisfies(this.Version)); }