merge -r 58060:58217
[mono.git] / mcs / class / Microsoft.Build.Tasks / Microsoft.Build.Tasks / AL.cs
1 //
2 // AL.cs: Task for assembly linker
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.Diagnostics;
32 using System.IO;
33 using Microsoft.Build.Framework;
34 using Microsoft.Build.Utilities;
35 using Mono.XBuild.Utilities;
36
37 namespace Microsoft.Build.Tasks {
38         public class AL : ToolTaskExtension {
39         
40                 Process alProcess;
41         
42                 public AL ()
43                 {
44                 }
45                 
46                 protected internal override void AddResponseFileCommands (
47                                                  CommandLineBuilderExtension commandLine)
48                 {
49                         commandLine.AppendSwitchIfNotNull ("/algid:", AlgorithmId);
50                         commandLine.AppendSwitchIfNotNull ("/baseaddress:", BaseAddress);
51                         commandLine.AppendSwitchIfNotNull ("/company:", CompanyName);
52                         commandLine.AppendSwitchIfNotNull ("/configuration:", Configuration);
53                         commandLine.AppendSwitchIfNotNull ("/copyright:", Copyright);
54                         commandLine.AppendSwitchIfNotNull ("/culture:", Culture);
55                         if (DelaySign == true)
56                                 commandLine.AppendSwitch ("/delaysign");
57                         if (EmbedResources != null)
58                                 foreach (ITaskItem item in EmbedResources)
59                                         commandLine.AppendSwitchIfNotNull ("/embedresource:", item.ItemSpec);
60                         commandLine.AppendSwitchIfNotNull ("/evidence:", EvidenceFile);
61                         commandLine.AppendSwitchIfNotNull ("/fileversion:", FileVersion);
62                         commandLine.AppendSwitchIfNotNull ("/flags:", Flags);
63                         if (GenerateFullPaths == true)
64                                 commandLine.AppendSwitch ("/fullpaths");
65                         commandLine.AppendSwitchIfNotNull ("/keyname:", KeyContainer);
66                         commandLine.AppendSwitchIfNotNull ("/keyfile:", KeyFile);
67                         if (LinkResources != null)
68                                 foreach (ITaskItem item in LinkResources)
69                                         commandLine.AppendSwitchIfNotNull ("/linkresource:", item.ItemSpec);
70                         commandLine.AppendSwitchIfNotNull ("/main:", MainEntryPoint);
71                         if (OutputAssembly != null)
72                                 commandLine.AppendSwitchIfNotNull ("/out:", OutputAssembly.ItemSpec);
73                         //platform
74                         commandLine.AppendSwitchIfNotNull ("/product:", ProductName);
75                         commandLine.AppendSwitchIfNotNull ("/productversion:", ProductVersion);
76                         if (ResponseFiles != null)
77                                 foreach (string s in ResponseFiles)
78                                         commandLine.AppendFileNameIfNotNull (String.Format ("@{0}", s));
79                         if (SourceModules != null)
80                                 foreach (ITaskItem item in SourceModules)
81                                         commandLine.AppendFileNameIfNotNull (item.ItemSpec);
82                         commandLine.AppendSwitchIfNotNull ("/target:", TargetType);
83                         commandLine.AppendSwitchIfNotNull ("/template:", TemplateFile);
84                         commandLine.AppendSwitchIfNotNull ("/title:", Title);
85                         commandLine.AppendSwitchIfNotNull ("/trademark:", Trademark);
86                         commandLine.AppendSwitchIfNotNull ("/version:", Version);
87                         commandLine.AppendSwitchIfNotNull ("/win32icon:", Win32Icon);
88                         commandLine.AppendSwitchIfNotNull ("/win32res:", Win32Resource);
89                 }
90                 
91                 public override bool Execute ()
92                 {
93                         CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
94                         AddResponseFileCommands (clbe);
95                         
96                         alProcess = new Process ();
97                         alProcess.StartInfo.Arguments = clbe.ToString ();
98                         alProcess.StartInfo.FileName = GenerateFullPathToTool ();
99                         alProcess.Start ();
100                         alProcess.WaitForExit ();
101                         return true;
102                 }
103
104                 protected override string GenerateFullPathToTool ()
105                 {
106                         return Path.Combine (ToolPath, ToolName);
107                 }
108
109                 public string AlgorithmId {
110                         get { return (string) Bag ["AlgorithmId"]; }
111                         set { Bag ["AlgorithmId"] = value; }
112                 }
113
114                 public string BaseAddress {
115                         get { return (string) Bag ["BaseAddress"]; }
116                         set { Bag ["BaseAddress"] = value; }
117                 }
118
119                 public string CompanyName {
120                         get { return (string) Bag ["CompanyName"]; }
121                         set { Bag ["CompanyName"] = value; }
122                 }
123
124                 public string Configuration {
125                         get { return (string) Bag ["Configuration"]; }
126                         set { Bag ["Configuration"] = value; }
127                 }
128
129                 public string Copyright {
130                         get { return (string) Bag ["Copyright"]; }
131                         set { Bag ["Copyright"] = value; }
132                 }
133
134                 public string Culture {
135                         get { return (string) Bag ["Culture"]; }
136                         set { Bag ["Culture"] = value; }
137                 }
138
139                 public bool DelaySign {
140                         get { return GetBoolParameterWithDefault ("DelaySign", false); }
141                         set { Bag ["DelaySign"] = value; }
142                 }
143
144                 public string Description {
145                         get { return (string) Bag ["Description"]; }
146                         set { Bag ["Description"] = value; }
147                 }
148
149                 public ITaskItem[] EmbedResources {
150                         get { return (ITaskItem[]) Bag ["EmbedResources"]; }
151                         set { Bag ["EmbedResources"] = value; }
152                 }
153
154                 public string EvidenceFile {
155                         get { return (string) Bag ["EvidenceFile"]; }
156                         set { Bag ["EvidenceFile"] = value; }
157                 }
158
159                 public string FileVersion {
160                         get { return (string) Bag ["FileVersion"]; }
161                         set { Bag ["FileVersion"] = value; }
162                 }
163
164                 public string Flags {
165                         get { return (string) Bag ["Flags"]; }
166                         set { Bag ["Flags"] = value; }
167                 }
168
169                 public bool GenerateFullPaths {
170                         get { return GetBoolParameterWithDefault ("GenerateFullPaths", false); }
171                         set { Bag ["GenerateFullPaths"] = value; }
172                 }
173
174                 public string KeyContainer {
175                         get { return (string) Bag ["KeyContainer"]; }
176                         set { Bag ["KeyContainer"] = value; }
177                 }
178
179                 public string KeyFile {
180                         get { return (string) Bag ["KeyFile"]; }
181                         set { Bag ["KeyFile"] = value; }
182                 }
183
184                 public ITaskItem[] LinkResources {
185                         get { return (ITaskItem[]) Bag ["LinkResources"]; }
186                         set { Bag ["LinkResources"] = value; }
187                 }
188
189                 public string MainEntryPoint {
190                         get { return (string) Bag ["MainEntryPoint"]; }
191                         set { Bag ["MainEntryPoint"] = value; }
192                 }
193
194                 [Required]
195                 public ITaskItem OutputAssembly {
196                         get { return (ITaskItem) Bag ["OutputAssembly"]; }
197                         set { Bag ["OutputAssembly"] = value; }
198                 }
199
200                 public string Platform {
201                         get { return (string) Bag ["Platform"]; }
202                         set { Bag ["Platform"] = value; }
203                 }
204
205                 public string ProductName {
206                         get { return (string) Bag ["ProductName"]; }
207                         set { Bag ["ProductName"] = value; }
208                 }
209
210                 public string ProductVersion {
211                         get { return (string) Bag ["ProductVersion"]; }
212                         set { Bag ["ProductVersion"] = value; }
213                 }
214
215                 public string[] ResponseFiles {
216                         get { return (string[]) Bag ["ResponseFiles"]; }
217                         set { Bag ["ResponseFiles"] = value; }
218                 }
219
220                 public ITaskItem[] SourceModules {
221                         get { return (ITaskItem[]) Bag ["SourceModules"]; }
222                         set { Bag ["SourceModules"] = value; }
223                 }
224
225                 public string TargetType {
226                         get { return (string) Bag ["TargetType"]; }
227                         set { Bag ["TargetType"] = value; }
228                 }
229
230                 public string TemplateFile {
231                         get { return (string) Bag ["TemplateFile"]; }
232                         set { Bag ["TemplateFile"] = value; }
233                 }
234
235                 public string Title {
236                         get { return (string) Bag ["Title"]; }
237                         set { Bag ["Title"] = value; }
238                 }
239
240                 protected override string ToolName {
241                         get {
242                                 return "al";
243                         }
244                 }
245
246                 public string Trademark {
247                         get { return (string) Bag ["Trademark"]; }
248                         set { Bag ["Trademark"] = value; }
249                 }
250
251                 public string Version {
252                         get { return (string) Bag ["Version"]; }
253                         set { Bag ["Version"] = value; }
254                 }
255
256                 public string Win32Icon {
257                         get { return (string) Bag ["Win32Icon"]; }
258                         set { Bag ["Win32Icon"] = value; }
259                 }
260
261                 public string Win32Resource {
262                         get { return (string) Bag ["Win32Resource"]; }
263                         set { Bag ["Win32Resource"] = value; }
264                 }
265         }
266 }
267
268 #endif