Merge pull request #799 from kebby/master
[mono.git] / mcs / class / Microsoft.Build.Tasks / Microsoft.Build.Tasks / CallTarget.cs
index e4001fffbc665e20110adcaa6b5a462420a1fc34..08a973d647c8752f487e789fea9053868dcf2644 100644 (file)
@@ -28,6 +28,8 @@
 #if NET_2_0
 
 using System;
+using System.Collections;
+using System.Collections.Generic;
 using System.IO;
 using Microsoft.Build.Framework;
 
@@ -35,17 +37,52 @@ namespace Microsoft.Build.Tasks {
        public class CallTarget : TaskExtension {
        
                bool            runEachTargetSeparately;
-               ITaskItem[]     targetOutputs;
+               List<ITaskItem> targetOutputs_list;
+               ITaskItem[]     targetOutputs_array;
                string[]        targets;
        
                public CallTarget ()
                {
+                       targetOutputs_list = new List<ITaskItem> ();
                }
                
-               [MonoTODO]
                public override bool Execute ()
                {
-                       return false;
+                       if (targets == null || targets.Length == 0)
+                               return true;
+
+                       Hashtable targets_table = new Hashtable ();
+
+                       if (!RunEachTargetSeparately) {
+                               bool ret = BuildEngine.BuildProjectFile (BuildEngine.ProjectFileOfTaskNode,
+                                               targets, null, targets_table);
+                               foreach (ITaskItem[] items in targets_table.Values) {
+                                       if (items != null)
+                                               targetOutputs_list.AddRange (items);
+                               }
+
+                               return ret;
+                       }
+
+                       // RunEachTargetSeparately
+                       bool allPassed = true;
+                       for (int i = 0; i < targets.Length; i ++) {
+                               string target = targets [i];
+                               bool result = BuildEngine.BuildProjectFile (BuildEngine.ProjectFileOfTaskNode,
+                                               new string[] { target }, null, targets_table);
+
+                               if (allPassed && !result)
+                                       allPassed = false;
+
+                               if (!targets_table.Contains (target))
+                                       continue;
+
+                               ITaskItem [] items = (ITaskItem[]) targets_table [target];
+                               if (items != null)
+                                       targetOutputs_list.AddRange (items);
+                       }
+
+                       return allPassed;
                }
                
                public bool RunEachTargetSeparately {
@@ -53,8 +90,13 @@ namespace Microsoft.Build.Tasks {
                        set { runEachTargetSeparately = value; }
                }
                
+               [Output]
                public ITaskItem[] TargetOutputs {
-                       get { return targetOutputs; }
+                       get {
+                               if (targetOutputs_array == null)
+                                       targetOutputs_array = targetOutputs_list.ToArray ();
+                               return targetOutputs_array;
+                       }
                }
                
                public string[] Targets {
@@ -64,4 +106,4 @@ namespace Microsoft.Build.Tasks {
        }
 }
 
-#endif
\ No newline at end of file
+#endif