Beispiel #1
0
        internal static RepoData Create(RepoConfig config, string sourcesPath, out List <NuGetPackageConflict> conflicts)
        {
            var nugetFeeds = new List <NuGetFeed>();

            foreach (var nugetConfig in NuGetConfigUtil.GetNuGetConfigFiles(sourcesPath))
            {
                var nugetFeed = NuGetConfigUtil.GetNuGetFeeds(nugetConfig);
                nugetFeeds.AddRange(nugetFeed);
            }

            conflicts = null;

            var fixedPackageSet    = new HashSet <NuGetPackage>(config.FixedPackages, default(Constants.IgnoreGenerateNameComparer));
            var floatingPackageMap = new Dictionary <string, NuGetPackageSource>(Constants.NugetPackageNameComparer);

            foreach (var filePath in ProjectJsonUtil.GetProjectJsonFiles(sourcesPath))
            {
                if (config.ProjectJsonExcludes.Any(x => x.IsMatch(filePath)))
                {
                    continue;
                }

                var fileName = FileName.FromFullPath(sourcesPath, filePath);
                foreach (var package in ProjectJsonUtil.GetDependencies(filePath))
                {
                    if (fixedPackageSet.Contains(package))
                    {
                        continue;
                    }

                    // If this is the first time we've seen the package then record where it was found.  Need the source
                    // information to provide better error messages later.
                    var packageSource = new NuGetPackageSource(package, fileName);
                    NuGetPackageSource originalSource;
                    if (floatingPackageMap.TryGetValue(package.Name, out originalSource))
                    {
                        if (originalSource.NuGetPackage.Version != package.Version)
                        {
                            var conflict = new NuGetPackageConflict(original: originalSource, conflict: packageSource);
                            conflicts = conflicts ?? new List <NuGetPackageConflict>();
                            conflicts.Add(conflict);
                        }
                    }
                    else
                    {
                        floatingPackageMap.Add(package.Name, packageSource);
                    }
                }
            }

            return(new RepoData(config, sourcesPath, nugetFeeds, floatingPackageMap.Values.Select(x => x.NuGetPackage)));
        }
Beispiel #2
0
        public bool Run(TextWriter writer, string[] args)
        {
            var list = args
                       .Select(x => new Regex(x))
                       .ToList();

            if (list.Count == 0)
            {
                list.Add(new Regex(".*"));
            }

            var map = new Dictionary <NuGetPackage, List <FileName> >();

            foreach (var filePath in ProjectJsonUtil.GetProjectJsonFiles(_sourcesPath))
            {
                var fileName = FileName.FromFullPath(_sourcesPath, filePath);
                foreach (var package in ProjectJsonUtil.GetDependencies(fileName.FullPath))
                {
                    if (list.All(x => !x.IsMatch(package.Name)))
                    {
                        continue;
                    }

                    List <FileName> nameList;
                    if (!map.TryGetValue(package, out nameList))
                    {
                        nameList     = new List <FileName>();
                        map[package] = nameList;
                    }

                    nameList.Add(fileName);
                }
            }

            foreach (var pair in map.OrderBy(x => x.Key.Name))
            {
                var package = pair.Key;
                writer.WriteLine($"{package.Name} - {package.Version}");
                foreach (var fileName in pair.Value)
                {
                    writer.WriteLine($"\t{fileName.RelativePath}");
                }
            }

            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Verify that all of the data contained in the repo configuration is valid.  In particular that it hasn't gotten
        /// stale and referring to invalid packages.
        /// </summary>
        /// <param name="writer"></param>
        private bool VerifyRepoConfig(TextWriter writer)
        {
            writer.WriteLine($"Verifying RepoData.json");
            var packages = ProjectJsonUtil
                           .GetProjectJsonFiles(_sourcesPath)
                           .SelectMany(x => ProjectJsonUtil.GetDependencies(x));
            var set     = new HashSet <NuGetPackage>(packages);
            var allGood = true;

            foreach (var package in _repoConfig.FixedPackages)
            {
                if (!set.Contains(package))
                {
                    writer.WriteLine($"Error: Fixed package {package.Name} - {package.Version} is not used anywhere");
                    allGood = false;
                }
            }

            return(allGood);
        }