support for nested Choose elements + fixed bug where the project reference would...
authorRodrigo B. de Oliveira <rbo@acm.org>
Thu, 21 Jan 2010 16:31:33 +0000 (16:31 -0000)
committerRodrigo B. de Oliveira <rbo@acm.org>
Thu, 21 Jan 2010 16:31:33 +0000 (16:31 -0000)
svn path=/trunk/mcs/; revision=149989

mcs/class/Microsoft.Build.Engine/ChangeLog
mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/BuildWhen.cs
mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/PropertyReference.cs
mcs/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/BuildChooseTest.cs
mcs/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/BuildPropertyTest.cs
mcs/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/ChangeLog

index c62af4fe872bdaf3fc8da016a4c881f277712ebb..2390f6e8d8c8880c1da7253ed0a891486412c02b 100644 (file)
@@ -1,3 +1,10 @@
+2010-01-21     Rodrigo B. de Oliveira <rodrigo@unity3d.com>
+
+       * Microsoft.Build.BuildEngine/BuildWhen.cs
+       * Microsoft.Build.BuildEngine/PropertyReference.cs:
+               support for nested Choose elements + fixed bug where the project reference
+               would be null during condition evaluation.
+               
 2010-01-12     Rodrigo B. de Oliveira <rodrigo@unity3d.com>
 
        * Microsoft.Build.BuildEngine/BuildWhen.cs
index 87799bbd4bd884aa29c718810e8376401c0b387d..09661da43599d8c27065abbb80ff539ac123c327 100644 (file)
@@ -39,26 +39,31 @@ namespace Microsoft.Build.BuildEngine {
        
                public BuildWhen (XmlElement whenElement, Project parentProject)
                {
-               
                        this.parentProject = parentProject;
-                       this.groupingCollection = new GroupingCollection (null);
+                       this.groupingCollection = new GroupingCollection (parentProject);
                        if (whenElement == null)
                                throw new ArgumentNullException ("whenElement");
                        this.whenElement = whenElement;
                        foreach (XmlElement xe in whenElement.ChildNodes) {
-                               if (xe.Name == "ItemGroup") {
-                                       BuildItemGroup big = new BuildItemGroup (xe, parentProject, null, true);
-                                       //big.BindToXml (xe);
-                                       groupingCollection.Add (big);
-                               // FIXME: add nested chooses
-                               } else if (xe.Name == "PropertyGroup") {
-                                       BuildPropertyGroup bpg = new BuildPropertyGroup (xe, parentProject, null, true);
-                                       //bpg.BindToXml (xe);
-                                       groupingCollection.Add (bpg);
-                               } else
-                                       throw new InvalidProjectFileException ("Invalid element in When.");
+                               switch (xe.Name) {
+                                       case "ItemGroup":
+                                               BuildItemGroup big = new BuildItemGroup (xe, parentProject, null, true);
+                                               //big.BindToXml (xe);
+                                               groupingCollection.Add (big);
+                                               break;
+                                       case "PropertyGroup":
+                                               BuildPropertyGroup bpg = new BuildPropertyGroup (xe, parentProject, null, true);
+                                               //bpg.BindToXml (xe);
+                                               groupingCollection.Add (bpg);
+                                               break;
+                                       case "Choose":
+                                               BuildChoose bc = new BuildChoose (xe, parentProject);
+                                               groupingCollection.Add (bc);
+                                               break;
+                                       default:
+                                               throw new InvalidProjectFileException ( string.Format ("Invalid element '{0}' in When.", xe.Name));
+                               }
                        }
-               
                }
 
                public void Evaluate()
index 285808ed5952c70fc1bfde7159c6bc2fb322f617..013519807b8be017da7f9900dd084c7d91ee6382 100644 (file)
@@ -55,6 +55,9 @@ namespace Microsoft.Build.BuildEngine {
                // so, always true, ignore @options
                public string ConvertToString (Project project, ExpressionOptions options)
                {
+                       if (project == null)
+                               throw new ArgumentNullException ("project");
+                       
                        BuildProperty bp = project.EvaluatedProperties [name];
                        if (bp == null)
                                return String.Empty;
index b794507afc2e8de2d81fdbb2a6d5e432ba481a82..01b2ab3b0d187330045a589338d60d588cf580c1 100644 (file)
@@ -329,5 +329,76 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                        
                        Assert.AreEqual ("Baz", project.GetEvaluatedProperty ("Foo"), "A1");
         }
+               
+               [Test]
+        public void NestedChooseInOtherwise () {
+            
+                       string documentString = @"
+                               <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
+                    <Choose>
+                        <When Condition=""'$(Configuration)' == 'dummy'"">
+                                               <PropertyGroup>
+                                                       <Foo>Bar</Foo>
+                                               </PropertyGroup>
+                        </When>
+                        <Otherwise>
+                                                       <Choose>
+                                                               <When Condition="" 'foo' == 'bar' "">
+                                                                       <PropertyGroup>
+                                                                               <Foo>Baz</Foo>
+                                                                       </PropertyGroup>
+                                                               </When>
+                                                               <Otherwise>
+                                                                       <PropertyGroup>
+                                                                               <Foo>Baz</Foo>
+                                                                       </PropertyGroup>
+                                                               </Otherwise>
+                                                       </Choose>
+                        </Otherwise>
+                    </Choose>
+                               </Project>
+                       ";
+
+                       Engine engine = new Engine (Consts.BinPath);
+            Project project = engine.CreateNewProject ();
+            project.LoadXml (documentString);
+                       
+                       Assert.AreEqual ("Baz", project.GetEvaluatedProperty ("Foo"), "A1");
+        }
+               
+               
+               [Test]
+               public void UndefinedPropertyInExistsCondition()
+               {
+                       string documentString = @"
+                               <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
+                                       <PropertyGroup>
+                                               <Foo>Bar</Foo>
+                                       </PropertyGroup>
+                                       <Choose>
+                                               <When Condition = "" '$(teamcity_dotnet_nunitlauncher_msbuild_task)' == '' "" >
+                                                       <Choose>
+                                                               <When Condition=""Exists('$(UndefinedProperty)\Foo\Bar')"">
+                                                                       <PropertyGroup>
+                                                                               <Exists>yes</Exists>
+                                                                       </PropertyGroup>
+                                                               </When>
+                                                               <Otherwise>
+                                                                       <PropertyGroup>
+                                                                               <Exists>no</Exists>
+                                                                       </PropertyGroup>
+                                                               </Otherwise>
+                                                       </Choose>
+                                               </When>
+                                       </Choose>
+                               </Project>
+                       ";
+
+                       Engine engine = new Engine (Consts.BinPath);
+            Project project = engine.CreateNewProject ();
+            project.LoadXml (documentString);
+                       
+                       Assert.AreEqual ("no", project.GetEvaluatedProperty ("Exists"), "A1");
+               }
        }
 }
