implement ProjectItemDefinition and co.
authorAtsushi Eno <atsushieno@veritas-vos-liberabit.com>
Mon, 14 Oct 2013 17:22:34 +0000 (02:22 +0900)
committerAtsushi Eno <atsushieno@veritas-vos-liberabit.com>
Fri, 29 Nov 2013 09:20:01 +0000 (18:20 +0900)
mcs/class/Microsoft.Build/Microsoft.Build.Evaluation/Project.cs
mcs/class/Microsoft.Build/Microsoft.Build.Evaluation/ProjectItem.cs
mcs/class/Microsoft.Build/Microsoft.Build.Evaluation/ProjectItemDefinition.cs
mcs/class/Microsoft.Build/Microsoft.Build.Evaluation/ProjectMetadata.cs
mcs/class/Microsoft.Build/Microsoft.Build.Evaluation/ProjectProperty.cs
mcs/class/Microsoft.Build/Microsoft.Build_test.dll.sources
mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ProjectItemDefinitionTest.cs [new file with mode: 0644]
mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ProjectPropertyTest.cs

index 6e4bf58c3452d3924317120f98d56a8d71b8f631..c186bbca2deb80ffcbe781f598fbdf1e6e2ad5fe 100644 (file)
@@ -162,7 +162,7 @@ namespace Microsoft.Build.Evaluation
                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) {
@@ -172,6 +172,13 @@ namespace Microsoft.Build.Evaluation
                                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);
+                                       }
                        }
                }
 
@@ -339,7 +346,7 @@ namespace Microsoft.Build.Evaluation
 
                public ProjectProperty GetProperty (string name)
                {
-                       throw new NotImplementedException ();
+                       return properties.FirstOrDefault (p => p.Name == name);
                }
 
                public void MarkDirty ()
@@ -409,7 +416,9 @@ namespace Microsoft.Build.Evaluation
 
                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; }
@@ -453,7 +462,7 @@ namespace Microsoft.Build.Evaluation
                }
 
                public bool IsBuildEnabled {
-                       get { throw new NotImplementedException (); }
+                       get { return ProjectCollection.IsBuildEnabled; }
                }
 
                public bool IsDirty {
index 393995e80cdc94c43a921170d7e6acc562a25bc4..16195da85727a346d8adf3bdb2b5645a6b5d606f 100644 (file)
@@ -69,7 +69,7 @@ namespace Microsoft.Build.Evaluation
                         throw new NotImplementedException ();
                 }
 
-                public void SetMetadataValue (string name, string unevaluatedValue)
+                public ProjectMetadata SetMetadataValue (string name, string unevaluatedValue)
                 {
                         throw new NotImplementedException ();
                 }
index ab30b1241ad4374e9d41797959abd47df36957fd..dce472253ee61e4138d19b6b4dbfc952075a1f84 100644 (file)
 
 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));
                }
        }
 }
-
index 45001f61a243323be0da41f561ba924338d06282..878588373ec8983310235f39509020a37709f1f0 100644 (file)
 //
 
 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; }
+               }
+       }
 }
 
index c7c8e36abe1c63372615bf278292f0567fa00875..96a014155ea9af5491299ab2e73d32438e691e7e 100644 (file)
@@ -172,5 +172,20 @@ namespace Microsoft.Build.Evaluation
                        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; }
+               }
+       }
 }
 
index 98ba5bc3eca86a2c6b2b265812354a06d6da75d6..667ff95a4d521eda19ac26a055bcd2c09d3af627 100644 (file)
@@ -1,6 +1,7 @@
 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
diff --git a/mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ProjectItemDefinitionTest.cs b/mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ProjectItemDefinitionTest.cs
new file mode 100644 (file)
index 0000000..9b4f6ba
--- /dev/null
@@ -0,0 +1,49 @@
+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");
+               }
+       }
+}
+
index 2e235cc9664120f454a33d63919bfa468755f796..eb727e0e5cc977a5837d4eb2c8ea687f90d2f891 100644 (file)
@@ -43,9 +43,8 @@ namespace MonoTests.Microsoft.Build.Evaluation
                        // 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]