// NAnt - A .NET build tool // Copyright (C) 2001-2004 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 // // Ian Maclean (imaclean@gmail.com) // Jaroslaw Kowalski (jkowalski@users.sourceforge.net) using System; using System.IO; using System.Collections; using System.Reflection; using System.Globalization; using NAnt.Core; using NAnt.Core.Types; using NAnt.Core.Attributes; using NAnt.Core.Util; namespace NAnt.Core.Functions { /// /// Provide information about the current environment and platform. /// [FunctionSet("environment", "Environment")] public class EnvironmentFunctions : FunctionSetBase { #region Public Instance Constructors public EnvironmentFunctions(Project project, PropertyDictionary properties) : base(project, properties) { } #endregion Public Instance Constructors #region Public Instance Methods /// /// Gets the path to the system special folder identified by the /// specified enumeration. /// /// An enumerated constant that identifies a system special folder. /// /// The path to the specified system special folder, if that folder /// physically exists on your computer; otherwise, the empty string (""). /// /// is not a member of . /// /// /// Copy "out.log" from the project base directory to the /// program files directory. /// /// /// /// ]]> /// /// [Function("get-folder-path")] public static string GetFolderPath(Environment.SpecialFolder folder) { return Environment.GetFolderPath(folder); } /// /// Gets the NetBIOS name of this local computer. /// /// /// The NetBIOS name of this local computer. /// /// The name of this computer cannot be obtained. [Function("get-machine-name")] public static string GetMachineName() { return Environment.MachineName; } /// /// Gets an object that represents the /// current operating system. /// /// /// An object that contains the current /// platform identifier and version number. /// /// /// /// Output string representation of the current operating system. /// /// /// /// ]]> /// /// If the operating system is Windows 2000, the output is: /// /// Microsoft Windows NT 5.0.2195.0 /// /// /// [Function("get-operating-system")] public static OperatingSystem GetOperatingSystem() { return Environment.OSVersion; } /// /// Gets the user name of the person who started the current thread. /// /// /// The name of the person logged on to the system who started the /// current thread. /// /// /// /// Modify the home directory of the current user on unix-based systems. /// /// /// /// /// /// /// /// ]]> /// /// [Function("get-user-name")] public static string GetUserName() { return Environment.UserName; } /// /// Returns the value of the specified environment variable. /// /// The environment variable of which the value should be returned. /// /// The value of the specified environment variable. /// /// Environment variable does not exist. [Function("get-variable")] public static string GetVariable(string name) { if (!VariableExists(name)) { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("NA1095"), name)); } return Environment.GetEnvironmentVariable(name); } /// /// Gets a value indicating whether the specified environment variable /// exists. /// /// The environment variable that should be checked. /// /// if the environment variable exists; otherwise, /// . /// /// /// /// Execute a set of tasks only if the "BUILD_DEBUG" environment /// variable is set. /// /// /// /// ... /// /// ]]> /// /// [Function("variable-exists")] public static bool VariableExists(string name) { return (Environment.GetEnvironmentVariable(name) != null); } /// /// Gets a object that describes the major, /// minor, build, and revision numbers of the Common Language Runtime. /// /// /// A Version object. /// /// /// Output the major version of the CLR. /// /// /// ]]> /// /// [Function("get-version")] public static Version GetVersion() { return Environment.Version; } #endregion Public Instance Methods } }