/// <summary> /// Get any regex entries that match no packages. Such entries are stale. /// </summary> internal static List<Regex> GetStaleRegex(GenerateData generateData, RepoData repoData) { return generateData .Packages .Where(r => repoData.FloatingPackages.All(p => !r.IsMatch(p.Name))) .ToList(); }
/// <summary> /// Get the subset of packages which match the specified filter for the generated file. /// </summary> internal static List<NuGetPackage> GetFilteredPackages(GenerateData generateData, RepoData repoData) { // Fixed packages are never included in generated output. Doing so would create conflicts because it's // possible for two versions to exist for the same package. Take for example System.Collections.Immuatble // which is both fixed and floating in Roslyn. return repoData .FloatingPackages .Where(x => generateData.Packages.Any(y => y.IsMatch(x.Name))) .ToList(); }
/// <summary> /// Get the subset of packages which match the specified filter for the generated file. /// </summary> internal static List<NuGetPackage> GetFilteredPackages(GenerateData generateData, RepoData repoData) { // Only fixed packages with 'generate names' are included in generated output. Doing // otherwise would create conflicts because it's possible for two versions to exist // for the same package. Take for example System.Collections.Immuatble which is both // fixed and floating in Roslyn. var fixedWithGenerate = repoData .FixedPackages .Where(x => x.GenerateNameOpt != null); return repoData .FloatingPackages .Concat(fixedWithGenerate) .OrderBy(x => x.Name) .Where(x => generateData.Packages.Any(y => y.IsMatch(x.Name))) .ToList(); }
/// <summary> /// Verify the packages listed in project.json are well formed. Packages should all either have the same version or /// be explicitly fixed in the config file. /// </summary> private bool VerifyProjectJsonContents(TextWriter writer, out RepoData repoData) { writer.WriteLine($"Verifying project.json contents"); List<NuGetPackageConflict> conflicts; repoData = RepoData.Create(_repoConfig, _sourcesPath, out conflicts); if (conflicts?.Count > 0) { foreach (var conflict in conflicts) { writer.WriteLine($"Error! Package {conflict.PackageName} has different versions:"); writer.WriteLine($"\t{conflict.Original.FileName} at {conflict.Original.NuGetPackage.Version}"); writer.WriteLine($"\t{conflict.Conflict.FileName} at {conflict.Conflict.NuGetPackage.Version}"); writer.WriteLine($"The versions must be the same or one must be explicitly listed as fixed in RepoData.json"); } return false; } return true; }
private bool VerifyGeneratedFiles(TextWriter writer, RepoData repoData) { var allGood = true; writer.WriteLine($"Verifying generated files"); if (_repoConfig.MSBuildGenerateData.HasValue) { var data = _repoConfig.MSBuildGenerateData.Value; var packages = GenerateUtil.GetFilteredPackages(data, repoData); // Need to verify the contents of the generated file are correct. var fileName = new FileName(_sourcesPath, data.RelativeFilePath); var actualContent = File.ReadAllText(fileName.FullPath, GenerateUtil.Encoding); var expectedContent = GenerateUtil.GenerateMSBuildContent(packages); if (actualContent != expectedContent) { writer.WriteLine($"{fileName.RelativePath} does not have the expected contents"); allGood = false; } if (!allGood) { writer.WriteLine($@"Generated contents out of date. Run ""RepoUtil.change"" to correct"); return false; } // Verify none of the regex entries are stale. var staleRegexList = GenerateUtil.GetStaleRegex(data, repoData); foreach (var regex in staleRegexList) { writer.WriteLine($"Regex {regex} matches no packages"); allGood = false; } } return allGood; }
private static bool TryParseCommand(string[] args, ref int index, out CreateCommand func) { func = null; if (index >= args.Length) { Console.WriteLine("Need a command to run"); return false; } var name = args[index]; switch (name) { case "verify": func = (c, s) => new VerifyCommand(c, s); break; case "view": func = (c, s) => new ViewCommand(c, s); break; case "consumes": func = (c, s) => new ConsumesCommand(RepoData.Create(c, s)); break; case "change": func = (c, s) => new ChangeCommand(RepoData.Create(c, s)); break; case "produces": func = (c, s) => new ProducesCommand(c, s); break; default: Console.Write($"Command {name} is not recognized"); return false; } index++; return true; }
internal ChangeCommand(RepoData repoData) { _repoData = repoData; }
internal ChangeCommand(RepoData repoData, string generateDir) { _repoData = repoData; _generateDirectory = generateDir; }
/// <summary> /// Get the subset of packages which match the specified filter for the generated file. /// </summary> internal static List <NuGetPackage> GetFilteredPackages(GenerateData generateData, RepoData repoData) { // Fixed packages are never included in generated output. Doing so would create conflicts because it's // possible for two versions to exist for the same package. Take for example System.Collections.Immuatble // which is both fixed and floating in Roslyn. return(repoData .FloatingPackages .Where(x => generateData.Packages.Any(y => y.IsMatch(x.Name))) .ToList()); }
internal ConsumesCommand(RepoData repoData) { _repoData = repoData; }
/// <summary> /// Get the subset of packages which match the specified filter for the generated file. /// </summary> internal static List <NuGetPackage> GetFilteredPackages(GenerateData generateData, RepoData repoData) { // Only fixed packages with 'generate names' are included in generated output. Doing // otherwise would create conflicts because it's possible for two versions to exist // for the same package. Take for example System.Collections.Immuatble which is both // fixed and floating in Roslyn. var fixedWithGenerate = repoData .FixedPackages .Where(x => x.GenerateNameOpt != null); return(repoData .FloatingPackages .Concat(fixedWithGenerate) .OrderBy(x => x.Name) .Where(x => generateData.Packages.Any(y => y.IsMatch(x.Name))) .ToList()); }