예제 #1
0
        /// <summary>
        /// Executes a task within a target. This method initializes a task engine for the given task, and then executes the task
        /// using the engine.
        /// </summary>
        /// <param name="taskNode"></param>
        /// <param name="hostObject"></param>
        /// <returns>true, if successful</returns>
        internal bool ExecuteOneTask(XmlElement taskNode, ITaskHost hostObject)
        {
            bool taskExecutedSuccessfully = false;

            string            projectFileOfTaskNode   = XmlUtilities.GetXmlNodeFile(taskNode, parentProject.FullFileName);
            BuildEventContext targetBuildEventContext = new BuildEventContext
                                                        (
                ParentProject.ProjectBuildEventContext.NodeId,
                this.id,
                ParentProject.ProjectBuildEventContext.ProjectContextId,
                ParentProject.ProjectBuildEventContext.TaskId
                                                        );
            int handleId = parentEngine.EngineCallback.CreateTaskContext(ParentProject, this, null, taskNode,
                                                                         EngineCallback.inProcNode, targetBuildEventContext);
            TaskExecutionModule taskExecutionModule = parentEngine.NodeManager.TaskExecutionModule;
            TaskEngine          taskEngine          = new TaskEngine(taskNode, hostObject, parentProject.FullFileName, projectFileOfTaskNode, parentEngine.LoggingServices, handleId, taskExecutionModule, targetBuildEventContext);

            taskExecutedSuccessfully =
                taskEngine.ExecuteTask
                (
                    TaskExecutionMode.ExecuteTaskAndGatherOutputs,
                    new Lookup(parentProject.evaluatedItemsByName, parentProject.evaluatedProperties, ParentProject.ItemDefinitionLibrary)
                );

            return(taskExecutedSuccessfully);
        }
