Ejemplo n.º 1
0
        internal static RepoData Create(RepoConfig config, string sourcesDir, out List <NuGetPackageConflict> conflicts)
        {
            var nugetFeeds = new List <NuGetFeed>();

            foreach (var nugetConfig in NuGetConfigUtil.GetNuGetConfigFiles(sourcesDir))
            {
                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(sourcesDir))
            {
                var fileName = FileName.FromFullPath(sourcesDir, filePath);

                if (config.ProjectJsonExcludes.Any(x => x.IsMatch(fileName.RelativePath)))
                {
                    continue;
                }

                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, sourcesDir, nugetFeeds, floatingPackageMap.Values.Select(x => x.NuGetPackage)));
        }
Ejemplo n.º 2
0
 internal NuGetPackageConflict(NuGetPackageSource original, NuGetPackageSource conflict)
 {
     Debug.Assert(Constants.NugetPackageNameComparer.Equals(original.NuGetPackage.Name, conflict.NuGetPackage.Name));
     Original = original;
     Conflict = conflict;
 }
Ejemplo n.º 3
0
 internal NuGetPackageConflict(NuGetPackageSource original, NuGetPackageSource conflict)
 {
     Debug.Assert(Constants.NugetPackageNameComparer.Equals(original.NuGetPackage.Name, conflict.NuGetPackage.Name));
     Original = original;
     Conflict = conflict;
 }
Ejemplo n.º 4
0
        internal static RepoData Create(RepoConfig config, string sourcesDir, out List<NuGetPackageConflict> conflicts)
        {
            var nugetFeeds = new List<NuGetFeed>();
            foreach (var nugetConfig in NuGetConfigUtil.GetNuGetConfigFiles(sourcesDir))
            {
                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(sourcesDir))
            {
                if (config.ProjectJsonExcludes.Any(x => x.IsMatch(filePath)))
                {
                    continue;
                }

                var fileName = FileName.FromFullPath(sourcesDir, 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, sourcesDir, nugetFeeds, floatingPackageMap.Values.Select(x => x.NuGetPackage));
        }