Example #1
0
        public void CopyMetadataFromITaskItem()
        {
            TaskItem from = new TaskItem();
            from.ItemSpec = "Monkey.txt";
            from.SetMetadata("Dog", "Bingo");
            from.SetMetadata("Cat", "Morris");
            from.SetMetadata("Bird", "Big");

            TaskItem to = new TaskItem();
            to.ItemSpec = "Bonobo.txt";
            to.SetMetadata("Sponge", "Bob");
            to.SetMetadata("Dog", "Harriet");
            to.SetMetadata("Cat", "Mike");
            from.CopyMetadataTo(to);

            Assert.AreEqual("Bonobo.txt", to.ItemSpec);          // ItemSpec is never overwritten
            Assert.AreEqual("Bob", to.GetMetadata("Sponge"));   // Metadata not in source are preserverd.
            Assert.AreEqual("Harriet", to.GetMetadata("Dog"));  // Metadata present on destination are not overwritten.
            Assert.AreEqual("Mike", to.GetMetadata("Cat"));
            Assert.AreEqual("Big", to.GetMetadata("Bird"));
        }
Example #2
0
 public void ReturnsFirstOne()
 {
     FindInList f = new FindInList();
     f.BuildEngine = new MockEngine();
     f.ItemSpecToFind = "a.cs";
     ITaskItem item1 = new TaskItem("a.cs");
     item1.SetMetadata("id", "1");
     ITaskItem item2 = new TaskItem("a.cs");
     item2.SetMetadata("id", "2");
     f.List = new ITaskItem[] { item1, item2 };
     Assert.True(f.Execute());
     Assert.Equal("a.cs", f.ItemFound.ItemSpec);
     Assert.Equal(item1.GetMetadata("id"), f.ItemFound.GetMetadata("id"));
 }
Example #3
0
 /// <summary>
 /// Add all items to the command line
 /// </summary>
 private static void AddLibraryName(IEnumerable<ITaskItem> items, List<ITaskItem> outputItems)
 {
     if (items == null) return;
     foreach (var x in items)
     {
         var outputItem = new TaskItem(x);
         x.CopyMetadataTo(outputItem);
         if (string.IsNullOrEmpty(outputItem.GetMetadata("LibraryName")))
         {
             outputItem.SetMetadata("LibraryName", Path.GetFileNameWithoutExtension(x.ItemSpec));
         }
         outputItems.Add(outputItem);
     }
 }
Example #4
0
 public void ReturnsLastOne()
 {
     FindInList f = new FindInList();
     f.BuildEngine = new MockEngine();
     f.ItemSpecToFind = "a.cs";
     f.FindLastMatch = true;
     ITaskItem item1 = new TaskItem("a.cs");
     item1.SetMetadata("id", "1");
     ITaskItem item2 = new TaskItem("a.cs");
     item2.SetMetadata("id", "2");
     f.List = new ITaskItem[] { item1, item2 };
     Assert.IsTrue(f.Execute(), "Expect success");
     Assert.AreEqual("a.cs", f.ItemFound.ItemSpec);
     Assert.AreEqual(item2.GetMetadata("id"), f.ItemFound.GetMetadata("id"));
 }
Example #5
0
        public void ConstructWithITaskItem()
        {
            TaskItem from = new TaskItem();
            from.ItemSpec = "Monkey.txt";
            from.SetMetadata("Dog", "Bingo");
            from.SetMetadata("Cat", "Morris");

            TaskItem to = new TaskItem((ITaskItem)from);
            Assert.AreEqual("Monkey.txt", to.ItemSpec);
            Assert.AreEqual("Monkey.txt", (string)to);
            Assert.AreEqual("Bingo", to.GetMetadata("Dog"));
            Assert.AreEqual("Morris", to.GetMetadata("Cat"));

            // Test that item metadata are case-insensitive.
            to.SetMetadata("CaT", "");
            Assert.AreEqual("", to.GetMetadata("Cat"));

            // manipulate the item-spec a bit
            Assert.AreEqual("Monkey", to.GetMetadata(FileUtilities.ItemSpecModifiers.Filename));
            Assert.AreEqual(".txt", to.GetMetadata(FileUtilities.ItemSpecModifiers.Extension));
            Assert.AreEqual(String.Empty, to.GetMetadata(FileUtilities.ItemSpecModifiers.RelativeDir));
        }
Example #6
0
        public void CreateTaskItemWithNullMetadata()
        {
            IDictionary<string, string> metadata = new Dictionary<string, string>();
            metadata.Add("m", null);

            TaskItem item = new TaskItem("bar", (IDictionary)metadata);
            Assert.AreEqual(String.Empty, item.GetMetadata("m"));
        }
Example #7
0
 public void SetNullMetadataValue()
 {
     TaskItem item = new TaskItem("bar");
     item.SetMetadata("m", null);
     Assert.AreEqual(String.Empty, item.GetMetadata("m"));
 }
Example #8
0
 public void NonexistentRequestIdentity()
 {
     TaskItem from = new TaskItem();
     from.ItemSpec = "Monkey.txt";
     Assert.AreEqual
     (
         "Monkey.txt",
         from.GetMetadata(FileUtilities.ItemSpecModifiers.Identity)
     );
 }
