Пример #1
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);
            }
        }
Пример #2
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");
            }
        }
Пример #3
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}");
        }
Пример #4
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);
        }
Пример #5
0
        public void CopyFiles()
        {
            lister
            .List(@"file_at_root1.txt")
            .List(@"subdir\file_at_root2.txt");

            LocalPath destDir = new LocalPath(@"dest\dir");

            packageDef.AddFolderSource("dir", new FullPath(@"source\dir"), true);

            CopyProcessor processor = new CopyProcessor(taskContext, copier, new FullPath(@"d:\brisi"));

            processor.AddTransformation("dir", destDir);

            processor.Process(packageDef);

            Assert.IsTrue(copier.DestinationFileNames.Contains(@"d:\brisi\dest\dir\file_at_root1.txt"));
            Assert.IsTrue(copier.DestinationFileNames.Contains(@"d:\brisi\dest\dir\subdir\file_at_root2.txt"));
        }
Пример #6
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]);
        }
Пример #7
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);
        }
Пример #8
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);
        }