Merge branch 'bugfix-main-thread-root'
[mono.git] / mcs / class / Microsoft.Build.Tasks / Microsoft.Build.Tasks / LC.cs
1 //
2 // LC.cs: Task for license compiler
3 //
4 // Author:
5 //   Ankit Jain (jankit@novell.com)
6 //
7 // Copyright 2010 Novell, Inc (http://www.novell.com)
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 SHLCL 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 DELCINGS 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 LC : ToolTaskExtension
39         {
40                 public LC ()
41                 {
42                 }
43
44                 protected internal override void AddCommandLineCommands (
45                                                 CommandLineBuilderExtension commandLine)
46                 {
47                         if (Sources.Length == 0)
48                                 return;
49
50                         foreach (ITaskItem item in Sources)
51                                 commandLine.AppendSwitchIfNotNull ("--complist=", item.ItemSpec);
52
53                         commandLine.AppendSwitchIfNotNull ("--target=", LicenseTarget);
54
55                         if (ReferencedAssemblies != null)
56                                 foreach (ITaskItem reference in ReferencedAssemblies)
57                                         commandLine.AppendSwitchIfNotNull ("--load=", reference.ItemSpec);
58
59                         string outdir;
60                         if (Bag ["OutputDirectory"] != null)
61                                 outdir = OutputDirectory;
62                         else
63                                 outdir = ".";
64
65                         commandLine.AppendSwitchIfNotNull ("--outdir=", outdir);
66
67                         if (Bag ["NoLogo"] != null && NoLogo)
68                                 commandLine.AppendSwitch ("--nologo");
69
70                         OutputLicense = new TaskItem (Path.Combine (OutputDirectory, LicenseTarget.ItemSpec + ".licenses"));
71                 }
72
73                 protected override string GenerateFullPathToTool ()
74                 {
75                         return Path.Combine (ToolPath, ToolExe);
76                 }
77
78                 protected override bool ValidateParameters()
79                 {
80                         return Sources.Length > 0;
81                 }
82
83                 [Required]
84                 public ITaskItem LicenseTarget {
85                         get { return (ITaskItem) Bag ["LicenseTarget"]; }
86                         set { Bag ["LicenseTarget"] = value; }
87                 }
88
89                 public bool NoLogo {
90                         get { return GetBoolParameterWithDefault ("NoLogo", false); }
91                         set { Bag ["NoLogo"] = value; }
92                 }
93
94                 public string OutputDirectory {
95                         get { return (string) Bag ["OutputDirectory"]; }
96                         set { Bag ["OutputDirectory"] = value; }
97                 }
98
99                 [Output]
100                 public ITaskItem OutputLicense {
101                         get { return (ITaskItem) Bag ["OutputLicense"]; }
102                         set { Bag ["OutputLicense"] = value; }
103                 }
104
105                 public ITaskItem[] ReferencedAssemblies {
106                         get { return (ITaskItem[]) Bag ["ReferencedAssemblies"]; }
107                         set { Bag ["ReferencedAssemblies"] = value; }
108                 }
109
110                 [Required]
111                 public ITaskItem[] Sources {
112                         get { return (ITaskItem[]) Bag ["Sources"]; }
113                         set { Bag ["Sources"] = value; }
114                 }
115
116                 protected override string ToolName {
117                         get {
118                                 return MSBuildUtils.RunningOnWindows ? "lc.bat" : "lc";
119                         }
120                 }
121         }
122 }
123
124 #endif