Example #9
0
        public void RequestTimeStamps()
        {
            TaskItem from = new TaskItem();
            from.ItemSpec = FileUtilities.GetTemporaryFile();

            Assert.IsTrue
            (
                from.GetMetadata(FileUtilities.ItemSpecModifiers.ModifiedTime).Length > 0
            );

            Assert.IsTrue
            (
                from.GetMetadata(FileUtilities.ItemSpecModifiers.CreatedTime).Length > 0
            );

            Assert.IsTrue
            (
                from.GetMetadata(FileUtilities.ItemSpecModifiers.AccessedTime).Length > 0
            );

            File.Delete(from.ItemSpec);

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

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

            Assert.IsTrue
            (
                from.GetMetadata(FileUtilities.ItemSpecModifiers.AccessedTime).Length == 0
            );
        }
Example #10
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");
		}
        public void TestReferenceWithMetadataAlreadySetBuildInProjectAttributeFalse()
        {
            // Test the case where the metadata is missing and we are not supposed to build the reference
            ITaskItem referenceItem = new TaskItem("TestItem");
            referenceItem.SetMetadata("BuildReference", "true");
            referenceItem.SetMetadata("ReferenceOutputAssembly", "true");

            XmlDocument doc = new XmlDocument();
            XmlElement element = doc.CreateElement("TestElement");
            element.SetAttribute("BuildProjectInSolution", "false");
            AssignProjectConfiguration.SetBuildInProjectAndReferenceOutputAssemblyMetadata(true, referenceItem, element);
            Assert.IsTrue(referenceItem.GetMetadata("BuildReference").Equals("true", StringComparison.OrdinalIgnoreCase));
            Assert.IsTrue(referenceItem.GetMetadata("ReferenceOutputAssembly").Equals("true", StringComparison.OrdinalIgnoreCase));

            // Test the case where only ReferenceOutputAssembly is not set
            referenceItem = new TaskItem("TestItem");
            referenceItem.SetMetadata("BuildReference", "true");
            doc = new XmlDocument();
            element = doc.CreateElement("TestElement");
            element.SetAttribute("BuildProjectInSolution", "false");
            AssignProjectConfiguration.SetBuildInProjectAndReferenceOutputAssemblyMetadata(true, referenceItem, element);
            Assert.IsTrue(referenceItem.GetMetadata("BuildReference").Equals("true", StringComparison.OrdinalIgnoreCase));
            Assert.IsTrue(referenceItem.GetMetadata("ReferenceOutputAssembly").Equals("false", StringComparison.OrdinalIgnoreCase));

            // Test the case where only BuildReference is not set
            referenceItem = new TaskItem("TestItem");
            referenceItem.SetMetadata("ReferenceOutputAssembly", "true");
            doc = new XmlDocument();
            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("true", StringComparison.OrdinalIgnoreCase));
        }
Example #12
0
 public void NonexistentRequestRootDir()
 {
     TaskItem from = new TaskItem();
     from.ItemSpec = "Monkey.txt";
     Assert.AreEqual
     (
         Path.GetPathRoot
         (
             from.GetMetadata(FileUtilities.ItemSpecModifiers.FullPath)
         ),
         from.GetMetadata(FileUtilities.ItemSpecModifiers.RootDir)
     );
 }
        public void CheckSetCopyLocalToFalseOnGacAssemblies()
        {
            string gacPath = @"C:\windows\gac";

            ResolveComReference rcr = new ResolveComReference();
            rcr.BuildEngine = new MockEngine();

            ArrayList taskItems = new ArrayList();
            TaskItem nonGacNoPrivate = new TaskItem(@"C:\windows\gar\test1.dll");
            TaskItem gacNoPrivate = new TaskItem(@"C:\windows\gac\assembly1.dll");

            TaskItem nonGacPrivateFalse = new TaskItem(@"C:\windows\gar\test1.dll");
            nonGacPrivateFalse.SetMetadata(ItemMetadataNames.privateMetadata, "false");
            TaskItem gacPrivateFalse = new TaskItem(@"C:\windows\gac\assembly1.dll");
            gacPrivateFalse.SetMetadata(ItemMetadataNames.privateMetadata, "false");

            TaskItem nonGacPrivateTrue = new TaskItem(@"C:\windows\gar\test1.dll");
            nonGacPrivateTrue.SetMetadata(ItemMetadataNames.privateMetadata, "true");
            TaskItem gacPrivateTrue = new TaskItem(@"C:\windows\gac\assembly1.dll");
            gacPrivateTrue.SetMetadata(ItemMetadataNames.privateMetadata, "true");

            taskItems.Add(nonGacNoPrivate);
            taskItems.Add(gacNoPrivate);

            taskItems.Add(nonGacPrivateFalse);
            taskItems.Add(gacPrivateFalse);

            taskItems.Add(nonGacPrivateTrue);
            taskItems.Add(gacPrivateTrue);

            rcr.SetCopyLocalToFalseOnGacOrNoPIAAssemblies(taskItems, gacPath);

            // if Private is missing, by default GAC items are CopyLocal=false, non GAC CopyLocal=true
            Assert.IsTrue(nonGacNoPrivate.GetMetadata(ItemMetadataNames.copyLocal) == "true", "Non Gac assembly, missing Private, should be TRUE");

            Assert.IsTrue(gacNoPrivate.GetMetadata(ItemMetadataNames.copyLocal) == "false", "Gac assembly, missing Private, should be FALSE");

            // if Private is set, it takes precedence
            Assert.IsTrue(nonGacPrivateFalse.GetMetadata(ItemMetadataNames.copyLocal) == "false", "Non Gac assembly, Private false, should be FALSE");

            Assert.IsTrue(gacPrivateFalse.GetMetadata(ItemMetadataNames.copyLocal) == "false", "Gac assembly, Private false, should be FALSE");

            Assert.IsTrue(nonGacPrivateTrue.GetMetadata(ItemMetadataNames.copyLocal) == "true", "Non Gac assembly, Private true, should be TRUE");

            Assert.IsTrue(gacPrivateTrue.GetMetadata(ItemMetadataNames.copyLocal) == "true", "Gac assembly, Private true, should be TRUE");
        }
