2006-12-04 Marek Sieradzki <marek.sieradzki@gmail.com>
[mono.git] / mcs / class / Microsoft.Build.Tasks / Microsoft.Build.Tasks / MSBuild.cs
1 //
2 // MSBuild.cs: Task that can run .*proj files
3 //
4 // Author:
5 //   Marek Sieradzki (marek.sieradzki@gmail.com)
6 //
7 // (C) 2005 Marek Sieradzki
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
28 #if NET_2_0
29
30 using System;
31 using System.Collections;
32 using Microsoft.Build.Framework;
33 using Microsoft.Build.Utilities;
34
35 namespace Microsoft.Build.Tasks {
36
37         [MonoTODO]
38         public class MSBuild : TaskExtension {
39         
40                 ITaskItem[]     projects;
41                 string[]                properties;
42                 bool            rebaseOutputs;
43                 bool            runEachTargetSeparately;
44                 bool            stopOnFirstFailure;
45                 ITaskItem[]     targetOutputs;
46                 string[]        targets;
47         
48                 public MSBuild ()
49                 {
50                 }
51
52                 public override bool Execute ()
53                 {
54                         string filename;
55                         bool result = true;
56                         stopOnFirstFailure = false;
57                 
58                         foreach (ITaskItem project in projects) {
59                                 filename = project.GetMetadata ("FullPath");
60                                 
61                                 result = BuildEngine.BuildProjectFile (filename, targets, new Hashtable (), new Hashtable ());
62                                 if (result == false) {
63                                         Log.LogError ("Error while building {0}", filename);
64                                         if (stopOnFirstFailure)
65                                                 break;
66                                 }
67                         }
68                         return result;
69                 }
70
71                 [Required]
72                 public ITaskItem[] Projects {
73                         get {
74                                 return projects;
75                         }
76                         set {
77                                 projects = value;
78                         }
79                 }
80
81                 public string[] Properties {
82                         get {
83                                 return properties;
84                         }
85                         set {
86                                 properties = value;
87                         }
88                 }
89
90                 public bool RebaseOutputs {
91                         get {
92                                 return rebaseOutputs;
93                         }
94                         set {
95                                 rebaseOutputs = value;
96                         }
97                 }
98
99                 public bool RunEachTargetSeparately {
100                         get {
101                                 return runEachTargetSeparately;
102                         }
103                         set {
104                                 runEachTargetSeparately = value;
105                         }
106                 }
107
108                 public bool StopOnFirstFailure {
109                         get {
110                                 return stopOnFirstFailure;
111                         }
112                         set {
113                                 stopOnFirstFailure = value;
114                         }
115                 }
116
117                 [Output]
118                 public ITaskItem[] TargetOutputs {
119                         get {
120                                 return targetOutputs;
121                         }
122                 }
123
124                 public string[] Targets {
125                         get {
126                                 return targets;
127                         }
128                         set {
129                                 targets = value;
130                         }
131                 }
132         }
133 }
134
135 #endif