implemented a lot of ProjectTargetInstance and its descendants. Fixed a lot of Locati...
[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 ConditionLocation { get; private set; }
119                  public ElementLocation DependsOnTargetsLocation { get; private set; }
120                  public ElementLocation InputsLocation { get; private set; }
121                  public ElementLocation KeepDuplicateOutputsLocation { get; private set; }
122                  public ElementLocation LabelLocation { get; private set; }
123                  public ElementLocation NameLocation { get; private set; }
124                  public ElementLocation OutputsLocation { get; private set; }
125                  public ElementLocation ReturnsLocation { get; private set; }
126 #else
127                  ElementLocation AfterTargetsLocation { get; set; }
128                  ElementLocation BeforeTargetsLocation { get; set; }
129                  ElementLocation ConditionLocation { get; set; }
130                  ElementLocation DependsOnTargetsLocation { get; set; }
131                  ElementLocation InputsLocation { get; set; }
132                  ElementLocation KeepDuplicateOutputsLocation { get; set; }
133                  ElementLocation LabelLocation { get; set; }
134                  ElementLocation NameLocation { get; set; }
135                  ElementLocation OutputsLocation { get; set; }
136                  ElementLocation ReturnsLocation { get; set; }
137 #endif
138
139                 internal override ProjectElement LoadChildElement (XmlReader reader)
140                 {
141                         switch (reader.LocalName) {
142                         case "OnError":
143                                 var error = new ProjectOnErrorElement (ContainingProject);
144                                 AppendChild (error);
145                                 return error;
146                         case "PropertyGroup":
147                                 return AddPropertyGroup ();
148                         case "ItemGroup":
149                                 return AddItemGroup ();
150                         default:
151                                 return AddTask (reader.LocalName);
152                         }
153                 }
154                 // This seriously needs to change to become able to fill ElementLocation...
155                 internal override void LoadAttribute (string name, string value)
156                 {
157                         switch (name) {
158                         case "Name":
159                                 Name = value;
160                                 break;
161                         case "DependsOnTargets":
162                                 DependsOnTargets = value;
163                                 break;
164                         case "Returns":
165                                 Returns = value;
166                                 break;
167                         case "Inputs":
168                                 Inputs = value;
169                                 break;
170                         case "Outputs":
171                                 Outputs = value;
172                                 break;
173                         case "BeforeTargets":
174                                 BeforeTargets = value;
175                                 break;
176                         case "AfterTargets":
177                                 AfterTargets = value;
178                                 break;
179                         case "KeepDuplicateOutputs":
180                                 KeepDuplicateOutputs = value;
181                                 break;
182                         default:
183                                 base.LoadAttribute (name, value);
184                                 break;
185                         }
186                 }
187                 internal override void SaveValue (System.Xml.XmlWriter writer)
188                 {
189                         SaveAttribute (writer, "Name", Name);
190                         SaveAttribute (writer, "DependsOnTargets", DependsOnTargets);
191                         SaveAttribute (writer, "Returns", Returns);
192                         SaveAttribute (writer, "Inputs", Inputs);
193                         SaveAttribute (writer, "Outputs", Outputs);
194                         SaveAttribute (writer, "BeforeTargets", BeforeTargets);
195                         SaveAttribute (writer, "AfterTargets", AfterTargets);
196                         SaveAttribute (writer, "KeepDuplicateOutputs", KeepDuplicateOutputs);
197                         base.SaveValue (writer);
198                 }
199         }
200 }