Example #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
            Assert.AreEqual("bamboo", t.GetMetadata(FileUtilities.ItemSpecModifiers.Filename));
            Assert.AreEqual(".baz", t.GetMetadata(FileUtilities.ItemSpecModifiers.Extension));
            Assert.AreEqual("hello", t.GetMetadata("CUSTOM"));
        }
Example #15
0
 public void NonexistentRequestFullPath()
 {
     TaskItem from = new TaskItem();
     from.ItemSpec = "Monkey.txt";
     Assert.AreEqual
     (
         Path.Combine
         (
             Directory.GetCurrentDirectory(),
             "Monkey.txt"
         ),
         from.GetMetadata(FileUtilities.ItemSpecModifiers.FullPath)
     );
 }
 public void ReturnsLastOne()
 {
     FindAppConfigFile f = new FindAppConfigFile();
     f.BuildEngine = new MockEngine();
     ITaskItem item1 = new TaskItem("app.config");
     item1.SetMetadata("id", "1");
     ITaskItem item2 = new TaskItem("app.config");
     item2.SetMetadata("id", "2");
     f.PrimaryList = new ITaskItem[] { item1, item2 };
     f.SecondaryList = new ITaskItem[] { };
     f.TargetPath = "targetpath";
     Assert.True(f.Execute());
     Assert.Equal("app.config", f.AppConfigFile.ItemSpec);
     Assert.Equal(item2.GetMetadata("id"), f.AppConfigFile.GetMetadata("id"));
 }
        /// <summary>
        /// Resolves a single reference item by searcheing for referenced items using the specified SearchPaths.
        /// This method is made public so the resolution logic can be reused by other tasks.
        /// </summary>
        /// <param name="reference">The referenced item.</param>
        /// <param name="searchPaths">The paths to search.</param>
        /// <param name="searchFilenameExtensions">Filename extensions to check.</param>
        /// <param name="log">Logging helper.</param>
        /// <returns>The resolved reference item, or the original reference if it could not be resolved.</returns>
        public static ITaskItem ResolveReference(ITaskItem reference, string[] searchPaths, string[] searchFilenameExtensions, TaskLoggingHelper log)
        {
            if (reference == null)
            {
                throw new ArgumentNullException("reference");
            }

            if (searchPaths == null)
            {
                // Nothing to search, so just return the original reference item.
                return reference;
            }

            if (searchFilenameExtensions == null)
            {
                searchFilenameExtensions = new string[] { };
            }

            // Copy all the metadata from the source
            TaskItem resolvedReference = new TaskItem(reference);
            log.LogMessage(MessageImportance.Low, "WixReference: {0}", reference.ItemSpec);

            // Now find the resolved path based on our order of precedence
            foreach (string searchPath in searchPaths)
            {
                log.LogMessage(MessageImportance.Low, "Trying {0}", searchPath);
                if (searchPath.Equals(HintPathToken, StringComparison.Ordinal))
                {
                    string path = reference.GetMetadata("HintPath");
                    log.LogMessage(MessageImportance.Low, "Trying path {0}", path);
                    if (File.Exists(path))
                    {
                        resolvedReference.ItemSpec = path;
                        break;
                    }
                }
                else if (searchPath.Equals(RawFileNameToken, StringComparison.Ordinal))
                {
                    log.LogMessage(MessageImportance.Low, "Trying path {0}", resolvedReference.ItemSpec);
                    if (File.Exists(resolvedReference.ItemSpec))
                    {
                        break;
                    }

                    if (ResolveWixReferences.ResolveFilenameExtensions(resolvedReference,
                        resolvedReference.ItemSpec, searchFilenameExtensions, log))
                    {
                        break;
                    }
                }
                else
                {
                    string path = Path.Combine(searchPath, Path.GetFileName(reference.ItemSpec));
                    log.LogMessage(MessageImportance.Low, "Trying path {0}", path);
                    if (File.Exists(path))
                    {
                        resolvedReference.ItemSpec = path;
                        break;
                    }

                    if (ResolveWixReferences.ResolveFilenameExtensions(resolvedReference,
                        path, searchFilenameExtensions, log))
                    {
                        break;
                    }
                }
            }

            // Normalize the item path
            resolvedReference.ItemSpec = resolvedReference.GetMetadata("FullPath");

            return resolvedReference;
        }
        public void VerifyCacheFileNames()
        {
            MockEngine engine = new MockEngine();
            GetSDKReferenceFiles t = new GetSDKReferenceFiles();
            t.BuildEngine = engine;
            t.CacheFileFolderPath = s_cacheDirectory;

            ITaskItem item = new TaskItem(s_sdkDirectory);
            item.SetMetadata("ExpandReferenceAssemblies", "true");
            item.SetMetadata("TargetedSDKConfiguration", "Retail");
            item.SetMetadata("TargetedSDKArchitecture", "x86");
            item.SetMetadata("OriginalItemSpec", "SDKWithManifest, Version=2.0");

            t.ResolvedSDKReferences = new ITaskItem[] { item };
            bool success = t.Execute(s_getAssemblyName, s_getAssemblyRuntimeVersion, FileUtilities.FileExistsNoThrow);
            Assert.IsTrue(success);
            ITaskItem[] references1 = t.References;

            // Verify the task created a cache file
            string sdkIdentity = item.GetMetadata("OriginalItemSpec");
            string sdkRoot = item.ItemSpec;
            string cacheFile = sdkIdentity + ",Set=" + FileUtilities.GetHexHash(sdkIdentity) + "-" + FileUtilities.GetHexHash(sdkRoot) + ",Hash=*.dat";
            Thread.Sleep(100);
            string[] existingCacheFiles = Directory.GetFiles(s_cacheDirectory, cacheFile);
            Assert.IsTrue(existingCacheFiles.Length == 1);

            GetSDKReferenceFiles t2 = new GetSDKReferenceFiles();
            t2.BuildEngine = engine;
            t2.CacheFileFolderPath = s_cacheDirectory;

            // Same SDK with different path
            ITaskItem item2 = new TaskItem(s_sdkDirectory2);
            item2.SetMetadata("ExpandReferenceAssemblies", "true");
            item2.SetMetadata("TargetedSDKConfiguration", "Retail");
            item2.SetMetadata("TargetedSDKArchitecture", "x86");
            item2.SetMetadata("OriginalItemSpec", "SDKWithManifest, Version=2.0");

            t2.ResolvedSDKReferences = new ITaskItem[] { item2 };
            bool success2 = t2.Execute(s_getAssemblyName, s_getAssemblyRuntimeVersion, FileUtilities.FileExistsNoThrow);
            ITaskItem[] references2 = t2.References;
            Assert.IsTrue(success2);

            // References from the two builds should not overlap, otherwise the cache files are being misused
            foreach (var ref2 in references2)
            {
                Assert.IsTrue(references1.Count(i => i.ItemSpec.Equals(ref2.ItemSpec, StringComparison.InvariantCultureIgnoreCase)) == 0);
            }

            Thread.Sleep(100);
            string sdkIdentity2 = item.GetMetadata("OriginalItemSpec");
            string sdkRoot2 = item.ItemSpec;
            string cacheFile2 = sdkIdentity2 + ",Set=" + FileUtilities.GetHexHash(sdkIdentity2) + "-" + FileUtilities.GetHexHash(sdkRoot2) + ",Hash=*.dat";
            string[] existingCacheFiles2 = Directory.GetFiles(s_cacheDirectory, cacheFile);
            Assert.IsTrue(existingCacheFiles2.Length == 1);

            // There should have two cache files with the same prefix and first hash
            Thread.Sleep(100);
            string[] allCacheFiles = Directory.GetFiles(s_cacheDirectory, sdkIdentity2 + ",Set=" + FileUtilities.GetHexHash(sdkIdentity2) + "*");
            Assert.IsTrue(allCacheFiles.Length == 2);
        }
 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.Equal(0, referenceItem.GetMetadata("BuildReference").Length);
     Assert.Equal(0, referenceItem.GetMetadata("ReferenceOutputAssembly").Length);
 }
