Пример #1
0
        private IReadOnlyList <IFileChange> GetFileChangesInternal(IEngineEnvironmentSettings environmentSettings, IDirectory sourceDir, string targetDir, IGlobalRunSpec spec)
        {
            EngineConfig cfg      = new EngineConfig(environmentSettings, EngineConfig.DefaultWhitespaces, EngineConfig.DefaultLineEndings, spec.RootVariableCollection);
            IProcessor   fallback = Processor.Create(cfg, spec.Operations);

            List <IFileChange> changes = new List <IFileChange>();
            List <KeyValuePair <IPathMatcher, IProcessor> > fileGlobProcessors = CreateFileGlobProcessors(sourceDir.MountPoint.EnvironmentSettings, spec);

            foreach (IFile file in sourceDir.EnumerateFiles("*", SearchOption.AllDirectories))
            {
                string sourceRel = file.PathRelativeTo(sourceDir);
                string fileName  = Path.GetFileName(sourceRel);

                if (spec.IgnoreFileNames.Contains(fileName))
                {   // The placeholder file should never get copied / created / processed. It just causes the dir to get created if needed.
                    // So this happens before all the include / exclude / copy checks.
                    CreateTargetDir(environmentSettings, sourceRel, targetDir, spec);
                    continue;
                }

                foreach (IPathMatcher include in spec.Include)
                {
                    if (include.IsMatch(sourceRel))
                    {
                        bool excluded = false;
                        foreach (IPathMatcher exclude in spec.Exclude)
                        {
                            if (exclude.IsMatch(sourceRel))
                            {
                                excluded = true;
                                break;
                            }
                        }

                        if (!excluded)
                        {
                            if (!spec.TryGetTargetRelPath(sourceRel, out string targetRel))
                            {
                                targetRel = sourceRel;
                            }

                            string targetPath = Path.Combine(targetDir, targetRel);

                            if (environmentSettings.Host.FileSystem.FileExists(targetPath))
                            {
                                changes.Add(new FileChange(targetRel, ChangeKind.Overwrite));
                            }
                            else
                            {
                                changes.Add(new FileChange(targetRel, ChangeKind.Create));
                            }
                        }

                        break;
                    }
                }
            }

            return(changes);
        }
Пример #2
0
        private static List <KeyValuePair <IPathMatcher, IProcessor> > CreateFileGlobProcessors(IGlobalRunSpec spec)
        {
            List <KeyValuePair <IPathMatcher, IProcessor> > processorList = new List <KeyValuePair <IPathMatcher, IProcessor> >();

            foreach (KeyValuePair <IPathMatcher, IRunSpec> runSpec in spec.Special)
            {
                IReadOnlyList <IOperationProvider> operations = runSpec.Value.GetOperations(spec.Operations);
                EngineConfig config    = new EngineConfig(EngineConfig.DefaultWhitespaces, EngineConfig.DefaultLineEndings, spec.RootVariableCollection);
                IProcessor   processor = Processor.Create(config, operations);

                processorList.Add(new KeyValuePair <IPathMatcher, IProcessor>(runSpec.Key, processor));
            }

            return(processorList);
        }
Пример #3
0
        public IReadOnlyList <IFileChange> GetFileChanges(string runSpecPath, IDirectory sourceDir, string targetDir)
        {
            IGlobalRunSpec spec;

            using (Stream stream = sourceDir.MountPoint.EnvironmentSettings.Host.FileSystem.OpenRead(runSpecPath))
            {
                spec = RunSpecLoader(stream);
                EngineConfig config    = new EngineConfig(sourceDir.MountPoint.EnvironmentSettings, EngineConfig.DefaultWhitespaces, EngineConfig.DefaultLineEndings, spec.RootVariableCollection);
                IProcessor   processor = Processor.Create(config, spec.Operations);
                stream.Position = 0;
                using (MemoryStream ms = new MemoryStream())
                {
                    processor.Run(stream, ms);
                    ms.Position = 0;
                    spec        = RunSpecLoader(ms);
                }
            }

            return(GetFileChangesInternal(sourceDir.MountPoint.EnvironmentSettings, sourceDir, targetDir, spec));
        }
Пример #4
0
        public void Run(string runSpecPath, IDirectory sourceDir, string targetDir)
        {
            IGlobalRunSpec spec;

            using (FileStream stream = File.OpenRead(runSpecPath))
            {
                spec = RunSpecLoader(stream);
                EngineConfig config    = new EngineConfig(EngineConfig.DefaultWhitespaces, EngineConfig.DefaultLineEndings, spec.RootVariableCollection);
                IProcessor   processor = Processor.Create(config, spec.Operations);
                stream.Position = 0;
                using (MemoryStream ms = new MemoryStream())
                {
                    processor.Run(stream, ms);
                    ms.Position = 0;
                    spec        = RunSpecLoader(ms);
                }
            }

            RunInternal(this, sourceDir, targetDir, spec);
        }
