Fix issue with VB projects
[mono.git] / mcs / class / Microsoft.Build.Tasks / Microsoft.Build.Tasks / CreateItem.cs
index e07f875a3fee2f0e1b77d9c43a7bfda74a91fc90..8de9dc10b5fa1ec1f38dde881903f8eae30d8d33 100644 (file)
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
-#if NET_2_0
 
 using System;
+using System.Collections.Generic;
+using System.IO;
 using Microsoft.Build.Framework;
 
 namespace Microsoft.Build.Tasks {
@@ -36,14 +37,46 @@ namespace Microsoft.Build.Tasks {
                string[]        additionalMetadata;
                ITaskItem[]     exclude;
                ITaskItem[]     include;
-       
+               bool            preserveExistingMetadata;
+
                public CreateItem ()
                {
                }
 
                public override bool Execute ()
                {
-                       throw new NotImplementedException ();
+                       if (include == null || include.Length == 0)
+                               return true;
+
+                       // Handle wild cards
+                       var directoryScanner = new Microsoft.Build.BuildEngine.DirectoryScanner ();
+                       directoryScanner.Includes = include;
+                       directoryScanner.Excludes = exclude;
+                       directoryScanner.BaseDirectory = new DirectoryInfo (Directory.GetCurrentDirectory ());
+
+                       directoryScanner.Scan ();
+
+                       List<ITaskItem> output = new List<ITaskItem> ();
+                       foreach (ITaskItem matchedItem in directoryScanner.MatchedItems) {
+                               output.Add (matchedItem);
+                               if (AdditionalMetadata == null)
+                                       continue;
+
+                               foreach (string metadata in AdditionalMetadata) {
+                                       //a=1
+                                       string [] parts = metadata.Split (new char [] {'='}, 2, StringSplitOptions.RemoveEmptyEntries);
+                                       if (parts.Length == 2) {
+                                               string name = parts [0].Trim ();
+                                               string oldValue = matchedItem.GetMetadata (name);
+                                               if (!preserveExistingMetadata || string.IsNullOrEmpty (oldValue))
+                                                       matchedItem.SetMetadata (name, parts [1].Trim ());
+                                       }
+                               }
+                       }
+
+                       include = output.ToArray ();
+
+                       return true;
                }
 
                public string[] AdditionalMetadata {
@@ -61,7 +94,11 @@ namespace Microsoft.Build.Tasks {
                        get { return include; }
                        set { include = value; }
                }
+
+               public bool PreserveExistingMetadata {
+                       get { return preserveExistingMetadata; }
+                       set { preserveExistingMetadata = value; }
+               }
        }
 }
 
-#endif