Merge pull request #819 from brendanzagaeski/patch-1
[mono.git] / mcs / class / Microsoft.Build / Microsoft.Build.Construction / ProjectTargetElement.cs
1 //
2 // ProjectTargetElement.cs
3 //
4 // Author:
5 //   Leszek Ciesielski (skolima@gmail.com)
6 //
7 // (C) 2011 Leszek Ciesielski
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 using System;
30 using System.Collections.Generic;
31 using System.Linq;
32 using System.Xml;
33 using Microsoft.Build.Internal;
34
35 namespace Microsoft.Build.Construction
36 {
37         [System.Diagnostics.DebuggerDisplayAttribute ("Name={Name} #Children={Count} Condition={Condition}")]
38         public class ProjectTargetElement : ProjectElementContainer
39         {
40                 internal ProjectTargetElement (string name, ProjectRootElement containingProject)
41                         : this(containingProject)
42                 {
43                         Name = name;
44                 }
45                 internal ProjectTargetElement (ProjectRootElement containingProject)
46                 {
47                         ContainingProject = containingProject;
48                 }
49                 string afterTargets;
50                 public string AfterTargets {
51                         get { return afterTargets ?? String.Empty; }
52                         set { afterTargets = value; }
53                 }
54                 string beforeTargets;
55                 public string BeforeTargets {
56                         get { return beforeTargets ?? String.Empty; }
57                         set { beforeTargets = value; }
58                 }
59                 string dependsOnTargets;
60                 public string DependsOnTargets {
61                         get { return dependsOnTargets ?? String.Empty; }
62                         set { dependsOnTargets = value; }
63                 }
64                 string inputs;
65                 public string Inputs { get { return inputs ?? String.Empty; } set { inputs = value; } }
66                 public ICollection<ProjectItemGroupElement> ItemGroups {
67                         get { return new CollectionFromEnumerable<ProjectItemGroupElement> (
68                                 new FilteredEnumerable<ProjectItemGroupElement> (Children)); }
69                 }
70                 string keepDuplicateOutputs;
71                 public string KeepDuplicateOutputs {
72                         get { return keepDuplicateOutputs ?? String.Empty; }
73                         set { keepDuplicateOutputs = value; }
74                 }
75                 string name;
76                 public string Name { get { return name ?? String.Empty; } set { name = value; } }
77                 public ICollection<ProjectOnErrorElement> OnErrors {
78                         get { return new CollectionFromEnumerable<ProjectOnErrorElement> (
79                                 new FilteredEnumerable<ProjectOnErrorElement> (Children)); }
80                 }
81                 string outputs;
82                 public string Outputs { get { return outputs ?? String.Empty; } set { outputs = value; } }
83                 public ICollection<ProjectPropertyGroupElement> PropertyGroups {
84                         get { return new CollectionFromEnumerable<ProjectPropertyGroupElement> (
85                                 new FilteredEnumerable<ProjectPropertyGroupElement> (Children)); }
86                 }
87                 string returns;
88                 public string Returns { get { return returns ?? String.Empty; } set { returns = value; } }
89                 public ICollection<ProjectTaskElement> Tasks {
90                         get { return new CollectionFromEnumerable<ProjectTaskElement> (
91                                 new FilteredEnumerable<ProjectTaskElement> (Children)); }
92                 }
93                 public ProjectItemGroupElement AddItemGroup ()
94                 {
95                         var item = ContainingProject.CreateItemGroupElement ();
96                         AppendChild (item);
97                         return item;
98                 }
99                 public ProjectPropertyGroupElement AddPropertyGroup ()
100                 {
101                         var property = ContainingProject.CreatePropertyGroupElement ();
102                         AppendChild (property);
103                         return property;
104                 }
105                 public ProjectTaskElement AddTask (string taskName)
106                 {
107                         var task = ContainingProject.CreateTaskElement (taskName);
108                         AppendChild (task);
109                         return task;
110                 }
111                 internal override string XmlName {
112                         get { return "Target"; }
113                 }
114
115 #if NET_4_5
116                  public ElementLocation AfterTargetsLocation { get; private set; }
117                  public ElementLocation BeforeTargetsLocation { get; private set; }
118                  public ElementLocation DependsOnTargetsLocation { get; private set; }
119                  public ElementLocation InputsLocation { get; private set; }
120                  public ElementLocation KeepDuplicateOutputsLocation { get; private set; }
121                  public ElementLocation NameLocation { get; private set; }
122                  public ElementLocation OutputsLocation { get; private set; }
123                  public ElementLocation ReturnsLocation { get; private set; }
124 #else
125                  internal ElementLocation AfterTargetsLocation { get; set; }
126                  internal ElementLocation BeforeTargetsLocation { get; set; }
127                  internal ElementLocation DependsOnTargetsLocation { get; set; }
128                  internal ElementLocation InputsLocation { get; set; }
129                  internal ElementLocation KeepDuplicateOutputsLocation { get; set; }
130                  internal ElementLocation LabelLocation { get; set; }
131                  internal ElementLocation NameLocation { get; set; }
132                  internal ElementLocation OutputsLocation { get; set; }
133                  internal ElementLocation ReturnsLocation { get; set; }
134 #endif
135
136                 internal override ProjectElement LoadChildElement (XmlReader reader)
137                 {
138                         switch (reader.LocalName) {
139                         case "OnError":
140                                 var error = new ProjectOnErrorElement (ContainingProject);
141                                 AppendChild (error);
142                                 return error;
143                         case "PropertyGroup":
144                                 return AddPropertyGroup ();
145                         case "ItemGroup":
146                                 return AddItemGroup ();
147                         default:
148                                 return AddTask (reader.LocalName);
149                         }
150                 }
151                 // This seriously needs to change to become able to fill ElementLocation...
152                 internal override void LoadAttribute (string name, string value)
153                 {
154                         switch (name) {
155                         case "Name":
156                                 Name = value;
157                                 break;
158                         case "DependsOnTargets":
159                                 DependsOnTargets = value;
160                                 break;
161                         case "Returns":
162                                 Returns = value;
163                                 break;
164                         case "Inputs":
165                                 Inputs = value;
166                                 break;
167                         case "Outputs":
168                                 Outputs = value;
169                                 break;
170                         case "BeforeTargets":
171                                 BeforeTargets = value;
172                                 break;
173                         case "AfterTargets":
174                                 AfterTargets = value;
175                                 break;
176                         case "KeepDuplicateOutputs":
177                                 KeepDuplicateOutputs = value;
178                                 break;
179                         default:
180                                 base.LoadAttribute (name, value);
181                                 break;
182                         }
183                 }
184                 internal override void SaveValue (System.Xml.XmlWriter writer)
185                 {
186                         SaveAttribute (writer, "Name", Name);
187                         SaveAttribute (writer, "DependsOnTargets", DependsOnTargets);
188                         SaveAttribute (writer, "Returns", Returns);
189                         SaveAttribute (writer, "Inputs", Inputs);
190                         SaveAttribute (writer, "Outputs", Outputs);
191                         SaveAttribute (writer, "BeforeTargets", BeforeTargets);
192                         SaveAttribute (writer, "AfterTargets", AfterTargets);
193                         SaveAttribute (writer, "KeepDuplicateOutputs", KeepDuplicateOutputs);
194                         base.SaveValue (writer);
195                 }
196         }
197 }