Exemplo n.º 1
0
        public override bool Execute()
        {
            var resultItemsList = new List <ITaskItem>();

            foreach (var item in Items)
            {
                var resultItem = new TaskItem(item);
                item.CopyMetadataTo(resultItem);

                if (File.Exists(resultItem.GetMetadata("FullPath")) &&
                    HasMetadata(resultItem.GetMetadata("FullPath")))
                {
                    resultItem.SetMetadata("IsPE", "True");
                }
                else
                {
                    resultItem.SetMetadata("IsPE", "False");
                }

                resultItemsList.Add(resultItem);
            }

            ResultItems = resultItemsList.ToArray();

            return(true);
        }
Exemplo n.º 2
0
        private List <TaskItem> CreateTaskItemsFromElements(
            string policyFilePath, XmlNodeList ruleSetVocabElements, XmlNamespaceManager xmlNs)
        {
            List <TaskItem> newTaskItems = new List <TaskItem>();

            foreach (XmlElement ruleSetVocabElement in ruleSetVocabElements)
            {
                // Save the name from the <ruleset> or <vocabulary>. This will be our policy name.
                string ruleSetVocabName = ruleSetVocabElement.Attributes["name"].Value;

                // Locate the <version> node with the most recent date attribute value
                XmlElement newestVersionNode = LocateNewestVersionNode(ruleSetVocabElement, xmlNs);

                string policyVersion = newestVersionNode.Attributes["major"].Value + "." + newestVersionNode.Attributes["minor"].Value;

                TaskItem newTaskItem = new TaskItem(ruleSetVocabName + "." + policyVersion);

                // Set the name and version into the new TaskItem
                newTaskItem.SetMetadata("SourcePath", policyFilePath);
                newTaskItem.SetMetadata("PolicyVersion", policyVersion);
                newTaskItem.SetMetadata("PolicyName", ruleSetVocabName);
                newTaskItem.SetMetadata("Luid", string.Format("RULE/{0}/{1}", ruleSetVocabName, policyVersion));

                newTaskItems.Add(newTaskItem);

                base.Log.LogMessage(
                    "    Added item [PolicyName:'{0}'; PolicyVersion:'{1}']",
                    newTaskItem.GetMetadata("PolicyName"),
                    newTaskItem.GetMetadata("PolicyVersion"));
            }

            return(newTaskItems);
        }
Exemplo n.º 3
0
        public void TestCtor_EscapedSpecialChar_BrokenEscaping()
        {
            // This is badly escaped, but MSBuild does not care.
            var metadata = "*****@*****.**";
            var item     = new TaskItem(metadata);

            Assert.AreEqual(metadata, item.ItemSpec, "#1");
            Assert.AreEqual(metadata, item.GetMetadata("Identity"), "#2");
            Assert.AreEqual(Path.GetFileNameWithoutExtension(metadata), item.GetMetadata("FileName"), "#3");
            Assert.IsTrue(item.GetMetadata("FullPath").EndsWith(metadata), "#4");
        }
Exemplo n.º 4
0
        public void TestReferenceWithNoMetadataNoBuildInProjectAttribute()
        {
            // Test the case where the metadata is missing and we are not supposed to build the reference
            ITaskItem   referenceItem = new TaskItem("TestItem");
            XmlDocument doc           = new XmlDocument();
            XmlElement  element       = doc.CreateElement("TestElement");

            AssignProjectConfiguration.SetBuildInProjectAndReferenceOutputAssemblyMetadata(true, referenceItem, element);
            Assert.Empty(referenceItem.GetMetadata("BuildReference"));
            Assert.Empty(referenceItem.GetMetadata("ReferenceOutputAssembly"));
        }
