using System;
using System.Reflection;
using System.Collections;
+using System.Collections.Generic;
using System.Xml;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace Microsoft.Build.BuildEngine {
public class BuildItemGroup : IEnumerable {
- XmlAttribute condition;
- bool isImported;
- IList buildItems;
+ List <BuildItem> buildItems;
+ ImportedProject importedProject;
+ XmlElement itemGroupElement;
GroupingCollection parentCollection;
Project parentProject;
- XmlElement itemGroupElement;
+ bool read_only;
public BuildItemGroup ()
- : this (null, null)
+ : this (null, null, null, false)
{
}
- internal BuildItemGroup (XmlElement xmlElement, Project project)
+ internal BuildItemGroup (XmlElement xmlElement, Project project, ImportedProject importedProject, bool readOnly)
{
+ this.buildItems = new List <BuildItem> ();
+ this.importedProject = importedProject;
this.itemGroupElement = xmlElement;
- this.buildItems = new ArrayList ();
- this.isImported = false;
this.parentProject = project;
+ this.read_only = readOnly;
- if (FromXml == false)
+ if (!FromXml)
return;
-
- this.condition = xmlElement.GetAttributeNode ("Condition");
+
foreach (XmlNode xn in xmlElement.ChildNodes) {
- if (xn is XmlElement == false)
- return;
+ if (!(xn is XmlElement))
+ continue;
XmlElement xe = (XmlElement) xn;
BuildItem bi = new BuildItem (xe, this);
buildItems.Add (bi);
- }
- }
-
- internal void Evaluate ()
- {
- foreach (BuildItem bi in buildItems) {
- bi.Evaluate ();
+ project.LastItemGroupContaining [bi.Name] = this;
}
}
return AddNewItem (itemName, itemInclude, false);
}
- // FIXME: use expression
[MonoTODO]
public BuildItem AddNewItem (string itemName,
string itemInclude,
bool treatItemIncludeAsLiteral)
{
- BuildItem bi = new BuildItem (itemName, itemInclude);
- buildItems.Add (bi);
- return bi;
- }
-
- internal void AddItem (BuildItem buildItem)
- {
- buildItems.Add (buildItem);
+ BuildItem item;
+
+ if (treatItemIncludeAsLiteral)
+ itemInclude = Utilities.Escape (itemInclude);
+
+ if (FromXml) {
+ XmlElement element = itemGroupElement.OwnerDocument.CreateElement (itemName, Project.XmlNamespace);
+ itemGroupElement.AppendChild (element);
+ element.SetAttribute ("Include", itemInclude);
+ item = new BuildItem (element, this);
+ } else {
+ item = new BuildItem (itemName, itemInclude);
+ }
+
+ item.Evaluate (null, true);
+
+ if (!read_only)
+ buildItems.Add (item);
+
+ if (parentProject != null) {
+ parentProject.MarkProjectAsDirty ();
+ parentProject.NeedToReevaluate ();
+ }
+
+ return item;
}
- internal void AddItem (string name, ITaskItem taskItem)
- {
- BuildItem buildItem;
- buildItem = new BuildItem (name, taskItem);
- buildItems.Add (buildItem);
- }
-
- [MonoTODO]
public void Clear ()
{
- //FIXME: should this remove all build items?
- buildItems = new ArrayList ();
+ if (FromXml)
+ itemGroupElement.RemoveAll ();
+
+ buildItems = new List <BuildItem> ();
+
+ if (parentProject != null) {
+ parentProject.MarkProjectAsDirty ();
+ parentProject.NeedToReevaluate ();
+ }
}
[MonoTODO]
public BuildItemGroup Clone (bool deepClone)
{
- BuildItemGroup big = new BuildItemGroup ();
- // FIXME: add copying of items
- return big;
+ if (deepClone) {
+ if (FromXml)
+ throw new NotImplementedException ();
+ else
+ throw new NotImplementedException ();
+ } else {
+ if (FromXml)
+ throw new InvalidOperationException ("A shallow clone of this object cannot be created.");
+ else
+ throw new NotImplementedException ();
+ }
}
public IEnumerator GetEnumerator ()
return buildItems.GetEnumerator ();
}
- [MonoTODO]
public void RemoveItem (BuildItem itemToRemove)
{
+ if (itemToRemove == null)
+ return;
+
+ itemToRemove.Detach ();
+
buildItems.Remove (itemToRemove);
}
- [MonoTODO]
public void RemoveItemAt (int index)
{
- buildItems.RemoveAt (index);
+ BuildItem item = buildItems [index];
+
+ RemoveItem (item);
}
public BuildItem[] ToArray ()
{
- BuildItem[] array;
- array = new BuildItem [Count];
- buildItems.CopyTo (array, 0);
- return array;
+ return buildItems.ToArray ();
}
-
- internal string ConvertToString (OldExpression transform, string separator)
+
+ internal void AddItem (BuildItem buildItem)
+ {
+ buildItems.Add (buildItem);
+ }
+
+ internal void AddItem (string name, ITaskItem taskItem)
+ {
+ BuildItem buildItem;
+ buildItem = new BuildItem (name, taskItem);
+ buildItems.Add (buildItem);
+ }
+
+ internal string ConvertToString (Expression transform,
+ Expression separator)
{
+ string separatorString;
+
+ if (separator == null)
+ separatorString = ";";
+ else
+ separatorString = (string) separator.ConvertTo (parentProject, typeof (string));
+
string[] items = new string [buildItems.Count];
int i = 0;
foreach (BuildItem bi in buildItems)
items [i++] = bi.ConvertToString (transform);
- return String.Join (separator, items);
+ return String.Join (separatorString, items);
}
-
- internal ITaskItem[] ConvertToITaskItemArray (OldExpression transform)
+
+ internal ITaskItem[] ConvertToITaskItemArray (Expression transform)
{
ITaskItem[] array = new ITaskItem [buildItems.Count];
int i = 0;
return array;
}
+ internal void Detach ()
+ {
+ if (!FromXml)
+ throw new InvalidOperationException ();
+
+ itemGroupElement.ParentNode.RemoveChild (itemGroupElement);
+ }
+
+ internal void Evaluate ()
+ {
+ foreach (BuildItem bi in buildItems) {
+ if (bi.Condition == String.Empty)
+ bi.Evaluate (parentProject, true);
+ else {
+ ConditionExpression ce = ConditionParser.ParseCondition (bi.Condition);
+ bi.Evaluate (parentProject, ce.BoolEvaluate (parentProject));
+ }
+ }
+ }
+
+ internal void ReplaceWith (BuildItem item, List <BuildItem> list)
+ {
+ int index = buildItems.IndexOf (item);
+ buildItems.RemoveAt (index);
+ buildItems.InsertRange (index, list);
+ }
+
public string Condition {
get {
- if (condition != null)
- return condition.Value;
+ if (FromXml)
+ return itemGroupElement.GetAttribute ("Condition");
else
- return null;
+ return String.Empty;
}
set {
- if (condition != null)
- condition.Value = value;
+ if (FromXml)
+ itemGroupElement.SetAttribute ("Condition", value);
+ else
+ throw new InvalidOperationException ("Cannot set a condition on an object not represented by an XML element in the project file.");
}
}
public int Count {
- get {
- if (buildItems != null)
- return buildItems.Count;
- else
- return 0;
- }
+ get { return buildItems.Count; }
}
public bool IsImported {
- get {
- return isImported;
- }
+ get { return importedProject != null; }
}
+
+ [MonoTODO]
public BuildItem this [int index] {
get {
- return (BuildItem) buildItems [index];
+ return buildItems [index];
}
}
set { parentCollection = value; }
}
- internal Project Project {
+ internal Project ParentProject {
get { return parentProject; }
}
return itemGroupElement != null;
}
}
+
+ internal XmlElement XmlElement {
+ get {
+ return itemGroupElement;
+ }
+ }
}
}