Example #20
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");
		}
        public void CheckSetCopyLocalToFalseOnEmbedInteropTypesAssemblies()
        {
            string gacPath = @"C:\windows\gac";

            ResolveComReference rcr = new ResolveComReference();
            rcr.BuildEngine = new MockEngine();

            // the matrix of TargetFrameworkVersion values we are testing
            string[] fxVersions =
            {
                "v2.0",
                "v3.0",
                "v3.5",
                "v4.0"
            };

            for (int i = 0; i < fxVersions.Length; i++)
            {
                string fxVersion = fxVersions[i];

                ArrayList taskItems = new ArrayList();

                TaskItem nonGacNoPrivate = new TaskItem(@"C:\windows\gar\test1.dll");
                nonGacNoPrivate.SetMetadata(ItemMetadataNames.embedInteropTypes, "true");

                TaskItem gacNoPrivate = new TaskItem(@"C:\windows\gac\assembly1.dll");
                gacNoPrivate.SetMetadata(ItemMetadataNames.embedInteropTypes, "true");

                TaskItem nonGacPrivateFalse = new TaskItem(@"C:\windows\gar\test1.dll");
                nonGacPrivateFalse.SetMetadata(ItemMetadataNames.privateMetadata, "false");
                nonGacPrivateFalse.SetMetadata(ItemMetadataNames.embedInteropTypes, "true");

                TaskItem gacPrivateFalse = new TaskItem(@"C:\windows\gac\assembly1.dll");
                gacPrivateFalse.SetMetadata(ItemMetadataNames.privateMetadata, "false");
                gacPrivateFalse.SetMetadata(ItemMetadataNames.embedInteropTypes, "true");

                TaskItem nonGacPrivateTrue = new TaskItem(@"C:\windows\gar\test1.dll");
                nonGacPrivateTrue.SetMetadata(ItemMetadataNames.privateMetadata, "true");
                nonGacPrivateTrue.SetMetadata(ItemMetadataNames.embedInteropTypes, "true");

                TaskItem gacPrivateTrue = new TaskItem(@"C:\windows\gac\assembly1.dll");
                gacPrivateTrue.SetMetadata(ItemMetadataNames.privateMetadata, "true");
                gacPrivateTrue.SetMetadata(ItemMetadataNames.embedInteropTypes, "true");

                taskItems.Add(nonGacNoPrivate);
                taskItems.Add(gacNoPrivate);

                taskItems.Add(nonGacPrivateFalse);
                taskItems.Add(gacPrivateFalse);

                taskItems.Add(nonGacPrivateTrue);
                taskItems.Add(gacPrivateTrue);

                rcr.TargetFrameworkVersion = fxVersion;
                rcr.SetFrameworkVersionFromString(rcr.TargetFrameworkVersion);

                rcr.SetCopyLocalToFalseOnGacOrNoPIAAssemblies(taskItems, gacPath);

                bool enabledNoPIA = false;
                switch (fxVersion)
                {
                    case "v4.0":
                        enabledNoPIA = true;
                        break;
                    default:
                        break;
                }

                // if Private is missing, by default GAC items are CopyLocal=false, non GAC CopyLocal=true
                Assert.IsTrue
                    (
                        nonGacNoPrivate.GetMetadata(ItemMetadataNames.copyLocal) == (enabledNoPIA ? "false" : "true"),
                        fxVersion + ": Non Gac assembly, missing Private"
                    );

                Assert.IsTrue
                    (
                        gacNoPrivate.GetMetadata(ItemMetadataNames.copyLocal) == (enabledNoPIA ? "false" : "false"),
                        fxVersion + ": Gac assembly, missing Private"
                    );

                // if Private is set, it takes precedence
                Assert.IsTrue
                    (
                        nonGacPrivateFalse.GetMetadata(ItemMetadataNames.copyLocal) == (enabledNoPIA ? "false" : "false"),
                        fxVersion + ": Non Gac assembly, Private false"
                    );

                Assert.IsTrue
                    (
                        gacPrivateFalse.GetMetadata(ItemMetadataNames.copyLocal) == (enabledNoPIA ? "false" : "false"),
                        fxVersion + ": Gac assembly, Private false"
                    );

                Assert.IsTrue
                    (
                        nonGacPrivateTrue.GetMetadata(ItemMetadataNames.copyLocal) == (enabledNoPIA ? "false" : "true"),
                        fxVersion + ": Non Gac assembly, Private true, should be TRUE"
                    );

                Assert.IsTrue
                    (
                        gacPrivateTrue.GetMetadata(ItemMetadataNames.copyLocal) == (enabledNoPIA ? "false" : "true"),
                        fxVersion + ": Gac assembly, Private true, should be TRUE"
                    );
            }
        }
