In class/Microsoft.Build.Tasks:
authorAnkit Jain <radical@corewars.org>
Sat, 22 Nov 2008 12:26:23 +0000 (12:26 -0000)
committerAnkit Jain <radical@corewars.org>
Sat, 22 Nov 2008 12:26:23 +0000 (12:26 -0000)
* Microsoft.Build.Tasks_test.dll.sources: Added AssignTargetPathTest.cs

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

* AssignTargetPath.cs (Execute): Implement.

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

* AssignTargetPathTest.cs: New.

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

mcs/class/Microsoft.Build.Tasks/ChangeLog
mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/AssignTargetPath.cs
mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/ChangeLog
mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks_test.dll.sources
mcs/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/AssignTargetPathTest.cs [new file with mode: 0755]
mcs/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/ChangeLog

index a3cd952311a02083a73a2a401b3436d2f9b29dde..81c5680fdcea310db76497e72c954151bf1c9fb2 100644 (file)
@@ -1,3 +1,7 @@
+2008-11-22  Ankit Jain  <jankit@novell.com>
+
+       * Microsoft.Build.Tasks_test.dll.sources: Added AssignTargetPathTest.cs
+
 2008-11-21  Ankit Jain  <jankit@novell.com>
 
        * Microsoft.Build.Tasks_test.dll.sources: Added TaskBatchingTest.cs and
index 20b75b0874737cd3f35611f4f81dd785e77df527..71895fc4fc81496e450f253921480780674ee4b9 100644 (file)
@@ -3,8 +3,10 @@
 //
 // Author:
 //   Marek Sieradzki (marek.sieradzki@gmail.com)
+//   Ankit Jain (jankit@novell.com)
 //
 // (C) 2006 Marek Sieradzki
+// Copyright 2008 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -30,6 +32,7 @@
 using System;
 using System.IO;
 using Microsoft.Build.Framework;
