static int Main(string[] args) { var optParams = parseOptions(args); if (optParams == null) { return -1; } var targetDir = optParams["target"]; var package = new ReleasePackage(optParams["input"]); var targetFile = Path.Combine(targetDir, package.SuggestedReleaseFileName); package.CreateReleasePackage(targetFile, optParams["pkgdir"] != "" ? optParams["pkgdir"] : null); var releaseFile = Path.Combine(targetDir, "RELEASES"); if (File.Exists(releaseFile)) { var releaseEntries = ReleaseEntry.ParseReleaseFile(File.ReadAllText(releaseFile, Encoding.UTF8)); var latestFullRelease = releaseEntries .Where(x => x.IsDelta == false) .MaxBy(x => x.Version) .Select(x => new ReleasePackage(Path.Combine(targetDir, x.Filename), true)) .FirstOrDefault(); var deltaFile = Path.Combine(targetDir, package.SuggestedReleaseFileName.Replace("full", "delta")); Console.WriteLine("{0} {1}", latestFullRelease.InputPackageFile, deltaFile); package.CreateDeltaPackage(latestFullRelease, deltaFile); } ReleaseEntry.BuildReleasesFile(targetDir); return 0; }
public void CreateDeltaPackageIntegrationTest() { var basePackage = IntegrationTestHelper.GetPath("fixtures", "Shimmer.Core.1.0.0.0.nupkg"); var newPackage = IntegrationTestHelper.GetPath("fixtures", "Shimmer.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); deltaPkg.GetFiles().Count().ShouldBeGreaterThan(0); this.Log().Info("Files in delta package:"); deltaPkg.GetFiles().ForEach(x => this.Log().Info(x.Path)); // 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 and shasums deltaPkg.GetFiles().Any(x => !x.Path.ToLowerInvariant().Contains("ionic.zip")).ShouldBeTrue(); deltaPkg.GetFiles() .Where(x => !x.Path.ToLowerInvariant().Contains("ionic.zip")) .All(x => x.Path.ToLowerInvariant().EndsWith("diff") || x.Path.ToLowerInvariant().EndsWith("shasum")) .ShouldBeTrue(); // Every .diff file should have a shasum file deltaPkg.GetFiles().Any(x => x.Path.ToLowerInvariant().EndsWith(".diff")).ShouldBeTrue(); deltaPkg.GetFiles() .Where(x => x.Path.ToLowerInvariant().EndsWith(".diff")) .ForEach(x => { var lookingFor = x.Path.Replace(".diff", ".shasum"); this.Log().Info("Looking for corresponding shasum file: {0}", lookingFor); deltaPkg.GetFiles().Any(y => y.Path == lookingFor).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); } }