Example #22
0
        public void SaveCompactedWriteTlog()
        {
            Console.WriteLine("Test: SaveCompactedWriteTlog");
            TaskItem fooItem = new TaskItem("foo");

            ITaskItem[] sources = new TaskItem[] {
                                    new TaskItem(Path.GetFullPath("TestFiles\\one.cpp")),
                                    new TaskItem(Path.GetFullPath("TestFiles\\two.cpp")),
                                    new TaskItem(Path.GetFullPath("TestFiles\\three.cpp"))};

            string rootMarker = FileTracker.FormatRootingMarker(sources);

            // Prepare files
            Thread.Sleep(sleepTimeMilliseconds); // need to wait since the timestamp check needs some time to register
            File.WriteAllLines("TestFiles\\one.tlog", new string[] {
                "#Command some-command",
                "^" + rootMarker,
                Path.GetFullPath("TestFiles\\oNe.obj"),
                "^" + fooItem.GetMetadata("Fullpath"),
                Path.GetFullPath("TestFiles\\foo1.bar"),
                Path.GetFullPath("TestFiles\\bar1.baz"),
            });

            File.WriteAllLines("TestFiles\\two.tlog", new string[] {
                "#Command some-command",
                "^" + rootMarker,
                Path.GetFullPath("TestFiles\\two.obj"),
                Path.GetFullPath("TestFiles\\three.obj"),
                "^" + fooItem.GetMetadata("Fullpath"),
                Path.GetFullPath("TestFiles\\foo2.bar"),
                Path.GetFullPath("TestFiles\\bar2.baz"),
            });

            ITaskItem[] tlogs = {
                                    new TaskItem("TestFiles\\one.tlog"),
                                    new TaskItem("TestFiles\\two.tlog")
                                };

            Thread.Sleep(sleepTimeMilliseconds); // need to wait since the timestamp check needs some time to register
            CanonicalTrackedOutputFiles d = new CanonicalTrackedOutputFiles(DependencyTestHelper.MockTask,
                    tlogs);

            ITaskItem[] outputs = d.OutputsForSource(sources);

            Assert.Equal(3, outputs.Length);
            Assert.Equal(outputs[0].ItemSpec, Path.GetFullPath("TestFiles\\oNe.obj"));
            Assert.Equal(outputs[1].ItemSpec, Path.GetFullPath("TestFiles\\two.obj"));
            Assert.Equal(outputs[2].ItemSpec, Path.GetFullPath("TestFiles\\three.obj"));

            outputs = d.OutputsForSource(fooItem);
            Assert.Equal(4, outputs.Length);
            Assert.Equal(outputs[0].ItemSpec, Path.GetFullPath("TestFiles\\foo1.bar"));
            Assert.Equal(outputs[1].ItemSpec, Path.GetFullPath("TestFiles\\bar1.baz"));
            Assert.Equal(outputs[2].ItemSpec, Path.GetFullPath("TestFiles\\foo2.bar"));
            Assert.Equal(outputs[3].ItemSpec, Path.GetFullPath("TestFiles\\bar2.baz"));

            // Compact the tlog removing all entries for "foo" leaving the other entries intact
            d.RemoveEntriesForSource(fooItem);
            d.SaveTlog();

            // All the tlogs need to still be there even after compaction
            // It's OK for them to be empty, but their absence might mean a partial clean
            // A missing tlog would mean a clean build
            Assert.True(Microsoft.Build.Utilities.TrackedDependencies.ItemsExist(tlogs));

            // All log information should now be in the tlog[0]
            ITaskItem[] tlogs2 = {
                                    tlogs[0]
                                 };

            CanonicalTrackedOutputFiles d2 = new CanonicalTrackedOutputFiles(DependencyTestHelper.MockTask,
                    tlogs2);

            outputs = d2.OutputsForSource(fooItem);
            Assert.Equal(0, outputs.Length);

            outputs = d2.OutputsForSource(sources);
            Assert.Equal(3, outputs.Length);
            Assert.Equal(outputs[0].ItemSpec, Path.GetFullPath("TestFiles\\oNe.obj"));
            Assert.Equal(outputs[1].ItemSpec, Path.GetFullPath("TestFiles\\two.obj"));
            Assert.Equal(outputs[2].ItemSpec, Path.GetFullPath("TestFiles\\three.obj"));

            // There should be no difference even if we send in all the original tlogs
            CanonicalTrackedOutputFiles d3 = new CanonicalTrackedOutputFiles(DependencyTestHelper.MockTask,
                    tlogs);

            outputs = d3.OutputsForSource(fooItem);
            Assert.Equal(0, outputs.Length);

            outputs = d3.OutputsForSource(sources);
            Assert.Equal(3, outputs.Length);
            Assert.Equal(outputs[0].ItemSpec, Path.GetFullPath("TestFiles\\oNe.obj"));
            Assert.Equal(outputs[1].ItemSpec, Path.GetFullPath("TestFiles\\two.obj"));
            Assert.Equal(outputs[2].ItemSpec, Path.GetFullPath("TestFiles\\three.obj"));
        }
