Beispiel #1
0
        /// <summary>
        /// This method returns the target directories (or pl, zip or ftp) for the given source path, for each :
        /// If CompileLocally, returns the directory of the source
        /// If the deployment dir is empty and we didn't match an absolute compilation path, returns the source directory as well
        /// </summary>
        private List <FileToDeploy> GetTargetsNeeded(string sourcePath, int step, DeployTransferRuleTarget targetType)
        {
            // local compilation? return only one path, MOVE next to the source
            if (step == 0 && _compileLocally)
            {
                return(new List <FileToDeploy> {
                    FileToDeploy.New(DeployType.Move, sourcePath, Path.GetDirectoryName(sourcePath), null)
                });
            }

            var outList = new List <FileToDeploy>();

            // for each transfer rule that match the source pattern
            foreach (var rule in DeployTransferRules.Where(rule => sourcePath.RegexMatch(GetRegexAndReplaceVariablesIn(rule.SourcePattern)) && rule.Step == step && rule.TargetType == targetType))
            {
                string targetBasePath;

                var deployTarget = ReplaceVariablesIn(rule.DeployTarget ?? sourcePath);

                if (rule.ShouldDeployTargetReplaceDollar)
                {
                    targetBasePath = sourcePath.RegexReplace(GetRegexAndReplaceVariablesIn(rule.SourcePattern), deployTarget);
                }
                else
                {
                    targetBasePath = deployTarget;
                }

                if (rule.Type != DeployType.Ftp && !Path.IsPathRooted(deployTarget))
                {
                    targetBasePath = Path.Combine(_deploymentDirectory, targetBasePath);
                }

                if (!outList.Exists(needed => needed.TargetBasePath.EqualsCi(targetBasePath)))
                {
                    outList.Add(FileToDeploy.New(rule.Type, sourcePath, targetBasePath, rule));
                }

                // stop ?
                if (!rule.ContinueAfterThisRule)
                {
                    break;
                }
            }

            // for the compilation step
            if (step == 0)
            {
                if (outList.Count == 0)
                {
                    // move to deployment directory by default
                    outList.Add(FileToDeploy.New(DeployType.Move, sourcePath, _deploymentDirectory, null));
                }
                else
                {
                    var lastCopy = outList.LastOrDefault() as FileToDeployCopy;
                    if (lastCopy != null)
                    {
                        // if the last deploy is a copy, make it a move
                        lastCopy.FinalDeploy = true;
                    }
                }
            }

            return(outList);
        }
Beispiel #2
0
        /// <summary>
        /// This method returns the transfer directories for the given source path, for each :
        /// If CompileLocally, returns the directory of the source
        /// If the deployment dir is empty and we didn't match an absolute compilation path, returns the source directoy as well
        /// </summary>
        public List <FileToDeploy> GetTargetDirsNeededForFile(string sourcePath, int step)
        {
            // local compilation? return only one path, MOVE next to the source
            if (step == 0 && ProEnv.CompileLocally)
            {
                return new List <FileToDeploy> {
                           new FileToDeploy(Path.GetDirectoryName(sourcePath), DeployType.Move, true)
                }
            }
            ;

            var outList = new List <FileToDeploy>();

            // for each transfer rule that match the source pattern
            foreach (var rule in DeployTransferRules.Where(
                         rule => sourcePath.RegexMatch(rule.SourcePattern.WildCardToRegex()) && rule.Step == step)
                     )
            {
                string outPath;

                if (rule.Type == DeployType.Ftp || Path.IsPathRooted(rule.DeployTarget))
                {
                    outPath = rule.DeployTarget;
                }
                else
                {
                    outPath = Path.Combine(ProEnv.BaseCompilationPath, rule.DeployTarget);
                }

                if (!outList.Exists(needed => needed.TargetDir.EqualsCi(outPath)))
                {
                    outList.Add(new FileToDeploy(outPath, rule.Type, !rule.ContinueAfterThisRule));
                }

                // stop ?
                if (!rule.ContinueAfterThisRule)
                {
                    break;
                }
            }

            // nothing matched?
            if (outList.Count == 0)
            {
                // for the compilation, move to deployment directory
                if (step == 0)
                {
                    outList.Add(new FileToDeploy(ProEnv.BaseCompilationPath, DeployType.Move, true));
                }
            }
            else
            {
                var lastDeploy = outList.LastOrDefault();
                if (lastDeploy != null)
                {
                    // flag last deploy
                    lastDeploy.FinalDeploy = true;

                    // for the compilation step, if the last deploy is a copy, make it a move
                    if (step == 0 && lastDeploy.DeployType == DeployType.Copy)
                    {
                        lastDeploy.DeployType = DeployType.Move;
                    }
                }
            }

            return(outList);
        }