Exemplo n.º 1
0
 public JobTaskService(IBuildTask buildTask,
                       IPullTask cloneTask,
                       IDeployTask deployTask,
                       IDeployDbTask deployDbTask,
                       IGenerateTask generateTask,
                       IMergeTask mergeTask,
                       IPublishArtifactTask publishArtifactTask,
                       IPushTask pushTask,
                       ITestTask testTask,
                       IDeleteRepositoryTask deleteRepositoryTask,
                       IDeleteHostingTask deleteHostingTask,
                       ICustomTask customTask)
 {
     BuildTask            = buildTask;
     CloneTask            = cloneTask;
     DeployTask           = deployTask;
     DeployDbTask         = deployDbTask;
     GenerateTask         = generateTask;
     MergeTask            = mergeTask;
     PublishArtifactTask  = publishArtifactTask;
     PushTask             = pushTask;
     TestTask             = testTask;
     DeleteRepositoryTask = deleteRepositoryTask;
     DeleteHostingTask    = deleteHostingTask;
     CustomTask           = customTask;
 }
Exemplo n.º 2
0
 // Parse task attributes to get list of referenced metadata and items
 // to determine batching
 //
 void ParseTaskAttributes(IBuildTask buildTask)
 {
     foreach (var attr in buildTask.GetAttributes())
     {
         ParseAttribute(attr);
     }
 }
Exemplo n.º 3
0
        /// <inheritdoc />
        protected override bool BuildTask(IBuildTask task, IBuildFeedback feedback)
        {
            if (this.cabwizTextWriter != null)
            {
                this.cabwizTextWriter.SetActiveTask(task);
            }

            try
            {
                var cabwizTask = task as ICabwizBuildTask;
                if (cabwizTask != null)
                {
                    return(cabwizTask.Build(this.Cabwiz, feedback));
                }
                else
                {
                    return(base.BuildTask(task, feedback));
                }
            }
            finally
            {
                if (this.cabwizTextWriter != null)
                {
                    this.cabwizTextWriter.SetActiveTask(null);
                }
            }
        }
Exemplo n.º 4
0
        public bool Build(IBuildTask buildTask, out bool executeOnErrors)
        {
            executeOnErrors = false;
            try {
                Init();

                // populate list of referenced items and metadata
                ParseTaskAttributes(buildTask);
                if (consumedMetadataReferences.Count == 0)
                {
                    // No batching required
                    if (ConditionParser.ParseAndEvaluate(buildTask.Condition, project))
                    {
                        return(buildTask.Execute());
                    }
                    else                     // skipped, it should be logged
                    {
                        return(true);
                    }
                }

                BatchAndPrepareBuckets();
                return(Run(buildTask, out executeOnErrors));
            } finally {
                consumedItemsByName          = null;
                consumedMetadataReferences   = null;
                consumedQMetadataReferences  = null;
                consumedUQMetadataReferences = null;
                batchedItemsByName           = null;
                commonItemsByName            = null;
            }
        }
Exemplo n.º 5
0
		bool Run (IBuildTask buildTask, TaskExecutionMode taskExecutionMode, out bool executeOnErrors)
		{
			executeOnErrors = false;

			// Run the task in batches
			bool retval = true;
			if (buckets.Count == 0) {
				// batched mode, but no values in the corresponding items!
				retval = Execute (buildTask, taskExecutionMode);
				if (!retval && !buildTask.ContinueOnError)
					executeOnErrors = true;

				return retval;
			}

			// batched
			foreach (Dictionary<string, BuildItemGroup> bucket in buckets) {
				project.PushBatch (bucket, commonItemsByName);
				try {
					retval = Execute (buildTask, taskExecutionMode);
					 if (!retval && !buildTask.ContinueOnError) {
						executeOnErrors = true;
						break;
					}
				} finally {
					project.PopBatch ();
				}
			}

			return retval;
		}
