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.
31 using System.Diagnostics;
33 using Microsoft.Build.Framework;
34 using Microsoft.Build.Utilities;
35 using Mono.XBuild.Utilities;
37 namespace Microsoft.Build.Tasks {
38 public class LC : ToolTaskExtension
44 protected internal override void AddCommandLineCommands (
45 CommandLineBuilderExtension commandLine)
47 if (Sources.Length == 0)
50 foreach (ITaskItem item in Sources)
51 commandLine.AppendSwitchIfNotNull ("--complist=", item.ItemSpec);
53 commandLine.AppendSwitchIfNotNull ("--target=", LicenseTarget);
55 if (ReferencedAssemblies != null)
56 foreach (ITaskItem reference in ReferencedAssemblies)
57 commandLine.AppendSwitchIfNotNull ("--load=", reference.ItemSpec);
60 if (Bag ["OutputDirectory"] != null)
61 outdir = OutputDirectory;
65 commandLine.AppendSwitchIfNotNull ("--outdir=", outdir);
67 if (Bag ["NoLogo"] != null && NoLogo)
68 commandLine.AppendSwitch ("--nologo");
70 OutputLicense = new TaskItem (Path.Combine (OutputDirectory, LicenseTarget.ItemSpec + ".licenses"));
73 protected override string GenerateFullPathToTool ()
75 if (!string.IsNullOrEmpty (ToolPath))
76 return Path.Combine (ToolPath, ToolExe);
77 return ToolLocationHelper.GetPathToDotNetFrameworkFile (ToolExe, TargetDotNetFrameworkVersion.VersionLatest);
80 protected override bool ValidateParameters()
82 return Sources.Length > 0;
86 public ITaskItem LicenseTarget {
87 get { return (ITaskItem) Bag ["LicenseTarget"]; }
88 set { Bag ["LicenseTarget"] = value; }
92 get { return GetBoolParameterWithDefault ("NoLogo", false); }
93 set { Bag ["NoLogo"] = value; }
96 public string OutputDirectory {
97 get { return (string) Bag ["OutputDirectory"]; }
98 set { Bag ["OutputDirectory"] = value; }
102 public ITaskItem OutputLicense {
103 get { return (ITaskItem) Bag ["OutputLicense"]; }
104 set { Bag ["OutputLicense"] = value; }
107 public ITaskItem[] ReferencedAssemblies {
108 get { return (ITaskItem[]) Bag ["ReferencedAssemblies"]; }
109 set { Bag ["ReferencedAssemblies"] = value; }
113 public ITaskItem[] Sources {
114 get { return (ITaskItem[]) Bag ["Sources"]; }
115 set { Bag ["Sources"] = value; }
118 protected override string ToolName {
120 return MSBuildUtils.RunningOnWindows ? "lc.bat" : "lc";