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