index c298624f2c8d263c47daf50762367e8781dc2f7a..d3c944c7d2bc301a272ca00a27132530a64f6f27 100644 (file)
@@ -349,35 +349,35 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                }
 
                [Test]
-                public void TestValueXml ()
-                {
-                        BuildPropertyGroup [] bpgs = new BuildPropertyGroup [1];
-                        BuildProperty [] props;
-                        XmlDocument xd;
-                        XmlNode node;
+               public void TestValueXml ()
+               {
+                       BuildPropertyGroup [] bpgs = new BuildPropertyGroup [1];
+                       BuildProperty [] props;
+                       XmlDocument xd;
+                       XmlNode node;
 
-                        string documentString = @"
-                                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
-                                        <PropertyGroup>
-                                                <Name>Value</Name>
-                                        </PropertyGroup>
-                                </Project>
-                        ";
+                       string documentString = @"
+                                       <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+                                                       <PropertyGroup>
+                                                                       <Name>Value</Name>
+                                                       </PropertyGroup>
+                                       </Project>
+                       ";
 
-                        engine = new Engine (Consts.BinPath);
+                       engine = new Engine (Consts.BinPath);
 
-                        project = engine.CreateNewProject ();
-                        project.LoadXml (documentString);
+                       project = engine.CreateNewProject ();
+                       project.LoadXml (documentString);
 
-                        project.PropertyGroups.CopyTo (bpgs, 0);
-                        bpgs[0].AddNewProperty("XmlProp", "<XmlStuff></XmlStuff>");
+                       project.PropertyGroups.CopyTo (bpgs, 0);
+                       bpgs[0].AddNewProperty("XmlProp", "<XmlStuff></XmlStuff>");
 
-                        xd = new XmlDocument ();
-                        xd.LoadXml (project.Xml);
+                       xd = new XmlDocument ();
+                       xd.LoadXml (project.Xml);
                        Console.WriteLine(project.Xml);
-                        node = xd.SelectSingleNode ("tns:Project/tns:PropertyGroup/tns:XmlProp/tns:XmlStuff", TestNamespaceManager.NamespaceManager);
-                        Assert.IsNotNull (node, "A1");
-                }
+                       node = xd.SelectSingleNode ("tns:Project/tns:PropertyGroup/tns:XmlProp/tns:XmlStuff", TestNamespaceManager.NamespaceManager);
+                       Assert.IsNotNull (node, "A1");
+               }
 
        }
 }
index 5d2f27da186f12c7520d46fe4f506dbd324f99d7..0dcb24084a566f96a823b720c024f51e21b97708 100644 (file)
@@ -1,3 +1,10 @@
+2010-01-21     Rodrigo B. de Oliveira <rodrigo@unity3d.com>
+
+       * BuildChooseTest.cs
+       * BuildPropertyTest.cs:
+               test cases for nested Choose elements and different property
+               evaluation scenarios.
+               
 2009-10-08  Ankit Jain  <jankit@novell.com>
 
        * ProjectTest.cs (TestBatchedMetadataRefInOutput): New.