// 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 // // Tom Jordan (tdjordan@users.sourceforge.net) // Giuseppe Greco (giuseppe.greco@agamura.com) using System.Globalization; 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 Visual J# programs using vjc, Microsoft's J# compiler. /// /// /// /// In order to have generate manifest resource names /// that match those generated by Microsoft Visual Studio.NET, the value of /// the attribute of the <> /// element should match the "Default Package" of the J#.NET project, and /// the value of the attribute /// should be set to "". /// /// /// /// Compile a "HelloWorld" application, including embedded resources. /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ]]> /// /// [TaskName("vjc")] [ProgramLocation(LocationType.FrameworkDir)] public class VjcTask : CompilerBase { #region Private Instance Fields private string _baseAddress; private DebugOutput _debugOutput = DebugOutput.None; private bool _secureScoping; private string _x; private string _libPath; private string _jcpa; private string _codepage; private string _warningLevel; #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\.\{]+|package\s+(?(\w+(\.\w+)*)+)|(?\w+))*"); #endregion Private Static Fields #region Public Instance Properties /// /// The preferred base address at which to load a DLL. The default base /// address for a DLL is set by the .NET Framework common language /// runtime. /// /// /// The preferred base address at which to load a DLL. /// /// /// This address can be specified as a decimal, hexadecimal, or octal /// number. /// public string BaseAddress { get { return _baseAddress; } set { _baseAddress = StringUtils.ConvertEmptyToNull(value); } } /// /// Specifies the type of debugging information generated by the /// compiler. The default is . /// [TaskAttribute("debug")] public DebugOutput DebugOutput { get { return _debugOutput; } set { _debugOutput = value; } } /// /// No longer expose this to build authors. Use /// instead. /// public override bool Debug { get { return DebugOutput != DebugOutput.None; } set { DebugOutput = DebugOutput.Enable; } } /// /// Specifies whether package-scoped members are accessible outside of /// the assembly. In other words, package scope is treated as assembly /// scope when emitting metadata. The default is . /// /// /// if the option should be passed to the compiler; /// otherwise, . /// /// /// /// Corresponds to the /securescoping flag. /// /// /// See the Visual J# Reference for details. /// /// /// /// ]]> /// [TaskAttribute("securescoping")] [BooleanValidator()] public bool SecureScoping { get { return _secureScoping; } set { _secureScoping = value; } } /// /// Specifies whether to disable language extensions. /// /// /// The value of this property must be either all, net, /// or an empty string. /// /// /// /// Corresponds to the /x flag. /// /// /// See the Visual J# Reference for details. /// /// /// /// To disable only the .NET Framework extensions: /// ]]> /// To disable the .NET Framework extensions and the VJ++ 6.0 extensions: /// ]]> /// [TaskAttribute("x")] public string X { get { return _x; } set { _x = StringUtils.ConvertEmptyToNull(value); } } /// /// Specifies the location of assemblies referenced by way of the /reference flag. /// /// /// /// Corresponds to the /libpath:dir[;dir2] flag. /// /// /// See the Visual J# Reference for details. /// /// [TaskAttribute("libpath")] public string LibPath { get { return _libPath; } set { _libPath = StringUtils.ConvertEmptyToNull(value); } } /// /// Associate Java-language/COM package names. /// /// /// The value of this propery. must be package=namespace, @filename, /// or an empty string. /// /// /// /// Corresponds to the /jcpa:package=namespace and /jcpa:@filename flags. /// /// /// See the Visual J# Reference for details. /// /// /// /// Map package 'x' to namespace 'y': /// ]]> /// [TaskAttribute("jcpa")] public string Jcpa { get { return _jcpa; } set { _jcpa = StringUtils.ConvertEmptyToNull(value); } } /// /// Specifies the code page to use for all source code files in the /// compilation. /// /// /// /// Corresponds with the /codepage flag. /// /// /// See the Visual J# Reference for details. /// /// [TaskAttribute("codepage")] public string Codepage { get { return _codepage; } set { _codepage = 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 option. /// /// [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 Visual J# /// compiler does not allow control over which warnings should be /// reported as errors. /// public override WarningAsError WarningAsError { get { return base.WarningAsError; } } #endregion Public Instance Properties #region Override implementation of CompilerBase /// /// Reference packages /// /// /// Override to avoid exposing this to build authors, as the Visual J# /// compiler does not support package references. /// public override PackageCollection Packages { get { return base.Packages; } set { base.Packages = value; } } /// /// Link the specified modules into this assembly. /// /// /// Override to avoid exposing this to build authors, as the Visual J# /// 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) { // the base address for the DLL if (BaseAddress != null) { WriteOption(writer, "baseaddress", BaseAddress); } // handle secure scoping. if (SecureScoping) { WriteOption(writer, "securescoping"); } // handle the disable framework extensions option. if (X != null) { WriteOption(writer, "x", X); } // handle the libpath option. if (LibPath != null ) { WriteOption(writer, "libpath", LibPath); } // handle the jcpa option. if (Jcpa != null) { WriteOption(writer, "jcpa", Jcpa); } // handle the codepage option. if (Codepage != null) { WriteOption(writer, "codepage", Codepage); } // handle debug builds. switch (DebugOutput) { case DebugOutput.None: break; case DebugOutput.Enable: WriteOption(writer, "debug"); WriteOption(writer, "define", "DEBUG"); WriteOption(writer, "define", "TRACE"); break; case DebugOutput.Full: WriteOption(writer, "debug"); break; case DebugOutput.PdbOnly: WriteOption(writer, "debug", "pdbonly"); break; default: throw new BuildException(string.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("NA2011"), DebugOutput), Location); } if (WarningLevel != null) { WriteOption(writer, "warn", WarningLevel); } } /// /// Gets the file extension required by the current compiler. /// /// /// For the J# compiler, the file extension is always jsl. /// public override string Extension { get { return "jsl"; } } /// /// 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; } } /// /// Override to avoid exposing the configuration setting for this /// task as Visual J# will never support package references. /// /// /// , as the Visual J# compiler will never /// support package references. /// public override bool SupportsPackageReferences { get { return false; } set { } } #endregion Override implementation of CompilerBase } }