5 // Marek Sieradzki (marek.sieradzki@gmail.com)
6 // Ankit Jain (jankit@novell.com)
8 // (C) 2006 Marek Sieradzki
9 // Copyright 2008 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using Microsoft.Build.Framework;
35 using Microsoft.Build.Utilities;
37 namespace Microsoft.Build.Tasks {
38 public class AssignTargetPath : TaskExtension {
40 ITaskItem[] assignedFiles;
44 public AssignTargetPath ()
48 public override bool Execute ()
50 if (files == null || files.Length == 0)
54 assignedFiles = new ITaskItem [files.Length];
55 for (int i = 0; i < files.Length; i ++) {
56 string file = files [i].ItemSpec;
57 string link = files [i].GetMetadata ("Link");
60 if (String.IsNullOrEmpty (link)) {
62 string normalized_root = Path.GetFullPath (rootFolder);
64 // cur dir should already be set to
66 file = Path.GetFullPath (file);
68 if (file.StartsWith (normalized_root)) {
69 afile = Path.GetFullPath (file).Substring (
70 normalized_root.Length);
72 if (afile [0] == '\\' ||
74 afile = afile.Substring (1);
77 afile = Path.GetFileName (file);
83 assignedFiles [i] = new TaskItem (files [i]);
84 assignedFiles [i].SetMetadata ("TargetPath", afile);
91 public ITaskItem[] AssignedFiles {
92 get { return assignedFiles; }
95 public ITaskItem[] Files {
97 set { files = value; }
101 public string RootFolder {
102 get { return rootFolder; }
103 set { rootFolder = value; }