* Makefile ($(build_lib)): Make CYCLIC_DEP_FILES depend on this.
[mono.git] / mcs / class / Microsoft.Build.Engine / Microsoft.Build.BuildEngine / BuildTask.cs
index c7a10113a251d1995a5b5c5cf62ff965246a2a77..c8654942580b416b3ad7c186bd99fc5980b8d283 100644 (file)
@@ -43,7 +43,6 @@ namespace Microsoft.Build.BuildEngine {
                Target                  parentTarget;
                XmlElement              taskElement;
        
-               // FIXME: implement
                internal BuildTask (XmlElement taskElement, Target parentTarget)
                {
                        if (taskElement == null)
@@ -59,12 +58,26 @@ namespace Microsoft.Build.BuildEngine {
                public void AddOutputItem (string taskParameter,
                                           string itemName)
                {
+                       XmlElement element = parentTarget.Project.XmlDocument.CreateElement ("Output", Project.XmlNamespace);
+                       taskElement.AppendChild (element);
+                       
+                       if (taskParameter != null)
+                               element.SetAttribute ("TaskParameter", taskParameter);
+                       if (itemName != null)
+                               element.SetAttribute ("ItemName", itemName);
                }
                
                [MonoTODO]
                public void AddOutputProperty (string taskParameter,
                                               string propertyName)
                {
+                       XmlElement element = parentTarget.Project.XmlDocument.CreateElement ("Output", Project.XmlNamespace);
+                       taskElement.AppendChild (element);
+                       
+                       if (taskParameter != null)
+                               element.SetAttribute ("TaskParameter", taskParameter);
+                       if (propertyName != null)
+                               element.SetAttribute ("PropertyName", propertyName);
                }
                
                [MonoTODO]
@@ -74,30 +87,31 @@ namespace Microsoft.Build.BuildEngine {
                        TaskEngine      taskEngine;
 
                        LogTaskStarted ();
-                       
-                       taskEngine = new TaskEngine (parentTarget.Project);
-                       
-                       taskEngine.Prepare (InitializeTask (), this.taskElement, GetParameters (), this.Type);
-                       
-                       result = taskEngine.Execute ();
-                       
-                       taskEngine.PublishOutput ();
-                       
+
+                       try {
+                               taskEngine = new TaskEngine (parentTarget.Project);             
+                               taskEngine.Prepare (InitializeTask (), this.taskElement, GetParameters (), this.Type);
+                               result = taskEngine.Execute ();
+                               if (result)
+                                       taskEngine.PublishOutput ();
+                       // FIXME: it should be logged (exception)
+                       } catch (Exception e) {
+                               Console.Error.WriteLine (e);
+                               result = false;
+                       }
+
                        LogTaskFinished (result);
                
                        return result;
                }
 
 
-               [MonoTODO]
                public string[] GetParameterNames ()
                {
                        List <string> tempNames = new List <string> ();
                        
                        foreach (XmlAttribute xmlAttribute in taskElement.Attributes) {
-                               if (xmlAttribute.Name == "Condition")
-                                       continue;
-                               if (xmlAttribute.Name == "ContinueOnError")
+                               if (xmlAttribute.Name == "Condition" || xmlAttribute.Name == "ContinueOnError")
                                        continue;
                                tempNames.Add (xmlAttribute.Name);
                        }
@@ -105,67 +119,68 @@ namespace Microsoft.Build.BuildEngine {
                        return tempNames.ToArray ();
                }
                
-               [MonoTODO]
                public string GetParameterValue (string attributeName)
                {
+                       if (attributeName == "Condition")
+                               throw new ArgumentException ("Condition attribute cannot be accessed using this method.");
+                       if (attributeName == "ContinueOnError")
+                               throw new ArgumentException ("ContinueOnError attribute cannot be accessed using this method.");
+
                        return taskElement.GetAttribute (attributeName);
                }
                
-               [MonoTODO]
                public void SetParameterValue (string parameterName,
                                               string parameterValue)
                {
                        SetParameterValue (parameterName, parameterValue, false);
                }
                
-               [MonoTODO]
                public void SetParameterValue (string parameterName,
                                               string parameterValue,
                                               bool treatParameterValueAsLiteral)
                {
-                       // FIXME: use expression for parameterValue
-                       taskElement.SetAttribute (parameterName, parameterValue);
+                       if (treatParameterValueAsLiteral)
+                               taskElement.SetAttribute (parameterName, Utilities.Escape (parameterValue));
+                       else
+                               taskElement.SetAttribute (parameterName, parameterValue);
                }
                
-               private void LogTaskStarted ()
+               void LogTaskStarted ()
                {
                        TaskStartedEventArgs tsea = new TaskStartedEventArgs ("Task started.", null, parentTarget.Project.FullFileName,
                                parentTarget.Project.FullFileName, taskElement.Name);
                        parentTarget.Project.ParentEngine.EventSource.FireTaskStarted (this, tsea);
                }
                
-               private void LogTaskFinished (bool succeeded)
+               void LogTaskFinished (bool succeeded)
                {
                        TaskFinishedEventArgs tfea = new TaskFinishedEventArgs ("Task finished.", null, parentTarget.Project.FullFileName,
                                parentTarget.Project.FullFileName, taskElement.Name, succeeded);
                        parentTarget.Project.ParentEngine.EventSource.FireTaskFinished (this, tfea);
                }
                
-               private ITask InitializeTask ()
+               ITask InitializeTask ()
                {
                        ITask task;
                        
                        task = (ITask)Activator.CreateInstance (this.Type);
-                       task.BuildEngine = new BuildEngine (parentTarget.Project.ParentEngine, 0, 0, ContinueOnError,
-                               parentTarget.Project.FullFileName);
+                       task.BuildEngine = new BuildEngine (parentTarget.Project.ParentEngine, parentTarget.Project, 0, 0, ContinueOnError);
                        
                        return task;
                }
                
-               private IDictionary <string, string> GetParameters ()
+               IDictionary <string, string> GetParameters ()
                {
                        Dictionary <string, string> parameters = new Dictionary <string, string> ();
                        
                        string[] parameterNames = GetParameterNames ();
                        
-                       foreach (string s in parameterNames) {
+                       foreach (string s in parameterNames)
                                parameters.Add (s, GetParameterValue (s));
-                       }
                        
                        return parameters;
                }
                
-               [MonoTODO]
                public string Condition {
                        get {
                                return taskElement.GetAttribute ("Condition");
@@ -179,10 +194,12 @@ namespace Microsoft.Build.BuildEngine {
                public bool ContinueOnError {
                        get {
                                string str = taskElement.GetAttribute ("ContinueOnError");
-                               if (str == String.Empty) {
+                               if (str == String.Empty)
                                        return false;
-                               } else {
-                                       return Boolean.Parse (str);
+                               else {
+                                       Expression exp = new Expression ();
+                                       exp.Parse (str, true);
+                                       return (bool) exp.ConvertTo (parentTarget.Project, typeof (bool));
                                }
                        }
                        set {