public void OneZipPerSearch_AddContainingFolder() { ZipProcessor processor = new ZipProcessor(); processor.SetParameter("OneZipFilePer", ProcessorScope.Search); processor.SetParameter("AddContainingFolder", true); processor.SetParameter("OutputPath", Path.Combine(CurrentTestResultsDirectoryPath, "output.zip")); processor.SetParameter("Overwrite", false); FileInfo file1 = GetTestFile(Path.Combine("ZipHierarchy", "Subdir1", "Subdir2", "TextFile1ForZip.txt")); FileInfo file2 = GetTestFile(Path.Combine("ZipHierarchy", "Subdir1", "Subdir2", "Subdir3", "TextFile2ForZip.txt")); FileInfo file3 = GetTestFile(Path.Combine("ZipHierarchy", "Subdir1", "Subdir2", "Subdir3", "TextFile3ForZip.txt")); FileInfo[] generatedFiles = new FileInfo[0]; string[] values = new string[0]; processor.Init(RunInfo); processor.Process(file1, MatchResultType.Yes, values, generatedFiles, ProcessInput.OriginalFile, CancellationToken.None); processor.Process(file2, MatchResultType.Yes, values, generatedFiles, ProcessInput.OriginalFile, CancellationToken.None); processor.Process(file3, MatchResultType.Yes, values, generatedFiles, ProcessInput.OriginalFile, CancellationToken.None); processor.ProcessAggregated(CancellationToken.None); processor.Cleanup(); }
public void OneZipPerSearch_DoesNotOverwrite() { ZipProcessor processor = new ZipProcessor(); string outputPath = Path.Combine(CurrentTestResultsDirectoryPath, "output.zip"); processor.SetParameter("OneZipFilePer", ProcessorScope.Search); processor.SetParameter("AddContainingFolder", false); processor.SetParameter("OutputPath", outputPath); processor.SetParameter("Overwrite", false); File.WriteAllText(outputPath, "This file will not be replaced. Also it's not really a zip file."); FileInfo file1 = GetTestFile(Path.Combine("ZipHierarchy", "Subdir1", "Subdir2", "TextFile1ForZip.txt")); FileInfo file2 = GetTestFile(Path.Combine("ZipHierarchy", "Subdir1", "Subdir2", "Subdir3", "TextFile2ForZip.txt")); FileInfo file3 = GetTestFile(Path.Combine("ZipHierarchy", "Subdir1", "Subdir2", "Subdir3", "TextFile3ForZip.txt")); FileInfo[] generatedFiles = new FileInfo[0]; string[] values = new string[0]; processor.Init(RunInfo); processor.Process(file1, MatchResultType.Yes, values, generatedFiles, ProcessInput.OriginalFile, CancellationToken.None); processor.Process(file2, MatchResultType.Yes, values, generatedFiles, ProcessInput.OriginalFile, CancellationToken.None); processor.Process(file3, MatchResultType.Yes, values, generatedFiles, ProcessInput.OriginalFile, CancellationToken.None); try { processor.ProcessAggregated(CancellationToken.None); Assert.Fail(); } catch (Exception) { } processor.Cleanup(); }
public void BasePackagingWithCopyProcessorAndZipProcessorTest() { ICopier copier = new Copier(Context); IZipper zipper = new Zipper(Context); IDirectoryFilesLister directoryFilesLister = new DirectoryFilesLister(); StandardPackageDef packageDef = new StandardPackageDef(); DirectorySource test = new DirectorySource(Context, directoryFilesLister, "test", new FullPath("tmp/test")); DirectorySource test2 = new DirectorySource(Context, directoryFilesLister, "test2", new FullPath("tmp/test2")); packageDef.AddFilesSource(test); packageDef.AddFilesSource(test2); CopyProcessor copyProcessor = new CopyProcessor( Context, copier, new FullPath("tmp/output")); copyProcessor .AddTransformation("test", new LocalPath(@"test")) .AddTransformation("test2", new LocalPath(@"test2")); IPackageDef copiedPackageDef = copyProcessor.Process(packageDef); ZipProcessor zipProcessor = new ZipProcessor(Context, zipper, new FileFullPath("tmp/test.zip"), new FullPath("tmp/output"), false, null, "test", "test2"); zipProcessor.Process(copiedPackageDef); using (ZipArchive archive = ZipFile.OpenRead("tmp/test.zip")) { Assert.Equal(4, archive.Entries.Count); var list = archive.Entries.ToList <ZipArchiveEntry>(); Assert.Contains(list, x => x.FullName == $"test{_seperator}test.txt"); Assert.Contains(list, x => x.FullName == $"test{_seperator}test2.txt"); Assert.Contains(list, x => x.FullName == $"test2{_seperator}test.txt"); Assert.Contains(list, x => x.FullName == $"test2{_seperator}test2.txt"); } }
public void OptimizeZipTest() { ICopier copier = new Copier(Context); IZipper zipper = new Zipper(Context); IDirectoryFilesLister directoryFilesLister = new DirectoryFilesLister(); StandardPackageDef packageDef = new StandardPackageDef(); DirectorySource test = new DirectorySource(Context, directoryFilesLister, "test", new FullPath("tmp\\test")); DirectorySource test2 = new DirectorySource(Context, directoryFilesLister, "test2", new FullPath("tmp\\test2")); packageDef.AddFilesSource(test); packageDef.AddFilesSource(test2); CopyProcessor copyProcessor = new CopyProcessor( Context, copier, new FullPath("tmp\\output")); copyProcessor .AddTransformation("test", new LocalPath(@"test")) .AddTransformation("test2", new LocalPath(@"test2")); IPackageDef copiedPackageDef = copyProcessor.Process(packageDef); ZipProcessor zipProcessor = new ZipProcessor(Context, zipper, new FileFullPath("tmp\\test.zip"), new FullPath("tmp\\output"), true, null, "test", "test2"); zipProcessor.Process(copiedPackageDef); using (ZipArchive archive = ZipFile.OpenRead("tmp\\test.zip")) { Assert.Equal(4, archive.Entries.Count); Assert.Equal("test2\\test.txt", archive.Entries[1].FullName); Assert.Equal("test2\\test2.txt", archive.Entries[0].FullName); Assert.Equal("test\\test2.txt", archive.Entries[2].FullName); Assert.Equal("_zipmetadata.json", archive.Entries[3].FullName); } }
public void TestZipProcessor() { IZipper zipper = MockRepository.GenerateMock <IZipper>(); ZipProcessor zipProcessor = new ZipProcessor( logger, zipper, "some.zip", "test", null, "console", "win.service"); IPackageDef zippedPackageDef = zipProcessor.Process(package); Assert.AreEqual(1, zippedPackageDef.ListChildSources().Count); }
public void OptimizeZipThenUnzipTest() { ICopier copier = new Copier(Context); IZipper zipper = new Zipper(Context); IDirectoryFilesLister directoryFilesLister = new DirectoryFilesLister(); StandardPackageDef packageDef = new StandardPackageDef(); DirectorySource test = new DirectorySource(Context, directoryFilesLister, "test", new FullPath("tmp/test")); DirectorySource test2 = new DirectorySource(Context, directoryFilesLister, "test2", new FullPath("tmp/test2")); packageDef.AddFilesSource(test); packageDef.AddFilesSource(test2); CopyProcessor copyProcessor = new CopyProcessor( Context, copier, new FullPath("tmp/output")); copyProcessor .AddTransformation("test", new LocalPath(@"test")) .AddTransformation("test2", new LocalPath(@"test2")); IPackageDef copiedPackageDef = copyProcessor.Process(packageDef); ZipProcessor zipProcessor = new ZipProcessor(Context, zipper, new FileFullPath("tmp/test.zip"), new FullPath("tmp/output"), true, null, "test", "test2"); zipProcessor.Process(copiedPackageDef); string zf = "tmp/test.zip"; using (ZipArchive archive = ZipFile.OpenRead(zf)) { Assert.Equal(4, archive.Entries.Count); var list = archive.Entries.ToList <ZipArchiveEntry>(); Assert.Contains(list, x => x.FullName == $"test2{_seperator}test.txt"); Assert.Contains(list, x => x.FullName == $"test2{_seperator}test2.txt"); Assert.Contains(list, x => x.FullName == $"test{_seperator}test2.txt"); Assert.Contains(list, x => x.FullName == "_zipmetadata.json"); } string unzipPath = "tmp/tt/"; UnzipTask unzip = new UnzipTask(zf, unzipPath); unzip.Execute(Context); var newLine = System.Environment.NewLine; CheckTestFile(Path.Combine(unzipPath, $"test2{_seperator}test.txt"), $"test.txt{newLine}"); CheckTestFile(Path.Combine(unzipPath, $"test2{_seperator}test2.txt"), $"test.txt{newLine}"); CheckTestFile(Path.Combine(unzipPath, $"test{_seperator}test.txt"), $"test.txt{newLine}"); CheckTestFile(Path.Combine(unzipPath, $"test{_seperator}test2.txt"), $"test2.txt{newLine}"); }
private static void TargetPackage(ITaskContext context) { FullPath packagesDir = new FullPath(context.Properties.Get(BuildProps.ProductRootDir, ".")); packagesDir = packagesDir.CombineWith(context.Properties.Get <string>(BuildProps.BuildDir)); FullPath simplexPackageDir = packagesDir.CombineWith("Detergent"); FileFullPath zipFileName = packagesDir.AddFileName( "Detergent-{0}.zip", context.Properties.Get <Version>(BuildProps.BuildVersion)); StandardPackageDef packageDef = new StandardPackageDef("Detergent", context); VSSolution solution = context.Properties.Get <VSSolution>(BuildProps.Solution); VSProjectWithFileInfo projectInfo = (VSProjectWithFileInfo)solution.FindProjectByName("Detergent"); LocalPath projectOutputPath = projectInfo.GetProjectOutputPath( context.Properties.Get <string>(BuildProps.BuildConfiguration)); FullPath projectTargetDir = projectInfo.ProjectDirectoryPath.CombineWith(projectOutputPath); packageDef.AddFolderSource( "bin", projectTargetDir, false); ICopier copier = new Copier(context); CopyProcessor copyProcessor = new CopyProcessor( context, copier, simplexPackageDir); copyProcessor .AddTransformation("bin", new LocalPath(string.Empty)); IPackageDef copiedPackageDef = copyProcessor.Process(packageDef); Zipper zipper = new Zipper(context); ZipProcessor zipProcessor = new ZipProcessor( context, zipper, zipFileName, simplexPackageDir, null, "bin"); zipProcessor.Process(copiedPackageDef); }
public void GeneratedFiles_PerGeneratedFile() { ZipProcessor processor = new ZipProcessor(); processor.SetParameter("OneZipFilePer", ProcessorScope.GeneratedOutputFile); processor.SetParameter("AddContainingFolder", false); processor.SetParameter("OutputPath", Path.Combine(CurrentTestResultsDirectoryPath, "{NameWithoutExtension}.zip")); processor.SetParameter("Overwrite", false); FileInfo file = GetTestFile("BasicTextFile.txt"); FileInfo file1 = GetTestFile(Path.Combine("ZipHierarchy", "Subdir1", "Subdir2", "TextFile1ForZip.txt")); FileInfo file2 = GetTestFile(Path.Combine("ZipHierarchy", "Subdir1", "Subdir2", "Subdir3", "TextFile2ForZip.txt")); FileInfo file3 = GetTestFile(Path.Combine("ZipHierarchy", "Subdir1", "Subdir2", "Subdir3", "TextFile3ForZip.txt")); FileInfo[] generatedFiles = new FileInfo[] { file1, file2, file3 }; string[] values = new string[0]; processor.Init(RunInfo); processor.Process(file, MatchResultType.Yes, values, generatedFiles, ProcessInput.GeneratedFiles, CancellationToken.None); processor.ProcessAggregated(CancellationToken.None); processor.Cleanup(); }
protected override int DoExecute(ITaskContextInternal context) { if (_sourcePackagingInfos.Count == 0) { return(0); } if (string.IsNullOrEmpty(_destinationRootDir)) { _destinationRootDir = context.Properties.GetOutputDir(); } FullPath df = new FullPath(_destinationRootDir); ICopier copier = new Copier(context, _logFiles); IZipper zipper = new Zipper(context); IDirectoryFilesLister directoryFilesLister = new DirectoryFilesLister(); StandardPackageDef packageDef = new StandardPackageDef(); CopyProcessor copyProcessor = new CopyProcessor(context, copier, df); List <string> sourceIds = new List <string>(); foreach (var sourceToPackage in _sourcePackagingInfos) { string sourceId; if (sourceToPackage.SourceType == SourceType.Directory) { var sourceFullPath = new FullPath(sourceToPackage.SourcePath); sourceId = sourceFullPath.GetHashCode().ToString(); DirectorySource directorySource = new DirectorySource(context, directoryFilesLister, sourceId, sourceFullPath, sourceToPackage.Recursive, sourceToPackage.DirectoryFilters); directorySource.SetFileFilter(sourceToPackage.FileFilters); packageDef.AddFilesSource(directorySource); } else { var fileFullPath = new FileFullPath(sourceToPackage.SourcePath); sourceId = fileFullPath.GetHashCode().ToString(); SingleFileSource fileSource = new SingleFileSource(sourceId, fileFullPath); packageDef.AddFilesSource(fileSource); } copyProcessor.AddTransformation(sourceId, sourceToPackage.DestinationPath); sourceIds.Add(sourceId); } IPackageDef copiedPackageDef = copyProcessor.Process(packageDef); if (ShouldPackageBeZipped) { string zipFile = _zipFileName; if (string.IsNullOrEmpty(zipFile)) { zipFile = _zipPrefix; _addVersionAsPostFixToZipFileName = true; _versionFieldCount = 3; } if (zipFile.EndsWith(".zip", StringComparison.OrdinalIgnoreCase)) { zipFile = zipFile.Substring(0, zipFile.Length - 4); } string tmp = _addVersionAsPostFixToZipFileName ? $"{zipFile}_{context.Properties.GetBuildVersion().Version.ToString(_versionFieldCount)}.zip" : $"{zipFile}.zip"; zipFile = Path.Combine(_destinationRootDir, tmp); DoLogInfo($"Creating zip file {zipFile}"); ZipProcessor zipProcessor = new ZipProcessor(context, zipper, new FileFullPath(zipFile), df, _optimizeZip, sourceIds, _logFiles); zipProcessor.Process(copiedPackageDef); } return(0); }
private static void TargetPackage(ITaskContext context) { FullPath packagesDir = new FullPath(context.Properties.Get(BuildProps.ProductRootDir, ".")); packagesDir = packagesDir.CombineWith(context.Properties.Get<string>(BuildProps.BuildDir)); FullPath simplexPackageDir = packagesDir.CombineWith("Detergent"); FileFullPath zipFileName = packagesDir.AddFileName( "Detergent-{0}.zip", context.Properties.Get<Version>(BuildProps.BuildVersion)); StandardPackageDef packageDef = new StandardPackageDef("Detergent", context); VSSolution solution = context.Properties.Get<VSSolution>(BuildProps.Solution); VSProjectWithFileInfo projectInfo = (VSProjectWithFileInfo)solution.FindProjectByName("Detergent"); LocalPath projectOutputPath = projectInfo.GetProjectOutputPath( context.Properties.Get<string>(BuildProps.BuildConfiguration)); FullPath projectTargetDir = projectInfo.ProjectDirectoryPath.CombineWith(projectOutputPath); packageDef.AddFolderSource( "bin", projectTargetDir, false); ICopier copier = new Copier(context); CopyProcessor copyProcessor = new CopyProcessor( context, copier, simplexPackageDir); copyProcessor .AddTransformation("bin", new LocalPath(string.Empty)); IPackageDef copiedPackageDef = copyProcessor.Process(packageDef); Zipper zipper = new Zipper(context); ZipProcessor zipProcessor = new ZipProcessor( context, zipper, zipFileName, simplexPackageDir, null, "bin"); zipProcessor.Process(copiedPackageDef); }