[Csmail-patches] CVS: csmail/nant/src/Tasks CallTask.cs,NONE,1.1 ChangeLog,NONE,1.1 CompilerBase.cs,
Status: Pre-Alpha
Brought to you by:
mastergaurav
Update of /cvsroot/csmail/csmail/nant/src/Tasks In directory usw-pr-cvs1:/tmp/cvs-serv25536/nant/src/Tasks Added Files: CallTask.cs ChangeLog CompilerBase.cs CopyTask.cs CscTask.cs DeleteTask.cs EchoTask.cs ExecTask.cs ExternalProgramBase.cs FailTask.cs IncludeTask.cs JscTask.cs McsTask.cs MkDirTask.cs MoveTask.cs NantTask.cs PropertyTask.cs SleepTask.cs StyleTask.cs TStampTask.cs TaskDefTask.cs VbcTask.cs Log Message: 2002-02-24 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> * Added the source code of NAnt. --- NEW FILE --- // NAnt - A .NET build tool // Copyright (C) 2001 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 (ger...@ya...) namespace SourceForge.NAnt { using System; using System.Collections.Specialized; using System.Diagnostics; using System.IO; using System.Xml; [TaskName("call")] public class CallTask : Task { [TaskAttribute("target", Required=true)] string _target = null; // Attribute properties public string TargetName { get { return _target; } } protected override void ExecuteTask() { Project.Execute(TargetName); } } } --- NEW FILE --- 2002-04-26 Martin Baulig <ma...@gn...> * CompilerBase.cs (WriteOption): New virtual method. The default implementation writes CSC-style command line options, but it can be overridden in derived class to write mcs-style command line arguments. (ExecuteTask): Use the new virtual `WriteOption' method to write options. * CscTask.cs (WriteOptions): Use the new `WriteOption' method. * McsTask.cs: New file. --- NEW FILE --- // NAnt - A .NET build tool // Copyright (C) 2001 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 (ger...@ya...) // Mike Krueger (mi...@ic...) namespace SourceForge.NAnt { using System; using System.Collections.Specialized; using System.Diagnostics; using System.IO; public abstract class CompilerBase : ExternalProgramBase { string _responseFileName; // Microsoft common compiler options [TaskAttribute("output", Required=true)] string _output = null; [TaskAttribute("target", Required=true)] string _target = null; [TaskAttribute("debug")] [BooleanValidator()] string _debug = Boolean.FalseString; [TaskAttribute("define")] string _define = null; [TaskAttribute("win32icon")] string _win32icon = null; [TaskFileSet("references")] FileSet _references = new FileSet(false); [TaskFileSet("resources")] FileSet _resources = new FileSet(false); [TaskFileSet("modules")] FileSet _modules = new FileSet(false); [TaskFileSet("sources")] FileSet _sources = new FileSet(true); // include all by default public string Output { get { return _output; } } public string OutputTarget { get { return _target; } } public bool Debug { get { return Convert.ToBoolean(_debug); } } public string Define { get { return _define; } } public string Win32Icon { get { return _win32icon; } } public FileSet References { get { return _references; } } public FileSet Resources { get { return _resources; } } public FileSet Modules { get { return _modules; } } public FileSet Sources { get { return _sources; } } public override string ProgramFileName { get { return Name; } } public override string ProgramArguments { get { return "@" + _responseFileName; } } protected virtual void WriteOptions(TextWriter writer) { } protected virtual void WriteOption(TextWriter writer, string name) { writer.WriteLine("/{0}", name); } protected virtual void WriteOption(TextWriter writer, string name, string arg) { writer.WriteLine("/{0}:{1}", name, arg); } protected string GetOutputPath() { return Path.GetFullPath(Path.Combine(BaseDirectory, Project.ExpandText(Output))); } protected virtual bool NeedsCompiling() { // return true as soon as we know we need to compile FileInfo outputFileInfo = new FileInfo(GetOutputPath()); if (!outputFileInfo.Exists) { return true; } if (FileSet.MoreRecentLastWriteTime(Sources.FileNames, outputFileInfo.LastWriteTime)) { return true; } if (FileSet.MoreRecentLastWriteTime(References.FileNames, outputFileInfo.LastWriteTime)) { return true; } if (FileSet.MoreRecentLastWriteTime(Modules.FileNames, outputFileInfo.LastWriteTime)) { return true; } // if we made it here then we don't have to recompile return false; } protected override void ExecuteTask() { if (NeedsCompiling()) { // create temp response file to hold compiler options _responseFileName = Path.GetTempFileName(); StreamWriter writer = new StreamWriter(_responseFileName); try { if (References.BaseDirectory == null) { References.BaseDirectory = BaseDirectory; } if (Modules.BaseDirectory == null) { Modules.BaseDirectory = BaseDirectory; } if (Sources.BaseDirectory == null) { Sources.BaseDirectory = BaseDirectory; } Log.WriteLine(LogPrefix + "Compiling {0} files to {1}", Sources.FileNames.Count, GetOutputPath()); // specific compiler options WriteOptions(writer); // Microsoft common compiler options WriteOption(writer, "nologo"); WriteOption(writer, "target", OutputTarget); WriteOption(writer, "out", GetOutputPath()); if (Debug) { WriteOption(writer, "debug"); WriteOption(writer, "define", "DEBUG"); WriteOption(writer, "define", "TRACE"); } if (Define != null) { WriteOption(writer, "define", Define); } if (Win32Icon != null) { WriteOption(writer, "win32icon", Win32Icon); } foreach (string fileName in References.FileNames) { WriteOption(writer, "reference", fileName); } foreach (string fileName in Modules.FileNames) { WriteOption(writer, "addmodule", fileName); } foreach (string fileName in Resources.FileNames) { WriteOption(writer, "resource", fileName); } foreach (string fileName in Sources.FileNames) { writer.WriteLine(fileName); } // Make sure to close the response file otherwise contents // will not be written to disc and EXecuteTask() will fail. writer.Close(); if (Verbose) { // display response file contents Log.WriteLine(LogPrefix + "Contents of " + _responseFileName); /* StreamReader reader = File.OpenText(_responseFileName); string line = reader.ReadLine(); while (line != null) { Log.WriteLine(LogPrefix + " " + line); line = reader.ReadLine(); } reader.Close(); */ StreamReader reader = File.OpenText(_responseFileName); Log.WriteLine(reader.ReadToEnd()); reader.Close(); } // call base class to do the work base.ExecuteTask(); } finally { // make sure we delete response file even if an exception is thrown writer.Close(); // make sure stream is closed or file cannot be deleted File.Delete(_responseFileName); _responseFileName = null; } } } } } --- NEW FILE --- // NAnt - A .NET build tool // Copyright (C) 2001 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 (ger...@ya...) // Ian MacLean (ian...@an...) namespace SourceForge.NAnt { using System; using System.IO; using System.Xml; using System.Text; using System.Collections; using System.Collections.Specialized; [TaskName("copy")] public class CopyTask : Task { [TaskAttribute("file")] string _sourceFile = null; [TaskAttribute("tofile")] string _toFile = null; [TaskAttribute("todir")] string _toDirectory = null; [TaskAttribute("filtering")] [BooleanValidator()] string _filtering = Boolean.FalseString; [TaskAttribute("flatten")] [BooleanValidator()] string _flatten = Boolean.FalseString; [TaskAttribute("includeEmptyDirs")] [BooleanValidator()] string _includeEmptyDirs = Boolean.FalseString; [TaskFileSet("fileset")] FileSet _fileset = new FileSet(true); // include all by default [TaskAttribute("overwrite")] [BooleanValidator()] string _overwrite = Boolean.FalseString; [TaskAttribute("verbose")] [BooleanValidator()] string _verbose = Boolean.FalseString; [TaskAttribute("preserveLastModified")] [BooleanValidator()] string _preserveLastModified = Boolean.FalseString; Hashtable _fileCopyMap = new Hashtable(); public string SourceFile { get { return _sourceFile; } } public string ToFile { get { return _toFile; } } public string ToDirectory { get { return _toDirectory; } } public bool Filtering { get { return Convert.ToBoolean(_filtering); } } public bool Flatten { get { return Convert.ToBoolean(_flatten); } } public bool IncludeEmptyDirs { get { return Convert.ToBoolean(_includeEmptyDirs); } } public bool Overwrite { get { return Convert.ToBoolean(_overwrite); } } public bool PreserveLastModified{ get { return Convert.ToBoolean(_preserveLastModified); } } public FileSet CopyFileSet { get { return _fileset; } } public bool Verbose { get { return (Project.Verbose || Convert.ToBoolean(_verbose)); } } protected Hashtable FileCopyMap { get { return _fileCopyMap; } } /// <summary> /// Actually does the file (and possibly empty directory) copies. /// </summary> protected virtual void DoFileOperations() { int fileCount = FileCopyMap.Keys.Count; if (fileCount > 0) { if (ToDirectory != null) { Log.WriteLine(LogPrefix + "Copying {0} files to {1}", fileCount, Project.GetFullPath(ToDirectory)); } else { Log.WriteLine(LogPrefix + "Copying {0} files", fileCount); } // loop thru our file list foreach (string sourcePath in FileCopyMap.Keys) { string dstPath = (string)FileCopyMap[sourcePath]; if (sourcePath == dstPath) { if (Verbose) { Log.WriteLine(LogPrefix + "Skipping self-copy of {0}" + sourcePath); } continue; } try { if (Verbose) { Log.WriteLine(LogPrefix + "Copying {0} to {1}", sourcePath, dstPath); } // create directory if not present string dstDirectory = Path.GetDirectoryName(dstPath); if (!Directory.Exists(dstDirectory)) { Directory.CreateDirectory(dstDirectory); if (Verbose) { Log.WriteLine(LogPrefix + "Created directory {0}", dstDirectory); } } File.Copy(sourcePath, dstPath, true); } catch (IOException ioe) { string msg = String.Format("Cannot copy {0} to {1}", sourcePath, dstPath); throw new BuildException(msg, Location, ioe); } } } // TODO: handle empty directories in the fileset, refer to includeEmptyDirs attribute at // http://jakarta.apache.org/ant/manual/CoreTasks/copy.html } protected override void ExecuteTask() { string dstDirectoryPath = Project.GetFullPath(ToDirectory); string srcFilePath = Project.GetFullPath(SourceFile); FileInfo srcInfo = new FileInfo(srcFilePath); string dstFilePath; if (ToFile == null) { dstFilePath = dstDirectoryPath + Path.DirectorySeparatorChar + srcInfo.Name; } else { dstFilePath = Project.GetFullPath(ToFile); } FileInfo dstInfo = new FileInfo(dstFilePath); if (SourceFile != null) { if (srcInfo.Exists) { // do the outdated check bool outdated = (!dstInfo.Exists) || (srcInfo.LastWriteTime > dstInfo.LastWriteTime); if (Overwrite || outdated) { // add to a copy map of absolute verified paths FileCopyMap.Add(srcFilePath, dstFilePath); } } else { Log.WriteLine(LogPrefix + "Could not find file {0} to copy.", srcFilePath); } } else { // get the complete path of the base directory of the fileset, ie, c:\work\nant\src string srcBasePath = Project.GetFullPath(CopyFileSet.BaseDirectory); string dstBasePath = Project.GetFullPath(ToDirectory); // if source file not specified use fileset foreach (string pathname in CopyFileSet.FileNames) { // replace the fileset path with the destination path // NOTE: big problems could occur if the file set base dir is rooted on a different drive string dstPath = pathname.Replace(srcBasePath, dstBasePath); srcInfo = new FileInfo(pathname); dstInfo = new FileInfo(dstPath); if (srcInfo.Exists) { // do the outdated check bool outdated = (!dstInfo.Exists) || (srcInfo.LastWriteTime > dstInfo.LastWriteTime); if (Overwrite || outdated) { FileCopyMap.Add(pathname, dstPath); } } else { Log.WriteLine(LogPrefix + "Could not find file {0} to copy.", srcFilePath); } } } // do all the actual copy operations now... DoFileOperations(); } } } --- NEW FILE --- // NAnt - A .NET build tool // Copyright (C) 2001 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 (ger...@ya...) // Mike Krueger (mi...@ic...) namespace SourceForge.NAnt { using System; using System.IO; [TaskName("csc")] public class CscTask : CompilerBase { // C# specific compiler options [TaskAttribute("doc")] string _doc = null; protected override void WriteOptions(TextWriter writer) { WriteOption(writer, "fullpaths"); if (_doc != null) { WriteOption(writer, "doc", _doc); } } protected override bool NeedsCompiling() { // TODO: add checks for any referenced files OR return false to always compile return base.NeedsCompiling(); } } } --- NEW FILE --- // NAnt - A .NET build tool // Copyright (C) 2001 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 (ger...@ya...) // TODO: move this into the task documentation (once we figure out how tasks // should be documented - xml?? /* verbose: Show name of each deleted file ("true"/"false"). Default is "false" when omitted. quiet: If the file does not exist, do not display a diagnostic message or modify the exit status to reflect an error (unless Ant has been invoked with the -verbose or -debug switches). This means that if a file or directory cannot be deleted, then no error is reported. This setting emulates the -f option to the Unix "rm" command. ("true"/"false"). Default is "false" meaning things are "noisy". Setting this to true, implies setting failonerror to false. failonerror: This flag (which is only of relevance if 'quiet' is false), controls whether an error -such as a failure to delete a file- stops the build task, or is merely reported to the screen. The default is "true" */ namespace SourceForge.NAnt { using System; using System.IO; [TaskName("delete")] public class DeleteTask : Task { [TaskAttribute("file")] string _file = null; [TaskAttribute("dir")] string _dir = null; [TaskAttribute("verbose")] [BooleanValidator()] string _verbose = Boolean.FalseString; [TaskAttribute("failonerror")] [BooleanValidator()] string _failOnError = Boolean.TrueString; /// <summary>If true then delete empty directories when using filesets.</summary> [TaskAttribute("includeEmptyDirs")] [BooleanValidator()] string _includeEmptyDirs = Boolean.FalseString; [TaskFileSet("fileset")] FileSet _fileset = new FileSet(false); public string FileName { get { return _file; } } public string DirectoryName { get { return _dir; } } public bool FailOnError { get { return Convert.ToBoolean(_failOnError); } } public bool IncludeEmptyDirectories { get { return Convert.ToBoolean(_includeEmptyDirs); } } public FileSet DeleteFileSet { get { return _fileset; } } public bool Verbose { get { return (Project.Verbose || Convert.ToBoolean(_verbose)); } } protected override void ExecuteTask() { // limit task to deleting either a file or a directory or a file set if (FileName != null && DirectoryName != null) { throw new BuildException("Cannot specify 'file' and 'dir' in the same delete task", Location); } // try to delete specified file if (FileName != null) { string path = null; try { path = Project.GetFullPath(FileName); } catch (Exception e) { string msg = String.Format("Could not determine path from {0}", FileName); throw new BuildException(msg, Location, e); } DeleteFile(path); // try to delete specified directory } else if (DirectoryName != null) { string path = null; try { path = Project.GetFullPath(DirectoryName); } catch (Exception e) { string msg = String.Format("Could not determine path from {0}", DirectoryName); throw new BuildException(msg, Location, e); } DeleteDirectory(path); // delete files/directories in fileset } else { // only use the file set if file and dir attributes have NOT been set foreach (string path in DeleteFileSet.FileNames) { DeleteFile(path); } if (IncludeEmptyDirectories) { foreach (string path in DeleteFileSet.DirectoryNames) { // only delete EMPTY directories (no files, no directories) DirectoryInfo dirInfo = new DirectoryInfo(path); if ((dirInfo.GetFiles().Length == 0) && (dirInfo.GetDirectories().Length == 0)) { DeleteDirectory(path); } } } } } void DeleteDirectory(string path) { try { if (Directory.Exists(path)) { if (Verbose) { Log.WriteLine(LogPrefix + "Deleting directory {0}", path); } if (path.Length > 10) { Directory.Delete(path, true); } else { // TODO: remove this once this task is fully tested and NAnt is at 1.0 Console.WriteLine(LogPrefix + "Path {0} is too close to root to delete this early in development", path); } } else { throw new DirectoryNotFoundException(); } } catch (Exception e) { if (FailOnError) { string msg = String.Format("Cannot delete directory {0}", path); throw new BuildException(msg, Location, e); } } } void DeleteFile(string path) { try { if (File.Exists(path)) { if (Verbose) { Log.WriteLine(LogPrefix + "Deleting file {0}", path); } File.Delete(path); } else { throw new FileNotFoundException(); } } catch (Exception e) { if (FailOnError) { string msg = String.Format("Cannot delete file {0}", path); throw new BuildException(msg, Location, e); } } } } } --- NEW FILE --- // NAnt - A .NET build tool // Copyright (C) 2001 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 (ger...@ya...) namespace SourceForge.NAnt { using System; [TaskName("echo")] public class EchoTask : Task { [TaskAttribute("message", Required=true)] string _message = null; protected override void ExecuteTask() { Log.WriteLine(LogPrefix + _message); } } } --- NEW FILE --- // NAnt - A .NET build tool // Copyright (C) 2001 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 (ger...@ya...) namespace SourceForge.NAnt { using System; using System.IO; [TaskName("exec")] public class ExecTask : ExternalProgramBase { [TaskAttribute("program", Required=true)] string _program = null; [TaskAttribute("commandline")] string _commandline = null; [TaskAttribute("basedir")] string _baseDirectory = null; // Stop the buildprocess if the command exits with a returncode other than 0. [TaskAttribute("failonerror")] [BooleanValidator()] string _failonerror = Boolean.TrueString; // TODO: change this to Int32Parameter to ensure value is a valid Int32 type after text expansion [TaskAttribute("timeout")] [Int32Validator()] string _timeout = Int32.MaxValue.ToString(); public override string ProgramFileName { get { return Project.GetFullPath(_program); } } public override string ProgramArguments { get { return _commandline; } } public override string BaseDirectory { get { return Project.GetFullPath(_baseDirectory); } } public override int TimeOut { get { return Convert.ToInt32(_timeout); } } public override bool FailOnError { get { return Convert.ToBoolean(_failonerror); } } protected override void ExecuteTask() { Log.WriteLine(LogPrefix + "{0} {1}", Path.GetFileName(ProgramFileName), GetCommandLine()); base.ExecuteTask(); } } } --- NEW FILE --- // NAnt - A .NET build tool // Copyright (C) 2001 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 (ger...@ya...) namespace SourceForge.NAnt { using System; using System.Collections.Specialized; using System.Diagnostics; using System.IO; using System.Text; using System.Xml; public abstract class ExternalProgramBase : Task { [TaskAttribute("verbose")] [BooleanValidator()] string _verbose = Boolean.FalseString; public abstract string ProgramFileName { get; } public abstract string ProgramArguments { get; } public virtual string BaseDirectory { get { if (Project != null) { return Project.BaseDirectory; } else { return null; } } } public virtual int TimeOut { get { return Int32.MaxValue; } } public virtual bool FailOnError { get { return true; } } public bool Verbose { get { return (Project.Verbose || Convert.ToBoolean(_verbose)); } } StringCollection _args = new StringCollection(); protected override void InitializeTask(XmlNode taskNode) { // initialize the _args collection foreach (XmlNode optionNode in taskNode.SelectNodes("arg")) { // TODO: decide if we should enforce arg elements not being able // to accept a file and value attribute on the same element. // Ideally this would be down via schema and since it doesn't // really hurt for now I'll leave it in. XmlNode valueNode = optionNode.SelectSingleNode("@value"); if (valueNode != null) { _args.Add(Project.ExpandText(valueNode.Value)); } XmlNode fileNode = optionNode.SelectSingleNode("@file"); if (fileNode != null) { _args.Add(Project.GetFullPath(Project.ExpandText(fileNode.Value))); } } } public string GetCommandLine() { // append any nested <arg> arguments to command line StringBuilder arguments = new StringBuilder(ProgramArguments); foreach (string arg in _args) { arguments = arguments.Append(' '); arguments = arguments.Append(arg); } return arguments.ToString(); } protected override void ExecuteTask() { try { // create process to launch compiler (redirect standard output to temp buffer) Process process = new Process(); process.StartInfo.FileName = ProgramFileName; process.StartInfo.Arguments = GetCommandLine(); process.StartInfo.RedirectStandardOutput = true; process.StartInfo.UseShellExecute = false; process.StartInfo.WorkingDirectory = BaseDirectory; if (Verbose) { Log.WriteLine(LogPrefix + "{0}>{1} {2}", process.StartInfo.WorkingDirectory, process.StartInfo.FileName, process.StartInfo.Arguments); } process.Start(); // display standard output StreamReader reader = process.StandardOutput; string output = reader.ReadToEnd(); if (output.Length > 0) { int indentLevel = Log.IndentLevel; Log.IndentLevel = 0; Log.WriteLine(output); Log.IndentLevel = indentLevel; } // wait for program to exit process.WaitForExit(TimeOut); if (FailOnError && process.ExitCode != 0) { throw new BuildException("Program error, see build log for details."); } } catch (Exception e) { throw new BuildException(e.Message, Location, e); } } } } --- NEW FILE --- // NAnt - A .NET build tool // Copyright (C) 2001 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 (ger...@ya...) namespace SourceForge.NAnt { using System; [TaskName("fail")] public class FailTask : Task { [TaskAttribute("message")] string _message = null; protected override void ExecuteTask() { string message = _message; if (message == null) { message = "No message"; } throw new BuildException(message); } } } --- NEW FILE --- // NAnt - A .NET build tool // Copyright (C) 2001 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 (ian...@an...) namespace SourceForge.NAnt { using System; using System.Xml; using System.Collections; using System.Collections.Specialized; /// <summary> /// Summary description for IncludeTask. /// </summary> [TaskName("include")] // TODO make into ant:include public class IncludeTask : Task { /// <summary>hours to to add to the sleep time</summary> [TaskAttribute("href", Required=true)] string _href = null; // Attribute properties public string Href { get { return _href; } } XPathTextPositionMap _positionMap; // created when Xml document is loaded TaskCollection _tasks = new TaskCollection(); // static members static System.Collections.Stack _includesStack = new Stack(); static bool IsIncluded( string href ) { bool result = false; IEnumerator stackenum = _includesStack.GetEnumerator(); while ( stackenum.MoveNext()) { if ( href == (string)stackenum.Current ) { result = true; break; } } return result; } protected void InitializeIncludedDocument(XmlDocument doc) { // Load line Xpath to linenumber array _positionMap = new XPathTextPositionMap(doc.BaseURI); // process all the non-target nodes (these are global tasks for the project) XmlNodeList taskList = doc.SelectNodes("project/*[name() != 'target']"); foreach (XmlNode taskNode in taskList) { // TODO: do somethiing like Project.CreateTask(taskNode) and have the project set the location TextPosition textPosition = _positionMap.GetTextPosition(taskNode); Task task = Project.CreateTask(taskNode); if (task != null) { // Store a local copy also so we can execute only those _tasks.Add(task); } } // execute global tasks now - before anything else // this lets us include tasks that do things like add more tasks // Here is where we should check for recursive dependencies // foreach (Task task in _tasks ) { task.Execute(); } // process all the targets XmlNodeList targetList = doc.SelectNodes("project/target"); foreach (XmlNode targetNode in targetList) { Target target = new Target(Project); target.Initialize(targetNode); Project.Targets.Add(target); } } /// <summary> /// verify parameters ///</summary> ///<param name="taskNode"> taskNode used to define this task instance </param> protected override void InitializeTask(XmlNode taskNode) { //TODO check where we are in document - if not at top level then bail out on error ... // basic recursion check if (IsIncluded( Project.GetFullPath(Href) )) { throw new BuildException("Recursive includes are not allowed", Location); } } protected override void ExecuteTask() { string fullpath = Project.GetFullPath(Href); // push ourselves onto the stack _includesStack.Push(fullpath); try { XmlDocument doc = new XmlDocument(); // Handle local file case doc.Load(fullpath); InitializeIncludedDocument(doc); } // Handling the case where a nested include causes an exception during initialization catch ( BuildException ) { throw; } catch ( Exception e) { throw new BuildException(e.Message, Location, e); } finally { // Pop off the stack _includesStack.Pop(); } } } } --- NEW FILE --- // NAnt - A .NET build tool // Copyright (C) 2001 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 (ger...@ya...) // Mike Krueger (mi...@ic...) namespace SourceForge.NAnt { using System; using System.IO; [TaskName("jsc")] public class JscTask : CompilerBase { // TODO: add JScript.NET specific compiler options here (see CscTask) protected override void WriteOptions(TextWriter writer) { // TODO: add support for compiler specific options } protected override bool NeedsCompiling() { // TODO: add checks for any referenced files OR return false to always compile return base.NeedsCompiling(); } } } --- NEW FILE --- // NAnt - A .NET build tool // Copyright (C) 2002 Ximian, Inc. // // 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 // // Martin Baulig (ma...@gn...) using System; using System.IO; namespace SourceForge.NAnt { [TaskName("mcs")] public class McsTask : CompilerBase { protected override void WriteOption(TextWriter writer, string name) { if (name.Equals("nologo")) { return; } else { writer.WriteLine("--{0}", name); } } protected override void WriteOption(TextWriter writer, string name, string arg) { if (name.Equals("out")) { writer.WriteLine("-o {0}", arg); } else if (name.Equals("reference")) { writer.WriteLine("-r {0}", arg); } else { writer.WriteLine("--{0} {1}", name, arg); } } } } --- NEW FILE --- // NAnt - A .NET build tool // Copyright (C) 2001 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 (ger...@ya...) // Ian MacLean (ian...@an...) namespace SourceForge.NAnt { using System; using System.IO; /// <summary>Creates a directory and any non-existent parent directories when necessary.</summary> [TaskName("mkdir")] public class MkDirTask : Task { [TaskAttribute("dir", Required=true)] string _dir = null; // the directory to create protected override void ExecuteTask() { try { string directory = Project.GetFullPath(_dir); if (!Directory.Exists(directory)) { Log.WriteLine(LogPrefix + "Creating directory {0}", directory); DirectoryInfo result = Directory.CreateDirectory(directory); if (result == null) { string msg = String.Format("Unknown error creating directory '{0}'", directory); throw new BuildException(msg, Location); } } } catch (Exception e) { throw new BuildException(e.Message, Location, e); } } } } --- NEW FILE --- // NAnt - A .NET build tool // Copyright (C) 2001 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 (ger...@ya...) // Ian MacLean (ian...@an...) namespace SourceForge.NAnt { using System; using System.IO; [TaskName("move")] public class MoveTask : CopyTask { /// <summary> /// Actually does the file (and possibly empty directory) copies. /// </summary> protected override void DoFileOperations() { if (FileCopyMap.Count > 0) { // loop thru our file list foreach (string sourcePath in FileCopyMap.Keys) { string destinationPath = (string)FileCopyMap[sourcePath]; if (sourcePath == destinationPath) { Log.WriteLine(LogPrefix + "Skipping self-move of {0}" + sourcePath); continue; } try { // check if directory exists if (Directory.Exists(sourcePath)) { Log.WriteLine(LogPrefix + "moving directory {0} to {1}", sourcePath, destinationPath); Directory.Move(sourcePath, destinationPath); } else { DirectoryInfo todir = new DirectoryInfo(destinationPath); if ( !todir.Exists ) { Directory.CreateDirectory( Path.GetDirectoryName(destinationPath) ); } Log.WriteLine(LogPrefix + "Moving {0} to {1}", sourcePath, destinationPath); // IM look into how Ant does this for directories File.Move(sourcePath, destinationPath); } } catch (IOException ioe) { string msg = String.Format("Failed to move {0} to {1}\n{2}", sourcePath, destinationPath, ioe.Message); throw new BuildException(msg, Location); } } } } } } --- NEW FILE --- // NAnt - A .NET build tool // Copyright (C) 2001 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 (ger...@ya...) namespace SourceForge.NAnt { using System; using System.Collections.Specialized; using System.Diagnostics; using System.IO; using System.Xml; [TaskName("nant")] public class NantTask : Task { [TaskAttribute("buildfile")] string _buildFileName = null; [TaskAttribute("basedir")] string _baseDirectory = null; // TODO: add support for multiple targets [TaskAttribute("target")] string _target = null; protected override void ExecuteTask() { string directory = Project.GetFullPath(_baseDirectory); string buildFileName = _buildFileName; if (buildFileName == null) { buildFileName = Project.FindBuildFileName(directory); } try { Log.WriteLine(LogPrefix + "{0} {1}", buildFileName, _target); Log.Indent(); Project project = new Project(); project.BaseDirectory = directory; project.BuildFileName = buildFileName; if (_target != null) { project.BuildTargets.Add(_target); } if (!project.Run()) { throw new BuildException("Nested build failed - refer to build log for exact reason."); } } finally { Log.Unindent(); } } } } --- NEW FILE --- // NAnt - A .NET build tool // Copyright (C) 2001 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 (ger...@ya...) namespace SourceForge.NAnt { using System; [TaskName("property")] public class PropertyTask : Task { [TaskAttribute("name", Required=true)] string _name = null; [TaskAttribute("value", Required=true)] string _value = String.Empty; protected override void ExecuteTask() { Project.Properties[_name] = _value; } } } --- NEW FILE --- // NAnt - A .NET build tool // Copyright (C) 2001 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 (ian...@an...) namespace SourceForge.NAnt { using System; using System.Xml; using System.Threading; /// <summary> /// A task for sleeping a short period of time, useful when a build or deployment process /// requires an interval between tasks. /// </summary> [TaskName("sleep")] public class SleepTask : Task { /// <summary>hours to to add to the sleep time</summary> [TaskAttribute("hours")] string _hours = null; /// <summary>minutes to add to the sleep time</summary> [TaskAttribute("minutes")] string _minutes = 0.ToString(); /// <summary>seconds to add to the sleep time</summary> [TaskAttribute("seconds")] string _seconds = 0.ToString(); /// <summary>milliseconds to add to the sleep time</summary> [TaskAttribute("milliseconds")] string _milliseconds = 0.ToString(); /// <summary>flag controlling whether to break the build on an error</summary> [TaskAttribute("failonerror")] [BooleanValidator()] string _failonerror = Boolean.FalseString; // Attribute properties public int Hours { get { return Convert.ToInt32(_hours); } } public int Minutes { get { return Convert.ToInt32(_minutes); } } public int Seconds { get { return Convert.ToInt32(_seconds); } } public int Milliseconds { get { return Convert.ToInt32(_milliseconds); } } public bool FailOnError { get { return Convert.ToBoolean(_failonerror); } } ///return time to sleep private int GetSleepTime() { return ((((int) Hours * 60) + Minutes) * 60 + Seconds) * 1000 + Milliseconds; } ///<summary> return time to sleep </summary> ///<param name="millis"> </param> private void DoSleep(int millis ) { Thread.Sleep(millis); } /// <summary> /// verify parameters ///</summary> ///<param name="taskNode"> taskNode used to define this task instance </param> protected override void InitializeTask(XmlNode taskNode) { if (GetSleepTime() < 0) { throw new BuildException("Negative sleep periods are not supported", Location); } } protected override void ExecuteTask() { int sleepTime = GetSleepTime(); Log.WriteLine(LogPrefix + "sleeping for {0} milliseconds", sleepTime); DoSleep(sleepTime); } } } --- NEW FILE --- // NAnt - A .NET build tool // Copyright (C) 2001 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 // // Serge (se...@wi...) // Gerry Shaw (ger...@ya...) namespace SourceForge.NAnt { using System; using System.IO; using System.Xml; using System.Xml.Xsl; using System.Xml.XPath; using System.Text.RegularExpressions; [TaskName("style")] public class StyleTask : Task { // TODO: consider prefixing private fields with _ to stay consistent (gs) [TaskAttribute("basedir", Required=false)] string baseDir = null; [TaskAttribute("destdir", Required=false)] string destDir = null; [TaskAttribute("extension", Required=false)] string extension = "html"; [TaskAttribute("style", Required=true)] string xsltFile = null; [TaskAttribute("in", Required=true)] string srcFile = null; [TaskAttribute("out", Required=false)] string destFile = null; private static string GetPath(string dir, string file) { // TODO: remove platform dependencies by using System.IO.Path (gs) string d = (dir == null) ? "" : Regex.Replace(dir, "/", "\\"); return (d==null || d=="") ? (file==null || file=="") ? "" : file : d.EndsWith("\\") ? d +file : d + "\\" + file; } private XmlReader CreateXmlReader(string dir, string file) { string xmlPath = GetPath(dir, file); XmlTextReader xmlReader = null; try { xmlReader = new XmlTextReader(new FileStream(xmlPath, FileMode.Open)); } catch (Exception) { xmlReader = null; } return xmlReader; } private XmlWriter CreateXmlWriter(string dir, string file) { string xmlPath = GetPath(dir, file); XmlWriter xmlWriter = null; string targetDir = Path.GetDirectoryName(Path.GetFullPath(xmlPath)); if (targetDir != null && targetDir != "" && !Directory.Exists(targetDir)) { Directory.CreateDirectory(targetDir); } try { // UTF-8 encoding will be used xmlWriter = new XmlTextWriter(xmlPath, null); } catch (Exception) { xmlWriter = null; } return xmlWriter; } protected override void ExecuteTask() { string destFile = this.destFile; if (destFile == null || destFile == "") { // TODO: use System.IO.Path (gs) string ext = extension[0]=='.' ? extension : "." + extension; int extPos = srcFile.LastIndexOf('.'); if (extPos == -1) { destFile = srcFile + ext; } else { destFile = srcFile.Substring(0, extPos) + ext; } } string srcPa... [truncated message content] |