Author: msierad
Date: 2007-01-14 16:38:50 -0500 (Sun, 14 Jan 2007)
New Revision: 70994
Modified:
trunk/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/BuildItem.cs
trunk/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/BuildItemGroup.cs
trunk/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ChangeLog
trunk/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/GroupingCollection.cs
trunk/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Project.cs
Log:
2007-01-14 Marek Sieradzki <[EMAIL PROTECTED]>
* BuildItemGroup.cs (Detach): Added.
(RemoveItem)
(RemoveItemAt): Used Detach ().
* BuildItem.cs: Made FromXml and HasParent internal and added
ParentItem and ParentItemGroup properties (internal).
(Detach): Added.
* GroupingCollection.cs (Remove): Used Detach ().
* Project.cs (ctor): Added PreserveWhitespace = false to get formatted
text on Save ().
(GetEvaluatedItemsByNameIgnoringCondition)
(GetEvaluatedItemsByName)
(GetEvaluatedProperty): Reevaluate if needed.
(RemoveItem)
(RemoveAllItemGroups)
(RemoveAllPropertyGroups): Implemented.
(DoLoad): Added closing of TextReader.
Modified:
trunk/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/BuildItem.cs
===================================================================
---
trunk/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/BuildItem.cs
2007-01-14 21:18:43 UTC (rev 70993)
+++
trunk/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/BuildItem.cs
2007-01-14 21:38:50 UTC (rev 70994)
@@ -47,7 +47,7 @@
bool isImported;
string itemInclude;
string name;
- BuildItemGroup parentItemGroup;
+ BuildItemGroup parent_item_group;
BuildItem parent_item;
//string recursiveDir;
IDictionary evaluatedMetadata;
@@ -86,7 +86,7 @@
isImported = parentItemGroup.IsImported;
unevaluatedMetadata =
CollectionsUtil.CreateCaseInsensitiveHashtable ();
evaluatedMetadata =
CollectionsUtil.CreateCaseInsensitiveHashtable ();
- this.parentItemGroup = parentItemGroup;
+ this.parent_item_group = parentItemGroup;
this.itemElement = itemElement;
@@ -100,7 +100,7 @@
name = parent.Name;
parent_item = parent;
parent_item.child_items.AddItem (this);
- parentItemGroup = parent.parentItemGroup;
+ parent_item_group = parent.parent_item_group;
unevaluatedMetadata =
CollectionsUtil.CreateCaseInsensitiveHashtable (parent.unevaluatedMetadata);
evaluatedMetadata =
CollectionsUtil.CreateCaseInsensitiveHashtable (parent.evaluatedMetadata);
}
@@ -200,10 +200,10 @@
void AddMetadata (string name, string value, bool literal)
{
- if (parentItemGroup != null) {
+ if (parent_item_group != null) {
Expression e = new Expression ();
e.Parse (value);
- evaluatedMetadata.Add (name, (string)
e.ConvertTo (parentItemGroup.Project, typeof (string)));
+ evaluatedMetadata.Add (name, (string)
e.ConvertTo (parent_item_group.Project, typeof (string)));
} else
evaluatedMetadata.Add (name, Utilities.Unescape
(value));
@@ -304,6 +304,17 @@
return taskItem;
}
+ internal void Detach ()
+ {
+ if (FromXml)
+ itemElement.ParentNode.RemoveChild
(itemElement);
+ else if (HasParent) {
+ if (parent_item.child_items.Count > 1)
+ SplitParentItem ();
+ parent_item.Detach ();
+ }
+ }
+
string GetItemSpecFromTransform (Expression transform)
{
StringBuilder sb;
@@ -316,9 +327,9 @@
if (o is string) {
sb.Append ((string)o);
} else if (o is PropertyReference) {
- sb.Append
(((PropertyReference)o).ConvertToString (parentItemGroup.Project));
+ sb.Append
(((PropertyReference)o).ConvertToString (parent_item_group.Project));
} else if (o is ItemReference) {
- sb.Append
(((ItemReference)o).ConvertToString (parentItemGroup.Project));
+ sb.Append
(((ItemReference)o).ConvertToString (parent_item_group.Project));
} else if (o is MetadataReference) {
sb.Append (GetMetadata
(((MetadataReference)o).MetadataName));
}
@@ -337,7 +348,7 @@
insertAfter = added.itemElement;
list.Add (added);
}
- parent.parentItemGroup.ReplaceWith (parent, list);
+ parent.parent_item_group.ReplaceWith (parent, list);
parent.itemElement.ParentNode.RemoveChild
(parent.itemElement);
}
@@ -354,7 +365,7 @@
newElement.AppendChild (xe.Clone ());
parent.itemElement.ParentNode.InsertAfter (newElement,
insertAfter);
- newParent = new BuildItem (newElement,
parent.parentItemGroup);
+ newParent = new BuildItem (newElement,
parent.parent_item_group);
newParent.child_items.AddItem (child);
child.parent_item = newParent;
@@ -408,13 +419,9 @@
if (FromXml)
itemElement.SetAttribute ("Include",
value);
else if (HasParent) {
- if (parent_item.child_items.Count == 1)
- parent_item.Include = value;
- else {
+ if (parent_item.child_items.Count > 1)
SplitParentItem ();
-
- parent_item.Include = value;
- }
+ parent_item.Include = value;
} else
itemInclude = value;
}
@@ -442,29 +449,30 @@
newElement.AppendChild
(xe.Clone ());
itemElement.ParentNode.ReplaceChild
(newElement, itemElement);
itemElement = newElement;
- } else if (HasParent)
- if (parent_item.child_items.Count == 1)
- parent_item.Name = value;
- else {
+ } else if (HasParent) {
+ if (parent_item.child_items.Count > 1)
SplitParentItem ();
- parent_item.Name = value;
- }
- else
+ parent_item.Name = value;
+ } else
name = value;
}
}
- bool FromXml {
- get {
- return itemElement != null;
- }
+ internal bool FromXml {
+ get { return itemElement != null; }
}
- bool HasParent {
- get {
- return parent_item != null;
- }
+ internal bool HasParent {
+ get { return parent_item != null; }
}
+
+ internal BuildItem ParentItem {
+ get { return parent_item; }
+ }
+
+ internal BuildItemGroup ParentItemGroup {
+ get { return parent_item_group; }
+ }
}
}
Modified:
trunk/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/BuildItemGroup.cs
===================================================================
---
trunk/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/BuildItemGroup.cs
2007-01-14 21:18:43 UTC (rev 70993)
+++
trunk/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/BuildItemGroup.cs
2007-01-14 21:38:50 UTC (rev 70994)
@@ -101,6 +101,11 @@
itemGroupElement.RemoveAll ();
buildItems = new List <BuildItem> ();
+
+ if (parentProject != null) {
+ parentProject.MarkProjectAsDirty ();
+ parentProject.NeedToReevaluate ();
+ }
}
[MonoTODO]
@@ -124,16 +129,21 @@
return buildItems.GetEnumerator ();
}
- [MonoTODO ("Doesn't remove item from XML")]
public void RemoveItem (BuildItem itemToRemove)
{
+ if (itemToRemove == null)
+ return;
+
+ itemToRemove.Detach ();
+
buildItems.Remove (itemToRemove);
}
- [MonoTODO ("Doesn't remove item from XML")]
public void RemoveItemAt (int index)
{
- buildItems.RemoveAt (index);
+ BuildItem item = buildItems [index];
+
+ RemoveItem (item);
}
public BuildItem[] ToArray ()
@@ -179,6 +189,14 @@
return array;
}
+ internal void Detach ()
+ {
+ if (!FromXml)
+ throw new InvalidOperationException ();
+
+ itemGroupElement.ParentNode.RemoveChild
(itemGroupElement);
+ }
+
internal void Evaluate ()
{
foreach (BuildItem bi in buildItems) {
@@ -198,8 +216,6 @@
buildItems.InsertRange (index, list);
}
- [MonoTODO]
- // FIXME: whether we can invoke get_Condition on BuildItemGroup
not based on XML
public string Condition {
get {
if (FromXml)
Modified:
trunk/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ChangeLog
===================================================================
---
trunk/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ChangeLog
2007-01-14 21:18:43 UTC (rev 70993)
+++
trunk/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ChangeLog
2007-01-14 21:38:50 UTC (rev 70994)
@@ -1,3 +1,25 @@
+2007-01-14 Marek Sieradzki <[EMAIL PROTECTED]>
+
+ * BuildItemGroup.cs (Detach): Added.
+ (RemoveItem)
+ (RemoveItemAt): Used Detach ().
+
+ * BuildItem.cs: Made FromXml and HasParent internal and added
+ ParentItem and ParentItemGroup properties (internal).
+ (Detach): Added.
+
+ * GroupingCollection.cs (Remove): Used Detach ().
+
+ * Project.cs (ctor): Added PreserveWhitespace = false to get formatted
+ text on Save ().
+ (GetEvaluatedItemsByNameIgnoringCondition)
+ (GetEvaluatedItemsByName)
+ (GetEvaluatedProperty): Reevaluate if needed.
+ (RemoveItem)
+ (RemoveAllItemGroups)
+ (RemoveAllPropertyGroups): Implemented.
+ (DoLoad): Added closing of TextReader.
+
2007-01-12 Marek Sieradzki <[EMAIL PROTECTED]>
* BuildPropertyGroup.cs: Don't trigger reevaluation just after a
Modified:
trunk/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/GroupingCollection.cs
===================================================================
---
trunk/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/GroupingCollection.cs
2007-01-14 21:18:43 UTC (rev 70993)
+++
trunk/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/GroupingCollection.cs
2007-01-14 21:38:50 UTC (rev 70994)
@@ -144,12 +144,13 @@
internal void Remove (BuildItemGroup big)
{
- big.XmlElement.ParentNode.RemoveChild (big.XmlElement);
+ big.Detach ();
list.Remove (big);
}
internal void Remove (BuildPropertyGroup bpg)
{
+ // FIXME: add bpg.Detach ();
bpg.XmlElement.ParentNode.RemoveChild (bpg.XmlElement);
list.Remove (bpg);
}
@@ -157,7 +158,6 @@
internal void Evaluate ()
{
Evaluate (EvaluationType.Property);
-
Evaluate (EvaluationType.Item);
}
Modified:
trunk/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Project.cs
===================================================================
---
trunk/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Project.cs
2007-01-14 21:18:43 UTC (rev 70993)
+++
trunk/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Project.cs
2007-01-14 21:38:50 UTC (rev 70994)
@@ -84,6 +84,7 @@
buildEnabled = ParentEngine.BuildEnabled;
xmlDocument = new XmlDocument ();
+ xmlDocument.PreserveWhitespace = false;
xmlDocument.AppendChild (xmlDocument.CreateElement
("Project", XmlNamespace));
xmlDocument.DocumentElement.SetAttribute ("xmlns", ns);
@@ -261,7 +262,12 @@
}
public BuildItemGroup GetEvaluatedItemsByName (string itemName)
- {
+ {
+ if (needToReevaluate) {
+ needToReevaluate = false;
+ Reevaluate ();
+ }
+
if (evaluatedItemsByName.ContainsKey (itemName))
return evaluatedItemsByName [itemName];
else
@@ -270,6 +276,11 @@
public BuildItemGroup GetEvaluatedItemsByNameIgnoringCondition
(string itemName)
{
+ if (needToReevaluate) {
+ needToReevaluate = false;
+ Reevaluate ();
+ }
+
if (evaluatedItemsByNameIgnoringCondition.ContainsKey
(itemName))
return evaluatedItemsByNameIgnoringCondition
[itemName];
else
@@ -278,6 +289,11 @@
public string GetEvaluatedProperty (string propertyName)
{
+ if (needToReevaluate) {
+ needToReevaluate = false;
+ Reevaluate ();
+ }
+
if (propertyName == null)
throw new ArgumentNullException
("propertyName");
@@ -328,22 +344,59 @@
timeOfLastDirty = DateTime.Now;
}
- [MonoTODO]
+ [MonoTODO ("Not tested")]
public void RemoveAllItemGroups ()
{
- throw new NotImplementedException ();
+ int length = ItemGroups.Count;
+ BuildItemGroup [] groups = new BuildItemGroup [length];
+ ItemGroups.CopyTo (groups, 0);
+
+ for (int i = 0; i < length; i++)
+ RemoveItemGroup (groups [i]);
+
+ MarkProjectAsDirty ();
+ NeedToReevaluate ();
}
- [MonoTODO]
+ [MonoTODO ("Not tested")]
public void RemoveAllPropertyGroups ()
{
- throw new NotImplementedException ();
+ int length = PropertyGroups.Count;
+ BuildPropertyGroup [] groups = new BuildPropertyGroup
[length];
+ PropertyGroups.CopyTo (groups, 0);
+
+ for (int i = 0; i < length; i++)
+ RemovePropertyGroup (groups [i]);
+
+ MarkProjectAsDirty ();
+ NeedToReevaluate ();
}
[MonoTODO]
public void RemoveItem (BuildItem itemToRemove)
{
- throw new NotImplementedException ();
+ if (itemToRemove == null)
+ throw new ArgumentNullException
("itemToRemove");
+
+ if (!itemToRemove.FromXml && !itemToRemove.HasParent)
+ throw new InvalidOperationException ("The
object passed in is not part of the project.");
+
+ BuildItemGroup big = itemToRemove.ParentItemGroup;
+
+ if (itemToRemove.FromXml) {
+ if (big.Count == 1)
+ groupingCollection.Remove (big);
+ else
+ big.RemoveItem (itemToRemove);
+ } else {
+ if (big.Count == 1)
+ groupingCollection.Remove (big);
+ else
+ big.RemoveItem
(itemToRemove.ParentItem);
+ }
+
+ MarkProjectAsDirty ();
+ NeedToReevaluate ();
}
[MonoTODO ("Not tested")]
@@ -558,6 +611,8 @@
ParentEngine.AddLoadedProject (this);
} catch (Exception e) {
throw new InvalidProjectFileException
(e.Message, e);
+ } finally {
+ textReader.Close ();
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches