internal void ExcludeFiles(ICollection <IPackageFile> packageFiles) { // Always exclude the nuspec file // Review: This exclusion should be done by the package builder because it knows which file would collide with the auto-generated // manifest file. var wildCards = _excludes.Concat(new[] { @"**\*" + NuGetConstants.ManifestExtension }); if (!_packArgs.NoDefaultExcludes) { // The user has not explicitly disabled default filtering. var excludedFiles = PathResolver.GetFilteredPackageFiles(packageFiles, ResolvePath, _defaultExcludes); if (excludedFiles != null) { foreach (var file in excludedFiles) { if (file is PhysicalPackageFile) { var physicalPackageFile = file as PhysicalPackageFile; _packArgs.Logger.Log(PackagingLogMessage.CreateWarning( string.Format(CultureInfo.CurrentCulture, Strings.Warning_FileExcludedByDefault, physicalPackageFile.SourcePath), NuGetLogCode.NU5119)); } } } } wildCards = wildCards.Concat(_packArgs.Exclude); PathResolver.FilterPackageFiles(packageFiles, ResolvePath, wildCards); }
public void FilterPathRemovesItemsThatMatchWildcard() { // Arrange var files = new List <IPackageFile>(new[] { new PhysicalPackageFile { TargetPath = @"foo.dll" }, new PhysicalPackageFile { TargetPath = @"content\foo.dll" }, new PhysicalPackageFile { TargetPath = @"bin\debug\baz.dll" }, new PhysicalPackageFile { TargetPath = @"bin\debug\notbaz.dll" }, new PhysicalPackageFile { TargetPath = @"bin\debug\baz.pdb" }, new PhysicalPackageFile { TargetPath = @"bin\debug\notbaz.pdb" }, }); // Act PathResolver.FilterPackageFiles(files, f => f.Path, new[] { @"**\f*.dll", @"**\*.pdb" }); // Assert Assert.Equal(2, files.Count()); Assert.Equal(@"bin\debug\baz.dll", files[0].Path); Assert.Equal(@"bin\debug\notbaz.dll", files[1].Path); }
private static void ExcludeFiles(ICollection <IPackageFile> packageFiles) { // Always exclude the nuspec file // Review: This exclusion should be done by the package builder because it knows which file would collide with the auto-generated // manifest file. var excludes = new HashSet <string>(StringComparer.OrdinalIgnoreCase); var wildCards = excludes.Concat(new[] { @"**\*" + Constants.ManifestExtension, @"**\*" + Constants.PackageExtension }); PathResolver.FilterPackageFiles(packageFiles, ResolvePath, wildCards); }
public void FilterPackageFiles_WithWildcard_RemovesWildcardMatches() { var sources = new List<string>(GetPlatformSpecificPaths(new[] { "c", "a{0}c", "a{0}b{0}c", "a{0}d" })); IEnumerable<string> wildcards = GetPlatformSpecificPaths(new[] { "**{0}c" }); PathResolver.FilterPackageFiles(sources, path => path, wildcards); IEnumerable<string> expectedResults = GetPlatformSpecificPaths(new[] { "a{0}d" }); Assert.Equal(expectedResults, sources); }
public void PathResolver_FilterPackageFiles_HandlesWildcard() { var sources = new List <string>(GetPlatformSpecificPaths(new[] { "c", "a{0}c", "a{0}b{0}c", "a{0}d" })); var wildcards = GetPlatformSpecificPaths(new[] { "**{0}c" }); PathResolver.FilterPackageFiles(sources, path => path, wildcards); var expectedResults = GetPlatformSpecificPaths(new[] { "a{0}d" }); Assert.Equal(expectedResults, sources); }
internal static void ExcludeFilesForSymbolPackage(ICollection <IPackageFile> files, SymbolPackageFormat symbolPackageFormat) { PathResolver.FilterPackageFiles(files, file => file.Path, _symbolPackageExcludes); if (symbolPackageFormat == SymbolPackageFormat.Snupkg) { var toRemove = files.Where(t => !string.Equals(Path.GetExtension(t.Path), ".pdb", StringComparison.OrdinalIgnoreCase)).ToList(); foreach (var fileToRemove in toRemove) { files.Remove(fileToRemove); } } }
internal void ExcludeFiles(ICollection <IPackageFile> packageFiles) { // Always exclude the nuspec file // Review: This exclusion should be done by the package builder because it knows which file would collide with the auto-generated // manifest file. var wildCards = _excludes.Concat(new[] { @"**\*" + Constants.ManifestExtension }); if (!NoDefaultExcludes) { // The user has not explicitly disabled default filtering. wildCards = wildCards.Concat(_defaultExcludes); } PathResolver.FilterPackageFiles(packageFiles, ResolvePath, wildCards); }
private static void ExcludeFiles(List<PhysicalPackageFile> searchFiles, string basePath, string exclude) { if (String.IsNullOrEmpty(exclude)) { return; } // One or more exclusions may be specified in the file. Split it and prepend the base path to the wildcard provided. var exclusions = exclude.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (var item in exclusions) { string wildCard = PathResolver.NormalizeWildcardForExcludedFiles(basePath, item); PathResolver.FilterPackageFiles(searchFiles, p => p.SourcePath, new[] { wildCard }); } }
internal static void ExcludeFilesForSymbolPackage(ICollection <IPackageFile> files) { PathResolver.FilterPackageFiles(files, file => file.Path, _symbolPackageExcludes); }
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}"); } }