Merge pull request #901 from Blewzman/FixAggregateExceptionGetBaseException
[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                         if (!string.IsNullOrEmpty (ToolPath))
76                                 return Path.Combine (ToolPath, ToolExe);
77                         return ToolLocationHelper.GetPathToDotNetFrameworkFile (ToolExe, TargetDotNetFrameworkVersion.VersionLatest);
78                 }
79
80                 protected override bool ValidateParameters()
81                 {
82                         return Sources.Length > 0;
83                 }
84
85                 [Required]
86                 public ITaskItem LicenseTarget {
87                         get { return (ITaskItem) Bag ["LicenseTarget"]; }
88                         set { Bag ["LicenseTarget"] = value; }
89                 }
90
91                 public bool NoLogo {
92                         get { return GetBoolParameterWithDefault ("NoLogo", false); }
93                         set { Bag ["NoLogo"] = value; }
94                 }
95
96                 public string OutputDirectory {
97                         get { return (string) Bag ["OutputDirectory"]; }
98                         set { Bag ["OutputDirectory"] = value; }
99                 }
100
101                 [Output]
102                 public ITaskItem OutputLicense {
103                         get { return (ITaskItem) Bag ["OutputLicense"]; }
104                         set { Bag ["OutputLicense"] = value; }
105                 }
106
107                 public ITaskItem[] ReferencedAssemblies {
108                         get { return (ITaskItem[]) Bag ["ReferencedAssemblies"]; }
109                         set { Bag ["ReferencedAssemblies"] = value; }
110                 }
111
112                 [Required]
113                 public ITaskItem[] Sources {
114                         get { return (ITaskItem[]) Bag ["Sources"]; }
115                         set { Bag ["Sources"] = value; }
116                 }
117
118                 protected override string ToolName {
119                         get {
120                                 return MSBuildUtils.RunningOnWindows ? "lc.bat" : "lc";
121                         }
122                 }
123         }
124 }
125
126 #endif