Example #23
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");
		}
        /// <summary>
        /// When overridden in a derived class, executes the task.
        /// </summary>
        /// <returns>Returns <see langword="true" /> if the task successfully
        /// executed; otherwise, <see langword="false" />.
        /// </returns>
        public override bool Execute()
        {
            bool success = true;
            this.resultItems = new ITaskItem[items.Length];
            for (int i = 0; i < resultItems.Length; i++)
            {
                ITaskItem newItem = new TaskItem(items[i]);
                this.items[i].CopyMetadataTo(newItem);
                //Need to set this so it is not reset
                newItem.SetMetadata("RecursiveDir", items[i].GetMetadata("RecursiveDir"));

                if (String.IsNullOrEmpty(this.metadataName))
                {
                    IDictionary<string, string> metadataBag = ParseMetadata(this.metadata);
                    foreach (string metadataName in metadataBag.Keys)
                    {
                        newItem.SetMetadata(metadataName, metadataBag[metadataName]);
                    }
                }
                else
                {
                    System.Collections.ArrayList names = new System.Collections.ArrayList(newItem.MetadataNames);
                    string value = String.Empty;
                    if (names.Contains(this.metadataName))
                    {
                        value = String.Format(CultureInfo.InvariantCulture, "{0};{1}", newItem.GetMetadata(this.metadataName), String.Join(";", this.metadata));
                    }
                    else
                    {
                        value = String.Join(";", this.metadata);
                    }
                    newItem.SetMetadata(this.metadataName, value);
                }
                this.resultItems[i] = newItem;
            }

            return success;
        }
