Пример #1
0
        public void BasicProxying()
        {          
            BuildItemGroup ig = new BuildItemGroup();
            BuildItem i1 = new BuildItem("name1", "value1");
            i1.SetMetadata("myMetaName", "myMetaValue");
            BuildItem i2 = new BuildItem("name2", "value2");
            ig.AddItem(i1);
            ig.AddItem(i2);

            BuildItemGroupProxy proxy = new BuildItemGroupProxy(ig);

            // Gather everything into our own table
            Hashtable list = new Hashtable(StringComparer.OrdinalIgnoreCase);
            foreach (DictionaryEntry item in proxy)
            {
                list.Add(item.Key, item.Value);
            }

            // Check we got all the items
            Assertion.AssertEquals(2, list.Count);
            Assertion.AssertEquals("value1", ((TaskItem)list["name1"]).ItemSpec);
            Assertion.AssertEquals("value2", ((TaskItem)list["name2"]).ItemSpec);

            // Check they have all their metadata
            int builtInMetadata = FileUtilities.ItemSpecModifiers.All.Length;
            Assertion.AssertEquals(1 + builtInMetadata, ((TaskItem)list["name1"]).MetadataCount);
            Assertion.AssertEquals(0 + builtInMetadata, ((TaskItem)list["name2"]).MetadataCount);
            Assertion.AssertEquals("myMetaValue", ((TaskItem)list["name1"]).GetMetadata("myMetaName"));
        }
Пример #2
0
        public static BuildItemGroup ToBuildItemGroup(object o, Type t, string name)
        {
            BuildItemGroup big = new BuildItemGroup();

            if (t == typeof(ITaskItem))
            {
                big.AddItem(name, (ITaskItem)o);
            }
            else if (t == typeof(ITaskItem []))
            {
                foreach (ITaskItem i in (ITaskItem [])o)
                {
                    big.AddItem(name, i);
                }
            }
            else if (t.IsArray)
            {
                return(ToBuildItemGroup(name, ToString((object [])o, t), true));
            }
            else
            {
                return(ToBuildItemGroup(name, ToString(o), false));
            }

            return(big);
        }
