示例#1
0
 private void AddDependencies(ITargetInternal target, List <ITargetInternal> targets)
 {
     foreach (var dependency in target.Dependencies)
     {
         var dependantTarget = _targetTree.GetTarget(dependency.TargetName);
         targets.Add(dependantTarget);
         AddDependencies(dependantTarget, targets);
     }
 }
示例#2
0
        public ITargetInternal AddTarget(ITargetInternal target)
        {
            if (_targets.ContainsKey(target.TargetName))
            {
                throw new ArgumentException($"Target with the name '{target.TargetName}' already exists");
            }

            _targets.Add(target.TargetName, target);
            return(target);
        }
示例#3
0
        public async Task RunTargetAsync(ITaskContextInternal taskContext, string targetName)
        {
            if (!_targets.ContainsKey(targetName))
            {
                throw new ArgumentException($"The target '{targetName}' does not exist");
            }

            ITargetInternal target = _targets[targetName];
            await target.ExecuteVoidAsync(taskContext);
        }
        public ITarget GetTargetFluentInterface(ITargetInternal target, ITaskContextInternal taskContext)
        {
            ITarget t = _sp.GetRequiredService <ITarget>();
            TargetFluentInterface targetFluent = (TargetFluentInterface)t;

            targetFluent.Target         = target;
            targetFluent.Context        = taskContext;
            targetFluent.CoreTaskFluent = GetCoreTaskFluentInterface(taskContext);
            targetFluent.TaskFluent     = GetTaskFluentInterface(taskContext);

            return(targetFluent);
        }
示例#5
0
        public void ConfigureSimpleTarget()
        {
            ITaskSession session = _sp.GetRequiredService <ITaskSession>();

            SimpleBuildScript bs = new SimpleBuildScript();

            bs.Run(session);

            Assert.True(session.TargetTree.HasAllTargets(new List <string>()
            {
                "test"
            }, out _));
            Assert.True(session.TargetTree.HasAllTargets(new List <string>()
            {
                "test1"
            }, out _));

            ITargetInternal t  = session.TargetTree.GetTarget("test");
            ITargetInternal t1 = session.TargetTree.GetTarget("test1");

            Assert.Equal(t.TargetName, t1.Dependencies.FirstOrDefault().Key);
        }
示例#6
0
        public void EnsureDependenciesExecuted(ITaskContextInternal taskContext, string targetName)
        {
            if (_args.NoDependencies)
            {
                taskContext.LogInfo("Skipping target dependencies.");
                return;
            }

            ITargetInternal target = _targets[targetName];
            int             n      = target.Dependencies.Count;
            List <Task>     tasks  = new List <Task>();

            for (int i = 0; i < n; i++)
            {
                var dependantTargetName = target.Dependencies.Keys.ElementAt(i);
                var executionMode       = target.Dependencies.Values.ElementAt(i);
                if (_executedTargets.Contains(dependantTargetName))
                {
                    continue;
                }

                if (_args.TargetsToExecute != null)
                {
                    if (!_args.TargetsToExecute.Contains(dependantTargetName))
                    {
                        throw new TaskExecutionException($"Target {dependantTargetName} is not on the TargetsToExecute list", 3);
                    }

                    DependenciesExecutedCount++;
                }

                if (executionMode == TaskExecutionMode.Synchronous)
                {
                    RunTarget(taskContext, dependantTargetName);
                }
                else
                {
                    tasks.Add(RunTargetAsync(taskContext, dependantTargetName));
                    if (i + 1 < n)
                    {
                        if (target.Dependencies.Values.ElementAt(i + 1) != TaskExecutionMode.Synchronous)
                        {
                            continue;
                        }
                        if (tasks.Count <= 0)
                        {
                            continue;
                        }

                        Task.WaitAll(tasks.ToArray());
                        tasks = new List <Task>();
                    }
                    else
                    {
                        if (tasks.Count > 0)
                        {
                            Task.WaitAll(tasks.ToArray());
                        }
                    }
                }
            }
        }
示例#7
0
 public void SetDefaultTarget(ITargetInternal target)
 {
     DefaultTargets.Add(target);
 }
示例#8
0
 public void MarkTargetAsExecuted(ITargetInternal target)
 {
     _executedTargets.Add(target.TargetName);
 }
示例#9
0
        public ITarget CreateTarget(string name)
        {
            ITargetInternal target = TargetTree.AddTarget(name);

            return(_fluentFactory.GetTargetFluentInterface(target, (ITaskContextInternal)this));
        }
示例#10
0
 public ITargetInternal AddTarget(ITargetInternal target)
 {
     _targets.Add(target.TargetName, target);
     return(target);
 }