Example #25
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");
		}
 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);
 }
Example #27
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");
		}
Example #28
0
 public void NonexistentRequestDirectoryUNC()
 {
     TaskItem from = new TaskItem();
     from.ItemSpec = @"\\local\share\subdir\Monkey.txt";
     Assert.AreEqual
     (
         @"subdir\",
         from.GetMetadata(FileUtilities.ItemSpecModifiers.Directory)
     );
 }
Example #29
0
        /// <summary>
        /// Set metadata on the items which will be output from RAR.
        /// </summary>
        private ITaskItem SetItemMetadata(ArrayList relatedItems, ArrayList satelliteItems, ArrayList serializationAssemblyItems, ArrayList scatterItems, string fusionName, Reference reference, AssemblyNameExtension assemblyName, FileExists fileExists)
        {
            // Set up the main item.
            ITaskItem referenceItem = new TaskItem();
            referenceItem.ItemSpec = reference.FullPath;
            referenceItem.SetMetadata(ItemMetadataNames.resolvedFrom, reference.ResolvedSearchPath);

            // Set the CopyLocal metadata.
            if (reference.IsCopyLocal)
            {
                referenceItem.SetMetadata(ItemMetadataNames.copyLocal, "true");
            }
            else
            {
                referenceItem.SetMetadata(ItemMetadataNames.copyLocal, "false");
            }

            // Set the FusionName metadata.
            referenceItem.SetMetadata(ItemMetadataNames.fusionName, fusionName);

            // Set the Redist name metadata.
            if (!String.IsNullOrEmpty(reference.RedistName))
            {
                referenceItem.SetMetadata(ItemMetadataNames.redist, reference.RedistName);
            }

            if (Reference.IsFrameworkFile(reference.FullPath, _frameworkPaths) || (_installedAssemblies != null && _installedAssemblies.FrameworkAssemblyEntryInRedist(assemblyName)))
            {
                if (!IsAssemblyRemovedFromDotNetFramework(assemblyName, reference.FullPath, _frameworkPaths, _installedAssemblies))
                {
                    referenceItem.SetMetadata(ItemMetadataNames.frameworkFile, "true");
                }
            }

            if (!String.IsNullOrEmpty(reference.ImageRuntime))
            {
                referenceItem.SetMetadata(ItemMetadataNames.imageRuntime, reference.ImageRuntime);
            }

            if (reference.IsWinMDFile)
            {
                referenceItem.SetMetadata(ItemMetadataNames.winMDFile, "true");

                // The ImplementationAssembly is only set if the implementation file exits on disk
                if (reference.ImplementationAssembly != null)
                {
                    if (VerifyArchitectureOfImplementationDll(reference.ImplementationAssembly, reference.FullPath))
                    {
                        referenceItem.SetMetadata(ItemMetadataNames.winmdImplmentationFile, Path.GetFileName(reference.ImplementationAssembly));

                        // Add the implementation item as a related file
                        ITaskItem item = new TaskItem(reference.ImplementationAssembly);
                        // Clone metadata.
                        referenceItem.CopyMetadataTo(item);
                        // Related files don't have a fusion name.
                        item.SetMetadata(ItemMetadataNames.fusionName, "");
                        RemoveNonForwardableMetadata(item);

                        // Add the related item.
                        relatedItems.Add(item);
                    }
                }

                if (reference.IsManagedWinMDFile)
                {
                    referenceItem.SetMetadata(ItemMetadataNames.winMDFileType, "Managed");
                }
                else
                {
                    referenceItem.SetMetadata(ItemMetadataNames.winMDFileType, "Native");
                }
            }

            // Set the IsRedistRoot metadata
            if (reference.IsRedistRoot == true)
            {
                referenceItem.SetMetadata(ItemMetadataNames.isRedistRoot, "true");
            }
            else if (reference.IsRedistRoot == false)
            {
                referenceItem.SetMetadata(ItemMetadataNames.isRedistRoot, "false");
            }
            else
            {
                // This happens when the redist root is "null". This means there
                // was no IsRedistRoot flag in the Redist XML (or there was no 
                // redist XML at all for this item).
            }

            // If there was a primary source item, then forward metadata from it.
            // It's important that the metadata from the primary source item
            // win over the same metadata from other source items, so that's
            // why we put this first.  (CopyMetadataTo will never override an 
            // already existing metadata.)  For example, if this reference actually
            // came directly from an item declared in the project file, we'd
            // want to use the metadata from it, not some other random item in
            // the project file that happened to have this reference as a dependency.
            if (reference.PrimarySourceItem != null)
            {
                reference.PrimarySourceItem.CopyMetadataTo(referenceItem);
            }
            else
            {
                bool hasImplementationFile = referenceItem.GetMetadata(ItemMetadataNames.winmdImplmentationFile).Length > 0;
                bool hasImageRuntime = referenceItem.GetMetadata(ItemMetadataNames.imageRuntime).Length > 0;
                bool hasWinMDFile = referenceItem.GetMetadata(ItemMetadataNames.winMDFile).Length > 0;

                // If there were non-primary source items, then forward metadata from them.
                ICollection sourceItems = reference.GetSourceItems();
                foreach (ITaskItem sourceItem in sourceItems)
                {
                    sourceItem.CopyMetadataTo(referenceItem);
                }

                // If the item originally did not have the implementation file metadata then we do not want to get it from the set of primary source items
                // since the implementation file is something specific to the source item and not supposed to be propigated.
                if (!hasImplementationFile)
                {
                    referenceItem.RemoveMetadata(ItemMetadataNames.winmdImplmentationFile);
                }

                // If the item originally did not have the ImageRuntime metadata then we do not want to get it from the set of primary source items
                // since the ImageRuntime is something specific to the source item and not supposed to be propigated.
                if (!hasImageRuntime)
                {
                    referenceItem.RemoveMetadata(ItemMetadataNames.imageRuntime);
                }

                // If the item originally did not have the WinMDFile metadata then we do not want to get it from the set of primary source items
                // since the WinMDFile is something specific to the source item and not supposed to be propigated
                if (!hasWinMDFile)
                {
                    referenceItem.RemoveMetadata(ItemMetadataNames.winMDFile);
                }
            }

            if (reference.ReferenceVersion != null)
            {
                referenceItem.SetMetadata(ItemMetadataNames.version, reference.ReferenceVersion.ToString());
            }
            else
            {
                referenceItem.SetMetadata(ItemMetadataNames.version, String.Empty);
            }

            // Now clone all properties onto the related files.
            foreach (string relatedFileExtension in reference.GetRelatedFileExtensions())
            {
                ITaskItem item = new TaskItem(reference.FullPathWithoutExtension + relatedFileExtension);
                // Clone metadata.
                referenceItem.CopyMetadataTo(item);
                // Related files don't have a fusion name.
                item.SetMetadata(ItemMetadataNames.fusionName, "");
                RemoveNonForwardableMetadata(item);

                // Add the related item.
                relatedItems.Add(item);
            }

            // Set up the satellites.
            foreach (string satelliteFile in reference.GetSatelliteFiles())
            {
                ITaskItem item = new TaskItem(Path.Combine(reference.DirectoryName, satelliteFile));
                // Clone metadata.
                referenceItem.CopyMetadataTo(item);
                // Set the destination directory.
                item.SetMetadata(ItemMetadataNames.destinationSubDirectory, FileUtilities.EnsureTrailingSlash(Path.GetDirectoryName(satelliteFile)));
                // Satellite files don't have a fusion name.
                item.SetMetadata(ItemMetadataNames.fusionName, "");
                RemoveNonForwardableMetadata(item);

                // Add the satellite item.
                satelliteItems.Add(item);
            }

            // Set up the serialization assemblies
            foreach (string serializationAssemblyFile in reference.GetSerializationAssemblyFiles())
            {
                ITaskItem item = new TaskItem(Path.Combine(reference.DirectoryName, serializationAssemblyFile));
                // Clone metadata.
                referenceItem.CopyMetadataTo(item);
                // serialization assemblies files don't have a fusion name.
                item.SetMetadata(ItemMetadataNames.fusionName, "");
                RemoveNonForwardableMetadata(item);

                // Add the serialization assembly item.
                serializationAssemblyItems.Add(item);
            }

            // Set up the scatter files.
            foreach (string scatterFile in reference.GetScatterFiles())
            {
                ITaskItem item = new TaskItem(Path.Combine(reference.DirectoryName, scatterFile));
                // Clone metadata.
                referenceItem.CopyMetadataTo(item);
                // We don't have a fusion name for scatter files.
                item.SetMetadata(ItemMetadataNames.fusionName, "");
                RemoveNonForwardableMetadata(item);

                // Add the satellite item.
                scatterItems.Add(item);
            }

            // As long as the item has not come from somewhere else say it came from rar (p2p's can come from somewhere else).
            if (referenceItem.GetMetadata(ItemMetadataNames.msbuildReferenceSourceTarget).Length == 0)
            {
                referenceItem.SetMetadata(ItemMetadataNames.msbuildReferenceSourceTarget, "ResolveAssemblyReference");
            }

            if (referenceItem.GetMetadata(ItemMetadataNames.msbuildReferenceSourceTarget).Equals("ProjectReference"))
            {
                if (reference.PrimarySourceItem != null)
                {
                    referenceItem.SetMetadata(ItemMetadataNames.projectReferenceOriginalItemSpec, reference.PrimarySourceItem.GetMetadata("OriginalItemSpec"));
                }
            }

            return referenceItem;
        }
Example #30
0
        public void NonexistentRequestRecursiveDir()
        {
            TaskItem from = new TaskItem();
            from.ItemSpec = "Monkey.txt";

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