Exemplo n.º 5
0
        public void TestReferenceWithNoMetadataBuildInProjectAttributeFalse()
        {
            // Test the case where the metadata is missing and we are not supposed to build the reference
            ITaskItem   referenceItem = new TaskItem("TestItem");
            XmlDocument doc           = new XmlDocument();
            XmlElement  element       = doc.CreateElement("TestElement");

            element.SetAttribute("BuildProjectInSolution", "false");
            AssignProjectConfiguration.SetBuildInProjectAndReferenceOutputAssemblyMetadata(true, referenceItem, element);
            Assert.IsTrue(referenceItem.GetMetadata("BuildReference").Equals("false", StringComparison.OrdinalIgnoreCase));
            Assert.IsTrue(referenceItem.GetMetadata("ReferenceOutputAssembly").Equals("false", StringComparison.OrdinalIgnoreCase));
        }
Exemplo n.º 6
0
        public void TestReferenceWithNoMetadataBadBuildInProjectAttribute()
        {
            // Test the case where the metadata is missing and we are not supposed to build the reference
            ITaskItem   referenceItem = new TaskItem("TestItem");
            XmlDocument doc           = new XmlDocument();
            XmlElement  element       = doc.CreateElement("TestElement");

            element.SetAttribute("BuildProjectInSolution", "IAmReallyABadOne");
            AssignProjectConfiguration.SetBuildInProjectAndReferenceOutputAssemblyMetadata(true, referenceItem, element);
            Assert.Equal(0, referenceItem.GetMetadata("BuildReference").Length);
            Assert.Equal(0, referenceItem.GetMetadata("ReferenceOutputAssembly").Length);
        }
Exemplo n.º 7
0
        public void CopyMetadataToWithDefaults()
        {
            BuildItem fromBuildItem = BuildItem_Tests.GetXmlBackedItemWithDefinitionLibrary(); // i1;  has m=m1 (default) and n=n1 (regular)
            TaskItem  from          = new TaskItem(fromBuildItem);

            TaskItem to = new TaskItem("i2");

            from.CopyMetadataTo(to);

            Assertion.AssertEquals("n1", to.GetMetadata("n"));
            Assertion.AssertEquals("m1", to.GetMetadata("m"));
        }
Exemplo n.º 8
0
        public void TestReferenceWithNoMetadataBuildInProjectAttributeFalseReferenceAndBuildProjectsDisabledInProjectConfiguration()
        {
            // Test the case where the metadata is missing and we are not supposed to build the reference
            ITaskItem   referenceItem = new TaskItem("TestItem");
            XmlDocument doc           = new XmlDocument();
            XmlElement  element       = doc.CreateElement("TestElement");

            element.SetAttribute("BuildProjectInSolution", "false");
            AssignProjectConfiguration.SetBuildInProjectAndReferenceOutputAssemblyMetadata(false, referenceItem, element);
            Assert.IsTrue(referenceItem.GetMetadata("BuildReference").Length == 0);
            Assert.IsTrue(referenceItem.GetMetadata("ReferenceOutputAssembly").Length == 0);
        }
Exemplo n.º 9
0
 public void TestCopyConstructor()
 {
     item1 = new TaskItem("itemSpec");
     item1.SetMetadata("meta1", "val1");
     item2 = new TaskItem(item1);
     Assert.AreEqual(item1.GetMetadata("meta1"), item2.GetMetadata("meta1"), "A1");
     item1.SetMetadata("meta1", "val2");
     Assert.AreEqual("val2", item1.GetMetadata("meta1"), "A2");
     Assert.AreEqual("val1", item2.GetMetadata("meta1"), "A3");
     item2.SetMetadata("meta1", "val3");
     Assert.AreEqual("val2", item1.GetMetadata("meta1"), "A4");
     Assert.AreEqual("val3", item2.GetMetadata("meta1"), "A5");
 }
Exemplo n.º 10
0
        public void NonexistentRequestRootDir()
        {
            TaskItem from = new TaskItem();

            from.ItemSpec = "Monkey.txt";
            Assert.Equal(
                Path.GetPathRoot
                (
                    from.GetMetadata(FileUtilities.ItemSpecModifiers.FullPath)
                ),
                from.GetMetadata(FileUtilities.ItemSpecModifiers.RootDir)
                );
        }