+using Microsoft.Build.Utilities;
 
 namespace Microsoft.Build.Tasks {
        public class AssignTargetPath : TaskExtension {
@@ -42,10 +45,27 @@ namespace Microsoft.Build.Tasks {
                {
                }
                
-               [MonoTODO]
                public override bool Execute ()
                {
-                       return false;
+                       assignedFiles = new ITaskItem [files.Length];
+                       for (int i = 0; i < files.Length; i ++) {
+                               string file = files [i].ItemSpec;
+                               string afile = null;
+                               //FIXME: Hack!
+                               string normalized_root = Path.GetFullPath (rootFolder);
+
+                               if (file.StartsWith (normalized_root)) {
+                                       afile = Path.GetFullPath (file).Substring (
+                                                       normalized_root.Length);
+                               } else {
+                                       afile = Path.GetFileName (file);
+                               }
+
+                               assignedFiles [i] = new TaskItem (files [i]);
+                               assignedFiles [i].SetMetadata ("TargetPath", afile);
+                       }
+
+                       return true;
                }
                
                [Output]
@@ -66,4 +86,4 @@ namespace Microsoft.Build.Tasks {
        }
 }
 
-#endif
\ No newline at end of file
+#endif
index 3974611319b88bdebb8fd0260fb2f706524043ae..11d2a616af552c0887fd48782f0d23ed047f45ce 100644 (file)
@@ -1,3 +1,7 @@
+2008-11-22  Ankit Jain  <jankit@novell.com>
+
+       * AssignTargetPath.cs (Execute): Implement.
+
 2008-11-21  Ankit Jain  <jankit@novell.com>
 
        * GenerateResource.cs (Execute): Use for loop instead of manually
index 80ba7c8e1a2c357b1fee93aa0c57b4d951d77c93..91fb134b9dc942bba818258b60b7c6693e3a9289 100644 (file)
@@ -1,4 +1,5 @@
 Microsoft.Build.Tasks/ALTest.cs
+Microsoft.Build.Tasks/AssignTargetPathTest.cs
 Microsoft.Build.Tasks/CombinePathTest.cs
 Microsoft.Build.Tasks/Consts.cs
 Microsoft.Build.Tasks/CreateItemTest.cs
diff --git a/mcs/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/AssignTargetPathTest.cs b/mcs/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/AssignTargetPathTest.cs
new file mode 100755 (executable)
index 0000000..6cac0b6
--- /dev/null
@@ -0,0 +1,151 @@
+//
+// AssignTargetPathTest.cs
+//
+// Author:
+//   Ankit Jain (jankit@novell.com)
+//
+// Copyright 2008 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+using System;
+using System.Text;
+using NUnit.Framework;
+using Microsoft.Build.BuildEngine;
+using System.IO;
+
+namespace MonoTests.Microsoft.Build.Tasks
+{
+       enum OsType {
+               Windows,
+               Unix,
+               Mac
+       }
+
+       [TestFixture]
+       public class AssignTargetPathTest
+       {
+               //inspired from PathTest.cs
+               static OsType OS;
+               static char DSC = Path.DirectorySeparatorChar;
+
+               [SetUp]
+               public void SetUp ()
+               {
+                       if ('/' == DSC) {
+                               OS = OsType.Unix;
+                       } else if ('\\' == DSC) {
+                               OS = OsType.Windows;
+                       } else {
+                               OS = OsType.Mac;
+                               //FIXME: For Mac. figure this out when we need it
+                       }
+               }
+
+               [Test]
+               public void TestExecute1()
+               {
+                       if (OS == OsType.Unix) {
+                               CheckTargetPath(
+                                       new string[] { "/a/b/./abc.cs", "/a/c/def.cs", "xyz.cs", "/different/xyz/foo.cs", "rel/bar.resx"},
+                                       new string[] { "b/abc.cs", "c/def.cs", "xyz.cs", "foo.cs", "bar.resx" },
+                                       "/a/./", "A");
+                       } else if (OS == OsType.Windows) {
+                               CheckTargetPath(
+                                       new string[] { @"C:\a\b\.\abc.cs", @"C:\a\c\def.cs", "xyz.cs", @"C:\different\xyz\foo.cs", @"rel\bar.resx"},
+                                       new string[] { @"b\abc.cs", @"c\def.cs", "xyz.cs", "foo.cs", "bar.resx" },
+                                       @"C:\a\.\", "A");
+                       }
+               }
+
+               [Test]
+               public void TestExecute2()
+               {
+                       if (OS == OsType.Unix) {
+                               CheckTargetPath(
+                                       new string[] { "//a/b/abc.cs", "k/../k/def.cs", "/xyz.cs", "/different/xyz/foo.cs"},
+                                       new string[] { "a/b/abc.cs", "def.cs", "xyz.cs", "different/xyz/foo.cs"},
+                                       "/", "A");
+                       } else if (OS == OsType.Windows) {
+                               CheckTargetPath(
+                                       new string[] { @"C:\\a\b\abc.cs", @"k\..\def.cs", @"C:\xyz.cs", @"C:\different\xyz\foo.cs"},
+                                       new string[] { "a\\b\\abc.cs", "def.cs", "xyz.cs", "different\\xyz\\foo.cs"},
+                                       "C:\\", "A");
+                       }
+               }
+
+               [Test]
+               public void TestExecute3()
+               {
+                       if (OS == OsType.Unix) {
+                               CheckTargetPath(
+                                       new string[] { "xyz.cs", "rel/bar.resx" },
+                                       new string[] { "xyz.cs", "bar.resx" },
+                                       "/", "A");
+                       } else if (OS == OsType.Windows) {
+                               CheckTargetPath(
+                                       new string[] { "xyz.cs", "rel\\bar.resx" },
+                                       new string[] { "xyz.cs", "bar.resx" },
+                                       "C:\\", "A");
+                       }
+               }
+
+               void CheckTargetPath(string[] files, string[] assignedFiles, string rootFolder, string id)
+               {
+                       Engine engine = new Engine(Consts.BinPath);
+                       Project project = engine.CreateNewProject();
+
+                       string projectText = CreateProjectString(files, rootFolder);
+                       project.LoadXml(projectText);
+
+                       Assert.IsTrue(project.Build("1"), id + "1 : Error in building");
+
+                       BuildItemGroup include = project.GetEvaluatedItemsByName("FooPath");
+                       Assert.AreEqual(files.Length, include.Count, id + "2");
+
+                       for (int i = 0; i < files.Length; i++) {
+                               Assert.AreEqual (files [i], include [i].FinalItemSpec, id + "3, file #" + i);
+                               Assert.IsTrue (include[i].HasMetadata ("TargetPath"), id + "4, file #" + i + ", TargetPath metadata missing");
+                               Assert.AreEqual (assignedFiles [i], include[i].GetMetadata("TargetPath"), id + "5, file #" + i);
+                               Assert.IsTrue (include [i].HasMetadata ("Child"), id + "6, file #" + i + ", Child metadata missing");
+                               Assert.AreEqual ("C" + files [i], include [i].GetMetadata ("Child"), id + "7, file #" + i + ", Child metadata value incorrect");
+                       }
+               }
+
+               string CreateProjectString(string[] files, string rootFolder)
+               {
+                       StringBuilder sb = new StringBuilder();
+                       sb.Append(@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""><ItemGroup>");
+                       foreach (string file in files)
+                               sb.AppendFormat("<FooFiles Include=\"{0}\"><Child>C{0}</Child></FooFiles>\n", file);
+
+                       sb.AppendFormat(@"</ItemGroup>
+                       <Target Name=""1"">
+                               <AssignTargetPath Files=""@(FooFiles)"" RootFolder=""{0}"">
+                                       <Output TaskParameter=""AssignedFiles"" ItemName=""FooPath"" />
+                               </AssignTargetPath>
+                       </Target>
+                       <Import Project=""$(MSBuildBinPath)\Microsoft.Common.targets"" />
+               </Project>", rootFolder);
+
+                       return sb.ToString();
+               }
+       }
+}
index c8a3727d518e0bb56da160d409c1a272374399e2..3e0c014cefcf9e8b9a5f6e82fc438aa0b148da4c 100644 (file)
@@ -1,3 +1,7 @@
+2008-11-22  Ankit Jain  <jankit@novell.com>
+
+       * AssignTargetPathTest.cs: New.
+
 2008-11-21  Ankit Jain  <jankit@novell.com>
 
        * CreateItemTest.cs (CheckBuildItem): Make public.