In class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine:
authorAnkit Jain <radical@corewars.org>
Fri, 27 Nov 2009 22:11:06 +0000 (22:11 -0000)
committerAnkit Jain <radical@corewars.org>
Fri, 27 Nov 2009 22:11:06 +0000 (22:11 -0000)
* Project.cs (TryGetEvaluatedItemByNameBatched): Item could be
available in either perBatchItemsByName or commonItemsByName
or the evaluatedItemsByName collection. Allows the use of
items which are not batched, but are consumed in case of batching.

In class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks:

* TaskBatchingTest.cs: Add new tests for batching, use on unbatched
items in a batching scenario.

svn path=/trunk/mcs/; revision=147049

mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ChangeLog
mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Project.cs
mcs/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/ChangeLog
mcs/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/TaskBatchingTest.cs [changed mode: 0644->0755]

index bf93bcfd73fc9233cf612d9e3df5b9f017e65df7..a4e1bc5eba4e7215ed9593b4c2d7ba379bf79abb 100644 (file)
@@ -1,3 +1,10 @@
+2009-11-28  Ankit Jain  <jankit@novell.com>
+
+       * Project.cs (TryGetEvaluatedItemByNameBatched): Item could be
+       available in either perBatchItemsByName or commonItemsByName
+       or the evaluatedItemsByName collection. Allows the use of
+       items which are not batched, but are consumed in case of batching.
+
 2009-11-26  Ankit Jain  <jankit@novell.com>
 
        * TargetBatchingImpl.cs (BuildTargetNeeded): Expand metadata
index 766bbfda84f8f018e0fa9256b2aefcc5abd11187..83b242ec788829ba8c59531eecc7b0dde351a1f2 100644 (file)
@@ -1078,17 +1078,14 @@ namespace Microsoft.Build.BuildEngine {
                // Honors batching
                internal bool TryGetEvaluatedItemByNameBatched (string itemName, out BuildItemGroup group)
                {
-                       if (perBatchItemsByName == null && commonItemsByName == null)
-                               return EvaluatedItemsByName.TryGetValue (itemName, out group);
-
-                       if (perBatchItemsByName != null)
-                               return perBatchItemsByName.TryGetValue (itemName, out group);
+                       if (perBatchItemsByName != null && perBatchItemsByName.TryGetValue (itemName, out group))
+                               return true;
 
-                       if (commonItemsByName != null)
-                               return commonItemsByName.TryGetValue (itemName, out group);
+                       if (commonItemsByName != null && commonItemsByName.TryGetValue (itemName, out group))
+                               return true;
 
                        group = null;
-                       return false;
+                       return EvaluatedItemsByName.TryGetValue (itemName, out group);
                }
 
                internal string GetMetadataBatched (string itemName, string metadataName)
index d0aae778525bf9929cf3f4824241cc3af6e61ec5..16988507ea4af23957fae3aba7ccedef49c04c36 100644 (file)
@@ -1,3 +1,8 @@
+2009-11-28  Ankit Jain  <jankit@novell.com>
+
+       * TaskBatchingTest.cs: Add new tests for batching, use on unbatched
+       items in a batching scenario.
+
 2009-10-08  Ankit Jain  <jankit@novell.com>
 
        * TestMessageLogger.cs (CheckLoggedAny): New.
old mode 100644 (file)
new mode 100755 (executable)
index eb8145d..bf904fb
@@ -5,6 +5,7 @@
 //   Ankit Jain (jankit@novell.com)
 //
 // Copyright 2008 Novell, Inc (http://www.novell.com)
+// Copyright 2009 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -611,6 +612,193 @@ namespace MonoTests.Microsoft.Build.Tasks
                        Assert.AreEqual (0, testLogger.NormalMessageCount, "Unexpected extra messages found");
                }
 