Exemplo n.º 11
0
 public void TestCopyMetadataTo()
 {
     item1 = new TaskItem("itemSpec");
     item2 = new TaskItem("itemSpec");
     item1.SetMetadata("A", "1");
     item1.SetMetadata("B", "1");
     item1.SetMetadata("C", "1");
     item2.SetMetadata("B", "2");
     item1.CopyMetadataTo(item2);
     Assert.AreEqual("1", item2.GetMetadata("A"), "1");
     Assert.AreEqual("2", item2.GetMetadata("B"), "2");
     Assert.AreEqual("1", item2.GetMetadata("C"), "3");
 }
Exemplo n.º 12
0
        public void TestCtor_UnescapedSpecialChar()
        {
            // If we instantiate with unescaped metadata, we get the same value back
            var metadata = "*****@*****.**";
            var item     = new TaskItem(metadata);

            item.SetMetadata("mine", metadata);

            Assert.AreEqual(metadata, item.ItemSpec, "#1");
            Assert.AreEqual(metadata, item.GetMetadata("Identity"), "#2");
            Assert.AreEqual(Path.GetFileNameWithoutExtension(metadata), item.GetMetadata("FileName"), "#3");
            Assert.IsTrue(item.GetMetadata("FullPath").EndsWith(metadata), "#4");
            Assert.AreEqual(metadata, item.GetMetadata("mine"), "#5");
        }
Exemplo n.º 13
0
        public static bool Execute(
            #region Parameters
            out Microsoft.Build.Framework.ITaskItem[] Result,
            Microsoft.Build.Framework.ITaskItem[] Items,
            Microsoft.Build.Framework.ITaskItem BaseItem,
            Microsoft.Build.Framework.ITaskItem Template = null)
        #endregion
        {
            #region Code
            Result = new ITaskItem[] { };
            var reserved = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase)
            {
                "AccessedTime", "CreatedTime", "DefiningProjectDirectory",
                "DefiningProjectExtension", "DefiningProjectFullPath", "DefiningProjectName",
                "Directory", "Extension", "Filename", "FullPath", "Identity", "ModifiedTime",
                "RecursiveDir", "RelativeDir", "RootDir",
            };
            var newItems = new List <ITaskItem>();
            foreach (var item in Items)
            {
                var newItem = new TaskItem(item);
                if (BaseItem != null)
                {
                    BaseItem.CopyMetadataTo(newItem);
                }
                var itemExt = newItem.GetMetadata("Extension");
                if (!string.IsNullOrEmpty(itemExt))
                {
                    newItem.SetMetadata("Suffix", itemExt.Substring(1));
                }
                if (Template != null)
                {
                    var metadataNames = Template.MetadataNames
                                        .Cast <string>().Where(x => !reserved.Contains(x));
                    foreach (var metadataName in metadataNames)
                    {
                        var metadataValue = Template.GetMetadata(metadataName);
                        newItem.SetMetadata(metadataName,
                                            Regex.Replace(metadataValue, @"(%<)(\w+)(>)",
                                                          match => newItem.GetMetadata(match.Groups[2].Value)));
                    }
                }
                newItems.Add(newItem);
            }
            Result = newItems.ToArray();
            #endregion

            return(true);
        }
Exemplo n.º 14
0
        public void ConstructFromDictionary()
        {
            Hashtable h = new Hashtable();

            h[FileUtilities.ItemSpecModifiers.Filename]  = "foo";
            h[FileUtilities.ItemSpecModifiers.Extension] = "bar";
            h["custom"] = "hello";

            TaskItem t = new TaskItem("bamboo.baz", h);

            // item-spec modifiers were not overridden by dictionary passed to constructor
            t.GetMetadata(FileUtilities.ItemSpecModifiers.Filename).ShouldBe("bamboo");
            t.GetMetadata(FileUtilities.ItemSpecModifiers.Extension).ShouldBe(".baz");
            t.GetMetadata("CUSTOM").ShouldBe("hello");
        }
