void ProcessXml ()
{
foreach (DictionaryEntry p in Environment.GetEnvironmentVariables ())
- this.properties.Add (new EnvironmentProjectProperty (this, (string) p.Key, (string) p.Value));
+ this.properties.Add (new EnvironmentProjectProperty (this, (string)p.Key, (string)p.Value));
foreach (var p in GlobalProperties)
this.properties.Add (new GlobalProjectProperty (this, p.Key, p.Value));
foreach (var child in Xml.Children) {
else if (child is ProjectItemGroupElement)
foreach (var p in ((ProjectItemGroupElement) child).Items)
this.raw_items.Add (new ProjectItem (p));
+ else if (child is ProjectItemDefinitionGroupElement)
+ foreach (var p in ((ProjectItemDefinitionGroupElement) child).ItemDefinitions) {
+ ProjectItemDefinition existing;
+ if (!item_definitions.TryGetValue (p.ItemType, out existing))
+ item_definitions.Add (p.ItemType, (existing = new ProjectItemDefinition (this, p.ItemType)));
+ existing.AddItems (p);
+ }
}
}
public ProjectProperty GetProperty (string name)
{
- throw new NotImplementedException ();
+ return properties.FirstOrDefault (p => p.Name == name);
}
public void MarkDirty ()
public ProjectProperty SetProperty (string name, string unevaluatedValue)
{
- throw new NotImplementedException ();
+ var p = new ManuallyAddedProjectProperty (this, name, unevaluatedValue);
+ properties.Add (p);
+ return p;
}
public ICollection<ProjectMetadata> AllEvaluatedItemDefinitionMetadata { get; private set; }
}
public bool IsBuildEnabled {
- get { throw new NotImplementedException (); }
+ get { return ProjectCollection.IsBuildEnabled; }
}
public bool IsDirty {
throw new NotImplementedException ();
}
- public void SetMetadataValue (string name, string unevaluatedValue)
+ public ProjectMetadata SetMetadataValue (string name, string unevaluatedValue)
{
throw new NotImplementedException ();
}
using System;
using System.Collections.Generic;
+using Microsoft.Build.Construction;
namespace Microsoft.Build.Evaluation
{
public class ProjectItemDefinition
{
- private ProjectItemDefinition ()
+ internal ProjectItemDefinition (Project project, string itemType)
{
- throw new NotImplementedException ();
+ this.project = project;
}
+ Project project;
+ string item_type;
+ List<ProjectMetadata> metadata = new List<ProjectMetadata> ();
+
public string ItemType {
- get { throw new NotImplementedException (); }
+ get { return item_type; }
}
public IEnumerable<ProjectMetadata> Metadata {
- get { throw new NotImplementedException (); }
+ get { return metadata; }
}
public int MetadataCount {
- get { throw new NotImplementedException (); }
+ get { return metadata.Count; }
}
public Project Project {
- get { throw new NotImplementedException (); }
+ get { return project; }
+ }
+
+ internal void AddItems (ProjectItemDefinitionElement xml)
+ {
+ foreach (var item in xml.Metadata)
+ metadata.Add (new ProjectMetadata (project, ItemType, metadata, m => metadata.Remove (m), item));
}
}
}
-
//
using Microsoft.Build.Construction;
-
using System;
+using System.Collections.Generic;
+using System.Linq;
namespace Microsoft.Build.Evaluation
{
- public class ProjectMetadata
- {
- private ProjectMetadata ()
- {
- throw new NotImplementedException ();
- }
+ public class ProjectMetadata
+ {
+ internal ProjectMetadata (Project project, string itemType, IEnumerable<ProjectMetadata> existingMetadata, Action<ProjectMetadata> remover, ProjectMetadataElement xml)
+ {
+ this.xml = xml;
+ this.project = project;
+ item_type = itemType;
+ predecessor = existingMetadata.FirstOrDefault (m => m.Name == xml.Name);
+ if (predecessor != null)
+ remover (predecessor);
+ }
+
+ Project project;
+ string item_type;
+ ProjectMetadataElement xml;
+ ProjectMetadata predecessor;
- public string EvaluatedValue {
- get { throw new NotImplementedException (); }
- }
+ public string EvaluatedValue {
+ get { return project.ExpandString (xml.Value); }
+ }
- public bool IsImported {
- get { throw new NotImplementedException (); }
- }
+ public bool IsImported {
+ get { throw new NotImplementedException (); }
+ }
- public string ItemType {
- get { throw new NotImplementedException (); }
- }
+ public string ItemType {
+ get { return item_type; }
+ }
- public string Name {
- get { throw new NotImplementedException (); }
- }
+ public string Name {
+ get { return xml.Name; }
+ }
- public ProjectMetadata Predecessor {
- get { throw new NotImplementedException (); }
- }
+ public ProjectMetadata Predecessor {
+ get { return predecessor; }
+ }
- public Project Project {
- get { throw new NotImplementedException (); }
- }
+ public Project Project {
+ get { return project; }
+ }
- public string UnevaluatedValue {
- get { throw new NotImplementedException (); }
- }
+ public string UnevaluatedValue {
+ get { return xml.Value; }
+ }
- public ProjectMetadataElement Xml {
- get { throw new NotImplementedException (); }
- }
- }
+ public ProjectMetadataElement Xml {
+ get { return xml; }
+ }
+ }
}
get { return null; }
}
}
+
+ internal class ManuallyAddedProjectProperty : BaseProjectProperty
+ {
+ public ManuallyAddedProjectProperty (Project project, string name, string value)
+ : base (project, PropertyType.Normal, name)
+ {
+ this.UnevaluatedValue = value;
+ }
+
+ public override string UnevaluatedValue { get; set; }
+
+ public override ProjectPropertyElement Xml {
+ get { return null; }
+ }
+ }
}
FunctionalTest.cs
Microsoft.Build.Construction/ProjectRootElementTest.cs
Microsoft.Build.Evaluation/ProjectCollectionTest.cs
+Microsoft.Build.Evaluation/ProjectItemDefinitionTest.cs
Microsoft.Build.Evaluation/ProjectTest.cs
Microsoft.Build.Evaluation/ProjectPropertyTest.cs
Microsoft.Build.Evaluation/ToolsetTest.cs
--- /dev/null
+using System;
+using System.IO;
+using System.Linq;
+using System.Xml;
+using Microsoft.Build.Construction;
+using Microsoft.Build.Evaluation;
+using Microsoft.Build.Execution;
+using NUnit.Framework;
+using System.Collections.Generic;
+
+namespace MonoTests.Microsoft.Build.Evaluation
+{
+ [TestFixture]
+ public class ProjectItemDefinitionTest
+ {
+ [Test]
+ public void Properties ()
+ {
+ string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
+ <ItemDefinitionGroup>
+ <Foo>
+ <prop1>value1</prop1>
+ <prop2>value1</prop2>
+ </Foo>
+ <!-- This one is merged into existing Foo definition above. -->
+ <Foo>
+ <prop1>valueX1</prop1><!-- this one overrides value1. -->
+ <prop3>value3</prop3>
+ </Foo>
+ </ItemDefinitionGroup>
+</Project>";
+ var xml = XmlReader.Create (new StringReader (project_xml));
+ var root = ProjectRootElement.Create (xml);
+ var proj = new Project (root);
+ Assert.AreEqual (1, proj.ItemDefinitions.Count, "#1"); // Foo
+ var def = proj.ItemDefinitions ["Foo"];
+ Assert.AreEqual (3, def.MetadataCount, "#2");
+ var md1 = def.Metadata.First (m => m.Name == "prop1");
+ Assert.AreEqual ("valueX1", md1.UnevaluatedValue, "#3");
+ // FIXME: enable it once we implemented it.
+ //Assert.AreEqual ("valueX1", md1.EvaluatedValue, "#4");
+ Assert.IsNotNull (md1.Predecessor, "#5");
+ Assert.AreEqual ("value1", md1.Predecessor.UnevaluatedValue, "#6");
+ // FIXME: enable it once we implemented it.
+ //Assert.AreEqual ("value1", md1.Predecessor.EvaluatedValue, "#7");
+ }
+ }
+}
+
// environment property could also be Predecessor (and removed...maybe.
// I could reproduce only NRE = .NET bug with environment property so far.)
prop = proj.Properties.First (p => p.Name == "PATH");
- Assert.AreEqual ("2", prop.UnevaluatedValue, "#7");
- Assert.IsNotNull (prop.Predecessor, "#5");
- Assert.AreEqual ("1", prop.Predecessor.UnevaluatedValue, "#6");
+ Assert.AreEqual ("overriden", prop.UnevaluatedValue, "#7");
+ Assert.IsNotNull (prop.Predecessor, "#8");
}
[Test]