2 // ProjectTargetElement.cs
5 // Leszek Ciesielski (skolima@gmail.com)
7 // (C) 2011 Leszek Ciesielski
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
30 using System.Collections.Generic;
33 using Microsoft.Build.Internal;
35 namespace Microsoft.Build.Construction
37 [System.Diagnostics.DebuggerDisplayAttribute ("Name={Name} #Children={Count} Condition={Condition}")]
38 public class ProjectTargetElement : ProjectElementContainer
40 internal ProjectTargetElement (string name, ProjectRootElement containingProject)
41 : this(containingProject)
45 internal ProjectTargetElement (ProjectRootElement containingProject)
47 ContainingProject = containingProject;
50 public string AfterTargets {
51 get { return afterTargets ?? String.Empty; }
52 set { afterTargets = value; }
55 public string BeforeTargets {
56 get { return beforeTargets ?? String.Empty; }
57 set { beforeTargets = value; }
59 string dependsOnTargets;
60 public string DependsOnTargets {
61 get { return dependsOnTargets ?? String.Empty; }
62 set { dependsOnTargets = value; }
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)); }
70 string keepDuplicateOutputs;
71 public string KeepDuplicateOutputs {
72 get { return keepDuplicateOutputs ?? String.Empty; }
73 set { keepDuplicateOutputs = value; }
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)); }
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)); }
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)); }
93 public ProjectItemGroupElement AddItemGroup ()
95 var item = ContainingProject.CreateItemGroupElement ();
99 public ProjectPropertyGroupElement AddPropertyGroup ()
101 var property = ContainingProject.CreatePropertyGroupElement ();
102 AppendChild (property);
105 public ProjectTaskElement AddTask (string taskName)
107 var task = ContainingProject.CreateTaskElement (taskName);
111 internal override string XmlName {
112 get { return "Target"; }
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; }
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; }
136 internal override ProjectElement LoadChildElement (XmlReader reader)
138 switch (reader.LocalName) {
140 var error = new ProjectOnErrorElement (ContainingProject);
143 case "PropertyGroup":
144 return AddPropertyGroup ();
146 return AddItemGroup ();
148 return AddTask (reader.LocalName);
151 // This seriously needs to change to become able to fill ElementLocation...
152 internal override void LoadAttribute (string name, string value)
158 case "DependsOnTargets":
159 DependsOnTargets = value;
170 case "BeforeTargets":
171 BeforeTargets = value;
174 AfterTargets = value;
176 case "KeepDuplicateOutputs":
177 KeepDuplicateOutputs = value;
180 base.LoadAttribute (name, value);
184 internal override void SaveValue (System.Xml.XmlWriter writer)
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);