Merge pull request #820 from brendanzagaeski/master
[mono.git] / mcs / class / Microsoft.Build / Microsoft.Build.Construction / ProjectTaskElement.cs
index ef84ef90dd65306575a69da3a7400da823060d61..fffe68eb1f30a99b80a6925ae82dfa6135c48529 100644 (file)
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using System.Collections.Generic;
 using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Xml;
+using Microsoft.Build.Exceptions;
+using Microsoft.Build.Internal;
 
 namespace Microsoft.Build.Construction
 {
+        [System.Diagnostics.DebuggerDisplayAttribute ("{Name} Condition={Condition} ContinueOnError={ContinueOnError} "
+                                                      + "#Outputs={Count}")]
         public class ProjectTaskElement : ProjectElementContainer
         {
-                public string ContinueOnError { get; set; }
-                public string Name {
-                        get {
-                                throw new NotImplementedException ();
-                        }
+                internal ProjectTaskElement (string taskName, ProjectRootElement containingProject)
+                        : this(containingProject)
+                {
+                        Name = taskName;
+                }
+                internal ProjectTaskElement (ProjectRootElement containingProject)
+                {
+                        ContainingProject = containingProject;
+                }
+                string continueOnError;
+                public string ContinueOnError {
+                        get { return continueOnError ?? String.Empty; }
+                        set { continueOnError = value; }
                 }
+                string name;
+                public string Name { get { return name ?? String.Empty; } private set { name = value; } }
                 public ICollection<ProjectOutputElement> Outputs {
-                        get {
-                                throw new NotImplementedException ();
-                        }
+                        get { return new CollectionFromEnumerable<ProjectOutputElement> (
+                                new FilteredEnumerable<ProjectOutputElement> (AllChildren)); }
                 }
                 public IDictionary<string, string> Parameters {
-                        get {
-                                throw new NotImplementedException ();
-                        }
+                        get { return parameters; }
                 }
                 public ProjectOutputElement AddOutputItem (string taskParameter, string itemType)
                 {
-                        throw new NotImplementedException ();
+                        return AddOutputItem (taskParameter, itemType, null);
                 }
                 public ProjectOutputElement AddOutputItem (string taskParameter, string itemType, string condition)
                 {
-                        throw new NotImplementedException ();
+                        var output = new ProjectOutputElement (taskParameter, itemType, null, ContainingProject);
+                        if( condition != null)
+                                output.Condition = condition;
+                        AppendChild (output);
+                        return output;
+                }
+                public ProjectOutputElement AddOutputProperty (string taskParameter, string propertyName)
+                {
+                        return AddOutputProperty (taskParameter, propertyName, null);
                 }
                 public ProjectOutputElement AddOutputProperty (string taskParameter, string propertyName,
                                                                string condition)
                 {
-                        throw new NotImplementedException ();
+                        var output = new ProjectOutputElement (taskParameter, null, propertyName, ContainingProject);
+                        if( condition != null)
+                                output.Condition = condition;
+                        AppendChild (output);
+                        return output;
                 }
                 public string GetParameter (string name)
                 {
-                        throw new NotImplementedException ();
+                        string value;
+                        if (parameters.TryGetValue (name, out value))
+                                return value;
+                        return string.Empty;
                 }
                 public void RemoveAllParameters ()
                 {
+                        parameters.Clear ();
                 }
                 public void RemoveParameter (string name)
                 {
+                        parameters.Remove (name);
                 }
                 public void SetParameter (string name, string unevaluatedValue)
                 {
+                        parameters[name] = unevaluatedValue;
                 }
                 internal override string XmlName {
-                        get {
-                                throw new NotImplementedException ();
+                        get { return Name; }
+                }
+                internal override ProjectElement LoadChildElement (XmlReader reader)
+                {
+                        switch (reader.LocalName) {
+                        case "Output":
+                                var output = ContainingProject.CreateOutputElement (null, null, null);
+                                AppendChild (output);
+                                return output;
+                        default:
+                                throw new InvalidProjectFileException (string.Format (
+                                        "Child \"{0}\" is not a known node type.", reader.LocalName));
+                        }
+                }
+                internal override void LoadAttribute (string name, string value)
+                {
+                        switch (name) {
+                        case "ContinueOnError":
+                                ContinueOnError = value;
+                                break;
+#if NET_4_5
+                        case "ExecuteTargets":
+                                ExecuteTargets = value;
+                                break;
+                        case "MSBuildArchitecture":
+                                MSBuildArchitecture = value;
+                                break;
+                        case "MSBuildRuntime":
+                                MSBuildRuntime = value;
+                                break;
+#endif
+                        case "xmlns":
+                                break;
+                        case "Label":
+                                Label = value;
+                                break;
+                        case "Condition":
+                                Condition = value;
+                                break;
+                        default:
+                                SetParameter (name, value);
+                                break;
                         }
                 }
+                internal override void SaveValue (XmlWriter writer)
+                {
+                        SaveAttribute (writer, "ContinueOnError", ContinueOnError);
+                        foreach (var parameter in parameters) {
+                                SaveAttribute (writer, parameter.Key, parameter.Value);
+                        }
+                        base.SaveValue (writer);
+                }
+                private Dictionary<string, string> parameters = new Dictionary<string, string> ();
+
+                public string ExecuteTargets { get; set; }
+                #if NET_4_5
+                public ElementLocation ExecuteTargetsLocation { get; set; }
+                public ElementLocation ContinueOnErrorLocation { get; set; }
+                public string MSBuildArchitecture { get; set; }
+                public ElementLocation MSBuildArchitectureLocation { get; set; }
+                public string MSBuildRuntime { get; set; }
+                public ElementLocation MSBuildRuntimeLocation { get; set; }
+                #endif
         }
 }