Пример #5
0
        private void RunInternal(IEngineEnvironmentSettings environmentSettings, IDirectory sourceDir, string targetDir, IGlobalRunSpec spec)
        {
            EngineConfig cfg      = new EngineConfig(environmentSettings, EngineConfig.DefaultWhitespaces, EngineConfig.DefaultLineEndings, spec.RootVariableCollection);
            IProcessor   fallback = Processor.Create(cfg, spec.Operations);

            List <KeyValuePair <IPathMatcher, IProcessor> > fileGlobProcessors = CreateFileGlobProcessors(sourceDir.MountPoint.EnvironmentSettings, spec);

            foreach (IFile file in sourceDir.EnumerateFiles("*", SearchOption.AllDirectories))
            {
                string sourceRel = file.PathRelativeTo(sourceDir);
                string fileName  = Path.GetFileName(sourceRel);

                if (spec.IgnoreFileNames.Contains(fileName))
                {   // The placeholder file should never get copied / created / processed. It just causes the dir to get created if needed.
                    // So this happens before all the include / exclude / copy checks.
                    CreateTargetDir(environmentSettings, sourceRel, targetDir, spec);
                    continue;
                }

                foreach (IPathMatcher include in spec.Include)
                {
                    if (include.IsMatch(sourceRel))
                    {
                        bool excluded = false;
                        foreach (IPathMatcher exclude in spec.Exclude)
                        {
                            if (exclude.IsMatch(sourceRel))
                            {
                                excluded = true;
                                break;
                            }
                        }

                        if (!excluded)
                        {
                            bool copy = false;
                            foreach (IPathMatcher copyOnly in spec.CopyOnly)
                            {
                                if (copyOnly.IsMatch(sourceRel))
                                {
                                    copy = true;
                                    break;
                                }
                            }

                            spec.LocalizationOperations.TryGetValue(sourceRel, out IReadOnlyList <IOperationProvider> locOperations);

                            if (!copy)
                            {
                                ProcessFile(file, sourceRel, targetDir, spec, fallback, fileGlobProcessors, locOperations);
                            }
                            else
                            {
                                string targetPath = CreateTargetDir(environmentSettings, sourceRel, targetDir, spec);

                                using (Stream sourceStream = file.OpenRead())
                                    using (Stream targetStream = environmentSettings.Host.FileSystem.CreateFile(targetPath))
                                    {
                                        sourceStream.CopyTo(targetStream);
                                    }
                            }
                        }

                        break;
                    }
                }
            }
        }
Пример #6
0
        private static void RunInternal(Orchestrator self, IDirectory sourceDir, string targetDir, IGlobalRunSpec spec)
        {
            EngineConfig cfg      = new EngineConfig(EngineConfig.DefaultWhitespaces, EngineConfig.DefaultLineEndings, spec.RootVariableCollection);
            IProcessor   fallback = Processor.Create(cfg, spec.Operations);

            Dictionary <IPathMatcher, IProcessor> specializations = spec.Special
                                                                    .ToDictionary(
                x => x.Key,
                x =>
            {
                IReadOnlyList <IOperationProvider> operations = x.Value.GetOperations(spec.Operations);
                EngineConfig config  = new EngineConfig(EngineConfig.DefaultWhitespaces, EngineConfig.DefaultLineEndings, spec.RootVariableCollection);
                IProcessor processor = Processor.Create(config, operations);
                return(processor);
            });

            foreach (IFile file in sourceDir.EnumerateFiles("*", SearchOption.AllDirectories))
            {
                string sourceRel = file.PathRelativeTo(sourceDir);

                foreach (IPathMatcher include in spec.Include)
                {
                    if (include.IsMatch(sourceRel))
                    {
                        bool excluded = false;
                        foreach (IPathMatcher exclude in spec.Exclude)
                        {
                            if (exclude.IsMatch(sourceRel))
                            {
                                excluded = true;
                                break;
                            }
                        }

                        if (!excluded)
                        {
                            bool copy = false;
                            foreach (IPathMatcher copyOnly in spec.CopyOnly)
                            {
                                if (copyOnly.IsMatch(sourceRel))
                                {
                                    copy = true;
                                    break;
                                }
                            }

                            if (!copy)
                            {
                                ProcessFile(self, file, sourceRel, targetDir, spec, fallback, specializations);
                            }
                            else
                            {
                                string targetRel;
                                if (!spec.TryGetTargetRelPath(sourceRel, out targetRel))
                                {
                                    targetRel = sourceRel;
                                }

                                string targetPath    = Path.Combine(targetDir, targetRel);
                                string fullTargetDir = Path.GetDirectoryName(targetPath);
                                Directory.CreateDirectory(fullTargetDir);

                                using (Stream sourceStream = file.OpenRead())
                                    using (Stream targetStream = File.Create(targetPath))
                                    {
                                        sourceStream.CopyTo(targetStream);
                                    }
                            }
                        }

                        break;
                    }
                }
            }
        }