Exemplo n.º 15
0
        public void TestCtor_EscapedSpecialChar()
        {
            // If we instantiate with the *escaped* metadata, it's unescaped automatically
            var metadata        = "*****@*****.**";
            var escapedMetadata = global::Microsoft.Build.BuildEngine.Utilities.Escape("*****@*****.**");
            var item            = new TaskItem(escapedMetadata);

            item.SetMetadata("mine", escapedMetadata);

            Assert.AreEqual(metadata, item.ItemSpec, "#1");
            Assert.AreEqual(metadata, item.GetMetadata("Identity"), "#2");
            Assert.AreEqual(Path.GetFileNameWithoutExtension(metadata), item.GetMetadata("FileName"), "#3");
            Assert.IsTrue(item.GetMetadata("FullPath").EndsWith(metadata), "#4");
            Assert.AreEqual(metadata, item.GetMetadata("mine"), "#5");
        }
 public override bool Execute()
 {
     try
     {
         var outputs = new List <ITaskItem>();
         foreach (var settingsFileTaskItem in SettingsFiles)
         {
             Log.LogMessage(MessageImportance.High, "Generating environment settings class '{0}'.", settingsFileTaskItem.GetMetadata("Identity"));
             var outputPath            = ComputeOutputPath(settingsFileTaskItem);
             var settingsClassTaskItem = new TaskItem(outputPath);
             settingsClassTaskItem.SetMetadata("DependentUpon", settingsFileTaskItem.GetMetadata("Filename") + settingsFileTaskItem.GetMetadata("Extension"));
             outputs.Add(settingsClassTaskItem);
             using (var reader = XmlReader.Create(settingsFileTaskItem.GetMetadata("FullPath")))
                 using (var writer = File.CreateText(settingsClassTaskItem.GetMetadata("FullPath")))
                 {
                     var arguments = new XsltArgumentList();
                     arguments.AddExtensionObject("urn:extensions.stateless.be:biztalk:environment-settings-class-generation:string:2015:10", new Stringifier());
                     arguments.AddExtensionObject("urn:extensions.stateless.be:biztalk:environment-settings-class-generation:typifier:2015:10", new Typifier());
                     arguments.AddParam("clr-namespace-name", string.Empty, ComputeNamespace(settingsClassTaskItem));
                     arguments.AddParam("clr-class-name", string.Empty, ComputeClassName(settingsClassTaskItem));
                     arguments.AddParam("settings-file-name", string.Empty, settingsFileTaskItem.GetMetadata("Filename"));
                     _xslt.Transform(reader, arguments, writer);
                 }
         }
         // TODO ensure all generated classes have the same target environment value list
         SettingsClass = outputs.ToArray();
         return(true);
     }
     catch (Exception exception)
     {
         Log.LogErrorFromException(exception, true, true, null);
         return(false);
     }
 }
Exemplo n.º 17
0
        public void SetNullMetadataValue()
        {
            TaskItem item = new TaskItem("bar");

            item.SetMetadata("m", null);
            Assert.Equal(String.Empty, item.GetMetadata("m"));
        }
Exemplo n.º 18
0
        public void NonexistentRequestRelativeDir()
        {
            TaskItem from = new TaskItem();

            from.ItemSpec = "Monkey.txt";
            Assert.Equal(0, from.GetMetadata(FileUtilities.ItemSpecModifiers.RelativeDir).Length);
        }
Exemplo n.º 19
0
        public void SetNullMetadataValue()
        {
            TaskItem item = new TaskItem("bar");

            item.SetMetadata("m", null);
            item.GetMetadata("m").ShouldBe(string.Empty);
        }
