示例#1
0
        public IEnumerable <string> DetermineTransformFileNames(string sourceFile, XmlConfigTransformDefinition transformation)
        {
            var defaultTransformFileName = DetermineTransformFileName(sourceFile, transformation, true);
            var transformFileName        = DetermineTransformFileName(sourceFile, transformation, false);

            string fullTransformPath;

            if (Path.IsPathRooted(transformFileName))
            {
                fullTransformPath = Path.GetFullPath(GetDirectoryName(transformFileName));
            }
            else
            {
                var relativeTransformPath = fileSystem.GetRelativePath(sourceFile, transformFileName);
                fullTransformPath = Path.GetFullPath(Path.Combine(GetDirectoryName(sourceFile), GetDirectoryName(relativeTransformPath)));
            }

            if (!fileSystem.DirectoryExists(fullTransformPath))
            {
                yield break;
            }

            // The reason we use fileSystem.EnumerateFiles here is to get the actual file-names from the physical file-system.
            // This prevents any issues with mis-matched casing in transform specifications.
            foreach (var transformFile in fileSystem.EnumerateFiles(fullTransformPath, GetFileName(defaultTransformFileName), GetFileName(transformFileName)))
            {
                var sourceFileName = (transformation?.SourcePattern?.Contains(Path.DirectorySeparatorChar) ?? false)
                    ? fileSystem.GetRelativePath(transformFile, sourceFile).TrimStart('.', Path.DirectorySeparatorChar)
                    : GetFileName(sourceFile);

                if (transformation.Advanced && !transformation.IsSourceWildcard && !string.Equals(transformation.SourcePattern, sourceFileName, StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }

                if (transformation.Advanced && transformation.IsSourceWildcard && !DoesFileMatchWildcardPattern(sourceFileName, transformation.SourcePattern))
                {
                    continue;
                }

                if (!fileSystem.FileExists(transformFile))
                {
                    continue;
                }

                if (string.Equals(sourceFile, transformFile, StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }

                yield return(transformFile);
            }
        }
        void ApplyTransformations(string sourceFile, XmlConfigTransformDefinition transformation,
                                  ISet <Tuple <string, string> > transformFilesApplied, ICollection <XmlConfigTransformDefinition> transformDefinitionsApplied)
        {
            if (transformation == null)
            {
                return;
            }

            foreach (var transformFile in DetermineTransformFileNames(sourceFile, transformation))
            {
                var sourceFileName = (transformation?.SourcePattern?.Contains(Path.DirectorySeparatorChar) ?? false)
                    ? fileSystem.GetRelativePath(transformFile, sourceFile).TrimStart('.', Path.DirectorySeparatorChar)
                    : GetFileName(sourceFile);

                if (transformation.Advanced && !transformation.IsSourceWildcard && !string.Equals(transformation.SourcePattern, sourceFileName, StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }

                if (transformation.Advanced && transformation.IsSourceWildcard && !DoesFileMatchWildcardPattern(sourceFileName, transformation.SourcePattern))
                {
                    continue;
                }

                if (!fileSystem.FileExists(transformFile))
                {
                    continue;
                }

                if (string.Equals(sourceFile, transformFile, StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }

                var transformFiles = new Tuple <string, string>(transformFile, sourceFile);
                if (transformFilesApplied.Contains(transformFiles))
                {
                    continue;
                }

                Log.Info("Transforming '{0}' using '{1}'.", sourceFile, transformFile);
                configurationTransformer.PerformTransform(sourceFile, transformFile, sourceFile);

                transformFilesApplied.Add(transformFiles);
                transformDefinitionsApplied.Add(transformation);
            }
        }
示例#3
0
        private string[] PerformTransform(string sourceFile)
        {
            fileSystem.EnumerateFiles(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>())
            .Returns(callInfo => files.Where(file => FilesMatch(callInfo, file)));
            var realFileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem();

            fileSystem.GetRelativePath(Arg.Any <string>(), Arg.Any <string>())
            .Returns(x => GetRelativePath(x, realFileSystem));
            var        transformFileLocator     = new TransformFileLocator(fileSystem);
            var        transform                = new XmlConfigTransformDefinition(transformDefinition);
            const bool diagnosticLoggingEnabled = false;
            var        result = transformFileLocator.DetermineTransformFileNames(sourceFile, transform, diagnosticLoggingEnabled).ToArray();

            return(result);
        }
示例#4
0
        private string[] PerformTransform(string sourceFile)
        {
            fileSystem.EnumerateFiles(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>())
            .Returns(callInfo => files.Where(file => FilesMatch(callInfo, file)));
            var realFileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem();

            fileSystem.GetRelativePath(Arg.Any <string>(), Arg.Any <string>())
            .Returns(x => GetRelativePath(x, realFileSystem));
            var transformFileLocator = new TransformFileLocator(fileSystem);
            var transform            = new XmlConfigTransformDefinition(transformDefinition);

            var deploymentVariables = new CalamariVariables();

            deploymentVariables[KnownVariables.OriginalPackageDirectoryPath] = extractionDirectory;
            var deployment = new RunningDeployment(null, deploymentVariables);

            const bool diagnosticLoggingEnabled = false;
            var        result = transformFileLocator.DetermineTransformFileNames(sourceFile, transform, diagnosticLoggingEnabled, deployment).ToArray();

            return(result);
        }
        public IEnumerable <string> DetermineTransformFileNames(string sourceFile, XmlConfigTransformDefinition transformation, bool diagnosticLoggingEnabled, string currentDirectory)
        {
            var defaultTransformFileName = DetermineTransformFileName(sourceFile, transformation, true);
            var transformFileName        = DetermineTransformFileName(sourceFile, transformation, false);

            string fullTransformDirectoryPath;

            if (Path.IsPathRooted(transformFileName))
            {
                fullTransformDirectoryPath = Path.GetFullPath(GetDirectoryName(transformFileName));
            }
            else
            {
                var relativeTransformPath = fileSystem.GetRelativePath(sourceFile, transformFileName);
                fullTransformDirectoryPath = Path.GetFullPath(Path.Combine(GetDirectoryName(sourceFile), GetDirectoryName(relativeTransformPath)));
            }

            if (!fileSystem.DirectoryExists(fullTransformDirectoryPath))
            {
                if (diagnosticLoggingEnabled)
                {
                    log.Verbose($" - Skipping as transform folder \'{fullTransformDirectoryPath}\' does not exist");
                }
                yield break;
            }

            // The reason we use fileSystem.EnumerateFiles here is to get the actual file-names from the physical file-system.
            // This prevents any issues with mis-matched casing in transform specifications.
            var enumerateFiles = fileSystem.EnumerateFiles(fullTransformDirectoryPath, GetFileName(defaultTransformFileName), GetFileName(transformFileName)).Distinct().ToArray();

            if (enumerateFiles.Any())
            {
                foreach (var transformFile in enumerateFiles)
                {
                    var sourceFileName = GetSourceFileName(sourceFile, transformation, transformFileName, transformFile, currentDirectory);

                    if (transformation.Advanced && !transformation.IsSourceWildcard &&
                        !string.Equals(transformation.SourcePattern, sourceFileName, StringComparison.OrdinalIgnoreCase))
                    {
                        if (diagnosticLoggingEnabled)
                        {
                            log.Verbose($" - Skipping as file name \'{sourceFileName}\' does not match the target pattern \'{transformation.SourcePattern}\'");
                        }
                        continue;
                    }

                    if (transformation.Advanced && transformation.IsSourceWildcard &&
                        !DoesFileMatchWildcardPattern(sourceFileName, transformation.SourcePattern))
                    {
                        if (diagnosticLoggingEnabled)
                        {
                            log.Verbose($" - Skipping as file name \'{sourceFileName}\' does not match the wildcard target pattern \'{transformation.SourcePattern}\'");
                        }
                        continue;
                    }

                    if (!fileSystem.FileExists(transformFile))
                    {
                        if (diagnosticLoggingEnabled)
                        {
                            log.Verbose($" - Skipping as transform \'{transformFile}\' does not exist");
                        }
                        continue;
                    }

                    if (string.Equals(sourceFile, transformFile, StringComparison.OrdinalIgnoreCase))
                    {
                        if (diagnosticLoggingEnabled)
                        {
                            log.Verbose($" - Skipping as target \'{sourceFile}\' is the same as transform \'{transformFile}\'");
                        }
                        continue;
                    }

                    yield return(transformFile);
                }
            }
            else if (diagnosticLoggingEnabled)
            {
                if (GetFileName(defaultTransformFileName) == GetFileName(transformFileName))
                {
                    log.Verbose($" - skipping as transform \'{GetFileName(defaultTransformFileName)}\' could not be found in \'{fullTransformDirectoryPath}\'");
                }
                else
                {
                    log.Verbose($" - skipping as neither transform \'{GetFileName(defaultTransformFileName)}\' nor transform \'{GetFileName(transformFileName)}\' could be found in \'{fullTransformDirectoryPath}\'");
                }
            }
        }