Пример #1
0
        /// <summary>
        /// Get the value of an attribute on a project element
        /// </summary>
        /// <param name="attributeName">Name of the attribute to get the value for</param>
        /// <returns>Value of the attribute</returns>
        public string GetMetadata(string attributeName)
        {
            if (this.IsVirtual)
            {
                // For virtual items, use our virtual property collection
                if (!virtualProperties.ContainsKey(attributeName))
                {
                    return(String.Empty);
                }
                return(virtualProperties[attributeName]);
            }

            // cannot ask MSBuild for Include, so intercept it and return the corresponding property
            if (String.Compare(attributeName, ProjectFileConstants.Include, StringComparison.OrdinalIgnoreCase) == 0)
            {
                return(item.FinalItemSpec);
            }

            // Build Action is the type, not a property, so intercept this one as well
            if (String.Compare(attributeName, ProjectFileConstants.BuildAction, StringComparison.OrdinalIgnoreCase) == 0)
            {
                return(item.Name);
            }

            return(item.GetMetadata(attributeName));
        }
Пример #2
0
		public ProjectRef(BuildItem item, TranslatePath fnTranslate)
		{
			this.RefType = String.Format("{0}", Check.NotNull(item).Name);
			if (item.GetMetadata("Private") == "True")
				CopyLocal = true;
			if (item.GetMetadata("SpecificVersion") == "True")
				SpecificVersion = true;
			if (!String.IsNullOrEmpty(item.Condition))
				this.Condition = item.Condition;
			if (RefType == "ProjectReference")
				this.FromProjectReference(item, Check.NotNull(fnTranslate));
			else if (RefType == "Reference")
				this.FromFileReference(item, Check.NotNull(fnTranslate));
			else
				throw new ApplicationException("Unkown reference type " + RefType);
		}
Пример #3
0
        public void SetMetadataSimple()
        {
            BuildItem item = new BuildItem("n", "i");
            item.SetMetadata("m", "v");

            Assertion.AssertEquals(true, item.HasMetadata("m"));
            Assertion.AssertEquals("v", item.GetMetadata("m"));
        }
Пример #4
0
		public void TestSetMetadata3 ()
		{
			item = new BuildItem ("name", "include");
			item.SetMetadata ("a", "$(A)");
			item.SetMetadata ("b", "$(A)", true);
			item.SetMetadata ("c", "$(A)", false);

			Assert.AreEqual ("$(A)", item.GetEvaluatedMetadata ("a"), "A1");
			Assert.AreEqual ("$(A)", item.GetEvaluatedMetadata ("b"), "A2");
			Assert.AreEqual ("$(A)", item.GetEvaluatedMetadata ("c"), "A3");
			Assert.AreEqual ("$(A)", item.GetMetadata ("a"), "A4");
			Assert.AreEqual (Utilities.Escape ("$(A)"), item.GetMetadata ("b"), "A5");
			Assert.AreEqual ("$(A)", item.GetMetadata ("c"), "A6");
		}
Пример #5
0
		public void TestGetMetadata2 ()
		{
			item = new BuildItem ("name", "spec");
			item.GetMetadata (null);
		}
Пример #6
0
		public void TestGetMetadata1 ()
		{
			string itemName = "a";
			string itemInclude = "a;b;c";
			string metadataName = "name";
			string metadataValue = "a;b;c";

			item = new BuildItem (itemName, itemInclude);

			Assert.AreEqual (String.Empty, item.GetMetadata (metadataName), "A1");

			item.SetMetadata (metadataName, metadataValue);

			Assert.AreEqual (metadataValue, item.GetMetadata (metadataName), "A2");
			Assert.IsTrue (item.GetMetadata ("FullPath").EndsWith (Utilities.Escape (itemInclude)), "A3");
			//Assert.IsTrue (String.Empty != item.GetMetadata ("RootDir"), "A4");
			Assert.AreEqual (itemInclude, item.GetMetadata ("Filename"), "A5");
			Assert.AreEqual (String.Empty, item.GetMetadata ("Extension"), "A6");
			Assert.AreEqual (String.Empty, item.GetMetadata ("RelativeDir"), "A7");
			Assert.IsTrue (String.Empty != item.GetMetadata ("Directory"), "A8");
			Assert.AreEqual (String.Empty, item.GetMetadata ("RecursiveDir"), "A9");
			Assert.AreEqual (itemInclude, item.GetMetadata ("Identity"), "A10");
			// FIXME: test with CreatedTime
			Assert.AreEqual (String.Empty, item.GetMetadata ("ModifiedTime"), "A11");
			Assert.AreEqual (String.Empty, item.GetMetadata ("ModifiedTime"), "A12");
			Assert.AreEqual (String.Empty, item.GetMetadata ("AccessedTime"), "A13");
		}
Пример #7
0
		public void TestCopyCustomMetadataTo1 ()
		{
			BuildItem source, destination;
			string itemName1 = "a";
			string itemName2 = "b";
			string itemInclude = "a;b;c";
			string metadataName = "name";
			string metadataValue = "value";

			source = new BuildItem (itemName1, itemInclude);
			destination = new BuildItem (itemName2, itemInclude);

			source.SetMetadata (metadataName, metadataValue);

			source.CopyCustomMetadataTo (destination);

			Assert.AreEqual (metadataValue, destination.GetMetadata (metadataName), "A1");
			Assert.AreEqual (metadataValue, destination.GetEvaluatedMetadata (metadataName), "A2");
		}
