Exemplo n.º 1
0
        // TODO: add HasLocalInstalledPackage() ?
        // ReSharper disable once CyclomaticComplexity
        public static IEnumerable <InstalledPackage> GetLocalInstalledPackages(
            string packagesConfigFile = null,
            bool includeDependencies  = false)
        {
            packagesConfigFile = packagesConfigFile ?? GetBuildPackagesConfigFile();
            ControlFlow.Assert(!IncludesDependencies(packagesConfigFile) || includeDependencies,
                               $"!IncludesDependencies({packagesConfigFile}) || includeDependencies");
            var packagesDirectory = GetPackagesDirectory(packagesConfigFile);

            var packageIds = XmlTasks.XmlPeek(
                packagesConfigFile,
                IsLegacyFile(packagesConfigFile)
                    ? ".//package/@id"
                    : ".//*[local-name() = 'PackageReference']/@Include");

            var installedPackages = new HashSet <InstalledPackage>(InstalledPackage.Comparer.Instance);

            foreach (var packageId in packageIds)
            {
                // TODO: use xml namespaces
                // TODO: version as tag
                var version = XmlTasks.XmlPeekSingle(
                    packagesConfigFile,
                    IsLegacyFile(packagesConfigFile)
                            ? $".//package[@id='{packageId}']/@version"
                            : $".//*[local-name() = 'PackageReference'][@Include='{packageId}']/@Version")
                              .NotNull("version != null");

                var packageData = GetGlobalInstalledPackage(packageId, version, packagesDirectory);
                if (packageData == null)
                {
                    continue;
                }

                installedPackages.Add(packageData);
                yield return(packageData);
            }

            if (includeDependencies)
            {
                var packagesToCheck = new Queue <InstalledPackage>(installedPackages);
                while (packagesToCheck.Any())
                {
                    var packageToCheck = packagesToCheck.Dequeue();

                    foreach (var dependentPackage in GetDependentPackages(packageToCheck, packagesDirectory))
                    {
                        if (installedPackages.Contains(dependentPackage))
                        {
                            continue;
                        }

                        installedPackages.Add(dependentPackage);
                        packagesToCheck.Enqueue(dependentPackage);

                        yield return(dependentPackage);
                    }
                }
            }
        }
