예제 #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");
            }
        }
예제 #2
0
        public IPackageDef Process(IPackageDef packageDef)
        {
            StandardPackageDef zippedPackageDef = new StandardPackageDef();
            List <string>      filesToZip       = new List <string>();

            foreach (IFilesSource childSource in packageDef.ListChildSources())
            {
                if (sourcesToZip.Contains(childSource.Id))
                {
                    foreach (PackagedFileInfo file in childSource.ListFiles())
                    {
                        if (false == LoggingHelper.LogIfFilteredOut(file.FullPath.ToString(), filter, logger))
                        {
                            continue;
                        }

                        logger.Log("Adding file '{0}' to zip package", file.FullPath);
                        filesToZip.Add(file.FullPath.ToString());
                    }
                }
            }

            zipper.ZipFiles(zipFileName, baseDir, compressionLevel, filesToZip);

            SingleFileSource singleFileSource = new SingleFileSource("zip", zipFileName);

            zippedPackageDef.AddFilesSource(singleFileSource);

            return(zippedPackageDef);
        }
예제 #3
0
        public IPackageDef Process(IPackageDef packageDef)
        {
            StandardPackageDef  zippedPackageDef = new StandardPackageDef();
            List <FileFullPath> filesToZip       = new List <FileFullPath>();

            foreach (IFilesSource childSource in packageDef.ListChildSources())
            {
                if (_sourcesToZip.Contains(childSource.Id))
                {
                    foreach (PackagedFileInfo file in childSource.ListFiles())
                    {
                        if (!LoggingHelper.LogIfFilteredOut(file.FileFullPath.ToString(), _filter, _taskContext, _logFiles))
                        {
                            continue;
                        }

                        if (_logFiles)
                        {
                            _taskContext.LogInfo($"Adding file '{file.FileFullPath}' to zip package");
                        }

                        filesToZip.Add(file.FileFullPath);
                    }
                }
            }

            _zipper.ZipFiles(_zipFileName, _baseDir, filesToZip, _optimizeFiles);

            SingleFileSource singleFileSource = new SingleFileSource("zip", _zipFileName);

            zippedPackageDef.AddFilesSource(singleFileSource);

            return(zippedPackageDef);
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
        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);
        }
예제 #6
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}");
        }
예제 #7
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);
        }
예제 #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);
        }
예제 #9
0
 public IPackageDef Process(IPackageDef packageDef)
 {
     return((IPackageDef)ProcessPrivate(packageDef, true));
 }