Make a copy of the old ZipLib
[mono.git] / mcs / class / Microsoft.Build.Engine / Microsoft.Build.BuildEngine / BuildItemGroup.cs
1 //
2 // BuildItemGroup.cs: Represents a group of build items.
3 //
4 // Author:
5 //   Marek Sieradzki (marek.sieradzki@gmail.com)
6 // 
7 // (C) 2005 Marek Sieradzki
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 #if NET_2_0
29
30 using System;
31 using System.Reflection;
32 using System.Collections;
33 using System.Xml;
34 using Microsoft.Build.Framework;
35 using Microsoft.Build.Utilities;
36
37 namespace Microsoft.Build.BuildEngine {
38         public class BuildItemGroup : ItemPropertyGroupingBase, IBuildItemGroup, IEnumerable {
39         
40                 XmlAttribute            condition;
41                 bool                    isImported;
42                 IList                   buildItems;
43                 GroupingCollection      parentCollection;
44                 Project                 parentProject;
45                 XmlElement              itemGroupElement;
46                 
47                 public BuildItemGroup ()
48                         : this (null)
49                 {
50                 }
51                 
52                 internal BuildItemGroup (Project project)
53                 {
54                         this.buildItems = new ArrayList ();
55                         this.isImported = false;
56                         this.parentProject = project;
57                 }
58
59                 public BuildItem AddNewItem (string itemName,
60                                              string itemInclude)
61                 {
62                         BuildItem bi = new BuildItem (itemName, itemInclude);
63                         buildItems.Add (bi);
64                         return bi;
65                 }
66                 
67                 internal BuildItem AddFromParentItem (BuildItem bi)
68                 {
69                         BuildItem buildItem = new BuildItem (bi);
70                         buildItems.Add (buildItem);
71                         return buildItem;
72                 }
73                 
74                 internal void AddItem (BuildItem buildItem)
75                 {
76                         buildItems.Add (buildItem);
77                 }
78                 
79                 internal void AddItem (string name, ITaskItem taskItem)
80                 {
81                         BuildItem buildItem;
82                         buildItem = new BuildItem (name, taskItem, this);
83                         buildItems.Add (buildItem);
84                 }
85
86                 public void Clear ()
87                 {
88                         //FIXME: should this remove all build items?
89                         buildItems = new ArrayList ();
90                 }
91
92                 public BuildItemGroup Clone (bool deepClone)
93                 {
94                         BuildItemGroup big = new BuildItemGroup ();
95                         // FIXME: add copying of items
96                         return big;
97                 }
98
99                 public override void Evaluate (BuildPropertyGroup parentPropertyBag,
100                                                bool ignoreCondition,
101                                                bool honorCondition,
102                                                Hashtable conditionedPropertiesTable,
103                                                ProcessingPass pass)
104                 {
105                 }
106
107                 public IEnumerator GetEnumerator ()
108                 {
109                         return buildItems.GetEnumerator ();
110                 }
111
112                 public void RemoveItem (BuildItem itemToRemove)
113                 {
114                         buildItems.Remove (itemToRemove);
115                 }
116
117                 public void RemoveItemAt (int index)
118                 {
119                         buildItems.RemoveAt (index);
120                 }
121
122                 public BuildItem[] ToArray ()
123                 {
124                         BuildItem[] array;
125                         array = new BuildItem [Count];
126                         buildItems.CopyTo (array,0);
127                         return array;
128                 }
129                 
130                 internal void BindToXml (XmlElement xmlElement)
131                 {
132                         if (xmlElement == null)
133                                 throw new ArgumentNullException ("xmlElement");
134                         this.condition = xmlElement.GetAttributeNode ("Condition");
135                         this.itemGroupElement = xmlElement;
136                         foreach (XmlNode xn in xmlElement.ChildNodes) {
137                                 if (xn is XmlElement) {
138                                         XmlElement xe = (XmlElement) xn;
139                                         BuildItem bi = new BuildItem (xe.Name, this);
140                                         bi.BindToXml (xe);
141                                         buildItems.Add (bi);
142                                 }
143                         }
144                 }
145                 
146                 internal string ToString (Expression transform, string separator)
147                 {
148                         string[] items = new string [buildItems.Count];
149                         int i = 0;
150                         foreach (BuildItem bi in  buildItems)
151                                 items [i++] = bi.ToString (transform);
152                         return String.Join (separator,items);
153                 }
154                 
155                 internal ITaskItem[] ToITaskItemArray (Expression transform)
156                 {
157                         ITaskItem[] array = new ITaskItem [buildItems.Count];
158                         int i = 0;
159                         foreach (BuildItem item in buildItems)
160                                 array [i++] = item.ToITaskItem (transform);
161                         return array;
162                 }
163
164                 public string Condition {
165                         get {
166                                 if (condition != null)
167                                         return condition.Value;
168                                 else
169                                         return null;
170                         }
171                         set {
172                                 if (condition != null)
173                                         condition.Value = value;
174                         }
175                 }
176
177                 public int Count {
178                         get {
179                                 if (buildItems != null)
180                                         return buildItems.Count;
181                                 else
182                                         return 0;
183                         }
184                 }
185
186                 public bool IsImported {
187                         get {
188                                 return isImported;
189                         }
190                 }
191
192                 public BuildItem this[int index] {
193                         get {
194                                 return (BuildItem) buildItems [index];
195                         }
196                 }
197                 
198                 internal GroupingCollection GroupingCollection {
199                         get { return parentCollection; }
200                         set { parentCollection = value; }
201                 }
202                 
203                 internal Project Project {
204                         get { return parentProject; }
205                 }
206         }
207 }
208
209 #endif