Пример #3
0
        public void ExpandAllIntoTaskItems3()
        {
            BuildPropertyGroup pg = new BuildPropertyGroup();

            BuildItemGroup ig = new BuildItemGroup();
            ig.AddItem(new BuildItem("Compile", "foo.cs"));
            ig.AddItem(new BuildItem("Compile", "bar.cs"));

            BuildItemGroup ig2 = new BuildItemGroup();
            ig2.AddItem(new BuildItem("Resource", "bing.resx"));

            Hashtable itemsByType = new Hashtable(StringComparer.OrdinalIgnoreCase);
            itemsByType["Compile"] = ig;
            itemsByType["Resource"] = ig2;

            Expander expander = new Expander(pg, itemsByType);

            List<TaskItem> itemsOut = expander.ExpandAllIntoTaskItems("foo;bar;@(compile);@(resource)", null);

            ObjectModelHelpers.AssertItemsMatch(@"
                foo
                bar
                foo.cs
                bar.cs
                bing.resx
                ", itemsOut.ToArray());
        }
Пример #4
0
        /// <summary>
        /// Removes all Items of a given typoe from the collection.
        /// Recurses into Chooses in the collection removing Items as well.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <owner>DavidLe</owner>
        /// <param name="itemName"></param>
        internal void RemoveItemsByName(string itemName)
        {
            BuildItemGroup itemsToRemove = new BuildItemGroup();

            foreach (BuildItemGroup itemGroup in this.ItemGroupsAll)
            {
                // Now loop through the Items in the BuildItemGroup, and keep track of the
                // ones that are of the requested item type.
                foreach (BuildItem item in itemGroup)
                {
                    if ((String.Equals(item.Name, itemName, StringComparison.OrdinalIgnoreCase)) &&
                        !item.IsImported
                        )
                    {
                        // We're not allowed to remove an item from a collection while
                        // the collection is being enumerated.  So we have to track it
                        // in a separate list.
                        itemsToRemove.AddItem(item);
                    }
                }
            }
            foreach (BuildItem itemToRemove in itemsToRemove)
            {
                itemToRemove.ParentPersistedItemGroup.ParentProject.RemoveItem(itemToRemove);
            }
        }
Пример #5
0
        // FIXME: cleanup + test
        void PublishItemGroup(PropertyInfo propertyInfo,
                              object o,
                              string itemName)
        {
            BuildItemGroup newItems = ChangeType.ToBuildItemGroup(o, propertyInfo.PropertyType, itemName);

            newItems.ParentProject = parentProject;

            if (parentProject.EvaluatedItemsByName.ContainsKey(itemName))
            {
                BuildItemGroup big = parentProject.EvaluatedItemsByName [itemName];
                foreach (BuildItem item in newItems)
                {
                    big.AddItem(item);
                }
            }
            else
            {
                parentProject.EvaluatedItemsByName.Add(itemName, newItems);
            }
            foreach (BuildItem bi in newItems)
            {
                parentProject.EvaluatedItems.AddItem(bi);
            }
        }
Пример #6
0
        /// <summary>
        /// Verify item is not in the table
        /// </summary>
        private void MustNotBeInTable(Hashtable table, BuildItem item)
        {
            BuildItemGroup group = new BuildItemGroup();

            group.AddItem(item);
            MustNotBeInTable(table, item.Name, group);
        }
Пример #7
0
        static BuildItemGroup ToBuildItemGroup(string name, string items, bool split)
        {
            BuildItemGroup big = new BuildItemGroup();

            if (split)
            {
                string [] splitItems = items.Split(';');
                foreach (string item in splitItems)
                {
                    big.AddItem(name, new TaskItem(item));
                }
            }
            else
            {
                big.AddItem(name, new TaskItem(items));
            }

            return(big);
        }
Пример #8
0
        // FIXME: cleanup + test
        void PublishItemGroup(PropertyInfo propertyInfo,
                              object o,
                              string itemName)
        {
            if (o == null)
            {
                return;
            }

            BuildItemGroup newItems;

            try
            {
                newItems = ChangeType.ToBuildItemGroup(o, propertyInfo.PropertyType, itemName);
            }
            catch (Exception e)
            {
                throw new Exception(String.Format("Error publishing Output from task property '{0} {1}' to item named '{2}' : {3}",
                                                  propertyInfo.PropertyType, propertyInfo.Name, itemName, e.Message),
                                    e);
            }

            newItems.ParentProject = parentProject;

            if (parentProject.EvaluatedItemsByName.ContainsKey(itemName))
            {
                BuildItemGroup big = parentProject.EvaluatedItemsByName [itemName];
                foreach (BuildItem item in newItems)
                {
                    big.AddItem(item);
                }
            }
            else
            {
                parentProject.EvaluatedItemsByName.Add(itemName, newItems);
            }
            foreach (BuildItem bi in newItems)
            {
                parentProject.EvaluatedItems.AddItem(bi);
            }
        }
Пример #9
0
        public void CantModifyThroughEnumerator()
        {
            BuildItemGroup ig = new BuildItemGroup();
            BuildItem i1 = new BuildItem("name1", "value1");
            i1.SetMetadata("myMetaName", "myMetaValue");
            ig.AddItem(i1);

            BuildItemGroupProxy proxy = new BuildItemGroupProxy(ig);

            Hashtable list = new Hashtable(StringComparer.OrdinalIgnoreCase);
            foreach (DictionaryEntry item in proxy)
            {
                list.Add(item.Key, item.Value);
            }

            // Change the item
            Assertion.AssertEquals("value1", ((TaskItem)list["name1"]).ItemSpec);
            ((TaskItem)list["name1"]).ItemSpec = "newItemSpec";
            ((TaskItem)list["name1"]).SetMetadata("newMetadata", "newMetadataValue");

            // We did change our copy
            Assertion.AssertEquals("newItemSpec", ((TaskItem)list["name1"]).ItemSpec);
            Assertion.AssertEquals("newMetadataValue", ((TaskItem)list["name1"]).GetMetadata("newMetadata"));
            Assertion.AssertEquals("myMetaValue", ((TaskItem)list["name1"]).GetMetadata("myMetaName"));

            // But get the item again
            list = new Hashtable(StringComparer.OrdinalIgnoreCase);
            foreach (DictionaryEntry item in proxy)
            {
                list.Add(item.Key, item.Value);
            }

            // Item value and metadata hasn't changed
            Assertion.AssertEquals("value1", ((TaskItem)list["name1"]).ItemSpec);
            Assertion.AssertEquals("", ((TaskItem)list["name1"]).GetMetadata("newMetadata"));
            Assertion.AssertEquals("myMetaValue", ((TaskItem)list["name1"]).GetMetadata("myMetaName"));
        }
Пример #10
0
        /// <summary>
        /// Removes all Items of a given typoe from the collection.
        /// Recurses into Chooses in the collection removing Items as well.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <owner>DavidLe</owner>
        /// <param name="itemName"></param>
        internal void RemoveItemsByName(string itemName)
        {
            BuildItemGroup itemsToRemove = new BuildItemGroup();

            foreach (BuildItemGroup itemGroup in this.ItemGroupsAll)
            {
                // Now loop through the Items in the BuildItemGroup, and keep track of the
                // ones that are of the requested item type.
                foreach (BuildItem item in itemGroup)
                {
                    if ((0 == String.Compare(item.Name, itemName, StringComparison.OrdinalIgnoreCase)) &&
                            !item.IsImported
                        )
                    {
                        // We're not allowed to remove an item from a collection while
                        // the collection is being enumerated.  So we have to track it
                        // in a separate list.
                        itemsToRemove.AddItem(item);
                    }
                }
            }
            foreach (BuildItem itemToRemove in itemsToRemove)
            {
                itemToRemove.ParentPersistedItemGroup.ParentProject.RemoveItem(itemToRemove);
            }
        }
Пример #11
0
        private static Lookup GenerateLookup(BuildPropertyGroup properties)
        {
            BuildItemGroup items = new BuildItemGroup();
            BuildItem item1 = new BuildItem("i0", "a1");
            BuildItem item2 = new BuildItem("i0", "a2");
            BuildItem item3 = new BuildItem("i0", "a3");
            BuildItem item4 = new BuildItem("i0", "a4");
            item1.SetMetadata("m", "m1");
            item1.SetMetadata("n", "n1");
            item2.SetMetadata("m", "m2");
            item2.SetMetadata("n", "n2");
            item3.SetMetadata("m", "m2");
            item3.SetMetadata("n", "n2");
            item4.SetMetadata("m", "m3");
            item4.SetMetadata("n", "n3");
            items.AddItem(item1);
            items.AddItem(item2);
            items.AddItem(item3);
            items.AddItem(item4);
            Hashtable itemsByName = new Hashtable(StringComparer.OrdinalIgnoreCase);
            itemsByName.Add("i0", items);

            Lookup lookup = LookupHelpers.CreateLookup(properties, itemsByName);

            return lookup;
        }
Пример #12
0
        public void ConditionedPropertyUpdateTests()
        {
            Parser p = new Parser();
            BuildPropertyGroup propertyBag = new BuildPropertyGroup();
            Hashtable conditionedProperties = new Hashtable(StringComparer.OrdinalIgnoreCase);

            BuildItemGroup myNewItemGroup = new BuildItemGroup();
            myNewItemGroup.AddItem(new BuildItem("Compile", "foo.cs"));
            myNewItemGroup.AddItem(new BuildItem("Compile", "bar.cs"));
            myNewItemGroup.AddItem(new BuildItem("Compile", "baz.cs"));
            Hashtable itemBag = new Hashtable(StringComparer.OrdinalIgnoreCase);
            itemBag["Compile"] = myNewItemGroup;

            Expander expander = new Expander(LookupHelpers.CreateLookup(itemBag).ReadOnlyLookup);
            ConditionEvaluationState state = new ConditionEvaluationState(DummyAttribute, expander, conditionedProperties, string.Empty);

            StringCollection sc;
            AssertParseEvaluate(p, "'0' == '1'", state, false);
            Assertion.Assert(conditionedProperties.Count == 0);

            AssertParseEvaluate(p, "$(foo) == foo", state, false);
            Assertion.Assert(conditionedProperties.Count == 1);
            sc = (StringCollection)conditionedProperties["foo"];
            Assertion.Assert(sc.Count == 1);

            AssertParseEvaluate(p, "'$(foo)' != 'bar'", state, true);
            Assertion.Assert(conditionedProperties.Count == 1);
            sc = (StringCollection)conditionedProperties["foo"];
            Assertion.Assert(sc.Count == 2);

            AssertParseEvaluate(p, "'$(branch)|$(build)|$(platform)' == 'lab22dev|debug|x86'", state, false);
            Assertion.Assert(conditionedProperties.Count == 4);
            sc = (StringCollection)conditionedProperties["foo"];
            Assertion.Assert(sc.Count == 2);
            sc = (StringCollection)conditionedProperties["branch"];
            Assertion.Assert(sc.Count == 1);
            sc = (StringCollection)conditionedProperties["build"];
            Assertion.Assert(sc.Count == 1);
            sc = (StringCollection)conditionedProperties["platform"];
            Assertion.Assert(sc.Count == 1);

            AssertParseEvaluate(p, "'$(branch)|$(build)|$(platform)' == 'lab21|debug|x86'", state, false);
            Assertion.Assert(conditionedProperties.Count == 4);
            sc = (StringCollection)conditionedProperties["foo"];
            Assertion.Assert(sc.Count == 2);
            sc = (StringCollection)conditionedProperties["branch"];
            Assertion.Assert(sc.Count == 2);
            sc = (StringCollection)conditionedProperties["build"];
            Assertion.Assert(sc.Count == 1);
            sc = (StringCollection)conditionedProperties["platform"];
            Assertion.Assert(sc.Count == 1);

            AssertParseEvaluate(p, "'$(branch)|$(build)|$(platform)' == 'lab23|retail|ia64'", state, false);
            Assertion.Assert(conditionedProperties.Count == 4);
            sc = (StringCollection)conditionedProperties["foo"];
            Assertion.Assert(sc.Count == 2);
            sc = (StringCollection)conditionedProperties["branch"];
            Assertion.Assert(sc.Count == 3);
            sc = (StringCollection)conditionedProperties["build"];
            Assertion.Assert(sc.Count == 2);
            sc = (StringCollection)conditionedProperties["platform"];
            Assertion.Assert(sc.Count == 2);
            DumpHashtable(conditionedProperties);
        }
Пример #13
0
        public void PropertyFunctionConsumingItemMetadata()
        {
            MockLogger logger = new MockLogger();
            Project project = ObjectModelHelpers.CreateInMemoryProject(@"
                <Project ToolsVersion=`3.5` xmlns=`msbuildnamespace`>
                </Project>
            ", logger);


            BuildPropertyGroup pg = new BuildPropertyGroup();
            pg.SetProperty("SomePath", @"c:\some\path");

            BuildItemGroup ig = new BuildItemGroup();
            BuildItem item = new BuildItem("Compile", "fOo.Cs");
            item.SetMetadata("SomeMeta", "fOo.Cs");
            ig.AddItem(item);

            Hashtable itemsByType = new Hashtable(StringComparer.OrdinalIgnoreCase);
            itemsByType["Compile"] = ig;

            Expander expander = new Expander(pg, itemsByType, ExpanderOptions.ExpandAll);
            expander.SetMetadataInMetadataTable("Compile", "SomeMeta", "fOo.Cs");

            string result = expander.ExpandAllIntoStringLeaveEscaped(@"$([System.IO.Path]::Combine($(SomePath),%(Compile.SomeMeta)))", null);

            Assertion.AssertEquals(@"c:\some\path\fOo.Cs", result);
        }
Пример #14
0
        public void AddItemEmptyPersistedGroup()
        {
            XmlDocument doc = new XmlDocument();
            XmlElement ig = doc.CreateElement("ItemGroup", XMakeAttributes.defaultXmlNamespace);
            BuildItemGroup group = new BuildItemGroup(ig, false, new Project());

            BuildItem item = CreatePersistedBuildItem(ig, "i", "i3");
            group.AddItem(item);
            VerifyPersistedItemPosition(group, item, 0);
        }
Пример #15
0
		static BuildItemGroup ToBuildItemGroup (string name, string items, bool split)
		{
			BuildItemGroup big = new BuildItemGroup ();
			if (split) {
				string [] splitItems = items.Split (';');
				foreach (string item in splitItems)
					big.AddItem (name, new TaskItem (item));
			} else {
				big.AddItem (name, new TaskItem (items));
			}

			return big;
		}
Пример #16
0
        public void StringExpansionTests()
        {
            Parser p = new Parser();
            BuildPropertyGroup propertyBag = new BuildPropertyGroup();
            Hashtable conditionedProperties = null;

            BuildItemGroup myNewItemGroup = new BuildItemGroup();
            myNewItemGroup.AddItem(new BuildItem("Compile", "foo.cs"));
            myNewItemGroup.AddItem(new BuildItem("Compile", "bar.cs"));
            myNewItemGroup.AddItem(new BuildItem("Compile", "baz.cs"));
            Hashtable itemBag = new Hashtable(StringComparer.OrdinalIgnoreCase);
            itemBag["COMPILE"] = myNewItemGroup;

            propertyBag = new BuildPropertyGroup();
            propertyBag.SetProperty("foo", "true");
            propertyBag.SetProperty("bar", "yes");
            propertyBag.SetProperty("one", "1");
            propertyBag.SetProperty("onepointzero", "1.0");
            propertyBag.SetProperty("two", "2");
            propertyBag.SetProperty("simple", "simplestring");
            propertyBag.SetProperty("complex", "This is a complex string");
            propertyBag.SetProperty("c1", "Another (complex) one.");
            propertyBag.SetProperty("c2", "Another (complex) one.");
            propertyBag.SetProperty("TestQuote", "Contains'Quote'");
            propertyBag.SetProperty("AnotherTestQuote", "Here's Johnny!");
            propertyBag.SetProperty("Atsign", "Test the @ replacement");

            Expander expander = new Expander(propertyBag, itemBag);
            ConditionEvaluationState state = new ConditionEvaluationState(DummyAttribute, expander, conditionedProperties, string.Empty);

            AssertParseEvaluate(p, "'simplestring: true foo.cs;bar.cs;baz.cs' == '$(simple): $(foo) @(compile)'", state, true);
            AssertParseEvaluate(p, "'$(c1) $(c2)' == 'Another (complex) one. Another (complex) one.'", state, true);
            AssertParseEvaluate(p, "'CONTAINS%27QUOTE%27' == '$(TestQuote)'", state, true);
            AssertParseEvaluate(p, "'Here%27s Johnny!' == '$(AnotherTestQuote)'", state, true);
            AssertParseEvaluate(p, "'Test the %40 replacement' == $(Atsign)", state, true);}
Пример #17
0
        public void ShallowCloneOfVirtualItemGroup()
        {
            BuildItemGroup group = new BuildItemGroup();
            group.AddNewItem("i", "i1");
            BuildItem i2 = new BuildItem("i", "i2");
            group.AddItem(i2);

            BuildItemGroup group2 = group.Clone(false /*shallow*/);

            Assertion.AssertEquals(2, group2.Count);
            Assertion.AssertEquals("i1", group2[0].FinalItemSpec);
            Assertion.Assert(i2.Equals(group2[1]));
        }
Пример #18
0
        public void ModifyItemTwiceInSameScope2()
        {
            Hashtable table1 = new Hashtable(StringComparer.OrdinalIgnoreCase);
            Lookup lookup = LookupHelpers.CreateLookup(table1);

            // Add an item with m=m1 and n=n1 and o=o1
            BuildItem item1 = new BuildItem("i1", "a2");
            item1.SetMetadata("m", "m1");
            item1.SetMetadata("n", "n1");
            item1.SetMetadata("o", "o1");
            lookup.PopulateWithItem(item1);

            lookup.EnterScope();

            // It's still m=m1, n=n1, o=o1
            BuildItemGroup group = lookup.GetItems("i1");
            Assertion.AssertEquals(1, group.Count);
            Assertion.AssertEquals("m1", group[0].GetMetadata("m"));
            Assertion.AssertEquals("n1", group[0].GetMetadata("n"));
            Assertion.AssertEquals("o1", group[0].GetMetadata("o"));

            // Make a modification to the item to be m=m2 and n=n2
            Dictionary<string, string> newMetadata = new Dictionary<string, string>();
            newMetadata.Add("m", "m2");
            newMetadata.Add("n", "n2");
            group = new BuildItemGroup();
            group.AddItem(item1);
            lookup.ModifyItems("i1", group, newMetadata);

            // It's now m=m2, n=n2, o=o1
            BuildItemGroup foundGroup = lookup.GetItems("i1");
            Assertion.AssertEquals(1, foundGroup.Count);
            Assertion.AssertEquals("m2", foundGroup[0].GetMetadata("m"));
            Assertion.AssertEquals("n2", foundGroup[0].GetMetadata("n"));
            Assertion.AssertEquals("o1", foundGroup[0].GetMetadata("o"));

            // Make a modification to the item to be n=n3 
            newMetadata = new Dictionary<string, string>();
            newMetadata.Add("n", "n3");
            lookup.ModifyItems("i1", group, newMetadata);

            // It's now m=m2, n=n3, o=o1
            foundGroup = lookup.GetItems("i1");
            Assertion.AssertEquals(1, foundGroup.Count);
            Assertion.AssertEquals("m2", foundGroup[0].GetMetadata("m"));
            Assertion.AssertEquals("n3", foundGroup[0].GetMetadata("n"));
            Assertion.AssertEquals("o1", foundGroup[0].GetMetadata("o"));

            // But the original item hasn't changed yet
            Assertion.AssertEquals("m1", item1.GetMetadata("m"));
            Assertion.AssertEquals("n1", item1.GetMetadata("n"));
            Assertion.AssertEquals("o1", item1.GetMetadata("o"));

            lookup.LeaveScope();

            // It's still m=m2, n=n3, o=o1
            foundGroup = lookup.GetItems("i1");
            Assertion.AssertEquals(1, foundGroup.Count);
            Assertion.AssertEquals("m2", foundGroup[0].GetMetadata("m"));
            Assertion.AssertEquals("n3", foundGroup[0].GetMetadata("n"));
            Assertion.AssertEquals("o1", foundGroup[0].GetMetadata("o"));

            // And the original item has changed
            Assertion.AssertEquals("m2", item1.GetMetadata("m"));
            Assertion.AssertEquals("n3", item1.GetMetadata("n"));
            Assertion.AssertEquals("o1", item1.GetMetadata("o"));
        }
Пример #19
0
        public void ModifyItemTwiceInSameScope1()
        {
            Hashtable table1 = new Hashtable(StringComparer.OrdinalIgnoreCase);
            Lookup lookup = LookupHelpers.CreateLookup(table1);

            // Add an item with m=m1 and n=n1 
            BuildItem item1 = new BuildItem("i1", "a2");
            item1.SetMetadata("m", "m1");
            lookup.PopulateWithItem(item1);

            lookup.EnterScope();

            // Make a modification to the item to be m=m2
            Dictionary<string, string> newMetadata = new Dictionary<string, string>();
            newMetadata.Add("m", "m2");
            BuildItemGroup group = new BuildItemGroup();
            group.AddItem(item1);
            lookup.ModifyItems(item1.Name, group, newMetadata);

            // Make an unrelated modification to the item
            newMetadata = new Dictionary<string, string>();
            newMetadata.Add("n", "n1");
            lookup.ModifyItems(item1.Name, group, newMetadata);

            // It's now m=m2
            group = lookup.GetItems("i1");
            Assertion.AssertEquals(1, group.Count);
            Assertion.AssertEquals("m2", group[0].GetMetadata("m"));
        }
Пример #20
0
        public void RemoveBeforeModifyShouldBeInvalid()
        {
            Hashtable table1 = new Hashtable(StringComparer.OrdinalIgnoreCase);
            Lookup lookup = LookupHelpers.CreateLookup(table1);

            // Start a target
            lookup.EnterScope();

            // Start a task (eg)
            lookup.EnterScope();
            BuildItem item1 = new BuildItem("i1", "a2");
            BuildItemGroup group = new BuildItemGroup();
            group.AddItem(item1);

            // Remove an item then modify it
            lookup.RemoveItem(item1);

            Dictionary<string, string> metadataChanges = new Dictionary<string, string>();
            metadataChanges.Add("x", "y");
            lookup.ModifyItems("i1", group, metadataChanges);
        }
Пример #21
0
        public void Removes()
        {
            // One item in the project
            BuildItemGroup group1 = new BuildItemGroup();
            BuildItem item1 = new BuildItem("i1", "a1");
            group1.AddItem(item1);
            Hashtable table1 = new Hashtable(StringComparer.OrdinalIgnoreCase);
            table1.Add("i1", group1);
            Lookup lookup = LookupHelpers.CreateLookup(table1);

            // Start a target
            lookup.EnterScope();

            // Start a task (eg) and add a new item
            lookup.EnterScope();
            BuildItem item2 = new BuildItem("i1", "a2");
            lookup.AddNewItem(item2);

            // Remove one item
            lookup.RemoveItem(item1);

            // We see one item
            Assertion.AssertEquals(1, lookup.GetItems("i1").Count);
            Assertion.AssertEquals("a2", lookup.GetItems("i1")[0].FinalItemSpec);

            // Remove the other item
            lookup.RemoveItem(item2);

            // We see no items
            Assertion.AssertEquals(0, lookup.GetItems("i1").Count);

            // Finish the task
            lookup.LeaveScope();

            // We still see no items
            Assertion.AssertEquals(0, lookup.GetItems("i1").Count);

            // But there's still one item in the project
            Assertion.AssertEquals("a1", group1[0].FinalItemSpec);
            Assertion.AssertEquals(1, group1.Count);

            // Finish the target
            lookup.LeaveScope();

            // We still see no items
            Assertion.AssertEquals(0, lookup.GetItems("i1").Count);

            // And now there are no items in the project either
            Assertion.AssertEquals(0, group1.Count);
        }
Пример #22
0
 public void AddItemEmptyNonPersistedGroup()
 {
     BuildItemGroup group = new BuildItemGroup();
     BuildItem item = new BuildItem("i", "i1");
     group.AddItem(item);
     Assertion.AssertEquals(item, group[0]); // should be last
     item = new BuildItem("i", "i0");
     group.AddItem(item);
     Assertion.AssertEquals(item, group[1]); // should be last again
 }
Пример #23
0
        public void OldSyntaxTests()
        {
            Parser p = new Parser();
            BuildPropertyGroup propertyBag = new BuildPropertyGroup();
            Hashtable conditionedProperties = null;

            BuildItemGroup myNewItemGroup = new BuildItemGroup();
            myNewItemGroup.AddItem(new BuildItem("Compile", "foo.cs"));
            myNewItemGroup.AddItem(new BuildItem("Compile", "bar.cs"));
            myNewItemGroup.AddItem(new BuildItem("Compile", "baz.cs"));
            Hashtable itemBag = new Hashtable(StringComparer.OrdinalIgnoreCase);
            itemBag["COMPILE"] = myNewItemGroup;

            propertyBag = new BuildPropertyGroup();
            propertyBag.SetProperty("foo", "true");
            propertyBag.SetProperty("bar", "yes");
            propertyBag.SetProperty("one", "1");
            propertyBag.SetProperty("onepointzero", "1.0");
            propertyBag.SetProperty("two", "2");
            propertyBag.SetProperty("simple", "simplestring");
            propertyBag.SetProperty("complex", "This is a complex string");
            propertyBag.SetProperty("c1", "Another (complex) one.");
            propertyBag.SetProperty("c2", "Another (complex) one.");

            Expander expander = new Expander(propertyBag, itemBag);
            ConditionEvaluationState state = new ConditionEvaluationState(DummyAttribute, expander, conditionedProperties, string.Empty);

            AssertParseEvaluate(p, "(($(foo) != 'two' and $(bar)) and 5 >= 1) or $(one) == 1", state, true);}
Пример #24
0
		public static BuildItemGroup ToBuildItemGroup (object o, Type t, string name)
		{
			BuildItemGroup big = new BuildItemGroup ();

			if (t == typeof (ITaskItem)) {
				big.AddItem (name, (ITaskItem) o);
			} else if (t ==  typeof (ITaskItem [])) {
				foreach (ITaskItem i in (ITaskItem []) o)
					big.AddItem (name, i);
			} else if (t.IsArray) {
				return ToBuildItemGroup (name, ToString ((object []) o, t), true);
			} else {
				return ToBuildItemGroup (name, ToString (o), false);
			}

			return big;
		}
Пример #25
0
        /// <summary>
        /// A whole bunch of conditionals, that should be true, false, or error 
        /// (many coincidentally like existing QA tests) to give breadth coverage.
        /// Please add more cases as they arise.
        /// </summary>
        /// <owner>danmose</owner>
        private void EvaluateAVarietyOfExpressions()
        {
            string[] files = { "a", "a;b", "a'b", ";", "'" };

            try
            {
                foreach (string file in files)
                {
                    using (StreamWriter sw = File.CreateText(file)) { ; }
                }

                Parser p = new Parser();
                GenericExpressionNode tree;

                BuildItemGroup itemGroupU = new BuildItemGroup();
                BuildItemGroup itemGroupV = new BuildItemGroup();
                BuildItemGroup itemGroupW = new BuildItemGroup();
                BuildItemGroup itemGroupX = new BuildItemGroup();
                BuildItemGroup itemGroupY = new BuildItemGroup();
                BuildItemGroup itemGroupZ = new BuildItemGroup();
                itemGroupU.AddItem(new BuildItem("u", "a'b;c"));
                itemGroupV.AddItem(new BuildItem("w", "a"));
                itemGroupW.AddItem(new BuildItem("w", "1"));
                itemGroupX.AddItem(new BuildItem("x", "true"));
                itemGroupY.AddItem(new BuildItem("y", "xxx"));
                itemGroupZ.AddItem(new BuildItem("z", "xxx"));
                itemGroupZ.AddItem(new BuildItem("z", "yyy"));
                Hashtable itemBag = new Hashtable(StringComparer.OrdinalIgnoreCase);
                itemBag["u"] = itemGroupU;
                itemBag["v"] = itemGroupV;
                itemBag["w"] = itemGroupW;
                itemBag["x"] = itemGroupX;
                itemBag["y"] = itemGroupY;
                itemBag["z"] = itemGroupZ;

                BuildPropertyGroup propertyBag = new BuildPropertyGroup();
                propertyBag.SetProperty("a", "no");
                propertyBag.SetProperty("b", "true");
                propertyBag.SetProperty("c", "1");
                propertyBag.SetProperty("d", "xxx");
                propertyBag.SetProperty("e", "xxx");
                propertyBag.SetProperty("and", "and");
                propertyBag.SetProperty("a_semi_b", "a;b");
                propertyBag.SetProperty("a_apos_b", "a'b");
                propertyBag.SetProperty("foo_apos_foo", "foo'foo");
                propertyBag.SetProperty("a_escapedsemi_b", "a%3bb");
                propertyBag.SetProperty("a_escapedapos_b", "a%27b");
                propertyBag.SetProperty("has_trailing_slash", @"foo\");

                Dictionary<string, string> itemMetadata = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
                itemMetadata["Culture"] = "french";

                Expander expander = new Expander(new ReadOnlyLookup(itemBag, propertyBag), itemMetadata);

                string[] trueTests = {
                    "true or (SHOULDNOTEVALTHIS)", // short circuit
                    "(true and false) or true",
                    "false or true or false",
                    "(true) and (true)",
                    "false or !false",
                    "($(a) or true)",
                    "('$(c)'==1 and (!false))",
                    "@(z -> '%(filename).z', '$')=='xxx.z$yyy.z'",
                    "false or (false or (false or (false or (false or (true)))))",
                    "!(true and false)",
                    "$(and)=='and'",
                    "0x1==1.0",
                    "0xa==10",
                    "0<0.1",
                    "+4>-4",
                    "'-$(c)'==-1",
                    "$(a)==faLse",
                    "$(a)==oFF",
                    "$(a)==no",
                    "$(a)!=true",
                    "$(b)== True",
                    "$(b)==on",
                    "$(b)==yes",
                    "$(b)!=1",
                    "$(c)==1",
                    "$(d)=='xxx'",
                    "$(d)==$(e)",
                    "$(d)=='$(e)'",
                    "@(y)==$(d)",
                    "'@(z)'=='xxx;yyy'",
                    "$(a)==$(a)",
                    "'1'=='1'",
                    "'1'==1",
                    "1\n==1",
                    "1\t==\t\r\n1",
                    "123=='0123.0'",
                    "123==123",
                    "123==0123",
                    "123==0123.0",
                    "123!=0123.01",
                    "00==0",
                    "0==0.0",
                    "1\n\t==1",
                    "+4==4",
                    "44==+44.0 and -44==-44.0",                    
                    "false==no",
                    "true==yes",
                    "true==!false",
                    "yes!=no",
                    "false!=1",
                    "$(c)>0",
                    "!$(a)",
                    "$(b)",
                    "($(d)==$(e))",
                    "!true==false",
                    "a_a==a_a",
                    "a_a=='a_a'",
                    "_a== _a",
                    "@(y -> '%(filename)')=='xxx'",
                    "@(z -> '%(filename)', '!')=='xxx!yyy'",
                    "'xxx!yyy'==@(z -> '%(filename)', '!')",
                    "'$(a)'==(false)",
                    "('$(a)'==(false))",
                    "1>0",
                    "2<=2",
                    "2<=3",
                    "1>=1",
                    "1>=-1",
                    "-1==-1",
                    "-1  <  0",
                    "(1==1)and('a'=='a')",
                    "(true) and ($(a)==off)",
                    "(true) and ($(d)==xxx)",
                    "(false)     or($(d)==xxx)",
                    "!(false)and!(false)",
                    "'and'=='AND'",
                    "$(d)=='XxX'",
                    "true or true or false",
                    "false or true or !true or'1'",
                    "$(a) or $(b)",
                    "$(a) or true",
                    "!!true",
                    "'$(e)1@(y)'=='xxx1xxx'",
                    "0x11==17",
                    "0x01a==26",
                    "0xa==0x0A",
                    "@(x)",
                    "'%77'=='w'",
                    "'%zz'=='%zz'",
                    "true or 1",
                    "true==!false",
                    "(!(true))=='off'",
                    "@(w)>0",
                    "1<=@(w)",
                    "%(culture)=='FRENCH'",
                    "'%(culture) fries' == 'FRENCH FRIES' ",
                    @"'%(HintPath)' == ''",
                    @"%(HintPath) != 'c:\myassemblies\foo.dll'",
                    "exists('a')",
                    "exists(a)",
                    "exists('a%3bb')", /* semicolon */
                    "exists('a%27b')", /* apostrophe */
                    "exists($(a_escapedsemi_b))",
                    "exists('$(a_escapedsemi_b)')",
                    "exists($(a_escapedapos_b))",
                    "exists('$(a_escapedapos_b)')",
                    "exists($(a_apos_b))",
                    "exists('$(a_apos_b)')",
                    "exists(@(v))",
                    "exists('@(v)')",
                    "exists('%3b')",
                    "exists('%27')",
                    "exists('@(v);@(nonexistent)')",
                    @"HASTRAILINGSLASH('foo\')", 
                    @"!HasTrailingSlash('foo')",
                    @"HasTrailingSlash('foo/')",
                    @"HasTrailingSlash($(has_trailing_slash))",
                    "'59264.59264' == '59264.59264'",
                    "1" + new String('0', 500) + "==" + "1" + new String('0', 500), /* too big for double, eval as string */
                    "'1" + new String('0', 500) + "'=='" + "1" + new String('0', 500) + "'" /* too big for double, eval as string */
                };

                string[] falseTests = {
                    "false and SHOULDNOTEVALTHIS", // short circuit
                    "$(a)!=no",
                    "$(b)==1.1",
                    "$(c)==$(a)",
                    "$(d)!=$(e)",
                    "!$(b)",
                    "false or false or false",
                    "false and !((true and false))",
                    "on and off",
                    "(true) and (false)",
                    "false or (false or (false or (false or (false or (false)))))",
                    "!$(b)and true",
                    "1==a",
                    "!($(d)==$(e))",
                    "$(a) and true",
                    "true==1",
                    "false==0",
                    "(!(true))=='x'",
                    "oops==false",
                    "oops==!false",
                    "%(culture) == 'english'",
                    "'%(culture) fries' == 'english fries' ",
                    @"'%(HintPath)' == 'c:\myassemblies\foo.dll'",
                    @"%(HintPath) == 'c:\myassemblies\foo.dll'",
                    "exists('')",
                    "exists(' ')",
                    "exists($(nonexistent))",  // DDB #141195
                    "exists('$(nonexistent)')",  // DDB #141195
                    "exists(@(nonexistent))",  // DDB #141195
                    "exists('@(nonexistent)')",  // DDB #141195
                    "exists('\t')",
                    "exists('@(u)')",
                    "exists('$(foo_apos_foo)')",
                    "!exists('a')",
                    "!!!exists(a)",
                    @"hastrailingslash('foo')",
                    @"hastrailingslash('')",
                    @"HasTrailingSlash($(nonexistent))",
                    "'59264.59264' == '59264.59265'",
                    "1" + new String('0', 500) + "==2", /* too big for double, eval as string */
                    "'1" + new String('0', 500) + "'=='2'", /* too big for double, eval as string */
                    "'1" + new String('0', 500) + "'=='01" + new String('0', 500) + "'" /* too big for double, eval as string */
                };

                string[] errorTests = {
                    "$",
                    "$(",
                    "$()",
                    "@",
                    "@(",
                    "@()",
                    "%",
                    "%(",
                    "%()",
                    "exists",
                    "exists(",
                    "exists()",
                    "exists( )",
                    "exists(,)",
                    "@(x->'",
                    "@(x->''",
                    "@(x-",
                    "@(x->'x','",
                    "@(x->'x',''",
                    "@(x->'x','')",
                    "-1>x",
                    "%00",
                    "\n",
                    "\t",
                    "+-1==1",
                    "1==-+1",
                    "1==+0xa",
                    "!$(c)",
                    "'a'==('a'=='a')",
                    "'a'!=('a'=='a')",
                    "('a'=='a')!=a",
                    "('a'=='a')==a",
                    "!'x'",
                    "!'$(d)'",
                    "ab#==ab#",
                    "#!=#",
                    "$(d)$(e)=='xxxxxx'",
                    "1=1=1",
                    "'a'=='a'=='a'",
                    "1 > 'x'",
                    "x1<=1",
                    "1<=x",
                    "1>x",
                    "x<x",
                    "@(x)<x",
                    "x>x",
                    "x>=x",
                    "x<=x",
                    "x>1",
                    "x>=1",
                    "1>=x",
                    "@(y)<=1",
                    "1<=@(z)",
                    "1>$(d)",
                    "$(c)@(y)>1",
                    "'$(c)@(y)'>1",
                    "$(d)>=1",
                    "1>=$(b)",
                    "1> =0",
                    "or true",
                    "1 and",
                    "and",
                    "or",
                    "not",
                    "not true",
                    "()",
                    "(a)",
                    "!",
                    "or=or",
                    "1==",
                    "1= =1",
                    "=",
                    "'true",
                    "'false''",
                    "'a'=='a",
                    "('a'=='a'",
                    "('a'=='a'))",
                    "'a'=='a')",
                    "!and",
                    "@(a)@(x)!=1",
                    "@(a) @(x)!=1",
                    "$(a==off",
                    "=='x'",
                    "==",
                    "!0",
                    ">",
                    "true!=false==",
                    "true!=false==true",
                    "()",
                    "!1",
                    "1==(2",
                    "$(a)==x>1==2",
                    "'a'>'a'",
                    "0",
                    "$(a)>0",
                    "!$(e)",
                    "1<=1<=1",
                    "true $(and) true",
                    "--1==1",
                    "$(and)==and",
                    "!@#$%^&*",
                    "-($(c))==-1",
                    "a==b or $(d)",
                    "false or $()",
                    "$(d) or true",
                    "%(Culture) or true",
                    "@(nonexistent) and true",
                    "$(nonexistent) and true",
                    "@(nonexistent)",
                    "$(nonexistent)",
                    "@(z) and true",
                    "@() and true",
                    "@()",
                    "$()",
                    "1",
                    "1 or true",
                    "false or 1",
                    "1 and true",
                    "true and 1",
                    "!1",
                    "false or !1",
                    "false or 'aa'",
                    "true blah",
                    "existsX",
                    "!",
                    "nonexistentfunction('xyz')",
                    "exists('a;b')", /* non scalar */
                    "exists(@(z))",
                    "exists('@(z)')",
                    "exists($(a_semi_b))",
                    "exists('$(a_semi_b)')",
                    "exists(@(v)x)",
                    "exists(@(v)$(nonexistent))",
                    "exists('@(v)$(a)')",
                    "HasTrailingSlash(a,'b')",
                    "HasTrailingSlash(,,)"
                };

                for (int i = 0; i < trueTests.GetLength(0); i++)
                {
                    tree = p.Parse(trueTests[i], DummyAttribute, ParserOptions.AllowAll);
                    ConditionEvaluationState state = new ConditionEvaluationState(DummyAttribute, expander, null, trueTests[i]);
                    Assertion.Assert("expected true from '" + trueTests[i] + "'", tree.Evaluate(state));
                }

                for (int i = 0; i < falseTests.GetLength(0); i++)
                {
                    tree = p.Parse(falseTests[i], DummyAttribute, ParserOptions.AllowAll);
                    ConditionEvaluationState state = new ConditionEvaluationState(DummyAttribute, expander, null, falseTests[i]);
                    Assertion.Assert("expected false from '" + falseTests[i] + "' and got true", !tree.Evaluate(state));
                }

                for (int i = 0; i < errorTests.GetLength(0); i++)
                {
                    // It seems that if an expression is invalid,
                    //      - Parse may throw, or
                    //      - Evaluate may throw, or
                    //      - Evaluate may return false causing its caller EvaluateCondition to throw
                    bool success = true;
                    bool caughtException = false;
                    bool value;
                    try
                    {
                        tree = p.Parse(errorTests[i], DummyAttribute, ParserOptions.AllowAll);
                        ConditionEvaluationState state = new ConditionEvaluationState(DummyAttribute, expander, null, errorTests[i]);
                        value = tree.Evaluate(state);
                        if (!success) Console.WriteLine(errorTests[i] + " caused Evaluate to return false");
                    }
                    catch (InvalidProjectFileException ex)
                    {
                        Console.WriteLine(errorTests[i] + " caused '" + ex.Message + "'");
                        caughtException = true;
                    }
                    Assertion.Assert("expected '" + errorTests[i] + "' to not parse or not be evaluated",
                        (success == false || caughtException == true));

                }
            }
            finally
            {
                foreach (string file in files)
                {
                    if (File.Exists(file)) File.Delete(file);
                }
            }
        }
Пример #26
0
        public void RemoveItemFromProjectPreviouslyModifiedAndGottenThroughGetItem()
        {
            // Create some project state with an item with m=m1 and n=n1 
            Hashtable table1 = new Hashtable(StringComparer.OrdinalIgnoreCase);
            BuildItem item1 = new BuildItem("i1", "a2");
            item1.SetMetadata("m", "m1");
            BuildItemGroup group0 = new BuildItemGroup();
            group0.AddExistingItem(item1);
            table1["i1"] = group0;

            Lookup lookup = LookupHelpers.CreateLookup(table1);

            lookup.EnterScope();

            // Make a modification to the item to be m=m2
            Dictionary<string, string> newMetadata = new Dictionary<string, string>();
            newMetadata.Add("m", "m2");
            BuildItemGroup group = new BuildItemGroup();
            group.AddItem(item1);
            lookup.ModifyItems(item1.Name, group, newMetadata);

            // Get the item (under the covers, it cloned it in order to apply the modification)
            BuildItemGroup group2 = lookup.GetItems(item1.Name);
            Assertion.AssertEquals(1, group2.Count);
            BuildItem item1b = group2[0];

            // Remove the item
            lookup.RemoveItem(item1b);

            // There's now no items at all
            BuildItemGroup group3 = lookup.GetItems(item1.Name);
            Assertion.AssertEquals(0, group3.Count);

            // Leave scope
            lookup.LeaveScope();

            // And now none left in the project either
            Assertion.AssertEquals(0, ((BuildItemGroup)table1["i1"]).Count);
        }
Пример #27
0
        public void AddItem1()
        {
            XmlElement ig = CreatePersistedItemGroupElement();
            BuildItemGroup group = new BuildItemGroup(ig, false, new Project());

            BuildItem item = CreatePersistedBuildItem(ig, "i", "i3");
            group.AddItem(item);
            VerifyPersistedItemPosition(group, item, 2); // should be last

            item = CreatePersistedBuildItem(ig, "h", "h1");
            group.AddItem(item);
            VerifyPersistedItemPosition(group, item, 3); // should be last, because there were no h's.

            item = CreatePersistedBuildItem(ig, "h", "h0");
            group.AddItem(item);
            VerifyPersistedItemPosition(group, item, 3);// should be 2nd last

            item = CreatePersistedBuildItem(ig, "i", "i2");
            group.AddItem(item);
            VerifyPersistedItemPosition(group, item, 1); // should be 2nd      

            item = CreatePersistedBuildItem(ig, "i", "i0");
            group.AddItem(item);
            VerifyPersistedItemPosition(group, item, 0); // should be first              
        }
Пример #28
0
        public void ModifyItemThatWasAddedInSameScope()
        {
            Hashtable table1 = new Hashtable(StringComparer.OrdinalIgnoreCase);
            Lookup lookup = LookupHelpers.CreateLookup(table1);

            lookup.EnterScope();

            // Add an item with m=m1
            BuildItem item1 = new BuildItem("i1", "a2");
            item1.SetMetadata("m", "m1");
            lookup.AddNewItem(item1);

            // Change the item to be m=m2
            Dictionary<string, string> newMetadata = new Dictionary<string, string>();
            newMetadata.Add("m", "m2");
            BuildItemGroup group = new BuildItemGroup();
            group.AddItem(item1);
            lookup.ModifyItems(item1.Name, group, newMetadata);

            // Now it has m=m2
            group = lookup.GetItems("i1");
            Assertion.AssertEquals(1, group.Count);
            Assertion.AssertEquals("m2", group[0].GetMetadata("m"));

            // But the original item hasn't changed yet
            Assertion.AssertEquals("m1", item1.GetMetadata("m"));

            lookup.LeaveScope();

            // It still has m=m2
            group = lookup.GetItems("i1");
            Assertion.AssertEquals(1, group.Count);
            Assertion.AssertEquals("m2", group[0].GetMetadata("m"));

            // But now the original item has changed as well
            Assertion.AssertEquals("m2", item1.GetMetadata("m"));
        }
Пример #29
0
        public void ItemListTests()
        {
            Parser p = new Parser();
            Hashtable conditionedProperties = null;

            BuildItemGroup myCompileItemGroup = new BuildItemGroup();
            myCompileItemGroup.AddItem(new BuildItem("Compile", "foo.cs"));
            myCompileItemGroup.AddItem(new BuildItem("Compile", "bar.cs"));
            myCompileItemGroup.AddItem(new BuildItem("Compile", "baz.cs"));

            BuildItemGroup myBooleanItemGroup = new BuildItemGroup();
            myBooleanItemGroup.AddItem(new BuildItem("Boolean", "true"));

            Hashtable itemsByType = new Hashtable(StringComparer.OrdinalIgnoreCase);
            itemsByType["Compile"] = myCompileItemGroup;
            itemsByType["Boolean"] = myBooleanItemGroup;

            Expander expander = new Expander(LookupHelpers.CreateLookup(itemsByType).ReadOnlyLookup);
            ConditionEvaluationState state = new ConditionEvaluationState(DummyAttribute, expander, conditionedProperties, string.Empty);

            AssertParseEvaluate(p, "@(Compile) == 'foo.cs;bar.cs;baz.cs'", state, true);
            AssertParseEvaluate(p, "@(Compile,' ') == 'foo.cs bar.cs baz.cs'", state, true);
            AssertParseEvaluate(p, "@(Compile,'') == 'foo.csbar.csbaz.cs'", state, true);
            AssertParseEvaluate(p, "@(Compile->'%(Filename)') == 'foo;bar;baz'", state, true);
            AssertParseEvaluate(p, "@(Compile -> 'temp\\%(Filename).xml', ' ') == 'temp\\foo.xml temp\\bar.xml temp\\baz.xml'", state, true);
            AssertParseEvaluate(p, "@(Compile->'', '') == ''", state, true);
            AssertParseEvaluate(p, "@(Compile->'') == ';;'", state, true);
            AssertParseEvaluate(p, "@(Compile->'%(Nonexistent)', '') == ''", state, true);
            AssertParseEvaluate(p, "@(Compile->'%(Nonexistent)') == ';;'", state, true);
            AssertParseEvaluate(p, "@(Boolean)", state, true);
            AssertParseEvaluate(p, "@(Boolean) == true", state, true);
            AssertParseEvaluate(p, "'@(Empty, ';')' == ''", state, true);}
Пример #30
0
        public void ModifyItemInProjectPreviouslyModifiedAndGottenThroughGetItem()
        {
            // Create some project state with an item with m=m1 and n=n1 
            Hashtable table1 = new Hashtable(StringComparer.OrdinalIgnoreCase);
            BuildItem item1 = new BuildItem("i1", "a2");
            item1.SetMetadata("m", "m1");
            BuildItemGroup group0 = new BuildItemGroup();
            group0.AddExistingItem(item1);
            table1["i1"] = group0;

            Lookup lookup = LookupHelpers.CreateLookup(table1);

            lookup.EnterScope();

            // Make a modification to the item to be m=m2
            Dictionary<string, string> newMetadata = new Dictionary<string, string>();
            newMetadata.Add("m", "m2");
            BuildItemGroup group = new BuildItemGroup();
            group.AddItem(item1);
            lookup.ModifyItems(item1.Name, group, newMetadata);

            // Get the item (under the covers, it cloned it in order to apply the modification)
            BuildItemGroup group2 = lookup.GetItems(item1.Name);
            Assertion.AssertEquals(1, group2.Count);
            BuildItem item1b = group2[0];

            // Modify to m=m3
            Dictionary<string, string> newMetadata2 = new Dictionary<string, string>();
            newMetadata2.Add("m", "m3");
            BuildItemGroup group3 = new BuildItemGroup();
            group3.AddItem(item1b);
            lookup.ModifyItems(item1b.Name, group3, newMetadata2);

            // Modifications are visible
            BuildItemGroup group4 = lookup.GetItems(item1b.Name);
            Assertion.AssertEquals(1, group4.Count);
            Assertion.AssertEquals("m3", group4[0].GetMetadata("m"));

            // Leave scope
            lookup.LeaveScope();

            // Still visible
            BuildItemGroup group5 = lookup.GetItems(item1b.Name);
            Assertion.AssertEquals(1, group5.Count);
            Assertion.AssertEquals("m3", group5[0].GetMetadata("m"));

            // And the one in the project is changed
            Assertion.AssertEquals("m3", item1.GetMetadata("m"));
        }
Пример #31
0
        public void RemoveItemPreviouslyModifiedAndGottenThroughGetItem()
        {
            Hashtable table1 = new Hashtable(StringComparer.OrdinalIgnoreCase);
            Lookup lookup = LookupHelpers.CreateLookup(table1);

            // Add an item with m=m1 and n=n1 
            BuildItem item1 = new BuildItem("i1", "a2");
            item1.SetMetadata("m", "m1");
            lookup.PopulateWithItem(item1);

            lookup.EnterScope();

            // Make a modification to the item to be m=m2
            Dictionary<string, string> newMetadata = new Dictionary<string, string>();
            newMetadata.Add("m", "m2");
            BuildItemGroup group = new BuildItemGroup();
            group.AddItem(item1);
            lookup.ModifyItems(item1.Name, group, newMetadata);

            // Get the item (under the covers, it cloned it in order to apply the modification)
            BuildItemGroup group2 = lookup.GetItems(item1.Name);
            Assertion.AssertEquals(1, group2.Count);
            BuildItem item1b = group2[0];

            // Remove the item
            lookup.RemoveItem(item1b);

            // There's now no items at all
            BuildItemGroup group3 = lookup.GetItems(item1.Name);
            Assertion.AssertEquals(0, group3.Count);
        }
Пример #32
0
        /// <summary>
        /// Determines if the target needs to be built/rebuilt/skipped if its inputs and outputs can be correlated.
        /// </summary>
        /// <owner>SumedhK</owner>
        /// <param name="itemVectorsInTargetInputs"></param>
        /// <param name="itemVectorsInTargetOutputs"></param>
        /// <param name="itemVectorsReferencedInBothTargetInputsAndOutputs"></param>
        /// <param name="changedTargetInputs"></param>
        /// <param name="upToDateTargetInputs"></param>
        /// <returns>Indication of how to build the target.</returns>
        private DependencyAnalysisResult PerformDependencyAnalysisIfCorrelatedInputsOutputs
        (
            Hashtable itemVectorsInTargetInputs,
            Hashtable itemVectorsInTargetOutputs,
            ArrayList itemVectorsReferencedInBothTargetInputsAndOutputs,
            out Hashtable changedTargetInputs,
            out Hashtable upToDateTargetInputs
        )
        {
            DependencyAnalysisResult result = DependencyAnalysisResult.SkipUpToDate;

            changedTargetInputs = new Hashtable(StringComparer.OrdinalIgnoreCase);
            upToDateTargetInputs = new Hashtable(StringComparer.OrdinalIgnoreCase);

            // indicates if an incremental build is really just a full build, because all input items have changed
            int numberOfInputItemVectorsWithAllChangedItems = 0;

            foreach (string itemVectorType in itemVectorsReferencedInBothTargetInputsAndOutputs)
            {
                Hashtable inputItemVectors = (Hashtable)itemVectorsInTargetInputs[itemVectorType];
                Hashtable outputItemVectors = (Hashtable)itemVectorsInTargetOutputs[itemVectorType];

                // NOTE: recall that transforms have been separated out already
                ErrorUtilities.VerifyThrow(inputItemVectors.Count == 1,
                    "There should only be one item vector of a particular type in the target inputs that can be filtered.");

                // NOTE: this loop only makes one iteration
                foreach (BuildItemGroup inputItems in inputItemVectors.Values)
                {
                    if (inputItems.Count > 0)
                    {
                        BuildItemGroup changedInputItems = new BuildItemGroup();
                        BuildItemGroup upToDateInputItems = new BuildItemGroup();

                        BuildItem[] inputItemsAssumedToBeUpToDate = inputItems.ToArray();

                        foreach (DictionaryEntry outputEntry in outputItemVectors)
                        {
                            BuildItemGroup outputItems = (BuildItemGroup)outputEntry.Value;
                            // Get the metadata name so if it is missing we can print out a nice error message.
                            string outputItemExpression = (string)outputEntry.Key;

                            ErrorUtilities.VerifyThrow(inputItems.Count == outputItems.Count,
                                "An item vector of a particular type must always contain the same number of items.");

                            for (int i = 0; i < inputItemsAssumedToBeUpToDate.Length; i++)
                            {

                                // if we haven't already determined that this input item has changed
                                if (inputItemsAssumedToBeUpToDate[i] != null)
                                {
                                    // Check to see if the outputItem specification is null or empty, if that is the case we need to error out saying that some metadata
                                    // on one of the items used in the target output is missing.
                                    bool outputEscapedValueIsNullOrEmpty = String.IsNullOrEmpty(outputItems[i].FinalItemSpecEscaped);
                                    ProjectErrorUtilities.VerifyThrowInvalidProject(!outputEscapedValueIsNullOrEmpty,
                                                                                    this.TargetToAnalyze.TargetElement,
                                                                                    "TargetOutputsSpecifiedAreMissing",
                                                                                    inputItemsAssumedToBeUpToDate[i].FinalItemSpecEscaped,
                                                                                    outputItems[i].Name,
                                                                                    outputItemExpression,
                                                                                    TargetToAnalyze.Name);

                                    // check if it has changed
                                    bool outOfDate = IsOutOfDate(inputItemsAssumedToBeUpToDate[i].FinalItemSpecEscaped, outputItems[i].FinalItemSpecEscaped, inputItemsAssumedToBeUpToDate[i].Name, outputItems[i].Name);
                                    if (outOfDate)
                                    {
                                        changedInputItems.AddItem(inputItemsAssumedToBeUpToDate[i]);
                                        inputItemsAssumedToBeUpToDate[i] = null;

                                        result = DependencyAnalysisResult.IncrementalBuild;
                                    }
                                }
                            }

                            if (changedInputItems.Count == inputItems.Count)
                            {
                                numberOfInputItemVectorsWithAllChangedItems++;
                                break;
                            }
                        }

                        if (changedInputItems.Count < inputItems.Count)
                        {
                            foreach (BuildItem item in inputItemsAssumedToBeUpToDate)
                            {
                                if (item != null)
                                {
                                    upToDateInputItems.AddItem(item);
                                }
                            }
                        }

                        changedTargetInputs[itemVectorType] = changedInputItems;
                        upToDateTargetInputs[itemVectorType] = upToDateInputItems;
                    }
                }
            }

            ErrorUtilities.VerifyThrow(numberOfInputItemVectorsWithAllChangedItems <= itemVectorsReferencedInBothTargetInputsAndOutputs.Count,
                "The number of vectors containing all changed items cannot exceed the number of correlated vectors.");

            // if all correlated input items have changed
            if (numberOfInputItemVectorsWithAllChangedItems == itemVectorsReferencedInBothTargetInputsAndOutputs.Count)
            {
                ErrorUtilities.VerifyThrow(result == DependencyAnalysisResult.IncrementalBuild,
                    "If inputs have changed, this must be an incremental build.");

                // then the incremental build is really a full build
                result = DependencyAnalysisResult.FullBuild;
            }

            return result;
        }
Пример #33
0
 /// <summary>
 /// Verify item is not in the table
 /// </summary>
 private void MustNotBeInTable(Hashtable table, BuildItem item)
 {
     BuildItemGroup group = new BuildItemGroup();
     group.AddItem(item);
     MustNotBeInTable(table, item.Name, group);
 }