Example #1
0
        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");
            }
        }
Example #2
0
 public void Setup()
 {
     taskContext = null;
     copier      = new MockCopier();
     lister      = new MockDirectoryFilesLister();
     packageDef  = new StandardPackageDef("package", taskContext, lister);
 }
        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);
            }
        }
Example #4
0
        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}");
        }
Example #5
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);
        }
Example #6
0
        private void Setup()
        {
            logger = MockRepository.GenerateStub <ILogger>();

            filesList1 = new[] { @"somedir1\file1.txt", @"somedir1\file2.txt", @"somedir1\file3.txt" };
            filesList2 = new[] { @"somedir2\file1.txt", @"somedir2\file2.txt", @"somedir2\file3.txt", @"somedir2\subdir\filex.txt" };

            ConvertToFullPath(filesList1);
            ConvertToFullPath(filesList2);

            package = new StandardPackageDef();

            directoryFilesLister = MockRepository.GenerateMock <IDirectoryFilesLister>();
            directoryFilesLister.Expect(x => x.ListFiles(
                                            Path.GetFullPath("somedir1"), true)).Return(filesList1);
            directoryFilesLister.Expect(x => x.ListFiles(
                                            Path.GetFullPath("somedir2"), true)).Return(filesList2);

            DirectorySource dir1 = new DirectorySource(
                logger,
                directoryFilesLister,
                "console",
                "somedir1");

            dir1.SetFilter(new RegexFileFilter("File3"));
            package.AddFilesSource(dir1);

            DirectorySource dir2 = new DirectorySource(
                logger,
                directoryFilesLister,
                "win.service",
                "somedir2");

            package.AddFilesSource(dir2);

            copier = MockRepository.GenerateMock <ICopier>();
        }
Example #7
0
        public void TestCopyProcessor()
        {
            CopyProcessor copyProcessor = new CopyProcessor(logger, copier, "dest");

            copyProcessor
            .AddTransformation("console", new LocalPath("Console"))
            .AddTransformation("win.service", new LocalPath("WinService"));

            StandardPackageDef transformedPackage = (StandardPackageDef)copyProcessor.Process(
                package);

            ICollection <PackagedFileInfo> transformedFiles = transformedPackage.ListFiles();

            Assert.AreEqual(6, transformedFiles.Count);
            Assert.Contains(transformedFiles, PackagedFileInfo.FromLocalPath(@"dest\Console\file1.txt"));
            Assert.Contains(transformedFiles, PackagedFileInfo.FromLocalPath(@"dest\WinService\subdir\filex.txt"));

            IList <object[]> calls = copier.GetArgumentsForCallsMadeOn(x => x.Copy(null, null));

            Assert.AreEqual(6, calls.Count);

            Assert.AreEqual(Path.GetFullPath(@"somedir1\file1.txt"), calls[0][0]);
            Assert.AreEqual(Path.GetFullPath(@"dest\Console\file1.txt"), calls[0][1]);
        }
Example #8
0
        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);
        }
Example #9
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);
        }