// NAnt - A .NET build tool // Copyright (C) 2001-2002 Gerry Shaw // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // Gerry Shaw (gerry_shaw@yahoo.com) // Mike Krueger (mike@icsharpcode.net) // Giuseppe Greco (giuseppe.greco@agamura.com) using System; using System.IO; using System.Text.RegularExpressions; using NAnt.Core; using NAnt.Core.Attributes; using NAnt.Core.Util; using NAnt.DotNet.Types; namespace NAnt.DotNet.Tasks { /// /// Compiles JScript.NET programs. /// /// /// Compile helloworld.js to helloworld.exe. /// /// /// /// /// /// /// ]]> /// /// [TaskName("jsc")] [ProgramLocation(LocationType.FrameworkDir)] public class JscTask : CompilerBase { #region Private Instance Fields private string _warningLevel; private string _codepage; private string _platform; // framework configuration settings private bool _supportsPlatform; #endregion Private Instance Fields #region Private Static Fields private static Regex _classNameRegex = new Regex(@"^((?/\*.*?(\*/|$))|[\s\.\{]+|class\s+(?\w+)|(?\w+))*"); private static Regex _namespaceRegex = new Regex(@"^((?/\*.*?(\*/|$))|[\s\.\{]+|namespace\s+(?(\w+(\.\w+)*)+)|(?\w+))*"); #endregion Private Static Fields #region Public Instance Properties /// /// Specifies which platform version of common language runtime (CLR) /// can run the output file. /// /// /// The platform version of common language runtime (CLR) that can run /// the output file. /// /// /// /// Corresponds with the /platform flag. /// /// [TaskAttribute("platform")] public string Platform { get { return _platform; } set { _platform = StringUtils.ConvertEmptyToNull(value); } } /// /// Specifies the warning level for the compiler to display. Valid /// values are 0-4. The default is 4. /// /// /// The warning level for the compiler to display. /// /// /// /// Corresponds with the /warn flag. /// /// [TaskAttribute("warninglevel")] [Int32Validator(0, 4)] public string WarningLevel { get { return _warningLevel; } set { _warningLevel = StringUtils.ConvertEmptyToNull(value); } } /// /// Controls which warnings should be reported as errors. /// /// /// Override to avoid exposing this to build authors, as the JScript.NET /// compiler does not allow control over which warnings should be /// reported as errors. /// public override WarningAsError WarningAsError { get { return base.WarningAsError; } } /// /// Specifies a comma-separated list of warnings that should be suppressed /// by the compiler. /// /// /// Override to avoid exposing this to build authors, as the JScript.NET /// compiler does not support package references. /// [Obsolete("Use the element instead.", false)] public override string NoWarn { get { return base.NoWarn; } set { base.NoWarn = value; } } /// /// Specifies a list of warnings that you want the compiler to suppress. /// /// /// Override to avoid exposing this to build authors, as the JScript.NET /// compiler does not support suppressing warnings. /// public override CompilerWarningCollection SuppressWarnings { get { return base.SuppressWarnings; } } /// /// Specifies the code page to use for all source code files in the /// compilation. /// /// /// /// Corresponds with the /codepage flag. /// /// [TaskAttribute("codepage")] public string Codepage { get { return _codepage; } set { _codepage = StringUtils.ConvertEmptyToNull(value); } } /// /// Specifies the key pair container used to strongname the assembly. /// /// /// Override to avoid exposing this to build authors, as the JScript.NET /// does not support this. /// public override string KeyContainer { get { return base.KeyContainer; } set { base.KeyContainer = value; } } /// /// Specifies a strong name key file. /// /// /// Override to avoid exposing this to build authors, as the JScript.NET /// does not support this. /// public override FileInfo KeyFile { get { return base.KeyFile; } set { base.KeyFile = value; } } /// /// Indicates whether the compiler for a given target framework supports /// the "keycontainer" option. The default is . /// /// /// . /// /// /// Override to avoid exposing this to build authors, as the JScript.NET /// does not support this. /// public override bool SupportsKeyContainer { get { return false; } set { } } /// /// Indicates whether the compiler for a given target framework supports /// the "keyfile" option. The default is . /// /// /// . /// /// /// Override to avoid exposing this to build authors, as the JScript.NET /// does not support this. /// public override bool SupportsKeyFile { get { return false; } set { } } /// /// Specifies whether the compiler for the active target framework /// supports limiting the platform on which the compiled code can run. /// The default is . /// [FrameworkConfigurable("supportsplatform")] public bool SupportsPlatform { get { return _supportsPlatform; } set { _supportsPlatform = value; } } #endregion Public Instance Properties #region Override implementation of CompilerBase /// /// Link the specified modules into this assembly. /// /// /// Override to avoid exposing this to build authors, as the JScript.NET /// compiler does not support linking modules. /// public override AssemblyFileSet Modules { get { return base.Modules; } set { base.Modules = value; } } /// /// Writes module references to the specified . /// /// The to which the module references should be written. protected override void WriteModuleReferences(TextWriter writer) { if (Modules.FileNames.Count > 0) { Log(Level.Warning, ResourceUtils.GetString("String_JscDoesNotSupportLinkingModules")); } } /// /// Writes the compiler options to the specified . /// /// to which the compiler options should be written. protected override void WriteOptions(TextWriter writer) { if (Debug) { WriteOption(writer, "debug"); WriteOption(writer, "define", "DEBUG"); WriteOption(writer, "define", "TRACE"); } if (WarningLevel != null) { WriteOption(writer, "warn" , WarningLevel); } if (Codepage != null) { WriteOption(writer, "codepage", Codepage); } // platform if (Platform != null) { if (SupportsPlatform) { WriteOption(writer, "platform", Platform); } else { Log(Level.Warning, ResourceUtils.GetString("String_CompilerDoesNotSupportPlatform"), Project.TargetFramework.Description); } } } /// /// Gets the file extension required by the current compiler. /// /// /// For the JScript.NET compiler, the file extension is always js. /// public override string Extension { get { return "js"; } } /// /// Gets the class name regular expression for the language of the /// current compiler. /// /// /// Class name regular expression for the language of the current /// compiler. /// protected override Regex ClassNameRegex { get { return _classNameRegex; } } /// /// Gets the namespace regular expression for the language of the /// current compiler. /// /// /// Namespace regular expression for the language of the current /// compiler. /// protected override Regex NamespaceRegex { get { return _namespaceRegex; } } #endregion Override implementation of CompilerBase } }