+               [Test]
+               public void TestBatchingWithUnbatchedItems () {
+                       string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" ToolsVersion=""3.5"">
+       <ItemGroup>
+               <Item1 Include=""One""/>
+               <Item1 Include=""Two""/>
+
+               <B Include=""abc""/>
+       </ItemGroup>
+       <Target Name='1'>
+               <Message Text=""Item1: %(Item1.Identity) | B: @(B)""/>
+       </Target>
+</Project>";
+
+                       Engine engine = new Engine (Consts.BinPath);
+                       Project project = engine.CreateNewProject ();
+
+                       TestMessageLogger testLogger = new TestMessageLogger ();
+                       engine.RegisterLogger (testLogger);
+
+                       project.LoadXml (projectString);
+                       if (!project.Build ("1")) {
+                               testLogger.DumpMessages ();
+                               Assert.Fail ("Build failed");
+                       }
+
+                       try {
+                               testLogger.CheckLoggedMessageHead ("Item1: One | B: abc", "A1");
+                               testLogger.CheckLoggedMessageHead ("Item1: Two | B: abc", "A2");
+
+                               Assert.AreEqual (0, testLogger.NormalMessageCount, "Unexpected extra messages found");
+                       } catch (AssertionException) {
+                               testLogger.DumpMessages ();
+                               throw;
+                       }
+               }
+
+               [Test]
+               public void TestPropertiesWithBatchedReferences () {
+                       string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" ToolsVersion=""3.5"">
+       <ItemGroup>
+               <Item1 Include=""One""/>
+               <Item1 Include=""Two""/>
+
+               <Item1Ref Include=""@(Item1)""/>
+       </ItemGroup>
+       <PropertyGroup>
+               <Prop1>@(Item1)</Prop1>
+               <Prop2>@(Item1Ref)</Prop2>
+       </PropertyGroup>
+       <Target Name='1'>
+               <Message Text=""Item1: %(Item1.Identity) | Prop1: $(Prop1) | Prop2: $(Prop2)""/>
+       </Target>
+</Project>";
+
+                       Engine engine = new Engine (Consts.BinPath);
+                       Project project = engine.CreateNewProject ();
+
+                       TestMessageLogger testLogger = new TestMessageLogger ();
+                       engine.RegisterLogger (testLogger);
+
+                       project.LoadXml (projectString);
+                       if (!project.Build ("1")) {
+
+                               testLogger.DumpMessages ();
+                               Assert.Fail ("Build failed");
+                       }
+
+                       try {
+                               testLogger.CheckLoggedMessageHead ("Item1: One | Prop1: One | Prop2: One;Two", "A1");
+                               testLogger.CheckLoggedMessageHead ("Item1: Two | Prop1: Two | Prop2: One;Two", "A2");
+
+                               Assert.AreEqual (0, testLogger.NormalMessageCount, "Unexpected extra messages found");
+                       } catch (AssertionException) {
+                               testLogger.DumpMessages ();
+                               throw;
+                       }
+               }
+
+               [Test]
+               public void TestPropertiesWithDynamicItems () {
+                       string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" ToolsVersion=""3.5"">
+       <ItemGroup>
+               <Item1 Include=""One""/>
+               <Item1 Include=""Two""/>
+
+               <Item2 Include=""Z""/>
+               <Item2Ref Include=""@(Item2)"" />
+       </ItemGroup>
+       <PropertyGroup>
+               <Prop1>@(Item2)</Prop1>
+               <Prop2>@(Item2Ref)</Prop2>
+       </PropertyGroup>
+       <Target Name='1'>
+               <Message Text=""Item1: %(Item1.Identity) | Prop1: $(Prop1) | Prop2: $(Prop2)""/>
+               <Message Text=""Item2: @(Item2) | Item2Ref: @(Item2Ref)""/>
+               <CreateItem Include=""A;B"">
+                       <Output TaskParameter=""Include"" ItemName=""Item2""/>
+               </CreateItem>
+               <Message Text=""Item1: %(Item1.Identity) | Prop1: $(Prop1) | Prop2: $(Prop2)""/>
+               <Message Text=""Item2: @(Item2) | Item2Ref: @(Item2Ref)""/>
+       </Target>
+</Project>";
+
+                       Engine engine = new Engine (Consts.BinPath);
+                       Project project = engine.CreateNewProject ();
+
+                       TestMessageLogger testLogger = new TestMessageLogger ();
+                       engine.RegisterLogger (testLogger);
+
+                       project.LoadXml (projectString);
+                       if (!project.Build ("1")) {
+
+                               testLogger.DumpMessages ();
+                               Assert.Fail ("Build failed");
+                       }
+
+                       try {
+
+                               testLogger.CheckLoggedMessageHead ("Item1: One | Prop1: Z | Prop2: Z", "A1");
+                               testLogger.CheckLoggedMessageHead ("Item1: Two | Prop1: Z | Prop2: Z", "A2");
+                               testLogger.CheckLoggedMessageHead ("Item2: Z | Item2Ref: Z", "A3");
+
+                               testLogger.CheckLoggedMessageHead ("Item1: One | Prop1: Z;A;B | Prop2: Z", "A4");
+                               testLogger.CheckLoggedMessageHead ("Item1: Two | Prop1: Z;A;B | Prop2: Z", "A5");
+                               testLogger.CheckLoggedMessageHead ("Item2: Z;A;B | Item2Ref: Z", "A3");
+
+                               Assert.AreEqual (0, testLogger.NormalMessageCount, "Unexpected extra messages found");
+                       } catch (AssertionException) {
+                               testLogger.DumpMessages ();
+                               throw;
+                       }
+               }
+
+               [Test]
+               public void TestBatchingWithUnqualifiedMetadataReference () {
+                       string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" ToolsVersion=""3.5"">
+       <ItemGroup>
+               <Item1 Include=""One""><Md>1</Md></Item1>
+               <Item1 Include=""Two""><Md>2</Md></Item1>
+               <Item1Ref Include=""@(Item1)"" />
+
+               <Item2 Include=""Three""><Md>3</Md></Item2>
+               <Item2 Include=""Four""><Md>4</Md></Item2>
+               <Item2Ref Include=""@(Item2)"" />
+       </ItemGroup>
+       <PropertyGroup>
+               <Prop1>@(Item1)</Prop1>
+               <Prop1Ref>@(Item1Ref)</Prop1Ref>
+
+               <Prop2>@(Item2)</Prop2>
+               <Prop2Ref>@(Item2Ref)</Prop2Ref>
+       </PropertyGroup>
+       <Target Name='1'>
+               <Message Text=""For md: %(Md) Item1: @(Item1) Item1Ref: @(Item1Ref) Item2: @(Item2) Item2Ref: @(Item2Ref) " +
+                                         @" Prop1: $(Prop1) Prop1Ref: $(Prop1Ref) Prop2: $(Prop2) Prop2Ref: $(Prop2Ref)""/>
+       </Target>
+</Project>";
+
+                       Engine engine = new Engine (Consts.BinPath);
+                       Project project = engine.CreateNewProject ();
+
+                       TestMessageLogger testLogger = new TestMessageLogger ();
+                       engine.RegisterLogger (testLogger);
+
+                       project.LoadXml (projectString);
+                       if (!project.Build ("1")) {
+
+                               testLogger.DumpMessages ();
+                               Assert.Fail ("Build failed");
+                       }
+                       testLogger.DumpMessages ();
+
+                       try {
+                               testLogger.CheckLoggedAny ("For md: 3 Item1:  Item1Ref:  Item2: Three Item2Ref: Three  Prop1:  Prop1Ref:  Prop2: Three Prop2Ref: Three", MessageImportance.Normal, "A1");
+                               testLogger.CheckLoggedAny ("For md: 4 Item1:  Item1Ref:  Item2: Four Item2Ref: Four  Prop1:  Prop1Ref:  Prop2: Four Prop2Ref: Four", MessageImportance.Normal, "A2");
+                               testLogger.CheckLoggedAny ("For md: 1 Item1: One Item1Ref: One Item2:  Item2Ref:   Prop1: One Prop1Ref: One Prop2:  Prop2Ref: ", MessageImportance.Normal, "A3");
+                               testLogger.CheckLoggedAny ("For md: 2 Item1: Two Item1Ref: Two Item2:  Item2Ref:   Prop1: Two Prop1Ref: Two Prop2:  Prop2Ref: ", MessageImportance.Normal, "A4");
+
+                               Assert.AreEqual (0, testLogger.NormalMessageCount, "Unexpected extra messages found");
+                       } catch (AssertionException) {
+                               testLogger.DumpMessages ();
+                               throw;
+                       }
+               }
+
+
                //Target batching
 
                [Test]