Exemplo n.º 20
0
        public void NonexistentRequestDirectory()
        {
            TaskItem from = new TaskItem();

            from.ItemSpec = NativeMethodsShared.IsWindows ? @"c:\subdir\Monkey.txt" : "/subdir/Monkey.txt";
            from.GetMetadata(FileUtilities.ItemSpecModifiers.Directory).ShouldBe(NativeMethodsShared.IsWindows ? @"subdir\" : "subdir/");
        }
Exemplo n.º 21
0
        public void NonexistentRequestIdentity()
        {
            TaskItem from = new TaskItem();

            from.ItemSpec = "Monkey.txt";
            from.GetMetadata(FileUtilities.ItemSpecModifiers.Identity).ShouldBe("Monkey.txt");
        }
        IEnumerable <ITaskItem> GetCompiledOutput(string baseOutputDir, IDictionary <string, IDictionary> mapping)
        {
            foreach (var path in Directory.EnumerateFiles(baseOutputDir, "*.*", SearchOption.AllDirectories))
            {
                IDictionary metadata = null;
                string      rpath    = null;

                foreach (var kvp in mapping)
                {
                    if (path.StartsWith(kvp.Key, StringComparison.Ordinal))
                    {
                        rpath    = path.Substring(kvp.Key.Length);
                        metadata = kvp.Value;
                        break;
                    }
                }

                if (metadata == null)
                {
                    continue;
                }

                var compiled = new TaskItem(path, metadata);

                // adjust the logical name
                var logicalName = compiled.GetMetadata("LogicalName");
                var bundleName  = Path.Combine(logicalName, rpath);

                compiled.SetMetadata("LogicalName", bundleName);

                yield return(compiled);
            }

            yield break;
        }
Exemplo n.º 23
0
        public void NonexistentRequestRelativeDir()
        {
            TaskItem from = new TaskItem();

            from.ItemSpec = "Monkey.txt";
            from.GetMetadata(FileUtilities.ItemSpecModifiers.RelativeDir).Length.ShouldBe(0);
        }
Exemplo n.º 24
0
        public void CopyMetadataToDoesNotCopyExtension()
        {
            TaskItem from = new TaskItem("myfile.txt");
            TaskItem to   = new TaskItem("myfile.bin");

            from.CopyMetadataTo(to);

            Assertion.AssertEquals(".bin", to.GetMetadata("Extension"));
        }
Exemplo n.º 25
0
        public void NonexistentRequestDirectoryUNC()
        {
            TaskItem from = new TaskItem();

            from.ItemSpec = @"\\local\share\subdir\Monkey.txt";
            Assert.Equal(
                @"subdir\",
                from.GetMetadata(FileUtilities.ItemSpecModifiers.Directory)
                );
        }
Exemplo n.º 26
0
        public void CreateTaskItemWithNullMetadata()
        {
            IDictionary <string, string> metadata = new Dictionary <string, string>();

            metadata.Add("m", null);

            TaskItem item = new TaskItem("bar", (IDictionary)metadata);

            item.GetMetadata("m").ShouldBe(string.Empty);
        }
Exemplo n.º 27
0
        public void NonexistentRequestIdentity()
        {
            TaskItem from = new TaskItem();

            from.ItemSpec = "Monkey.txt";
            Assert.Equal(
                "Monkey.txt",
                from.GetMetadata(FileUtilities.ItemSpecModifiers.Identity)
                );
        }
Exemplo n.º 28
0
        public void CreateTaskItemWithNullMetadata()
        {
            IDictionary <string, string> metadata = new Dictionary <string, string>();

            metadata.Add("m", null);

            TaskItem item = new TaskItem("bar", (IDictionary)metadata);

            Assert.Equal(String.Empty, item.GetMetadata("m"));
        }
Exemplo n.º 29
0
        public void NonexistentRequestExtension()
        {
            TaskItem from = new TaskItem();

            from.ItemSpec = "Monkey.txt";
            Assert.AreEqual
            (
                ".txt",
                from.GetMetadata(FileUtilities.ItemSpecModifiers.Extension)
            );
        }
Exemplo n.º 30
0
        public void NonexistentRequestRecursiveDir()
        {
            TaskItem from = new TaskItem();

            from.ItemSpec = "Monkey.txt";

            Assert.IsTrue
            (
                from.GetMetadata(FileUtilities.ItemSpecModifiers.RecursiveDir).Length == 0
            );
        }