Exemplo n.º 6
0
        /// <summary>
        /// 执行构建流程
        /// </summary>
        /// <returns>如果成功返回TRUE,否则返回FALSE</returns>
        public static bool Run(List <IBuildTask> pipeline, BuildContext context)
        {
            if (pipeline == null)
            {
                throw new ArgumentNullException("pipeline");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool succeed = true;

            for (int i = 0; i < pipeline.Count; i++)
            {
                IBuildTask task = pipeline[i];
                try
                {
                    var taskAttribute = task.GetType().GetCustomAttribute <TaskAttribute>();
                    Log($"---------------------------------------->{taskAttribute.Desc}");
                    task.Run(context);
                }
                catch (Exception e)
                {
                    Debug.LogError($"Build task {task.GetType().Name} failed !");
                    Debug.LogError($"Build error : {e}");
                    succeed = false;
                    break;
                }
            }

            // 返回运行结果
            return(succeed);
        }
Exemplo n.º 7
0
		public bool Build (IBuildTask buildTask, out bool executeOnErrors)
		{
			executeOnErrors = false;
			try {
				Init ();

				// populate list of referenced items and metadata
				ParseTaskAttributes (buildTask);
				if (consumedMetadataReferences.Count == 0) {
					// No batching required
					if (ConditionParser.ParseAndEvaluate (buildTask.Condition, project))
						return buildTask.Execute ();
					else // skipped, it should be logged
						return true;
				}

				BatchAndPrepareBuckets ();
				return Run (buildTask, out executeOnErrors);
			} finally {
				consumedItemsByName = null;
				consumedMetadataReferences = null;
				consumedQMetadataReferences = null;
				consumedUQMetadataReferences = null;
				batchedItemsByName = null;
				commonItemsByName = null;
			}
		}
        public void CanInjectAndExtractWithStructs()
        {
            IInjectionContext injection = new InjectionStruct();

            injection.State = 1;

            IBuildContext context = new BuildContext();

            context.SetContextObject(injection);

            TaskStruct task = new TaskStruct(2);

            Assert.IsNull(task.InjectedObject);

            // Still need to box / unbox the struct task
            IBuildTask boxed = task;

            ContextInjector.Inject(context, boxed);
            task = (TaskStruct)boxed;

            Assert.IsNotNull(task.InjectedObject);
            Assert.AreEqual(1, task.InjectedObject.State);

            ReturnCode result = task.Run();

            Assert.AreEqual(ReturnCode.Success, result);

            ContextInjector.Extract(context, task);

            IInjectionContext modifiedInjection = context.GetContextObject <IInjectionContext>();

            Assert.AreEqual(task.NewState, modifiedInjection.State);
        }
Exemplo n.º 9
0
 /// <summary>
 ///   Initializes an instance of the build task result.
 /// </summary>
 public BuildTaskResult(IBuildTask buildTask, string taskSignature, string taskOutputDir,
                        ImmutableArray <BuildTaskResult> dependenciesResults)
 {
     BuildTask           = buildTask;
     TaskSignature       = taskSignature;
     TaskOutputDir       = taskOutputDir;
     DependenciesResults = dependenciesResults;
 }
Exemplo n.º 10
0
        public void AddTask(IBuildTask task)
        {
            _tasks.Add(task);

            //foreach (var item in _project.GetItems().ToList())
            {
                PushTask(Proceed(task, _project.GetItems().ToList()));
            }
        }
Exemplo n.º 11
0
        private void AssertUniqueSignature(IBuildTask buildTask, string taskSignature)
        {
            var storedTask = signatureToBuildTask.GetOrAdd(taskSignature, buildTask);

            if (storedTask != buildTask)
            {
                throw new BuildTaskClashException(storedTask, buildTask, taskSignature);
            }
        }
        static void ExtractTestData(IBuildTask task, out CustomAssets customAssets, out TestContent content, out TestDependencyData dependencyData)
        {
            IBuildContext context = new BuildContext();

            ContextInjector.Extract(context, task);
            customAssets   = (CustomAssets)context.GetContextObject <ICustomAssets>();
            content        = (TestContent)context.GetContextObject <IBundleBuildContent>();
            dependencyData = (TestDependencyData)context.GetContextObject <IDependencyData>();
        }
Exemplo n.º 13
0
        bool RunTargetWithBucket(Dictionary <string, BuildItemGroup> bucket, Target target, out bool executeOnErrors)
        {
            bool target_result = true;

            executeOnErrors = false;

            LogTargetStarted(target);
            if (bucket != null)
            {
                project.PushBatch(bucket, commonItemsByName);
            }
            try {
                string reason;
                if (!BuildTargetNeeded(out reason))
                {
                    LogTargetSkipped(target, reason);
                    return(true);
                }

                if (!String.IsNullOrEmpty(reason))
                {
                    target.Engine.LogMessage(MessageImportance.Low, reason);
                }

                for (int i = 0; i < target.BuildTasks.Count; i++)
                {
                    //FIXME: parsing attributes repeatedly
                    IBuildTask bt = target.BuildTasks [i];

                    TaskBatchingImpl batchingImpl = new TaskBatchingImpl(project);
                    bool             task_result  = batchingImpl.Build(bt, out executeOnErrors);
                    if (task_result)
                    {
                        continue;
                    }

                    // task failed, if ContinueOnError,
                    // ignore failed state for target
                    target_result = bt.ContinueOnError;

                    if (!bt.ContinueOnError)
                    {
                        executeOnErrors = true;
                        return(false);
                    }
                }
            } finally {
                if (bucket != null)
                {
                    project.PopBatch();
                }
                LogTargetFinished(target, target_result);
            }

            return(target_result);
        }
Exemplo n.º 14
0
        /// <inheritdoc />
        public override IBuildResult Build(IBuildTask[] tasks, IBuildFeedback feedback)
        {
            // Wrap the feedback object to a textwriter instance so we may channel
            // the output from the cabwiz.exe application to the feedback object.
            this.cabwizTextWriter = new CabwizTextWriter(feedback);

            this.Cabwiz.StandardOutput = this.cabwizTextWriter;
            this.Cabwiz.StandardError = this.cabwizTextWriter;

            return base.Build(tasks, feedback);
        }
Exemplo n.º 15
0
        private void GraphNodeAction(IBuildTask buildTask)
        {
            // At this point all dependencies will have been evaluated.
            var dependenciesResults = GetResults(buildTask.Dependencies);
            var taskSignature       = buildTask.Signature(SourceDir, dependenciesResults);

            AssertUniqueSignature(buildTask, taskSignature);
            var buildTaskResult = ExecuteBuildTask(buildTask, taskSignature, dependenciesResults);

            buildTasksToResults.TryAdd(buildTask, buildTaskResult);
        }
Exemplo n.º 16
0
        static ReturnCode RunTask <T>(params IContextObject[] args) where T : IBuildTask
        {
            IBuildContext context  = new BuildContext(args);
            IBuildTask    instance = Activator.CreateInstance <T>();

            ContextInjector.Inject(context, instance);
            var result = instance.Run();

            ContextInjector.Extract(context, instance);
            return(result);
        }
Exemplo n.º 17
0
        /// <summary>
        /// 向任务管线中增加任务
        /// </summary>
        /// <param name="task"></param>
        public ATBuildPipline AddBuildTask(IBuildTask task)
        {
            if (Tasks == null)
            {
                Tasks = new Queue <IBuildTask>();
            }

            Tasks.Enqueue(task);

            return(_instance);
        }
Exemplo n.º 18
0
            public void Run()
            {
                while (!mAbort)
                {
                    IBuildTask task = null;

                    lock (mSemaphore)
                    {
                        if (mTask != null && mTask.TaskState == BuildTaskState.Inactive)
                        {
                            task  = mTask;
                            mTask = null;
                        }
                    }

                    if (task == null)
                    {
                        Thread.Sleep(100);
                    }
                    else
                    {
                        // Have to re-check.  State may have changed.
                        if (task.TaskState == BuildTaskState.Inactive)
                        {
                            /*
                             * Design note:
                             *
                             * This is a trade-off to deal with poorly written tasks. Technically,
                             * the task is responsible for catching and reporting its own
                             * exceptions.  But if it doesn't it can bring down the processor
                             * thread.
                             *
                             * This method forces the task to abort so the main manager can detect
                             * and discard it.  But if the task is so poorly written that the
                             * abort doesn't work, or throws another exception, then the processor
                             * will become a zombie, unresponsive to new requests from the manager.
                             */
                            try
                            {
                                task.Run();
                            }
                            catch (Exception ex)
                            {
                                task.Abort("Exception detected by processor: " + ex.Message);
                            }
                        }
                    }
                }
            }
Exemplo n.º 19
0
        private BuildTaskResult ExecuteBuildTask(IBuildTask buildTask,
                                                 string taskSignature,
                                                 ImmutableArray <BuildTaskResult> dependenciesResults)
        {
            var taskOutputDir = Combine(PerTaskOutputDir, taskSignature);

            if (!Exists(taskOutputDir))
            {
                var partialTaskOutputDir = Combine(PerTaskPartialOutputDir, taskSignature);
                CreateDirectory(partialTaskOutputDir);
                buildTask.Execute(SourceDir, partialTaskOutputDir, dependenciesResults);
                Move(partialTaskOutputDir, taskOutputDir);
            }
            return(new BuildTaskResult(buildTask, taskSignature, taskOutputDir, dependenciesResults));
        }
Exemplo n.º 20
0
        bool Run(IBuildTask buildTask, out bool executeOnErrors)
        {
            executeOnErrors = false;

            // Run the task in batches
            bool retval = true;

            if (buckets.Count == 0)
            {
                // batched mode, but no values in the corresponding items!
                if (ConditionParser.ParseAndEvaluate(buildTask.Condition, project))
                {
                    retval = buildTask.Execute();
                    if (!retval && !buildTask.ContinueOnError)
                    {
                        executeOnErrors = true;
                    }
                }

                return(retval);
            }

            // batched
            foreach (Dictionary <string, BuildItemGroup> bucket in buckets)
            {
                project.PushBatch(bucket, commonItemsByName);
                try {
                    if (ConditionParser.ParseAndEvaluate(buildTask.Condition, project))
                    {
                        retval = buildTask.Execute();
                        if (!retval && !buildTask.ContinueOnError)
                        {
                            executeOnErrors = true;
                            break;
                        }
                    }
                } finally {
                    project.PopBatch();
                }
            }

            return(retval);
        }
Exemplo n.º 21
0
        private async Task Proceed(IBuildTask task, IList<ProjectItem> items)
        {
            if (!task.DependsOn.IsMatch(items))
                return;

            var querySets = task.DependsOn.Select(_project.GetItems(), items).ToList();
            foreach (var querySet in querySets)
            {
                var sources = task.Proceed(querySet.GetItems());
                if (sources == null)
                    throw new InvalidOperationException("The proceed method has to return a value.");

                foreach (var source in sources)
                {
                    ProjectItem existing;
                    if (_project.TryGetItemById(source.Identifier, out existing))
                    {
                        var defferred = existing as DefferedProjectItem;
                        defferred?.SetDirty(source.Content);

                        var inMemory = existing as InMemoryProjectItem;
                        inMemory?.SetContent((await CopyToStream(source)).GetBuffer());

                        _project.Touch(existing);
                    }
                    else
                    {
                        ProjectItem item2;
                        if (task.Options == BuildOptions.BuildInBackground)
                        {
                            item2 = await BuildInMemoryItem(source);
                        }
                        else
                            item2 = new DefferedProjectItem(source.Identifier, source.Content);

                        _project.AddItem(item2);

                        foreach (var linkedItem in querySet.GetItems())
                            _project.AddLink(linkedItem, new ProjectItemLinkDescriptionFromBuilder(task.Name, this, linkedItem), item2);
                    }
                }
            }
        }
Exemplo n.º 22
0
        bool Execute(IBuildTask buildTask, TaskExecutionMode taskExecutionMode)
        {
            if (ConditionParser.ParseAndEvaluate(buildTask.Condition, project))
            {
                switch (taskExecutionMode)
                {
                case TaskExecutionMode.Complete:
                    return(buildTask.Execute());

                case TaskExecutionMode.SkipAndSetOutput:
                    return(buildTask.ResolveOutputItems());

                default:
                    throw new NotImplementedException();
                }
            }

            return(true);
        }
Exemplo n.º 23
0
 public JobTaskService(IBuildTask buildTask,
                       ICloneTask cloneTask,
                       IDeployTask deployTask,
                       IDeployDbTask deployDbTask,
                       IGenerateTask generateTask,
                       IMergeTask mergeTask,
                       IPublishArtifactTask publishArtifactTask,
                       IPushTask pushTask,
                       ITestTask testTask)
 {
     BuildTask           = buildTask;
     CloneTask           = cloneTask;
     DeployTask          = deployTask;
     DeployDbTask        = deployDbTask;
     GenerateTask        = generateTask;
     MergeTask           = mergeTask;
     PublishArtifactTask = publishArtifactTask;
     PushTask            = pushTask;
     TestTask            = testTask;
 }
Exemplo n.º 24
0
        /// <summary>
        /// Queues a task to be run.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The processor will only queue inactive tasks that are threadsafe.
        /// </para>
        /// </remarks>
        /// <param name="task">The task to queue.</param>
        /// <returns>True if the task was accepted.</returns>
        public bool QueueTask(IBuildTask task)
        {
            if (task == null || task.TaskState != BuildTaskState.Inactive || !task.IsThreadSafe)
            {
                return(false);
            }

            lock (mTaskQueue)
            {
                if (mAbort)
                {
                    return(false);
                }

                if (mProcessors[0] == null)
                {
                    for (int i = 0; i < mProcessors.Length; i++)
                    {
                        mProcessors[i] = new Processor();
                        Thread t = new Thread(new ThreadStart(mProcessors[i].Run));
                        t.Start();
                    }
                }

                mTaskQueue.Add(task);

                mTaskCount = mTaskQueue.Count;
                foreach (IBuildTask item in mActiveTasks)
                {
                    if (item != null)
                    {
                        mTaskCount++;
                    }
                }

                return(true);
            }
        }
Exemplo n.º 25
0
		public bool Build (IBuildTask buildTask, TaskExecutionMode taskExecutionMode, out bool executeOnErrors)
		{
			executeOnErrors = false;
			try {
				Init ();

				// populate list of referenced items and metadata
				ParseTaskAttributes (buildTask);
				if (consumedMetadataReferences.Count == 0) {
					return Execute (buildTask, taskExecutionMode);
				}

				BatchAndPrepareBuckets ();
				return Run (buildTask, taskExecutionMode, out executeOnErrors);
			} finally {
				consumedItemsByName = null;
				consumedMetadataReferences = null;
				consumedQMetadataReferences = null;
				consumedUQMetadataReferences = null;
				batchedItemsByName = null;
				commonItemsByName = null;
			}
		}
Exemplo n.º 26
0
        public bool Build(IBuildTask buildTask, TaskExecutionMode taskExecutionMode, out bool executeOnErrors)
        {
            executeOnErrors = false;
            try {
                Init();

                // populate list of referenced items and metadata
                ParseTaskAttributes(buildTask);
                if (consumedMetadataReferences.Count == 0)
                {
                    return(Execute(buildTask, taskExecutionMode));
                }

                BatchAndPrepareBuckets();
                return(Run(buildTask, taskExecutionMode, out executeOnErrors));
            } finally {
                consumedItemsByName          = null;
                consumedMetadataReferences   = null;
                consumedQMetadataReferences  = null;
                consumedUQMetadataReferences = null;
                batchedItemsByName           = null;
                commonItemsByName            = null;
            }
        }
Exemplo n.º 27
0
        public static void Run(List <IBuildTask> pipeline, BuildContext context)
        {
            if (pipeline == null)
            {
                throw new ArgumentNullException("pipeline");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            for (int i = 0; i < pipeline.Count; i++)
            {
                IBuildTask task = pipeline[i];
                try
                {
                    task.Run(context);
                }
                catch (Exception e)
                {
                    throw new Exception($"Build task {task.GetType().Name} failed : {e}");
                }
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// 任务管线的执行函数
        /// </summary>
        public void Run()
        {
            //任务管线中无任务队列
            if (Tasks.Count == 0)
            {
                //EditorUtility.DisplayDialog("提示", "任务管线中无任务队列!", "OK");
                EndATBuildPipline();//重置相关属性
                return;
            }

            //上次执行任务如果失败,直接返回,管线终止
            if (LastTask == TaskStatus.Failure)
            {
                //EndATBuildPipline();//重置相关属性
                OnReverseTasks();
                return;
            }

            PiplineStatus = ATBuildPiplineStatus.Occupied;
            if (Tasks.Count > 0)
            {
                IBuildTask currentTask = Tasks.Peek();

                switch (currentTask.Status)
                {
                case TaskStatus.None:
                {        //只执行一次
                    currentTask.Status = TaskStatus.Start;
                    _currentTask       = currentTask;
                    currentTask.OnStatusChanged(currentTask.Status);
                    _lastTime = DateTime.Now;
                }
                break;

                case TaskStatus.Start:
                {        //开始任务
                    if (OnRePaintWindow())
                    {    //此处为了Repaint
                        currentTask.Status = TaskStatus.Running;
                        currentTask.OnReady();
                        currentTask.DoTask();
                    }
                }
                break;

                case TaskStatus.Running:
                {        //和刷新的帧数一样
                }
                break;

                case TaskStatus.Success:
                {
                    //TODO
                    currentTask.OnFinal();
                    currentTask = null;

                    IBuildTask task = Tasks.Dequeue();
                    ExcutedTasks.Add(task);
                    _currentTask = null;
                    _currentTime = new DateTime();
                    _lastTime    = new DateTime();
                }
                break;

                case TaskStatus.Failure:
                {
                    //TODO
                    //任务失败
                    currentTask.OnFinal();
                    currentTask = null;

                    LastTask     = TaskStatus.Failure;
                    _currentTime = new DateTime();
                    _lastTime    = new DateTime();
                }
                break;
                }
            }
        }
Exemplo n.º 29
0
 /// <summary>
 /// Add IBuildTask object to build pipeline as a task
 /// </summary>
 /// <param name="buildTask">Build task</param>
 public static void RegisterScenePostprocessTask(IBuildTask buildTask)
 {
     s_Tasks.Add(buildTask);
 }
Exemplo n.º 30
0
		bool Execute (IBuildTask buildTask, TaskExecutionMode taskExecutionMode)
		{
			if (ConditionParser.ParseAndEvaluate (buildTask.Condition, project)) {
				switch (taskExecutionMode) {
				case TaskExecutionMode.Complete:
					return buildTask.Execute ();
				case TaskExecutionMode.SkipAndSetOutput:
					return buildTask.ResolveOutputItems ();
				default:
					throw new NotImplementedException ();
				}
			}

			return true;
		}
Exemplo n.º 31
0
		// Parse task attributes to get list of referenced metadata and items
		// to determine batching
		//
		void ParseTaskAttributes (IBuildTask buildTask)
		{
			foreach (var attr in buildTask.GetAttributes ()) {
				ParseAttribute (attr);
			}
		}
Exemplo n.º 32
0
 public void AddPreBuildTask(IBuildTask task)
 {
     preBuildTasks.Add(task);
 }
Exemplo n.º 33
0
        /// <summary>
        /// Executes a collection of build tasks using the specified feedback object.
        /// </summary>
        /// <param name="tasks">An array of build tasks to execute.</param>
        /// <returns>The build result for all tasks.</returns>
        public virtual IBuildResult Build(IBuildTask[] tasks, IBuildFeedback feedback)
        {
            if (tasks == null)
            {
                throw new ArgumentNullException("tasks");
            }

            if (feedback == null)
            {
                throw new ArgumentNullException("feedback");
            }

            var result = new BuildResult()
            {
                Success = true,
                TotalSteps = tasks.Length
            };

            foreach (var task in tasks)
            {
                try
                {
                    feedback.WriteLine("------ Build started: {0} ------", task.ToString());

                    result.Success = this.BuildTask(task, feedback);

                    feedback.WriteLine();
                }
                catch (Exception x)
                {
                    var message = new BuildMessage(x)
                    {
                        Project = task.ProjectName,
                        Configuration = task.Configuration
                    };

                    feedback.AddMessage(message);

                    result.Success = false;
                }

                if (result.Success)
                {
                    result.TasksSuccesful++;
                }
                else
                {
                    feedback.Write("aborting build... ");

                    result.TasksAborted++;

                    break;
                }
            }

            if (!result.Success)
            {
                feedback.WriteLine("aborted!");
                feedback.WriteLine();
            }

            feedback.WriteLine(
                "========== Build: {1} succeeded, {2} failed, {3} skipped ==========",
                result.Success ? "succeeded" : "failed",
                result.TasksSuccesful,
                result.TasksAborted,
                result.TasksSkipped,
                result.TotalSteps);

            return result;
        }
Exemplo n.º 34
0
 /// <summary>
 /// Stores the given exception parameters into properties.
 /// </summary>
 public BuildTaskClashException(IBuildTask buildTask1, IBuildTask buildTask2, string clashingSignature)
 {
     BuildTask1        = buildTask1;
     BuildTask2        = buildTask2;
     ClashingSignature = clashingSignature;
 }
Exemplo n.º 35
0
 public void RunTask(IBuildTask task)
 {
     lock (mSemaphore) { mTask = task; }
 }
Exemplo n.º 36
0
        /// <summary>
        /// Runs the processor.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This method will block until the processor is aborted.  So the expected use
        /// case is that this method will be run on its own thread.
        /// </para>
        /// <para>
        /// Processors are single use.  They cannot be run again after they are aborted.
        /// </para>
        /// </remarks>
        public void Run()
        {
            lock (mTaskQueue)
            {
                if (mAbort || mIsRunning)
                {
                    return;
                }

                mIsRunning = true;
            }

            while (!mAbort)
            {
                int activeCount = 0;

                lock (mTaskQueue)
                {
                    mTaskQueue.Sort(mComparer);

                    for (int i = 0; i < mActiveTasks.Length; i++)
                    {
                        IBuildTask task = mActiveTasks[i];

                        if (task == null || task.IsFinished)
                        {
                            // Task complete.  Clear it out.
                            mActiveTasks[i] = null;
                            task            = null;
                        }
                        else
                        {
                            // Task still being processed.
                            activeCount++;
                            continue;
                        }

                        // Need to assign a new task to this slot.
                        while (task == null && mTaskQueue.Count > 0)
                        {
                            task = mTaskQueue[mTaskQueue.Count - 1];
                            mTaskQueue.RemoveAt(mTaskQueue.Count - 1);

                            if (task.TaskState != BuildTaskState.Inactive)
                            {
                                task = null;
                            }
                        }

                        if (task != null)
                        {
                            // Found a task to run.
                            activeCount++;
                            mActiveTasks[i] = task;
                            mProcessors[i].RunTask(task);
                        }
                    }

                    mTaskCount = mTaskQueue.Count + activeCount;
                }

                // Pause longer if there are no active tasks.
                if (activeCount > 0)
                {
                    Thread.Sleep(10);
                }
                else
                {
                    Thread.Sleep(100);
                }
            }

            mTaskCount = 0;

            foreach (Processor processor in mProcessors)
            {
                if (processor == null)
                {
                    // The processors were never started.
                    break;
                }

                processor.Abort();
            }

            mIsRunning = false;
        }
Exemplo n.º 37
0
        /// <summary>
        /// Queues a task to be run.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The processor will only queue inactive tasks that are threadsafe.
        /// </para>
        /// </remarks>
        /// <param name="task">The task to queue.</param>
        /// <returns>True if the task was accepted.</returns>
        public bool QueueTask(IBuildTask task)
        {
            if (task == null || task.TaskState != BuildTaskState.Inactive || !task.IsThreadSafe)
                return false;

            lock (mTaskQueue)
            {
                if (mAbort)
                    return false;

                if (mProcessors[0] == null)
                {
                    for (int i = 0; i < mProcessors.Length; i++)
                    {
                        mProcessors[i] = new Processor();
                        Thread t = new Thread(new ThreadStart(mProcessors[i].Run));
                        t.Start();
                    }
                }

                mTaskQueue.Add(task);

                mTaskCount = mTaskQueue.Count;
                foreach (IBuildTask item in mActiveTasks)
                {
                    if (item != null)
                        mTaskCount++;
                }

                return true;
            }
        }
Exemplo n.º 38
0
 public void SetActiveTask(IBuildTask task)
 {
     this.activeTask = task;
 }
Exemplo n.º 39
0
        /// <inheritdoc />
        protected override bool BuildTask(IBuildTask task, IBuildFeedback feedback)
        {
            if (this.cabwizTextWriter != null)
            {
                this.cabwizTextWriter.SetActiveTask(task);
            }

            try
            {
                var cabwizTask = task as ICabwizBuildTask;
                if (cabwizTask != null)
                {
                    return cabwizTask.Build(this.Cabwiz, feedback);
                }
                else
                {
                    return base.BuildTask(task, feedback);
                }
            }
            finally
            {
                if (this.cabwizTextWriter != null)
                {
                    this.cabwizTextWriter.SetActiveTask(null);
                }
            }
        }
Exemplo n.º 40
0
 public void RunTask(IBuildTask task)
 {
     lock (mSemaphore) { mTask = task; }
 }
Exemplo n.º 41
0
            public void Run()
            {
                while (!mAbort)
                {
                    IBuildTask task = null;

                    lock (mSemaphore)
                    {
                        if (mTask != null && mTask.TaskState == BuildTaskState.Inactive)
                        {
                            task = mTask;
                            mTask = null;
                        }
                    }

                    if (task == null)
                        Thread.Sleep(100);
                    else
                    {
                        // Have to re-check.  State may have changed.
                        if (task.TaskState == BuildTaskState.Inactive)
                        {
                            /*
                             * Design note: 
                             * 
                             * This is a trade-off to deal with poorly written tasks. Technically, 
                             * the task is responsible for catching and reporting its own 
                             * exceptions.  But if it doesn't it can bring down the processor 
                             * thread.  
                             * 
                             * This method forces the task to abort so the main manager can detect 
                             * and discard it.  But if the task is so poorly written that the 
                             * abort doesn't work, or throws another exception, then the processor 
                             * will become a zombie, unresponsive to new requests from the manager.
                             */
                            try
                            {
                                task.Run();
                            }
                            catch (Exception ex)
                            {
                                task.Abort("Exception detected by processor: " + ex.Message);
                            }
                        }
                    }
                }
            }
Exemplo n.º 42
0
        bool RunTargetWithBucket(Dictionary <string, BuildItemGroup> bucket, Target target, out bool executeOnErrors)
        {
            bool target_result = true;

            executeOnErrors = false;

            LogTargetStarted(target);

            if (bucket != null)
            {
                project.PushBatch(bucket, commonItemsByName);
            }

            try {
                TaskExecutionMode taskExecutionMode;
                string            reason;
                bool skip_completely;
                if (!BuildTargetNeeded(out reason, out skip_completely))
                {
                    LogTargetSkipped(target, reason);
                    if (skip_completely)
                    {
                        return(true);
                    }

                    taskExecutionMode = TaskExecutionMode.SkipAndSetOutput;
                }
                else
                {
                    taskExecutionMode = TaskExecutionMode.Complete;

                    if (!String.IsNullOrEmpty(reason))
                    {
                        target.Engine.LogMessage(MessageImportance.Low, reason);
                    }
                }

                for (int i = 0; i < target.BuildTasks.Count; i++)
                {
                    //FIXME: parsing attributes repeatedly
                    IBuildTask bt = target.BuildTasks [i];

                    // HACK: need some form of cross references checks
                    var tem = taskExecutionMode;
                    if (tem == TaskExecutionMode.SkipAndSetOutput)
                    {
                        var bti = bt as BuildTask;

                        //
                        // BuildTargetNeeded checks only files timestamps but ignores any metadata dependencies
                        // that way we can end up in the situation when output metadata are populated but from
                        // incomplete dependencies.
                        //
                        // E.g.
                        // <CreateItem Include="$(IntermediateOutputPath)%(_PngImage.LogicalName)" AdditionalMetadata="LogicalName=%(_PngImage.LogicalName)">
                        //		<Output TaskParameter="Include" />
                        // </CreateItem>
                        //
                        if (bti != null && bti.Name == "CreateItem")
                        {
                            tem = TaskExecutionMode.Complete;
                        }
                    }

                    TaskBatchingImpl batchingImpl = new TaskBatchingImpl(project);
                    bool             task_result  = batchingImpl.Build(bt, tem, out executeOnErrors);
                    if (task_result)
                    {
                        continue;
                    }

                    // task failed, if ContinueOnError,
                    // ignore failed state for target
                    target_result = bt.ContinueOnError;

                    if (!bt.ContinueOnError)
                    {
                        executeOnErrors = true;
                        return(false);
                    }
                }
            } finally {
                if (bucket != null)
                {
                    project.PopBatch();
                }

                LogTargetFinished(target, target_result);
            }

            return(target_result);
        }
Exemplo n.º 43
0
 public void AddPostPublishTask(IBuildTask task)
 {
     postPublishTasks.Add(task);
 }
Exemplo n.º 44
0
 public void SetActiveTask(IBuildTask task)
 {
     this.activeTask = task;
 }
Exemplo n.º 45
0
 /// <summary>
 /// Executes the Build method of the specified task.
 /// </summary>
 /// <param name="task">The build task to execute.</param>
 /// <param name="feedback">The feedback object.</param>
 /// <returns>The value returned by the task's Build method.</returns>
 protected virtual bool BuildTask(IBuildTask task, IBuildFeedback feedback)
 {
     return task.Build(feedback);
 }