public void GetMatchesPerformsExactMatches() { // Arrange var files = new[] { new PhysicalPackageFile { SourcePath = @"foo.dll" }, new PhysicalPackageFile { SourcePath = @"content\foo.dll" }, new PhysicalPackageFile { SourcePath = @"bin\debug\baz.dll" }, new PhysicalPackageFile { SourcePath = @"bin\debug\notbaz.dll" }, }; // Act var matches = PathResolver.GetMatches(files, f => f.SourcePath, new[] { @"foo.dll", @"bin\*\b*.dll" }); // Assert Assert.Equal(2, matches.Count()); Assert.Equal(@"foo.dll", matches.ElementAt(0).SourcePath); Assert.Equal(@"bin\debug\baz.dll", matches.ElementAt(1).SourcePath); }
public void GetMatchesPerformsRecursiveWildcardSearch() { // Arrange var files = new[] { new PhysicalPackageFile { SourcePath = @"content\1.txt" }, new PhysicalPackageFile { SourcePath = @"content\foo\bar.txt" }, new PhysicalPackageFile { SourcePath = @"lib\baz.pdb" }, new PhysicalPackageFile { SourcePath = @"baz.dll" }, }; // Act var matches = PathResolver.GetMatches(files, f => f.SourcePath, new[] { @"content\**\.txt", "**.pdb" }); // Assert Assert.Equal(3, matches.Count()); Assert.Equal(@"content\1.txt", matches.ElementAt(0).SourcePath); Assert.Equal(@"content\foo\bar.txt", matches.ElementAt(1).SourcePath); Assert.Equal(@"lib\baz.pdb", matches.ElementAt(2).SourcePath); }
public void GetMatchesAgainstUnixStylePaths() { // Arrange var files = new[] { new PhysicalPackageFile { SourcePath = @"content\1.txt" }, new PhysicalPackageFile { SourcePath = @"content\foo\bar.txt" }, new PhysicalPackageFile { SourcePath = @"lib\baz.pdb" }, new PhysicalPackageFile { SourcePath = @"baz.dll" }, }; // Act var matches = PathResolver.GetMatches(files, f => f.SourcePath, new[] { @"content/**/.txt", "**.pdb" }); // Assert Assert.Equal(3, matches.Count()); Assert.Equal(@"content\1.txt", matches.ElementAt(0).SourcePath); Assert.Equal(@"content\foo\bar.txt", matches.ElementAt(1).SourcePath); Assert.Equal(@"lib\baz.pdb", matches.ElementAt(2).SourcePath); }
public void PathResolver_GetMatches_HandlesQuestionMark() { var sources = new[] { "a", "ab", "abc", "ac", "adc" }; var wildcards = new[] { "a?c" }; var actualResults = PathResolver.GetMatches(sources, source => source, wildcards); var expectedResults = new[] { "abc", "adc" }; Assert.Equal(expectedResults, actualResults); }
public void PathResolver_GetMatchesHandlesStar() { var sources = GetPlatformSpecificPaths(new[] { "a{0}d", "a{0}de", "a{0}b{0}d", "a{0}b{0}de", "a{0}b{0}c{0}d", "a{0}b{0}c{0}de" }); var wildcards = GetPlatformSpecificPaths(new[] { "a{0}*{0}*{0}d" }); var actualResults = PathResolver.GetMatches(sources, source => source, wildcards); var expectedResults = GetPlatformSpecificPaths(new[] { "a{0}b{0}c{0}d" }); Assert.Equal(expectedResults, actualResults); }
public void PathResolver_GetMatches_WithGlobstarSlashFileNameMatchesFileName() { var sources = GetPlatformSpecificPaths(new[] { ".{0}c", "a{0}c", "a{0}bc", "bc" }); var wildcards = GetPlatformSpecificPaths(new[] { "**{0}c" }); var actualResults = PathResolver.GetMatches(sources, source => source, wildcards); var expectedResults = GetPlatformSpecificPaths(new[] { ".{0}c", "a{0}c" }); Assert.Equal(expectedResults, actualResults); }
public void PathResolver_GetMatches_HandlesDotGlobstar() { var sources = GetPlatformSpecificPaths(new[] { ".{0}a{0}.c", ".{0}a{0}c", ".{0}.c", ".{0}c", "bc", "b.c", "c", ".c" }); var wildcards = new[] { ".**" }; var actualResults = PathResolver.GetMatches(sources, source => source, wildcards); var expectedResults = GetPlatformSpecificPaths(new[] { ".c" }); Assert.Equal(expectedResults, actualResults); }
public void GetMatches_WithStar_ReturnsMatches() { IEnumerable <string> sources = GetPlatformSpecificPaths(new[] { "a{0}d", "a{0}de", "a{0}b{0}d", "a{0}b{0}de", "a{0}b{0}c{0}d", "a{0}b{0}c{0}de" }); IEnumerable <string> wildcards = GetPlatformSpecificPaths(new[] { "a{0}*{0}*{0}d" }); IEnumerable <string> actualResults = PathResolver.GetMatches(sources, source => source, wildcards); IEnumerable <string> expectedResults = GetPlatformSpecificPaths(new[] { "a{0}b{0}c{0}d" }); Assert.Equal(expectedResults, actualResults); }
public void GetMatches_WithGlobstarSlashFileName_ReturnsFileNameMatches() { IEnumerable <string> sources = GetPlatformSpecificPaths(new[] { ".{0}c", "a{0}c", "a{0}bc", "bc" }); IEnumerable <string> wildcards = GetPlatformSpecificPaths(new[] { "**{0}c" }); IEnumerable <string> actualResults = PathResolver.GetMatches(sources, source => source, wildcards); IEnumerable <string> expectedResults = GetPlatformSpecificPaths(new[] { ".{0}c", "a{0}c" }); Assert.Equal(expectedResults, actualResults); }
public void GetMatches_WithQuestionMark_ReturnsMatches() { string[] sources = new[] { "a", "ab", "abc", "ac", "adc" }; string[] wildcards = new[] { "a?c" }; IEnumerable<string> actualResults = PathResolver.GetMatches(sources, source => source, wildcards); string[] expectedResults = new[] { "abc", "adc" }; Assert.Equal(expectedResults, actualResults); }
public void GetMatches_WithDotGlobstar_ReturnsMatches() { IEnumerable<string> sources = GetPlatformSpecificPaths(new[] { ".{0}a{0}.c", ".{0}a{0}c", ".{0}.c", ".{0}c", "bc", "b.c", "c", ".c" }); string[] wildcards = new[] { ".**" }; IEnumerable<string> actualResults = PathResolver.GetMatches(sources, source => source, wildcards); IEnumerable<string> expectedResults = GetPlatformSpecificPaths(new[] { ".c" }); Assert.Equal(expectedResults, actualResults); }
public void GetMatches_WithGlobstar_ReturnsMatches() { IEnumerable <string> sources = GetPlatformSpecificPaths(new[] { "a{0}d", "a{0}de", "a{0}b{0}d", "a{0}b{0}de", "a{0}b{0}c{0}d", "a{0}b{0}c{0}de" }); IEnumerable <string> wildcards = GetPlatformSpecificPaths(new[] { "a{0}**d" }); IEnumerable <string> actualResults = PathResolver.GetMatches(sources, source => source, wildcards); IEnumerable <string> expectedResults = GetPlatformSpecificPaths(new[] { "a{0}d", "a{0}b{0}d", "a{0}b{0}c{0}d" }); IEnumerable <string> orderedActualResults = actualResults.OrderBy(path => path); IEnumerable <string> orderedExpectedResults = expectedResults.OrderBy(path => path); Assert.Equal(orderedExpectedResults, orderedActualResults); }
public void GetMatches_WithGlobstarSlashDotFileName_ReturnsFileNameMatches() { IEnumerable <string> sources = GetPlatformSpecificPaths(new[] { ".{0}.c", "a{0}.c", "a{0}{0}.c", "a{0}bc", "bc", "b.c", "a{0}b{0}bc.c", "a{0}b{0}.c", "a{0}b{0}c" }); IEnumerable <string> wildcards = GetPlatformSpecificPaths(new[] { "**.c" }); IEnumerable <string> actualResults = PathResolver.GetMatches(sources, source => source, wildcards); IEnumerable <string> expectedResults = GetPlatformSpecificPaths(new[] { ".{0}.c", "a{0}.c", "a{0}{0}.c", "b.c", "a{0}b{0}bc.c", "a{0}b{0}.c" }); IEnumerable <string> orderedActualResults = actualResults.OrderBy(path => path); IEnumerable <string> orderedExpectedResults = expectedResults.OrderBy(path => path); Assert.Equal(orderedExpectedResults, orderedActualResults); }
public void GetMatchesFiltersByWildCards() { // Arrange var files = new[] { new PhysicalPackageFile { SourcePath = @"content\1.txt" }, new PhysicalPackageFile { SourcePath = @"content\foo\bar.txt" }, new PhysicalPackageFile { SourcePath = @"baz.pdb" }, }; // Act var matches = PathResolver.GetMatches(files, f => f.SourcePath, new[] { @"content\*.txt", "*.pdb" }); // Assert Assert.Equal(2, matches.Count()); Assert.Equal(@"content\1.txt", matches.ElementAt(0).SourcePath); Assert.Equal(@"baz.pdb", matches.ElementAt(1).SourcePath); }
public void Pack(string nuspecPath, string nupkgPath, Manifest manifest, bool packSymbols) { bool creatingSymbolsPackage = packSymbols && (Path.GetExtension(nupkgPath) == _symbolsPackageExtension); try { PackageBuilder builder = new PackageBuilder(); string baseDirectoryPath = (string.IsNullOrEmpty(BaseDirectory)) ? Path.GetDirectoryName(nuspecPath) : BaseDirectory; builder.Populate(manifest.Metadata); builder.PopulateFiles(baseDirectoryPath, manifest.Files); if (creatingSymbolsPackage) { // For symbols packages, filter out excludes PathResolver.FilterPackageFiles( builder.Files, file => file.Path, SymbolPackageExcludes); // Symbol packages are only valid if they contain both symbols and sources. Dictionary <string, bool> pathHasMatches = LibPackageExcludes.ToDictionary( path => path, path => PathResolver.GetMatches(builder.Files, file => file.Path, new[] { path }).Any()); if (!pathHasMatches.Values.Any(i => i)) { Log.LogMessage(LogImportance.Low, $"Nuspec {nuspecPath} does not contain symbol or source files. Not creating symbol package."); return; } foreach (var pathPair in pathHasMatches.Where(pathMatchPair => !pathMatchPair.Value)) { Log.LogMessage(LogImportance.Low, $"Nuspec {nuspecPath} does not contain any files matching {pathPair.Key}. Not creating symbol package."); return; } } else if (!packSymbols) { // for packages which do not include symbols (not symbols or packed packages), filter lib excludes PathResolver.FilterPackageFiles( builder.Files, file => file.Path, LibPackageExcludes); } var directory = Path.GetDirectoryName(nupkgPath); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } using (var fileStream = File.Create(nupkgPath)) { builder.Save(fileStream); } Log.LogMessage($"Created '{nupkgPath}'"); } catch (Exception e) { string packageType = "lib"; if (creatingSymbolsPackage) { packageType = "symbol"; } else if (packSymbols) { packageType = "packed"; } Log.LogError($"Error when creating nuget {packageType} package from {nuspecPath}. {e}"); } }
public void Pack(string nuspecPath, Func <string, string> nuspecPropertyProvider, bool packSymbols) { try { PackageBuilder builder = new PackageBuilder(); using (var nuspecFile = File.Open(nuspecPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete)) { string baseDirectoryPath = (string.IsNullOrEmpty(BaseDirectory)) ? Path.GetDirectoryName(nuspecPath) : BaseDirectory; Manifest manifest = Manifest.ReadFrom(nuspecFile, nuspecPropertyProvider, false); builder.Populate(manifest.Metadata); builder.PopulateFiles(baseDirectoryPath, manifest.Files); PathResolver.FilterPackageFiles( builder.Files, file => file.Path, packSymbols ? SymbolPackageExcludes : LibPackageExcludes); } if (packSymbols) { // Symbol packages are only valid if they contain both symbols and sources. Dictionary <string, bool> pathHasMatches = LibPackageExcludes.ToDictionary( path => path, path => PathResolver.GetMatches(builder.Files, file => file.Path, new[] { path }).Any()); if (!pathHasMatches.Values.Any(i => i)) { Log.LogMessage(LogImportance.Low, $"Nuspec {nuspecPath} does not contain symbol or source files. Not creating symbol package."); return; } foreach (var pathPair in pathHasMatches.Where(pathMatchPair => !pathMatchPair.Value)) { Log.LogMessage(LogImportance.Low, $"Nuspec {nuspecPath} does not contain any files matching {pathPair.Key}. Not creating symbol package."); return; } } // Overriding the Version from the Metadata if one gets passed in. if (!string.IsNullOrEmpty(PackageVersion)) { NuGetVersion overrideVersion; if (NuGetVersion.TryParse(PackageVersion, out overrideVersion)) { builder.Version = overrideVersion; } else { Log.LogError($"Failed to parse Package Version: '{PackageVersion}' is not a valid version."); return; } } string id = builder.Id, version = builder.Version.ToString(); if (String.IsNullOrEmpty(id)) { Log.LogError($"Nuspec {nuspecPath} does not contain a valid Id"); return; } if (String.IsNullOrEmpty(version)) { Log.LogError($"Nuspec {nuspecPath} does not contain a valid version"); return; } string nupkgOutputDirectory = OutputDirectory; if (packSymbols && !string.IsNullOrEmpty(SymbolPackageOutputDirectory)) { nupkgOutputDirectory = SymbolPackageOutputDirectory; } string nupkgExtension = packSymbols ? ".symbols.nupkg" : ".nupkg"; string nupkgPath = Path.Combine(nupkgOutputDirectory, $"{id}.{version}{nupkgExtension}"); var directory = Path.GetDirectoryName(nupkgPath); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } using (var fileStream = File.Create(nupkgPath)) { builder.Save(fileStream); } Log.LogMessage($"Created '{nupkgPath}'"); } catch (Exception e) { string packageType = packSymbols ? "symbol" : "lib"; Log.LogError($"Error when creating nuget {packageType} package from {nuspecPath}. {e}"); } }