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 29 using System; 30 using System.Diagnostics; 31 using System.IO; 32 using Microsoft.Build.Framework; 33 using Microsoft.Build.Utilities; 34 using Mono.XBuild.Utilities; 35 36 namespace Microsoft.Build.Tasks { 37 public class LC : ToolTaskExtension 38 { LC()39 public LC () 40 { 41 } 42 AddCommandLineCommands( CommandLineBuilderExtension commandLine)43 protected internal override void AddCommandLineCommands ( 44 CommandLineBuilderExtension commandLine) 45 { 46 if (Sources.Length == 0) 47 return; 48 49 foreach (ITaskItem item in Sources) 50 commandLine.AppendSwitchIfNotNull ("--complist=", item.ItemSpec); 51 52 commandLine.AppendSwitchIfNotNull ("--target=", LicenseTarget); 53 54 if (ReferencedAssemblies != null) 55 foreach (ITaskItem reference in ReferencedAssemblies) 56 commandLine.AppendSwitchIfNotNull ("--load=", reference.ItemSpec); 57 58 string outdir; 59 if (Bag ["OutputDirectory"] != null) 60 outdir = OutputDirectory; 61 else 62 outdir = "."; 63 64 commandLine.AppendSwitchIfNotNull ("--outdir=", outdir); 65 66 if (Bag ["NoLogo"] != null && NoLogo) 67 commandLine.AppendSwitch ("--nologo"); 68 69 OutputLicense = new TaskItem (Path.Combine (OutputDirectory, LicenseTarget.ItemSpec + ".licenses")); 70 } 71 GenerateFullPathToTool()72 protected override string GenerateFullPathToTool () 73 { 74 if (!string.IsNullOrEmpty (ToolPath)) 75 return Path.Combine (ToolPath, ToolExe); 76 return ToolLocationHelper.GetPathToDotNetFrameworkFile (ToolExe, TargetDotNetFrameworkVersion.VersionLatest); 77 } 78 ValidateParameters()79 protected override bool ValidateParameters() 80 { 81 return Sources.Length > 0; 82 } 83 84 [Required] 85 public ITaskItem LicenseTarget { 86 get { return (ITaskItem) Bag ["LicenseTarget"]; } 87 set { Bag ["LicenseTarget"] = value; } 88 } 89 90 public bool NoLogo { 91 get { return GetBoolParameterWithDefault ("NoLogo", false); } 92 set { Bag ["NoLogo"] = value; } 93 } 94 95 public string OutputDirectory { 96 get { return (string) Bag ["OutputDirectory"]; } 97 set { Bag ["OutputDirectory"] = value; } 98 } 99 100 [Output] 101 public ITaskItem OutputLicense { 102 get { return (ITaskItem) Bag ["OutputLicense"]; } 103 set { Bag ["OutputLicense"] = value; } 104 } 105 106 public ITaskItem[] ReferencedAssemblies { 107 get { return (ITaskItem[]) Bag ["ReferencedAssemblies"]; } 108 set { Bag ["ReferencedAssemblies"] = value; } 109 } 110 111 [Required] 112 public ITaskItem[] Sources { 113 get { return (ITaskItem[]) Bag ["Sources"]; } 114 set { Bag ["Sources"] = value; } 115 } 116 117 protected override string ToolName { 118 get { 119 return MSBuildUtils.RunningOnWindows ? "lc.bat" : "lc"; 120 } 121 } 122 } 123 } 124 125