Пример #8
0
		static void CheckBuildItem (BuildItem item, string name, string [,] metadata, string finalItemSpec, string prefix)
		{
			Assert.AreEqual (name, item.Name, prefix + "#1");
			for (int i = 0; i < metadata.GetLength (0); i++) {
				string key = metadata [i, 0];
				string val = metadata [i, 1];
				Assert.IsTrue (item.HasMetadata (key), String.Format ("{0}#2: Expected metadata '{1}' not found", prefix, key));
				Assert.AreEqual (val, item.GetMetadata (key), String.Format ("{0}#3: Value for metadata {1}", prefix, key));
				Assert.AreEqual (val, item.GetEvaluatedMetadata (key), String.Format ("{0}#4: Value for evaluated metadata {1}", prefix, key));
			}
			Assert.AreEqual (finalItemSpec, item.FinalItemSpec, prefix + "#5");
		}
Пример #9
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"));
        }
Пример #10
0
		private void FromProjectReference(BuildItem bi, TranslatePath fnTranslate)
		{
			if (!String.IsNullOrEmpty(bi.Include))
			{
				string path = bi.Include;
				if (fnTranslate(ref path))
					this.Project = path;
			}
			if (!String.IsNullOrEmpty(bi.GetMetadata("Project")))
				this.Guid = new Guid(bi.GetMetadata("Project"));
			if (!String.IsNullOrEmpty(bi.GetMetadata("Name")))
				this.Assembly = new AssemblyName(bi.GetMetadata("Name"));
		}
Пример #11
0
		private void FromFileReference(BuildItem bi, TranslatePath fnTranslate)
		{
			if (!String.IsNullOrEmpty(bi.Include))
			{
				this.Assembly = new AssemblyName(bi.Include);
				SpecificVersion |= this.Assembly.Version != null;
			}
			if (!String.IsNullOrEmpty(bi.GetMetadata("HintPath")))
			{
				string path = bi.GetMetadata("HintPath");
				fnTranslate(ref path);//< output file doesn't nessessarily exist
				this.Output = path;
			}
			this.RequiresVersion = bi.GetMetadata("RequiredTargetFramework");
		}
 private string GetAssemblyPathFromHintPath(BuildItem item, string projectDir)
 {
     string path = item.GetMetadata(STR_HintPath);
     path = PathUtilities.GetPath(projectDir, path);
     if (File.Exists(path))
     {
         return path;
     }
     return null;
 }
Пример #13
0
		public void GetMetadata_EscapedItemSpec ()
		{
			string itemInclude = "a;b;c";
			string escapedItemInclude = Utilities.Escape (itemInclude);

			item = new BuildItem ("name", escapedItemInclude);
			Assert.IsTrue (item.GetMetadata ("FullPath").EndsWith (escapedItemInclude), "#1a");
			Assert.IsTrue (item.GetEvaluatedMetadata ("FullPath").EndsWith (itemInclude), "#1b");

			Assert.AreEqual (escapedItemInclude, item.GetMetadata ("FileName"), "#2b");
			Assert.AreEqual (itemInclude, item.GetEvaluatedMetadata ("FileName"), "#2b");

			Assert.AreEqual (escapedItemInclude, item.GetMetadata ("Identity"), "#3a");
			Assert.AreEqual ("a;b;c", item.GetEvaluatedMetadata ("Identity"), "#3b");
		}
Пример #14
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"));
        }
Пример #15
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"));
        }
Пример #16
0
        public void CloneVirtual()
        {
            BuildItem item = new BuildItem("n", "i");
            item.SetMetadata("m1", "v1");
            item.SetMetadata("m2", "v2");
            BuildItem clone = item.Clone();

            Assertion.AssertEquals("v1", clone.GetMetadata("m1"));
            Assertion.AssertEquals("v2", clone.GetMetadata("m2"));

            clone.SetMetadata("m2", "newValue");

            Assertion.AssertEquals("v2", item.GetMetadata("m2"));
            Assertion.AssertEquals("newValue", clone.GetMetadata("m2"));
        }
Пример #17
0
        public void ConstructHasMetadata()
        {
            BuildItem item = new BuildItem("m", "v");

            Assertion.AssertEquals(false, item.HasMetadata("m"));
            Assertion.AssertEquals(string.Empty, item.GetEvaluatedMetadata("m"));
            Assertion.AssertEquals(string.Empty, item.GetMetadata("m"));
            Assertion.AssertEquals(builtInMetadataNames.Length, item.MetadataCount);
            Assertion.AssertEquals(0, item.CustomMetadataCount);
        }
Пример #18
0
        public void AddExistingItemAt()
        {
            MockLogger logger = new MockLogger();
            Project p = ObjectModelHelpers.CreateInMemoryProject(@"
                <Project xmlns=`msbuildnamespace`>
                  <ItemDefinitionGroup>
                    <i>
                      <m>m1</m>
                    </i>
                  </ItemDefinitionGroup> 
                </Project>
            ", logger);

            BuildItemGroup group = p.AddNewItemGroup();
            BuildItem item = new BuildItem("i", "i1");
            group.AddExistingItemAt(0, item);
            Expander expander = new Expander(new BuildPropertyGroup());
            item.EvaluateAllItemMetadata(expander, ParserOptions.AllowPropertiesAndItemLists, null, null);

            Assertion.AssertEquals("m1", item.GetMetadata("m"));
        }