2 // LC.cs: Task for license compiler
5 // Ankit Jain (jankit@novell.com)
7 // Copyright 2010 Novell, Inc (http://www.novell.com)
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
30 using System.Diagnostics;
32 using Microsoft.Build.Framework;
33 using Microsoft.Build.Utilities;
34 using Mono.XBuild.Utilities;
36 namespace Microsoft.Build.Tasks {
37 public class LC : ToolTaskExtension
43 protected internal override void AddCommandLineCommands (
44 CommandLineBuilderExtension commandLine)
46 if (Sources.Length == 0)
49 foreach (ITaskItem item in Sources)
50 commandLine.AppendSwitchIfNotNull ("--complist=", item.ItemSpec);
52 commandLine.AppendSwitchIfNotNull ("--target=", LicenseTarget);
54 if (ReferencedAssemblies != null)
55 foreach (ITaskItem reference in ReferencedAssemblies)
56 commandLine.AppendSwitchIfNotNull ("--load=", reference.ItemSpec);
59 if (Bag ["OutputDirectory"] != null)
60 outdir = OutputDirectory;
64 commandLine.AppendSwitchIfNotNull ("--outdir=", outdir);
66 if (Bag ["NoLogo"] != null && NoLogo)
67 commandLine.AppendSwitch ("--nologo");
69 OutputLicense = new TaskItem (Path.Combine (OutputDirectory, LicenseTarget.ItemSpec + ".licenses"));
72 protected override string GenerateFullPathToTool ()
74 if (!string.IsNullOrEmpty (ToolPath))
75 return Path.Combine (ToolPath, ToolExe);
76 return ToolLocationHelper.GetPathToDotNetFrameworkFile (ToolExe, TargetDotNetFrameworkVersion.VersionLatest);
79 protected override bool ValidateParameters()
81 return Sources.Length > 0;
85 public ITaskItem LicenseTarget {
86 get { return (ITaskItem) Bag ["LicenseTarget"]; }
87 set { Bag ["LicenseTarget"] = value; }
91 get { return GetBoolParameterWithDefault ("NoLogo", false); }
92 set { Bag ["NoLogo"] = value; }
95 public string OutputDirectory {
96 get { return (string) Bag ["OutputDirectory"]; }
97 set { Bag ["OutputDirectory"] = value; }
101 public ITaskItem OutputLicense {
102 get { return (ITaskItem) Bag ["OutputLicense"]; }
103 set { Bag ["OutputLicense"] = value; }
106 public ITaskItem[] ReferencedAssemblies {
107 get { return (ITaskItem[]) Bag ["ReferencedAssemblies"]; }
108 set { Bag ["ReferencedAssemblies"] = value; }
112 public ITaskItem[] Sources {
113 get { return (ITaskItem[]) Bag ["Sources"]; }
114 set { Bag ["Sources"] = value; }
117 protected override string ToolName {
119 return MSBuildUtils.RunningOnWindows ? "lc.bat" : "lc";