예제 #2
0
        public void SetUp()
        {
            // Whole bunch of setup code.
            XmlElement taskNode = new XmlDocument().CreateElement("MockTask");
            LoadedType taskClass = new LoadedType(typeof(MockTask), new AssemblyLoadInfo(typeof(MockTask).Assembly.FullName, null));
            engine = new Engine(@"c:\");
            Project project = new Project(engine);
            EngineCallback engineCallback = new EngineCallback(engine);
            taskExecutionModule = new MockTaskExecutionModule(engineCallback);
            int handleId = engineCallback.CreateTaskContext(project, null, null, taskNode, EngineCallback.inProcNode, new BuildEventContext(BuildEventContext.InvalidNodeId, BuildEventContext.InvalidTargetId, BuildEventContext.InvalidProjectContextId, BuildEventContext.InvalidTaskId));
            TaskEngine taskEngine = new TaskEngine
                                (
                                    taskNode,
                                    null, /* host object */
                                    "In Memory",
                                    project.FullFileName,
                                    engine.LoggingServices,
                                    handleId,
                                    taskExecutionModule,
                                    null
                                );
            taskEngine.TaskClass = taskClass;

            engineProxy = new EngineProxy(taskExecutionModule, handleId, project.FullFileName, project.FullFileName, engine.LoggingServices, null);
            taskExecutionModule2 = new MockTaskExecutionModule(engineCallback, TaskExecutionModule.TaskExecutionModuleMode.MultiProcFullNodeMode);
            engineProxy2 = new EngineProxy(taskExecutionModule2, handleId, project.FullFileName, project.FullFileName, engine.LoggingServices, null);

        }
예제 #3
0
        public bool Execute()
        {
            TaskEngine taskEngine;

            LogTaskStarted();
            ITask task;

            try {
                task = InitializeTask();
            } catch (Exception e) {
                LogError("Error initializing task {0}: {1}", taskElement.LocalName, e.Message);
                LogMessage(MessageImportance.Low, "Error initializing task {0}: {1}",
                           taskElement.LocalName, e.ToString());
                return(false);
            }

            try {
                taskEngine = new TaskEngine(parentTarget.Project, task, Type);
                taskEngine.Prepare(GetParameters());
                var result = taskEngine.Execute();
                if (result)
                {
                    taskEngine.PublishOutput(taskElement, taskEngine.ValueFromExecution);
                }

                LogTaskFinished(result);
                return(result);
            } catch (Exception e) {
                task_logger.LogError("Error executing task {0}: {1}", taskElement.LocalName, e.Message);
                task_logger.LogMessage(MessageImportance.Low,
                                       "Error executing task {0}: {1}", taskElement.LocalName, e.ToString());
                return(false);
            }
        }
예제 #4
0
 /// <summary>
 /// Since we could not derrive from TaskEngine and have no Interface, we need to overide the method in here and
 /// replace the calls when testing the class because of the calls to TaskEngine. If at a future time we get a mock task
 /// engine, Interface or a non sealed TaskEngine these methods can disappear.
 /// </summary>
 /// <returns></returns>
 virtual internal bool TaskEngineExecuteTask(
     TaskEngine taskEngine,
     TaskExecutionMode howTaskShouldBeExecuted,
     Lookup lookup
     )
 {
     return(taskEngine.ExecuteTask
            (
                howTaskShouldBeExecuted,
                lookup
            ));
 }
예제 #5
0
        bool IBuildTask.ResolveOutputItems()
        {
            var taskEngine = new TaskEngine(parentTarget.Project, null, Type);

            taskEngine.PublishOutput(taskElement, l => {
                var pv = GetParameterValue(l.Name);

                Expression exp = new Expression();
                exp.Parse(pv, ParseOptions.AllowItemsNoMetadataAndSplit);
                return(exp.ConvertTo(parentTarget.Project, l.PropertyType));
            });

            return(true);
        }
예제 #6
0
        public bool Execute()
        {
            bool       result = false;
            TaskEngine taskEngine;

            LogTaskStarted();
            ITask task = null;

            try
            {
                try
                {
                    task = InitializeTask();
                }
                catch (Exception e)
                {
                    LogError("Error initializing task {0}: {1}", taskElement.LocalName, e.Message);
                    LogMessage(MessageImportance.Low, "Error initializing task {0}: {1}",
                               taskElement.LocalName, e.ToString());
                    return(false);
                }

                try
                {
                    taskEngine = new TaskEngine(parentTarget.Project);
                    taskEngine.Prepare(task, this.taskElement, GetParameters(), this.Type);
                    result = taskEngine.Execute();
                    if (result)
                    {
                        taskEngine.PublishOutput();
                    }
                }
                catch (Exception e)
                {
                    task_logger.LogError("Error executing task {0}: {1}", taskElement.LocalName, e.Message);
                    task_logger.LogMessage(MessageImportance.Low,
                                           "Error executing task {0}: {1}", taskElement.LocalName, e.ToString());
                    result = false;
                }
            }
            finally
            {
                LogTaskFinished(result);
            }

            return(result);
        }
예제 #7
0
파일: BuildTask.cs 프로젝트: rabink/mono
		public bool Execute ()
		{
			bool		result = false;
			TaskEngine	taskEngine;

			LogTaskStarted ();
			ITask task = null;

			try {
				try {
					task = InitializeTask ();
				} catch (Exception e) {
					LogError ("Error initializing task {0}: {1}", taskElement.LocalName, e.Message);
					LogMessage (MessageImportance.Low, "Error initializing task {0}: {1}",
							taskElement.LocalName, e.ToString ());
					return false;
				}

				try {
					taskEngine = new TaskEngine (parentTarget.Project);
					taskEngine.Prepare (task, this.taskElement, GetParameters (), this.Type);
					result = taskEngine.Execute ();
					if (result)
						taskEngine.PublishOutput ();
				} catch (Exception e) {
					task_logger.LogError ("Error executing task {0}: {1}", taskElement.LocalName, e.Message);
					task_logger.LogMessage (MessageImportance.Low,
							"Error executing task {0}: {1}", taskElement.LocalName, e.ToString ());
					result = false;
				}
			} finally {
				LogTaskFinished (result);
			}

			return result;
		}
예제 #8
0
파일: Target.cs 프로젝트: nikson/msbuild
        /// <summary>
        /// Executes a task within a target. This method initializes a task engine for the given task, and then executes the task
        /// using the engine.
        /// </summary>
        /// <param name="taskNode"></param>
        /// <param name="hostObject"></param>
        /// <returns>true, if successful</returns>
        internal bool ExecuteOneTask(XmlElement taskNode, ITaskHost hostObject)
        {
            bool taskExecutedSuccessfully = false;

            string projectFileOfTaskNode = XmlUtilities.GetXmlNodeFile(taskNode, parentProject.FullFileName);
            BuildEventContext targetBuildEventContext = new BuildEventContext
                                (
                                    ParentProject.ProjectBuildEventContext.NodeId,
                                    this.id,
                                    ParentProject.ProjectBuildEventContext.ProjectContextId,
                                    ParentProject.ProjectBuildEventContext.TaskId
                                );
            int handleId = parentEngine.EngineCallback.CreateTaskContext(ParentProject,this, null, taskNode, 
                                                                            EngineCallback.inProcNode, targetBuildEventContext);
            TaskExecutionModule taskExecutionModule = parentEngine.NodeManager.TaskExecutionModule;
            TaskEngine taskEngine = new TaskEngine(taskNode, hostObject, parentProject.FullFileName, projectFileOfTaskNode, parentEngine.LoggingServices, handleId, taskExecutionModule, targetBuildEventContext);

            taskExecutedSuccessfully =
                taskEngine.ExecuteTask
                (
                    TaskExecutionMode.ExecuteTaskAndGatherOutputs,
                    new Lookup(parentProject.evaluatedItemsByName, parentProject.evaluatedProperties, ParentProject.ItemDefinitionLibrary)
                );

            return taskExecutedSuccessfully;
        }
예제 #9
0
 /// <summary>
 /// Mock out and override the method inside of TaskExecutionState which makes the calls to the task engine.
 /// </summary>
 internal override bool TaskEngineExecuteTask(TaskEngine taskEngine, TaskExecutionMode howToExecuteTask, Lookup lookup)
 {
     return targetInferenceSuccessful;
 }
예제 #10
0
        /// <summary>
        /// Creates an instance of a MockTask, and returns the objects necessary to exercise
        /// taskEngine.InitializeTask
        /// </summary>
        /// <param name="taskNode"></param>
        /// <param name="taskEngine"></param>
        /// <param name="mockTask"></param>
        /// <param name="itemBucket"></param>
        /// <owner>RGoel</owner>
        private void InstantiateMockTaskHelper
            (
            XmlElement taskNode,
            out TaskEngine taskEngine,
            out MockTask mockTask,
            out ItemBucket itemBucket,
            out EngineProxy engineProxy,
            string condition
            )
        {
            LoadedType taskClass = new LoadedType(typeof(MockTask), new AssemblyLoadInfo(typeof(MockTask).Assembly.FullName, null));
            Engine engine = new Engine(@"c:\");
            Project project = new Project(engine);
            EngineCallback engineCallback = new EngineCallback(engine);
            TaskExecutionModule taskExecutionModule = new TaskExecutionModule(engineCallback, 
                                        TaskExecutionModule.TaskExecutionModuleMode.SingleProcMode, false);
            ProjectBuildState buildContext = new ProjectBuildState(null, null, new BuildEventContext(0, 1, 1, 1));
            int nodeProxyID = engineCallback.CreateTaskContext(project, null, buildContext, taskNode, EngineCallback.inProcNode, new BuildEventContext(BuildEventContext.InvalidNodeId, BuildEventContext.InvalidTargetId, BuildEventContext.InvalidProjectContextId, BuildEventContext.InvalidTaskId));
            taskEngine = new TaskEngine
                                (
                                    taskNode,
                                    null, /* host object */
                                    "In Memory",
                                    project.FullFileName,
                                    engine.LoggingServices,
                                    nodeProxyID,
                                    taskExecutionModule, 
                                    new BuildEventContext(0, 1, 1, 1)
                                );
            taskEngine.TaskClass = taskClass;
            engineProxy = new EngineProxy(taskExecutionModule, nodeProxyID, project.FullFileName, project.FullFileName, engine.LoggingServices, null);
            mockTask = new MockTask(new EngineProxy(taskExecutionModule, nodeProxyID, project.FullFileName, project.FullFileName, engine.LoggingServices, null));

            // The code below creates an item table that is equivalent to the following MSBuild syntax:
            //
            //      <ItemGroup>
            //          <ItemListContainingOneItem Include="a.cs">
            //              <Culture>fr-fr</Culture>
            //          </ItemListContainingOneItem>
            //
            //          <ItemListContainingTwoItems Include="b.cs">
            //              <HintPath>c:\foo</HintPath>
            //          </ItemListContainingTwoItems>
            //          <ItemListContainingTwoItems Include="c.cs">
            //              <HintPath>c:\bar</HintPath>
            //          </ItemListContainingTwoItems>
            //      </ItemGroup>
            //
            Hashtable itemsByName = new Hashtable(StringComparer.OrdinalIgnoreCase);

            BuildItemGroup itemListContainingOneItem = new BuildItemGroup();
            BuildItem a = itemListContainingOneItem.AddNewItem("ItemListContainingOneItem", "a.cs");
            a.SetMetadata("Culture", "fr-fr");
            itemsByName["ItemListContainingOneItem"] = itemListContainingOneItem;

            BuildItemGroup itemListContainingTwoItems = new BuildItemGroup();
            BuildItem b = itemListContainingTwoItems.AddNewItem("ItemListContainingTwoItems", "b.cs");
            b.SetMetadata("HintPath", "c:\\foo");
            BuildItem c = itemListContainingTwoItems.AddNewItem("ItemListContainingTwoItems", "c.cs");
            c.SetMetadata("HintPath", "c:\\bar");
            itemsByName["ItemListContainingTwoItems"] = itemListContainingTwoItems;

            itemBucket = new ItemBucket(new string[0], new Dictionary<string, string>(), LookupHelpers.CreateLookup(itemsByName), 0);
        }
예제 #11
0
 /*********************************************************************************
  * 
  *                                     Helpers
  * 
  *********************************************************************************/
 private void InstantiateMockTaskHelper
     (
     XmlElement taskNode,
     out TaskEngine taskEngine,
     out MockTask mockTask,
     out ItemBucket itemBucket,
     out EngineProxy engineProxy
     )
 {
     InstantiateMockTaskHelper(taskNode, out taskEngine, out mockTask, out itemBucket, out engineProxy, null);
 }
예제 #12
0
 /// <summary>
 /// Since we could not derrive from TaskEngine and have no Interface, we need to overide the method in here and 
 /// replace the calls when testing the class because of the calls to TaskEngine. If at a future time we get a mock task 
 /// engine, Interface or a non sealed TaskEngine these methods can disappear.
 /// </summary>
 /// <returns></returns>
 virtual internal bool TaskEngineExecuteTask(
     TaskEngine taskEngine,
     TaskExecutionMode howTaskShouldBeExecuted,
     Lookup lookup
 )
 {
     return taskEngine.ExecuteTask
          (
              howTaskShouldBeExecuted,
              lookup
          );
 }
예제 #13
0
        /// <summary>
        /// The thread procedure executes the tasks and calls callback once it is done
        /// </summary>
        virtual internal void ExecuteTask()
        {
            bool taskExecutedSuccessfully = true;

            Exception thrownException = null;
            bool dontPostOutputs = false;

            if (profileExecution)
            {
                startTime = DateTime.Now.Ticks;
            }

            try
            {
                TaskEngine taskEngine = new TaskEngine(
                            taskXmlNode,
                            hostObject,
                            projectFileOfTaskNode,
                            parentProjectFullFileName,
                            loggingService,
                            handleId,
                            parentModule,
                            buildEventContext);

                // Set the directory to the one appropriate for the task
                if (FileUtilities.GetCurrentDirectoryStaticBuffer(currentDirectoryBuffer) != executionDirectory)
                {
                    Directory.SetCurrentDirectory(executionDirectory);
                }
                // if we're skipping task execution because the target is up-to-date, we
                // need to go ahead and infer all the outputs that would have been emitted;
                // alternatively, if we're doing an incremental build, we need to infer the
                // outputs that would have been produced if all the up-to-date items had
                // been built by the task
                if ((howToExecuteTask & TaskExecutionMode.InferOutputsOnly) != TaskExecutionMode.Invalid)
                {
                    bool targetInferenceSuccessful = false;

                    targetInferenceSuccessful =
                       TaskEngineExecuteTask
                        (   taskEngine,
                            TaskExecutionMode.InferOutputsOnly,
                            lookupForInference
                        );

                    ErrorUtilities.VerifyThrow(targetInferenceSuccessful, "A task engine should never fail to infer its task's up-to-date outputs.");
                }

                // execute the task using the items that need to be (re)built
                if ((howToExecuteTask & TaskExecutionMode.ExecuteTaskAndGatherOutputs) != TaskExecutionMode.Invalid)
                {
                    taskExecutedSuccessfully =
                      TaskEngineExecuteTask
                        (   taskEngine,
                            TaskExecutionMode.ExecuteTaskAndGatherOutputs,
                            lookupForExecution
                        );
                }
            }
            // We want to catch all exceptions and pass them on to the engine
            catch (Exception e)
            {
                thrownException = e;
                taskExecutedSuccessfully = false;

                // In single threaded mode the exception can be thrown on the current thread
                if (parentModule.RethrowTaskExceptions())
                {
                    dontPostOutputs = true;
                    throw;
                }
            }
            finally
            {
                if (!dontPostOutputs)
                {
                    long executionTime = profileExecution ? DateTime.Now.Ticks - startTime : 0;
                    // Post the outputs to the engine
                    parentModule.PostTaskOutputs(handleId, taskExecutedSuccessfully, thrownException, executionTime);
                }
            }
        }
예제 #14
0
		bool IBuildTask.ResolveOutputItems ()
		{
			var taskEngine = new TaskEngine (parentTarget.Project, null, Type);

			taskEngine.PublishOutput (taskElement, l => {
				var pv = GetParameterValue (l.Name);

				Expression exp = new Expression ();
				exp.Parse (pv, ParseOptions.AllowItemsNoMetadataAndSplit);
				return exp.ConvertTo (parentTarget.Project, l.PropertyType);
			});

			return true;
		}
예제 #15
0
        /// <summary>
        /// The thread procedure executes the tasks and calls callback once it is done
        /// </summary>
        virtual internal void ExecuteTask()
        {
            bool taskExecutedSuccessfully = true;

            Exception thrownException = null;
            bool      dontPostOutputs = false;

            if (profileExecution)
            {
                startTime = DateTime.Now.Ticks;
            }

            try
            {
                TaskEngine taskEngine = new TaskEngine(
                    taskXmlNode,
                    hostObject,
                    projectFileOfTaskNode,
                    parentProjectFullFileName,
                    loggingService,
                    handleId,
                    parentModule,
                    buildEventContext);

                // Set the directory to the one appropriate for the task
                if (FileUtilities.GetCurrentDirectoryStaticBuffer(currentDirectoryBuffer) != executionDirectory)
                {
                    Directory.SetCurrentDirectory(executionDirectory);
                }
                // if we're skipping task execution because the target is up-to-date, we
                // need to go ahead and infer all the outputs that would have been emitted;
                // alternatively, if we're doing an incremental build, we need to infer the
                // outputs that would have been produced if all the up-to-date items had
                // been built by the task
                if ((howToExecuteTask & TaskExecutionMode.InferOutputsOnly) != TaskExecutionMode.Invalid)
                {
                    bool targetInferenceSuccessful = false;

                    targetInferenceSuccessful =
                        TaskEngineExecuteTask
                            (taskEngine,
                            TaskExecutionMode.InferOutputsOnly,
                            lookupForInference
                            );

                    ErrorUtilities.VerifyThrow(targetInferenceSuccessful, "A task engine should never fail to infer its task's up-to-date outputs.");
                }

                // execute the task using the items that need to be (re)built
                if ((howToExecuteTask & TaskExecutionMode.ExecuteTaskAndGatherOutputs) != TaskExecutionMode.Invalid)
                {
                    taskExecutedSuccessfully =
                        TaskEngineExecuteTask
                            (taskEngine,
                            TaskExecutionMode.ExecuteTaskAndGatherOutputs,
                            lookupForExecution
                            );
                }
            }
            // We want to catch all exceptions and pass them on to the engine
            catch (Exception e)
            {
                thrownException          = e;
                taskExecutedSuccessfully = false;

                // In single threaded mode the exception can be thrown on the current thread
                if (parentModule.RethrowTaskExceptions())
                {
                    dontPostOutputs = true;
                    throw;
                }
            }
            finally
            {
                if (!dontPostOutputs)
                {
                    long executionTime = profileExecution ? DateTime.Now.Ticks - startTime : 0;
                    // Post the outputs to the engine
                    parentModule.PostTaskOutputs(handleId, taskExecutedSuccessfully, thrownException, executionTime);
                }
            }
        }
예제 #16
0
        internal EngineProxy CreateEngineProxyWithDummyTaskEngine(Engine e, Project p)
        {
            // UNDONE need a real handle Id and a real TEM pointer
            XmlElement taskNode = new XmlDocument().CreateElement("MockTask");

            BuildRequest request = new BuildRequest(EngineCallback.invalidEngineHandle, "mockproject", null, (BuildPropertyGroup)null, null, -1, false, false);
            ProjectBuildState context = new ProjectBuildState(request, new ArrayList(), new BuildEventContext(0, 0, 0, 0));
            int handleId = e.EngineCallback.CreateTaskContext(p, null, context, taskNode, 0, new BuildEventContext(0, 0, 0, 0));
            TaskEngine taskEngine = new TaskEngine
                                (
                                    taskNode,
                                    null, /* host object */
                                    p.FullFileName,
                                    p.FullFileName,
                                    e.LoggingServices,
                                    handleId,
                                    e.NodeManager.TaskExecutionModule,
                                    new BuildEventContext(0, 0, 0, 0)
                                );
            e.Scheduler.Initialize(new INodeDescription[] { null });
            return new EngineProxy(e.NodeManager.TaskExecutionModule, handleId, p.FullFileName, p.FullFileName, e.LoggingServices, new BuildEventContext(0, 0, 0, 0));
        }