public void CreateDeltaPackage(ReleasePackage baseFixture, string outputFile) { var baseTempPath = new DirectoryInfo(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString())); baseTempPath.Create(); var tempPath = new DirectoryInfo(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString())); tempPath.Create(); try { var zf = new ZipFile(baseFixture.ReleasePackageFile); zf.ExtractAll(baseTempPath.FullName); zf = new ZipFile(ReleasePackageFile); zf.ExtractAll(tempPath.FullName); var baseLibFiles = baseTempPath.GetAllFilesRecursively() .Where(x => x.FullName.ToLowerInvariant().Contains("lib" + Path.DirectorySeparatorChar)) .ToDictionary(k => k.FullName.Replace(baseTempPath.FullName, ""), v => v.FullName); var libDir = tempPath.GetDirectories().First(x => x.Name.ToLowerInvariant() == "lib"); libDir.GetAllFilesRecursively().ForEach(libFile => { var relativePath = libFile.FullName.Replace(tempPath.FullName, ""); if (!baseLibFiles.ContainsKey(relativePath)) { this.Log().Info("{0} not found in base package, marking as new", relativePath); return; } var oldData = File.ReadAllBytes(baseLibFiles[relativePath]); var newData = File.ReadAllBytes(libFile.FullName); if (bytesAreIdentical(oldData, newData)) { this.Log().Info("{0} hasn't changed, writing dummy file", relativePath); File.Create(libFile.FullName + ".diff").Dispose(); libFile.Delete(); return; } this.Log().Info("Delta patching {0} => {1}", baseLibFiles[relativePath], libFile.FullName); using (var of = File.Create(libFile.FullName + ".diff")) { BinaryPatchUtility.Create(oldData, newData, of); libFile.Delete(); } }); zf = new ZipFile(outputFile); zf.AddDirectory(tempPath.FullName); zf.Save(); } finally { baseTempPath.Delete(true); tempPath.Delete(true); } }
public void CreateDeltaPackageIntegrationTest() { var basePackage = IntegrationTestHelper.GetPath("fixtures", "NSync.Core.1.0.0.0.nupkg"); var newPackage = IntegrationTestHelper.GetPath("fixtures", "NSync.Core.1.1.0.0.nupkg"); var sourceDir = IntegrationTestHelper.GetPath("..", "packages"); (new DirectoryInfo(sourceDir)).Exists.ShouldBeTrue(); var baseFixture = new ReleasePackage(basePackage); var fixture = new ReleasePackage(newPackage); var tempFiles = Enumerable.Range(0, 3) .Select(_ => Path.GetTempPath() + Guid.NewGuid().ToString() + ".nupkg") .ToArray(); try { baseFixture.CreateReleasePackage(tempFiles[0], sourceDir); fixture.CreateReleasePackage(tempFiles[1], sourceDir); (new FileInfo(baseFixture.ReleasePackageFile)).Exists.ShouldBeTrue(); (new FileInfo(fixture.ReleasePackageFile)).Exists.ShouldBeTrue(); fixture.CreateDeltaPackage(baseFixture, tempFiles[2]); var fullPkg = new ZipPackage(tempFiles[1]); var deltaPkg = new ZipPackage(tempFiles[2]); fullPkg.Id.ShouldEqual(deltaPkg.Id); fullPkg.Version.CompareTo(deltaPkg.Version).ShouldEqual(0); // v1.1 adds a dependency on DotNetZip deltaPkg.GetFiles() .Any(x => x.Path.ToLowerInvariant().Contains("ionic.zip")) .ShouldBeTrue(); // All the other files should be diffs deltaPkg.GetFiles() .Where(x => !x.Path.ToLowerInvariant().Contains("ionic.zip")) .All(x => x.Path.ToLowerInvariant().EndsWith("diff")) .ShouldBeTrue(); // Delta packages should be smaller than the original! var fileInfos = tempFiles.Select(x => new FileInfo(x)).ToArray(); this.Log().Info("Base Size: {0}, Current Size: {1}, Delta Size: {2}", fileInfos[0].Length, fileInfos[1].Length, fileInfos[2].Length); (fileInfos[2].Length - fileInfos[1].Length).ShouldBeLessThan(0); } finally { tempFiles.ForEach(File.Delete); } }
public void SpecFileMarkdownRenderingTest() { var dontcare = IntegrationTestHelper.GetPath("fixtures", "NSync.Core.1.1.0.0.nupkg"); var inputSpec = IntegrationTestHelper.GetPath("fixtures", "NSync.Core.1.1.0.0.nuspec"); var fixture = new ReleasePackage(dontcare); var targetFile = Path.GetTempFileName(); File.Copy(inputSpec, targetFile, true); try { // NB: For No Reason At All, renderReleaseNotesMarkdown is // invulnerable to ExposedObject. Whyyyyyyyyy var renderMinfo = fixture.GetType().GetMethod("renderReleaseNotesMarkdown", BindingFlags.NonPublic | BindingFlags.Instance); renderMinfo.Invoke(fixture, new object[] {targetFile}); var doc = XDocument.Load(targetFile); XNamespace ns = "http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"; var relNotesElement = doc.Descendants(ns + "releaseNotes").First(); var htmlText = relNotesElement.Value; this.Log().Info("HTML Text:\n{0}", htmlText); htmlText.Contains("## Release Notes").ShouldBeFalse(); } finally { File.Delete(targetFile); } }
public void ReleasePackageIntegrationTest() { var inputPackage = IntegrationTestHelper.GetPath("fixtures", "NSync.Core.1.0.0.0.nupkg"); var outputPackage = Path.GetTempFileName() + ".nupkg"; var fixture = new ReleasePackage(inputPackage); var sourceDir = IntegrationTestHelper.GetPath("..", "packages"); (new DirectoryInfo(sourceDir)).Exists.ShouldBeTrue(); try { fixture.CreateReleasePackage(outputPackage, sourceDir); this.Log().Info("Resulting package is at {0}", outputPackage); var pkg = new ZipPackage(outputPackage); int refs = pkg.References.Count(); this.Log().Info("Found {0} refs", refs); refs.ShouldEqual(0); this.Log().Info("Files in release package:"); pkg.GetFiles().ForEach(x => this.Log().Info(x.Path)); pkg.GetFiles().Any(x => x.Path.ToLowerInvariant().Contains(@"lib\sl")).ShouldBeFalse(); pkg.GetFiles().Any(x => x.Path.ToLowerInvariant().Contains(@".xml")).ShouldBeFalse(); } finally { File.Delete(outputPackage); } }