Пример #7
0
        private void RunInternal(IDirectory sourceDir, string targetDir, IGlobalRunSpec spec)
        {
            EngineConfig cfg      = new EngineConfig(_logger, EngineConfig.DefaultWhitespaces, EngineConfig.DefaultLineEndings, spec.RootVariableCollection);
            IProcessor   fallback = Processor.Create(cfg, spec.Operations);

            List <KeyValuePair <IPathMatcher, IProcessor> > fileGlobProcessors = CreateFileGlobProcessors(_logger, spec);

            foreach (IFile file in sourceDir.EnumerateFiles("*", SearchOption.AllDirectories))
            {
                string sourceRel = file.PathRelativeTo(sourceDir);
                string fileName  = Path.GetFileName(sourceRel);
                bool   checkingDirWithPlaceholderFile = false;

                if (spec.IgnoreFileNames.Contains(fileName))
                {
                    // The placeholder file should never get copied / created / processed. It just causes the dir to get created if needed.
                    // The change checking / reporting is different, setting this variable tracks it.
                    checkingDirWithPlaceholderFile = true;
                }

                foreach (IPathMatcher include in spec.Include)
                {
                    if (include.IsMatch(sourceRel))
                    {
                        bool excluded = false;
                        foreach (IPathMatcher exclude in spec.Exclude)
                        {
                            if (exclude.IsMatch(sourceRel))
                            {
                                excluded = true;
                                break;
                            }
                        }

                        if (!excluded)
                        {
                            bool copy = false;
                            foreach (IPathMatcher copyOnly in spec.CopyOnly)
                            {
                                if (copyOnly.IsMatch(sourceRel))
                                {
                                    copy = true;
                                    break;
                                }
                            }

                            if (checkingDirWithPlaceholderFile)
                            {
                                CreateTargetDir(_fileSystem, sourceRel, targetDir, spec);
                            }
                            else if (!copy)
                            {
                                ProcessFile(file, sourceRel, targetDir, spec, fallback, fileGlobProcessors);
                            }
                            else
                            {
                                string targetPath = CreateTargetDir(_fileSystem, sourceRel, targetDir, spec);

                                using (Stream sourceStream = file.OpenRead())
                                    using (Stream targetStream = _fileSystem.CreateFile(targetPath))
                                    {
                                        sourceStream.CopyTo(targetStream);
                                    }
                            }
                        }

                        break;
                    }
                }
            }
        }
Пример #8
0
        private IReadOnlyList <IFileChange2> GetFileChangesInternal(IDirectory sourceDir, string targetDir, IGlobalRunSpec spec)
        {
            EngineConfig cfg      = new EngineConfig(_logger, EngineConfig.DefaultWhitespaces, EngineConfig.DefaultLineEndings, spec.RootVariableCollection);
            IProcessor   fallback = Processor.Create(cfg, spec.Operations);

            List <IFileChange2> changes = new List <IFileChange2>();
            List <KeyValuePair <IPathMatcher, IProcessor> > fileGlobProcessors = CreateFileGlobProcessors(_logger, spec);

            foreach (IFile file in sourceDir.EnumerateFiles("*", SearchOption.AllDirectories))
            {
                string sourceRel = file.PathRelativeTo(sourceDir);
                string fileName  = Path.GetFileName(sourceRel);
                bool   checkingDirWithPlaceholderFile = false;

                if (spec.IgnoreFileNames.Contains(fileName))
                {
                    // The placeholder file should never get copied / created / processed. It just causes the dir to get created if needed.
                    // The change checking / reporting is different, setting this variable tracks it.
                    checkingDirWithPlaceholderFile = true;
                }

                foreach (IPathMatcher include in spec.Include)
                {
                    if (include.IsMatch(sourceRel))
                    {
                        bool excluded = false;
                        foreach (IPathMatcher exclude in spec.Exclude)
                        {
                            if (exclude.IsMatch(sourceRel))
                            {
                                excluded = true;
                                break;
                            }
                        }

                        if (!excluded)
                        {
                            if (!spec.TryGetTargetRelPath(sourceRel, out string targetRel))
                            {
                                targetRel = sourceRel;
                            }

                            string targetPath = Path.Combine(targetDir, targetRel);

                            if (checkingDirWithPlaceholderFile)
                            {
                                targetPath = Path.GetDirectoryName(targetPath);
                                targetRel  = Path.GetDirectoryName(targetRel);

                                if (_fileSystem.DirectoryExists(targetPath))
                                {
                                    changes.Add(new FileChange(sourceRel, targetRel, ChangeKind.Overwrite));
                                }
                                else
                                {
                                    changes.Add(new FileChange(sourceRel, targetRel, ChangeKind.Create));
                                }
                            }
                            else if (_fileSystem.FileExists(targetPath))
                            {
                                changes.Add(new FileChange(sourceRel, targetRel, ChangeKind.Overwrite));
                            }
                            else
                            {
                                changes.Add(new FileChange(sourceRel, targetRel, ChangeKind.Create));
                            }
                        }

                        break;
                    }
                }
            }

            return(changes);
        }