public static async Task <FeedVersion> GetLatestVersion(
            this PackageReference reference,
            CancellationToken ct,
            UpdaterParameters parameters
            )
        {
            if (parameters.VersionOverrides.TryGetValue(reference.Identity.Id, out var manualVersion) && manualVersion.forceVersion)
            {
                PackageFeed.Logger.LogInformation($"Overriding version for {reference.Identity.Id}");
                return(new FeedVersion(manualVersion.range.MinVersion));
            }

            var availableVersions = await Task.WhenAll(parameters
                                                       .Feeds
                                                       .Select(f => f.GetPackageVersions(ct, reference, parameters.PackageAuthor))
                                                       );

            var versionsPerTarget = availableVersions
                                    .SelectMany(x => x)
                                    .Where(v => manualVersion.range?.Satisfies(v.Version) ?? true)
                                    .OrderByDescending(v => v)
                                    .GroupBy(version => parameters.TargetVersions.FirstOrDefault(t => version.IsMatchingVersion(t, parameters.Strict)))
                                    .Where(g => g.Key.HasValue());

            return(versionsPerTarget
                   .Select(g => g.FirstOrDefault())
                   .OrderByDescending(v => v.Version)
                   .FirstOrDefault());
        }
Exemplo n.º 2
0
        internal NuGetUpdater(UpdaterParameters parameters, UpdaterLogger log)
        {
            _parameters = parameters.Validate();
            _log        = log;

            PackageFeed.Logger = _log;
        }
        public static UpdaterParameters Validate(this UpdaterParameters parameters)
        {
            if (parameters.SolutionRoot.IsNullOrEmpty())
            {
                throw new InvalidOperationException("The solution root must be specified");
            }

            return(parameters);
        }
Exemplo n.º 4
0
        public static async Task <IEnumerable <UpdateResult> > UpdateAsync(
            CancellationToken ct,
            UpdaterParameters parameters,
            TextWriter logWriter     = null,
            TextWriter summaryWriter = null
            )
        {
            var updater = new NuGetUpdater(parameters, logWriter, summaryWriter);

            return(await updater.UpdatePackages(ct));
        }
        /// <summary>
        /// Gets the latest version for the given reference by looking up first in a list of known packages.
        /// Useful in the cases where refernces to multiple versions of the same packages are found.
        /// </summary>
        public static async Task <FeedVersion> GetLatestVersion(
            this PackageReference reference,
            CancellationToken ct,
            IEnumerable <UpdaterPackage> knownPackages,
            UpdaterParameters parameters
            )
        {
            var knownVersion = knownPackages.FirstOrDefault(p => p.PackageId == reference.Identity.Id)?.Version;

            if (knownVersion == null)
            {
                knownVersion = await reference.GetLatestVersion(ct, parameters);
            }

            return(knownVersion);
        }
        public async Task GivenPackageWithNoMatchingVersion_NoVersionIsFound()
        {
            var parameters = new UpdaterParameters
            {
                TargetVersions = { "stable" },
            };

            var packageVersion = "1.0-beta.1";
            var packageId      = "nventive.NuGet.Updater";

            var reference = new PackageReference(packageId, packageVersion);

            var version = await reference.GetLatestVersion(CancellationToken.None, parameters);

            Assert.IsNull(version);
        }
Exemplo n.º 7
0
        public async Task GivenUnspecifiedTarget_NoUpdateIsMade()
        {
            var parameters = new UpdaterParameters
            {
                SolutionRoot   = "MySolution.sln",
                UpdateTarget   = FileType.Unspecified,
                TargetVersions = { "stable" },
                Feeds          = { TestFeed },
            };

            var logger = new UpdaterLogger(Console.Out);

            var updater = new NuGetUpdater(parameters, logger);

            await updater.UpdatePackages(CancellationToken.None);

            Assert.IsTrue(logger.GetUpdates().None());
        }
        public async Task GivenPackageWithMatchingVersion_VersionIsFound()
        {
            var parameters = new UpdaterParameters
            {
                TargetVersions = { "beta" },
                Feeds          = { TestFeed },
            };

            var packageVersion = "1.0-beta.1";
            var packageId      = "nventive.NuGet.Updater";

            var reference = new PackageReference(packageId, packageVersion);

            var version = await reference.GetLatestVersion(CancellationToken.None, parameters);

            Assert.IsNotNull(version);
            Assert.AreEqual(version.Version.OriginalVersion, packageVersion);
        }
        internal static IEnumerable <string> GetSummary(this UpdaterParameters parameters)
        {
            yield return($"## Configuration");

            yield return($"- Targeting solution {MarkdownHelper.CodeBlock(parameters.SolutionRoot)}");

            var files = parameters.UpdateTarget == FileType.All
                                ? Enum
                        .GetValues(typeof(FileType))
                        .Cast <FileType>()
                        .Select(t => t.GetDescription())
                        .Trim()
                                : new[] { parameters.UpdateTarget.GetDescription() };

            yield return($"- Updating files of type {MarkdownHelper.CodeBlocksEnumeration(files)}");

            if (parameters.Feeds?.Any() ?? false)
            {
                yield return($"- Fetching packages from {MarkdownHelper.CodeBlocksEnumeration(parameters.Feeds.Select(s => s.Url.OriginalString))}");
            }

            if (parameters.PackageAuthor.HasValue())
            {
                yield return($"- Limiting to public packages authored by {MarkdownHelper.Bold(parameters.PackageAuthor)}");
            }

            yield return($"- Using {MarkdownHelper.CodeBlocksEnumeration(parameters.TargetVersions)} versions {(parameters.Strict ? "(exact match)" : "")}");

            if (parameters.IsDowngradeAllowed)
            {
                yield return($"- Downgrading packages if a lower version is found");
            }

            if (parameters.PackagesToUpdate?.Any() ?? false)
            {
                yield return($"- Updating only {MarkdownHelper.CodeBlocksEnumeration(parameters.PackagesToUpdate)}");
            }
        }
Exemplo n.º 10
0
 public NuGetUpdater(UpdaterParameters parameters, TextWriter logWriter, TextWriter summaryWriter)
     : this(parameters, new UpdaterLogger(logWriter, summaryWriter))
 {
 }