Exemplo n.º 2
0
    public override object GetValue(MemberInfo member, object instance)
    {
        var rssFile = NukeBuild.TemporaryDirectory / $"{_groupId}-{_artifactId ?? _groupId}.xml";

        HttpTasks.HttpDownloadFile($"https://{_repository.TrimStart("https").TrimStart("http").TrimStart("://").TrimEnd("/")}/m2/{_groupId.Replace(".", "/")}/{_artifactId ?? _groupId}/maven-metadata.xml", rssFile);
        return(XmlTasks.XmlPeek(rssFile, ".//version").Last());
    }
Exemplo n.º 3
0
        private static IEnumerable <InstalledPackage> GetLocalInstalledPackagesFromConfigFile(
            string packagesConfigFile,
            bool resolveDependencies = true)
        {
            var packageIds = XmlTasks.XmlPeek(
                packagesConfigFile,
                IsLegacyFile(packagesConfigFile)
                        ? ".//package/@id"
                        : ".//*[local-name() = 'PackageReference' or local-name() = 'PackageDownload']/@Include")
                             .Distinct();

            var installedPackages = new HashSet <InstalledPackage>(InstalledPackage.Comparer.Instance);

            foreach (var packageId in packageIds)
            {
                // TODO: use xml namespaces
                // TODO: version as tag
                var versions = XmlTasks.XmlPeek(
                    packagesConfigFile,
                    IsLegacyFile(packagesConfigFile)
                            ? $".//package[@id='{packageId}']/@version"
                            : $".//*[local-name() = 'PackageReference' or local-name() = 'PackageDownload'][@Include='{packageId}']/@Version")
                               .SelectMany(x => x.Split(';'));

                foreach (var version in versions)
                {
                    var package = GetGlobalInstalledPackage(packageId, version, packagesConfigFile);
                    if (package == null)
                    {
                        continue;
                    }

                    installedPackages.Add(package);
                    yield return(package);
                }
            }

            if (resolveDependencies && !IsLegacyFile(packagesConfigFile))
            {
                var packagesToCheck = new Queue <InstalledPackage>(installedPackages);
                while (packagesToCheck.Any())
                {
                    var packageToCheck = packagesToCheck.Dequeue();

                    foreach (var dependentPackage in GetDependentPackages(packageToCheck, packagesConfigFile))
                    {
                        if (installedPackages.Contains(dependentPackage))
                        {
                            continue;
                        }

                        installedPackages.Add(dependentPackage);
                        packagesToCheck.Enqueue(dependentPackage);

                        yield return(dependentPackage);
                    }
                }
            }
        }
    public override object GetValue(MemberInfo member, object instance)
    {
        var rssFile = NukeBuild.TemporaryDirectory / $"{_feed}.xml";

        HttpTasks.HttpDownloadFile($"https://www.myget.org/RSS/{_feed}", rssFile);
        return(XmlTasks.XmlPeek(rssFile, ".//title")
               // TODO: regex?
               .First(x => x.Contains($"/{_package} "))
               .Split('(').Last()
               .Split(')').First()
               .TrimStart("version "));
    }
Exemplo n.º 5
0
        // TODO: check for config ( repositoryPath / globalPackagesFolder )
        public static string GetPackagesDirectory(string packagesConfigFile)
        {
            var packagesDirectory = EnvironmentInfo.Variable("NUGET_PACKAGES");

            if (packagesDirectory != null)
            {
                return(packagesDirectory);
            }

            var configSetting = GetConfigFiles(packagesConfigFile)
                                .Select(x => new
            {
                File    = x,
                Setting = XmlTasks.XmlPeek(x, ".//add[@key='globalPackagesFolder']/@value").FirstOrDefault()
            })
                                .Where(x => x.Setting != null)
                                .FirstOrDefault();

            if (configSetting != null)
            {
                return(Path.IsPathRooted(configSetting.Setting)
                    ? configSetting.Setting
                    : Path.Combine(Path.GetDirectoryName(configSetting.File).NotNull(), configSetting.Setting));
            }

            if (packagesConfigFile == null || !IsLegacyFile(packagesConfigFile))
            {
                return(Path.Combine(
                           EnvironmentInfo.SpecialFolder(SpecialFolders.UserProfile)
                           .NotNull("EnvironmentInfo.SpecialFolder(SpecialFolders.UserProfile) != null"),
                           ".nuget",
                           "packages"));
            }

            if (NukeBuild.Instance != null)
            // TODO SK
#pragma warning disable 618
            {
                return(Path.Combine(Path.GetDirectoryName(NukeBuild.Instance.SolutionFile).NotNull(), "packages"));
            }
#pragma warning restore 618

            packagesDirectory = new FileInfo(packagesConfigFile).Directory.NotNull()
                                .DescendantsAndSelf(x => x.Parent)
                                .SingleOrDefault(x => x.GetFiles("*.sln").Any() && x.GetDirectories("packages").Any())
                                ?.FullName;

            return(packagesDirectory.NotNull("GetPackagesDirectory != null"));
        }
Exemplo n.º 6
0
    void ReportTestCount()
    {
        IEnumerable <string> GetOutcomes(AbsolutePath file)
        => XmlTasks.XmlPeek(
            file,
            "/xn:TestRun/xn:Results/xn:UnitTestResult/@outcome",
            ("xn", "http://microsoft.com/schemas/VisualStudio/TeamTest/2010"));

        var resultFiles  = TestResultDirectory.GlobFiles("*.trx");
        var outcomes     = resultFiles.SelectMany(GetOutcomes).ToList();
        var passedTests  = outcomes.Count(x => x == "Passed");
        var failedTests  = outcomes.Count(x => x == "Failed");
        var skippedTests = outcomes.Count(x => x == "NotExecuted");

        ReportSummary(_ => _
                      .When(failedTests > 0, _ => _
                            .AddPair("Failed", failedTests.ToString()))
                      .AddPair("Passed", passedTests.ToString())
                      .When(skippedTests > 0, _ => _
                            .AddPair("Skipped", skippedTests.ToString())));
    }