[Csmail-patches] CVS: csmail/nant/src AssemblyInfo.cs,NONE,1.1 BuildException.cs,NONE,1.1 DirectoryS
Status: Pre-Alpha
Brought to you by:
mastergaurav
From: Gaurav V. <mas...@us...> - 2002-07-24 10:57:57
|
Update of /cvsroot/csmail/csmail/nant/src In directory usw-pr-cvs1:/tmp/cvs-serv1717/nant/src Added Files: AssemblyInfo.cs BuildException.cs DirectoryScanner.cs FileSet.cs Location.cs NAnt.cs NAnt.exe Project.cs PropertyDictionary.cs Target.cs TargetCollection.cs Task.cs TaskBuilder.cs TaskBuilderCollection.cs TaskCollection.cs TaskFactory.cs Log Message: 2002-02-24 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> * **.**/** -- Final single commit for all the files. --- 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...) using System.Reflection; using System.Runtime.CompilerServices; [assembly: AssemblyTitle("NAnt")] [assembly: AssemblyDescription("A .NET Build Tool")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("http://nant.sourceforge.net/")] [assembly: AssemblyProduct("NAnt")] [assembly: AssemblyCopyright("Copyright (C) 2001 Gerry Shaw")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] [assembly: AssemblyVersion("0.6.0.*")] // This will not compile with Visual Studio. If you want to build a signed // executable use the NAnt build file. To build under Visual Studio just // exclude this file from the build. [assembly: AssemblyDelaySign(false)] [assembly: AssemblyKeyName("")] --- 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; /// <summary> /// Thrown whenever an error occurs during the build. /// </summary> public class BuildException : ApplicationException { private Location _location = Location.UnknownLocation; /// <summary> /// Constructs a build exception with no descriptive information. /// </summary> public BuildException() : base() { } /// <summary> /// Constructs an exception with a descriptive message. /// </summary> public BuildException(String message) : base(message) { } /// <summary> /// Constructs an exception with a descriptive message and an /// instance of the Exception that is the cause of the current Exception. /// </summary> public BuildException(String message, Exception e) : base(message, e) { } /// <summary> /// Constructs an exception with a descriptive message and location /// in the build file that caused the exception. /// </summary> /// <param name="location">Location in the build file where the exception occured.</param> public BuildException(String message, Location location) : base(message) { _location = location; } /// <summary> /// Constructs an exception with the given descriptive message, the /// location in the build file and an instance of the Exception that /// is the cause of the current Exception. /// </summary> /// <param name="message">The error message that explains the reason for the exception.</param> /// <param name="location">Location in the build file where the exception occured.</param> /// <param name="e">An instance of Exception that is the cause of the current Exception.</param> public BuildException(String message, Location location, Exception e) : base(message, e) { _location = location; } public override string Message { get { string message = base.Message; // only include location string if not empty string locationString = _location.ToString(); if (locationString != String.Empty) { message = locationString + " " + message; } return 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...) /* Examples: "**\*.class" matches all .class files/dirs in a directory tree. "test\a??.java" matches all files/dirs which start with an 'a', then two more characters and then ".java", in a directory called test. "**" matches everything in a directory tree. "**\test\**\XYZ*" matches all files/dirs that start with "XYZ" and where there is a parent directory called test (e.g. "abc\test\def\ghi\XYZ123"). Example of usage: DirectoryScanner scanner = DirectoryScanner(); scanner.Includes.Add("**\\*.class"); scanner.Exlucdes.Add("modules\\*\\**"); scanner.BaseDirectory = "test"; scanner.Scan(); foreach (string filename in GetIncludedFiles()) { Console.WriteLine(filename); } */ namespace SourceForge.NAnt { using System; using System.Collections.Specialized; using System.IO; using System.Text; using System.Text.RegularExpressions; public class DirectoryScanner { string _baseDirectory = Environment.CurrentDirectory; // holds the nant patterns StringCollection _includes = new StringCollection(); StringCollection _excludes = new StringCollection(); // holds the nant patterns converted to regular expression patterns StringCollection _includePatterns = null; StringCollection _excludePatterns = null; // holds the result from a scan StringCollection _fileNames = null; StringCollection _directoryNames = null; public StringCollection Includes { get { return _includes; } } public StringCollection Excludes { get { return _excludes; } } public string BaseDirectory { get { return _baseDirectory; } set { _baseDirectory = value; } } public StringCollection FileNames { get { if (_fileNames == null) { Scan(); } return _fileNames; } } public StringCollection DirectoryNames { get { if (_directoryNames == null) { Scan(); } return _directoryNames; } } public void Scan() { _includePatterns = new StringCollection(); foreach (string pattern in Includes) { _includePatterns.Add(ToRegexPattern(pattern)); } _excludePatterns = new StringCollection(); foreach (string pattern in Excludes) { _excludePatterns.Add(ToRegexPattern(pattern)); } _fileNames = new StringCollection(); _directoryNames = new StringCollection(); ScanDirectory(Path.GetFullPath(BaseDirectory)); } void ScanDirectory(string path) { // get info for the current directory DirectoryInfo currentDirectoryInfo = new DirectoryInfo(path); // scan subfolders foreach (DirectoryInfo directoryInfo in currentDirectoryInfo.GetDirectories()) { ScanDirectory(directoryInfo.FullName); } // scan files foreach (FileInfo fileInfo in currentDirectoryInfo.GetFiles()) { string filename = Path.Combine(path, fileInfo.Name); if (IsPathIncluded(filename)) { _fileNames.Add(filename); } } // Check current path last so that delete task will correctly // delete empty directories. This may *seem* like a special case // but it is more like formalizing something in a way that makes // writing the delete task easier :) if (IsPathIncluded(path)) { _directoryNames.Add(path); } } bool IsPathIncluded(string path) { bool included = false; // check path against includes foreach (string pattern in _includePatterns) { Match m = Regex.Match(path, pattern); if (m.Success) { included = true; break; } } // check path against excludes if (included) { foreach (string pattern in _excludePatterns) { Match m = Regex.Match(path, pattern); if (m.Success) { included = false; break; } } } return included; } string ToRegexPattern(string nantPattern) { StringBuilder pattern = new StringBuilder(nantPattern); // NAnt patterns can use either / \ as a directory seperator. // We must replace both of these characters with Path.DirectorySeperatorChar pattern.Replace('/', Path.DirectorySeparatorChar); pattern.Replace('\\', Path.DirectorySeparatorChar); // Patterns MUST be full paths. if (!Path.IsPathRooted(pattern.ToString())) { pattern = new StringBuilder(Path.Combine(BaseDirectory, pattern.ToString())); } // The '\' character is a special character in regular expressions // and must be escaped before doing anything else. pattern.Replace(@"\", @"\\"); // Escape the rest of the regular expression special characters. // NOTE: Characters other than . $ ^ { [ ( | ) * + ? \ match themselves. // TODO: Decide if ] and } are missing from this list, the above // list of characters was taking from the .NET SDK docs. pattern.Replace(".", @"\."); pattern.Replace("$", @"\$"); pattern.Replace("^", @"\^"); pattern.Replace("{", @"\{"); pattern.Replace("[", @"\["); pattern.Replace("(", @"\("); pattern.Replace(")", @"\)"); pattern.Replace("+", @"\+"); // Special case directory seperator string under Windows. string seperator = Path.DirectorySeparatorChar.ToString(); if (seperator == @"\") { seperator = @"\\"; } // Convert NAnt pattern characters to regular expression patterns. // SPECIAL CASE: to match subdirectory OR current directory. If // we don't do this then we can write something like 'src/**/*.cs' // to match all the files ending in .cs in the src directory OR // subdirectories of src. pattern.Replace(seperator + "**", "(" + seperator + ".|)|"); // | is a place holder for * to prevent it from being replaced in next line pattern.Replace("**", ".|"); pattern.Replace("*", "[^" + seperator + "]*"); pattern.Replace("?", "[^" + seperator + "]?"); pattern.Replace('|', '*'); // replace place holder string // Help speed up the search pattern.Insert(0, '^'); // start of line pattern.Append('$'); // end of line return pattern.ToString(); } } } --- 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.IO; public class FileSet { /// <summary> /// Used to determine if a file has a more recent last write time then the specified write time. /// </summary> /// <param name="fileNames">A collection of filenames to check last write times against.</param> /// <param name="targetLastWriteTime">The datetime to compare against.</param> /// <returns><c>True</c> if at least one file in <c>fileNames</c> has a last write time greater than <c>targetLastWriteTime</c>.</returns> public static bool MoreRecentLastWriteTime(StringCollection fileNames, DateTime targetLastWriteTime) { foreach (string fileName in fileNames) { FileInfo fileInfo = new FileInfo(fileName); if (!fileInfo.Exists) { return true; } if (fileInfo.LastWriteTime > targetLastWriteTime) { return true; } } return false; } // We can't just use the DirectoryScanner's includes/excludes collections // because when we do a Scan() we need to first expand any macros. StringCollection _includes = new StringCollection(); StringCollection _excludes = new StringCollection(); DirectoryScanner _scanner = null; string _baseDirectory; bool _includeAllByDefault; Task _task = null; public FileSet(bool includeAllByDefault) { IncludeAllByDefault = includeAllByDefault; Excludes.Add("**/CVS/*"); Excludes.Add("**/.cvsignore"); } /// <remarks> /// Will be automagically set in Task.AutoInitializeAttributes() if /// file set has TaskFileSetAttribute set on it. /// </remarks> // TODO: change this to IMacroExpander public Task Task { get { return _task; } set { _task = value; } } public string BaseDirectory { get { return _baseDirectory; } set { _baseDirectory = value; } } /// <summary>Determines if scan should produce everything or nothing /// if there are no Includes set. Default false.</summary> public bool IncludeAllByDefault { get { return _includeAllByDefault; } set { _includeAllByDefault = value; } } public StringCollection Includes { get { return _includes; } } public StringCollection Excludes { get { return _excludes; } } public void Scan() { // get project (only for expanding macros) Project expander = Task.Project; _scanner = new DirectoryScanner(); _scanner.BaseDirectory = expander.GetFullPath(BaseDirectory);; foreach (string path in Includes) { _scanner.Includes.Add(expander.ExpandText(path)); } if (Includes.Count <= 0 && IncludeAllByDefault) { _scanner.Includes.Add("**"); } foreach (string path in Excludes) { _scanner.Excludes.Add(expander.ExpandText(path)); } _scanner.Scan(); } public StringCollection DirectoryNames { get { if (_scanner == null) { Scan(); } return _scanner.DirectoryNames; } } public StringCollection FileNames { get { if (_scanner == null) { Scan(); } return _scanner.FileNames; } } } } --- 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...) // Gerry Shaw (ger...@ya...) namespace SourceForge.NAnt { using System; using System.IO; /// <summary> /// Stores the file name and line number in a file. /// </summary> public class Location { string _fileName; int _lineNumber; int _columnNumber; public static readonly Location UnknownLocation = new Location(); /// <summary> /// Creates a location consisting of a file name and line number. ///</summary> public Location(string fileName, int lineNumber, int columnNumber) { Uri uri = new Uri(fileName); string strfileName = uri.LocalPath; // convert from URI syntax to local path Init(strfileName, lineNumber, columnNumber); } /// <summary> /// Creates a location consisting of a file name but no line number. ///</summary> public Location(string fileName) { Init(fileName, 0, 0); } /// <summary> /// Creates an "unknown" location. ///</summary> private Location() { Init(null, 0, 0); } /// <summary> /// Private Init function. ///</summary> private void Init(string fileName, int lineNumber, int columnNumber) { _fileName = fileName; _lineNumber = lineNumber; _columnNumber = columnNumber; } /// <summary> /// Returns the file name, line number and a trailing space. An error /// message can be appended easily. For unknown locations, returns /// an empty string. ///</summary> public override string ToString() { string message = ""; if (_fileName != null) { message += _fileName; if (_lineNumber != 0) { message += ":"; message += _lineNumber.ToString(); } message += ":"; } return 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.Diagnostics; using System.IO; using System.Text.RegularExpressions; public class NAnt { public static int Main(string[] args) { int returnCode = 0; Log.IndentSize = 12; Project project = new Project(); const string buildfileOption = "-buildfile:"; const string basedirOption = "-basedir:"; const string setOption = "-set:"; const string helpOption = "-h"; // allow -h and -help const string verboseOption = "-verbose"; bool showHelp = false; foreach (string arg in args) { if (arg.StartsWith(buildfileOption)) { project.BuildFileName = arg.Substring(buildfileOption.Length); } else if (arg.StartsWith(basedirOption)) { project.BaseDirectory = arg.Substring(basedirOption.Length); } else if (arg.StartsWith(basedirOption)) { project.BaseDirectory = arg.Substring(basedirOption.Length); } else if (arg.StartsWith(setOption)) { // TODO: implement user defined properties // user defined properties from command line or file should be // marked so that they cannot be overwritten by the build file // ie, once set they are set for the rest of the build. Match match = Regex.Match(arg, @"-set:(\w+)=(\w*)"); if (match.Success) { string name = match.Groups[1].Value; string value = match.Groups[2].Value; project.Properties.AddReadOnly(name, value); } } else if (arg.StartsWith(helpOption)) { showHelp = true; } else if (arg.StartsWith(verboseOption)) { project.Verbose = true; } else if (arg.Length > 0) { // must be a target (or mistake ;) project.BuildTargets.Add(arg); } } // Get version information directly from assembly. This takes more // work but prevents the version numbers from getting out of sync. ProcessModule module = Process.GetCurrentProcess().MainModule; FileVersionInfo info = FileVersionInfo.GetVersionInfo(module.FileName); string programName = Path.GetFileNameWithoutExtension(info.FileName); // in case the user has renamed the program if (showHelp) { const int optionPadding = 23; Console.WriteLine("NAnt Version {0} Copyright (C) 2001 Gerry Shaw", info.FileMajorPart + "." + info.FileMinorPart + "." + info.FileBuildPart); Console.WriteLine("http://nant.sourceforge.net/"); Console.WriteLine(); Console.WriteLine("NAnt comes with ABSOLUTELY NO WARRANTY."); Console.WriteLine("This is free software, and you are welcome to redistribute it under certain"); Console.WriteLine("conditions set out by the GNU General Public License. A copy of the license"); Console.WriteLine("is available in the distribution package and from the NAnt web site."); Console.WriteLine(); Console.WriteLine("usage: {0} [options] [target]", programName); Console.WriteLine(); Console.WriteLine("options:"); Console.WriteLine(" {0} use given buildfile", (buildfileOption + "<file>").PadRight(optionPadding)); Console.WriteLine(" {0} set project base directory", (basedirOption + "<dir>").PadRight(optionPadding)); Console.WriteLine(" {0} use value for given property", (setOption + "<property>=<value>").PadRight(optionPadding)); Console.WriteLine(" {0} print this message", helpOption.PadRight(optionPadding)); Console.WriteLine(); Console.WriteLine("If no buildfile is specified the first file ending in .build will be used."); } else { if (!project.Run()) { Console.WriteLine("Try `{0} -help' for more information.", programName); returnCode = 1; // set return code to indicate an error occurred } } Log.Close(); return returnCode; } } } --- NEW FILE --- MZ $ * ( &Þ&r ( Þ + + ( ( ( Þ&rÇ ( Þ ( + + + ( + } + + ( Ð ( t + ~ + + + 8Ø 8² ( t o -$ o ( o ( o Ð ( t t# 9æ ,o oÆ o" +0o# t o oÉ o$ &o% -ÇÞu* Ür o" +,o# t o o$ &o% -ËÞu* Ü X i?Cþÿÿo' Ð @þÿÿ* 8é 8à ( t t! Ð (( t +E o o ( i2³ X i?2ÿÿÿo' Ð @ÿÿÿ* *0 + + + + + + + o" +o o# t r ,{ oë &r ,({ oë & o% -Þ u* Ü* { + o- o. o/ o0 -ào1 + o3 o- o3 (4 o3 o6 o3 o7 o3 o/ (2 o9 ¢o3 o: ¢o3 o; ¢(¨ &o= o> o? 1( &o1 ,rA ( } } + + + + + + + + + + + (F + oH -+X(? (Á (Á (Á } (< " rÛ ró (9 r (: (; (< +o- rq o0 -ã(> +o- r o0 -ã(= +o- r o0 -ã(? +o- oM o0 -æoO (2 (¦ o> (¦ (5 { } } + + + + + + + + + + + + oT > oU 8è t! t! ,#(P (¦ (Y -3 (Z &(P Þ r¿ ( :ÿÿÿÞu* Ü* ( (H < (_ +( (G ,;oH ,oI oI (` +(M +$( 8 ob sG sG oH ,=oH ,oI oI (` + (M ,(Q +$( :dÿÿÿoR } } } } }! }" }# {$ * + + + + + + + + ( Þ rÇ ( ( + o- (` -æ([ +0 o- sd oe i-of i-(_ -Ç* ,T(] 1 (g +( (h +si zÞ% (Z ( ,1(] +sk zÞ% (Z ( }' }( }) (¦ + + + + + o- ¢(4 }/ }0 -rX s± + ~5 +o# t! , +o% -á+ s¬ o" +7o# t &o% -ÀÞu* Ü{4 +o# t -âÞu* Ürª o" +7o# t &o% -ÀÞu* Ü* ~5 su ov (o ( &Ü* 5 + (Y -G( -r< ( ( >' oU 8í t! (Q t! ,( (¦ ,2( +Ksd oH -(X (Z &( Þ# r ( ( :ÿÿÿÞu* Ü* {7 &oä }; + + + + + + * ( }= }> }? }@ +rb ,1rb -$r^ -r^ +( +,rb -+rb s s Þ&Þ (F (X ,rb ,(Y -(Z &s Þ&Þ ? , rb ,^{C ..rd +{C 3{E +{E ( {A sG sG oH -rh -r¨ ,*oI oI (` -oI oI (` + 9+ {A ( (¦ 9Í s ( ( (¦ Þ"oB s² s² ¢rN ¢( (¦ ÞoB s² ( ( ( ( (¦ oñ oñ oñ + * * Ü* + + + or &~K + +o# t ( .oO o% -ÞÞu* Ü* +o# t o o% -æÞu* Ü* z( r¢ &o1 QL +o# t o o% -åÞu* Ü( +o# t o% -æÞu* Ü* (¦ +o# t oM o% -åÞu* Ü( +o# t o% -æÞu* ÜL (¤ (¦ }P rZ rb s {P 8î Q r¦ 9Ï Q r¼ 9° Q rÒ 9 Q rþ 9r rb /a< rb X X2ß Xo XYo + o 1 o +" & X X2äo y" +o y" rZ ,+ rZ ¢ r: {P o¤ sª o o¥ :þÿÿ*0 (® ,{P y +~M + rb o© & oª & o« ,+X o« , o¬ -æo© &o T r> --Xr rb ,+rZ o T r> :@ÿÿÿrZ + * * *0 }Q }Q {Q ( , r¢ + + + + + + }U +o- {U &o0 -ÞsD }V +o- {V &o0 -ÞsD }W }X (½ of +o² (½ +/o^ (E (¾ &Xi2É(¾ &* {U +o- (³ o´ , + o0 -Û,6{V +o- (³ o´ , + o0 -Ù+ /~] oµ &\~] oµ &o1 (¶ -(¸ (E s+ r^ &rd &rT &r^ &rh &r &rx &r &r &~] (¸ r^ ,rH rx o· &r &r¬ o· &r¼ o· &|*oµ &^o¹ &$o. &o1 + }R }S }T *0 +, o- sG oH -ÞoI (` ,Þ o0 -Ì+ }Y }Z (È &(Ê &*0 + + + + + sÀ + o- {[ & o0 -Ù(É 0(Ç &(Ê + o- {[ & o0 -Ù{[ + + s» o¼ (Ñ (Ñ (Ñ {_ {` |` ( rô + ( , rø o¾ oÝ , r o¾ oÛ , r o¾ oÛ ,O r0 o´ ,7o¿ oÀ oÁ o¿ oÀ oÁ oâ ,+, rX , oß 1 oà &Xi?Øþÿÿ( oà oÄ (Å oÆ (Ç 9 " " " (h rÈ (Ì r rR rë r (Ì r (Ì rM r_ (h r· (h r (h r (h (Ì r¿ +oä ( + *0 * sd ~c i1o^ (E + }i s + + + + + + + + ( (Ú (Û (Û (W ,4(Ú s± (Ü Þ r2 s² (Ï (¥ i" ÞX(¥ (¦ ,oÑ oB (¦ (¦ +(Ô oÕ +HÐ oÖ ,*o× -"{m s o (Ù o (Û o }e oÚ oU +1o# t! t! oï -ÆÞu* Üoq s¬ o" +9o# t &o% -¾Þu* Ü(á +o# t -âÞu* Ürª o" +-o# t oü or &o% -ÊÞu* Ü*4 -(à &(à +o- (è -ê*0 -rÚ s± + ,-{l {N 9 oÝ +Vo# tU 1@oß o¿ oÀ oà oá oÁ (â ob o% -¡Þu* Ü+ ,(¶ - (E +(F + -{o &(ä oå * - (ä oå *0 oÛ t! + - (ä oæ *0 *0 }o * }t (ø + + + + + -r2 (ö ,Xo < +, oé o? 1(û & X i2Ìr¬ o" +0o# t &o% -ÇÞu* Ü* +9 o- (÷ s± -¿(¥ +o# t -äÞu* ÜÞ}r +o# t( oõ ,Þo% -ÚÞu* Ü+ * }u ( Ð ( t + + + +( + t o Þ o (r & + +o# t* o ,Þo% -ÚÞu* Ü+ * * ( + + ( s± 4 4 ¨ × ) ) ) ) ) ) ) ) « Û à ôc r ³$¹ 9 ÌI8 LEX¦ÉsÛ Ô Q Ì ±`8 xÛ á¸4 ¹ÁÓ/ É Ñ4 i^£ Ùø4 áø4 é û y y Öy÷Ñn ùA î = e n y ~ ° Ó ß å ë 3Hip¯Ëßõü &, A % % % % t_Captures ¨ ¨¬ ± references ==é± ¡| ¡ ¥© 1= %¥© %%¥© ͱ ±a ¨ --- 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.Reflection; using System.Text.RegularExpressions; using System.Xml; using System.Xml.XPath; using System.Collections; using System.Collections.Specialized; /// <summary> /// Central representation of an NAnt project. /// </summary> public class Project { public static readonly string BuildFilePattern = "*.build"; /// <summary> /// Finds the file name for the build file in the specified directory. /// </summary> /// <param name="directory">The directory to look for a build file. When in doubt use Environment.CurrentDirectory for directory.</param> /// <returns>The path to the build file or <c>null</c> if no build file could be found.</returns> public static string FindBuildFileName(string directory) { string buildFileName = null; // find first file ending in .build DirectoryInfo directoryInfo = new DirectoryInfo(directory); FileInfo[] files = directoryInfo.GetFiles(BuildFilePattern); if (files.Length > 0) { buildFileName = Path.Combine(directory, files[0].Name); } return buildFileName; } string _name; string _defaultTargetName; string _baseDirectory; string _buildFileName; bool _verbose = false; StringCollection _buildTargets = new StringCollection(); TaskCollection _tasks = new TaskCollection(); TargetCollection _targets = new TargetCollection(); XPathTextPositionMap _positionMap; // created when Xml document is loaded TaskFactory _taskFactory; // created in constructor PropertyDictionary _properties = new PropertyDictionary(); public Project() { _taskFactory = new TaskFactory(this); } /// <summary> /// The name of the project. /// </summary> public string Name { get { return _name; } set { _name = value; } } public string BaseDirectory { get { return _baseDirectory; } set { _baseDirectory = value; } } public string BuildFileName { get { return _buildFileName; } set { _buildFileName = value; } } /// <summary> /// When true tasks should output more output. /// </summary> public bool Verbose { get { return _verbose; } set { _verbose = value; } } /// <summary> /// The list of targets to built. /// </summary> /// <remarks> /// Targets are built in the order they appear in the collection. If /// the collection is empty the default target will be built. /// </remarks> public StringCollection BuildTargets { get { return _buildTargets; } } /// <summary> /// The list of tasks to perform before any targets executed. /// </summary> /// <remarks> /// Tasks are executed in the order they appear in the collection. /// </remarks> public TaskCollection Tasks { get { return _tasks; } } public PropertyDictionary Properties { get { return _properties; } } public TargetCollection Targets { get { return _targets; } } public bool Run() { bool buildResult = false; try { DateTime startTime = DateTime.Now; if (BaseDirectory == null) { BaseDirectory = Environment.CurrentDirectory; } BaseDirectory = Path.GetFullPath(BaseDirectory); if (BuildFileName == null || BuildFileName == String.Empty) { BuildFileName = FindBuildFileName(BaseDirectory); if (BuildFileName == null) { throw new BuildException(String.Format("Could not find a '{0}' file in '{1}'", BuildFilePattern, BaseDirectory)); } } Log.WriteLine("Buildfile: {0}", BuildFileName); if (Verbose) { Log.WriteLine("Base Directory: {0}", BaseDirectory); } XmlDocument doc = new XmlDocument(); try { doc.Load(BuildFileName); // TODO: validate against xsd schema } catch (XmlException e) { throw new BuildException(String.Format("Could not load '{0}'", BuildFileName), e); } Initialize(doc); Properties.Add("nant.buildfile", BuildFileName); Execute(); Log.WriteLine(); Log.WriteLine("BUILD SUCCEEDED"); TimeSpan buildTime = DateTime.Now - startTime; Log.WriteLine(); Log.WriteLine("Total time: {0} seconds", (int) buildTime.TotalSeconds); buildResult = true; } catch (BuildException e) { Log.WriteLine(); Log.WriteLine("BUILD FAILED"); Log.WriteLine(e.Message); if (e.InnerException != null) { Log.WriteLine(e.InnerException.Message); } } catch (Exception e) { // all other exceptions should have been caught Log.WriteLine(); Log.WriteLine("INTERNAL ERROR"); Log.WriteLine(e.ToString()); } return buildResult; } public int AddTasks(string assemblyPath) { Assembly assembly; if (assemblyPath == null) { assembly = Assembly.GetExecutingAssembly(); } else { assembly = Assembly.LoadFrom(assemblyPath); } int taskCount = 0; foreach(Type type in assembly.GetTypes()) { if (type.IsSubclassOf(typeof(Task)) && !type.IsAbstract) { if (_taskFactory.Builders.Add(new TaskBuilder(type.FullName, assemblyPath))) { taskCount++; } } } return taskCount; } public void Initialize(XmlDocument doc) { Name = doc.SelectSingleNode("project/@name").Value; // make it possible for user to override this value if (BaseDirectory == null) { BaseDirectory = doc.SelectSingleNode("project/@basedir").Value; } // used only if BuildTargets collection is empty _defaultTargetName = doc.SelectSingleNode("project/@default").Value; // initialize builtin tasks AddTasks(null); // init static built in properties Properties.Add("nant.project.name", Name); Properties.Add("nant.base.dir", BaseDirectory); Properties.Add("nant.default.name", _defaultTargetName); // add all environment variables IDictionary variables = Environment.GetEnvironmentVariables(); foreach (string name in variables.Keys) { string value = (string) variables[name]; Properties.Add("nant.env." + name, value); } // 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 = CreateTask(taskNode); if (task != null) { Tasks.Add(task); } } // execute global tasks now - before anything else // this lets us include tasks that do things like add more tasks 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(this); target.Initialize(targetNode); Targets.Add(target); } } public void Execute() { if (BuildTargets.Count == 0) { BuildTargets.Add(_defaultTargetName); } foreach(string targetName in BuildTargets) { Execute(targetName); } } public void Execute(string targetName) { Target target = Targets.Find(targetName); if (target == null) { throw new BuildException(String.Format("unknown target '{0}'", targetName)); } target.Execute(); } public Task CreateTask(XmlNode taskNode) { return CreateTask(taskNode, null); } public Task CreateTask(XmlNode taskNode, Target target) { Task task = _taskFactory.CreateTask(taskNode, target); if (task != null) { // save task location in case of error TextPosition pos = _positionMap.GetTextPosition(taskNode); // initialize the task task.Initialize(taskNode, new Location(taskNode.BaseURI, pos.Line, pos.Column)); } return task; } public string ExpandText(string input) { string output = input; if (input != null) { const string pattern = @"\$\{([^\}]*)\}"; foreach (Match m in Regex.Matches(input, pattern)) { if (m.Length > 0) { string token = m.ToString(); string propertyName = m.Groups[1].Captures[0].Value; string propertyValue = Properties[propertyName]; if (propertyValue != null) { output = output.Replace(token, propertyValue); } } } } return output; } public string GetFullPath(string path) { string baseDir = ExpandText(BaseDirectory); if (path != null) { if (!Path.IsPathRooted(path)) { path = Path.Combine(baseDir, path); } } else { path = baseDir; } return Path.GetFullPath(path); } } } --- 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.Collections; using System.Collections.Specialized; public class PropertyDictionary : DictionaryBase { /// <summary> /// Maintains a list of the property names that are readonly. /// </summary> StringCollection _readOnlyProperties = new StringCollection(); /// <summary> /// Adds a property that cannot be changed. /// </summary> /// <remarks> /// Properties added with this method can never be changed. Note that /// they are removed if the <c>Clear</c> method is called. /// </remarks> /// <param name="name">Name of property</param> /// <param name="value">Value of property</param> public void AddReadOnly(string name, string value) { if (!_readOnlyProperties.Contains(name)) { _readOnlyProperties.Add(name); Dictionary.Add(name, value); } } /// <summary> /// Adds a property to the collection. /// </summary> /// <param name="name">Name of property</param> /// <param name="value">Value of property</param> public void Add(string name, string value) { if (!_readOnlyProperties.Contains(name)) { Dictionary.Add(name, value); } } public string this[string name] { get { return (string) Dictionary[(object) name]; } set { if (!_readOnlyProperties.Contains(name)) { Dictionary[name] = value; } } } protected override void OnClear() { _readOnlyProperties.Clear(); } } } --- 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.Collections.Specialized; using System.Xml; public class Target { string _name; Project _project; bool _hasExecuted = false; TaskCollection _tasks = new TaskCollection(); StringCollection _dependencies = new StringCollection(); public Target(Project project) { Project = project; } public string Name { get { return _name; } set { _name = value; } } public Project Project { get { return _project; } set { _project = value; } } public bool HasExecuted { get { return _hasExecuted; } } public TaskCollection Tasks { get { return _tasks; } } public StringCollection Dependencies { get { return _dependencies; } } public void Initialize(XmlNode targetNode) { // get target name XmlNode nameNode = targetNode.SelectSingleNode("@name"); if (nameNode == null) { // TODO: add Location to exception throw new BuildException("target must have a name attribute"); } Name = nameNode.Value; // add dependicies XmlNode dependsNode = targetNode.SelectSingleNode("@depends"); if (dependsNode != null) { string depends = dependsNode.Value; foreach (string str in depends.Split(new char[]{','})) { string dependency = str.Trim(); if (dependency.Length > 0) { Dependencies.Add(dependency); } } } // select all the non-target nodes (these are global tasks for the project) XmlNodeList taskList = targetNode.SelectNodes("*"); foreach (XmlNode taskNode in taskList) { Task task = Project.CreateTask(taskNode, this); if (task != null) { Tasks.Add(task); } } } public void Execute() { if (!HasExecuted) { try { foreach (string targetName in Dependencies) { Target target = Project.Targets.Find(targetName); if (target == null) { // TODO: add Location to exception throw new BuildException(String.Format("unknown dependent target '{0}' of target '{1}'", targetName, Name)); } target.Execute(); } Log.WriteLine(); Log.WriteLine("{0}:", Name); foreach (Task task in Tasks) { task.Execute(); } } finally { _hasExecuted = true; } } } } } --- 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; public class TargetCollection : ArrayList { public Target Find(string targetName) { foreach(Target target in this) { if (target.Name == targetName) return target; } return 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...) // Mike Krueger (mi...@ic...) // Ian MacLean (ian...@an...) namespace SourceForge.NAnt { using System; using System.Reflection; using System.Xml; public abstract class Task { /// <summary>Gets and sets how much spacing log prefix names will be padded.</summary> /// <remarks> /// Includes characters for a space after the name and the [ ] brackets. Default is 12. /// </remarks> public static int LogPrefixPadding = Log.IndentSize; Location _location = Location.UnknownLocation; Target _target = null; Project _project = null; /// <summary> /// Location in build file where task is defined. /// </summary> protected Location Location { get { return _location; } set { _location = value; } } public string Name { get { string name = null; TaskNameAttribute taskName = (TaskNameAttribute) Attribute.GetCustomAttribute(GetType(), typeof(TaskNameAttribute)); if (taskName != null) { name = taskName.Name; } return name; } } public string LogPrefix { get { string prefix = "[" + Name + "] "; return prefix.PadLeft(LogPrefixPadding); } } public Target Target { get { return _target; } set { _target = value; } } public Project Project { get { return _project; } set { _project = value; } } protected void AutoInitializeAttributes(XmlNode taskNode) { // TODO: BooleanValidatorAttribute and Int32ValidatorAttribute implementation in Task // Go down the inheritance tree to find the private fields in the object. // We are looking for task attributes to initialize. Type currentType = GetType(); while (currentType != typeof(object)) { FieldInfo[] fieldInfoArray = currentType.GetFields(BindingFlags.NonPublic|BindingFlags.Instance); foreach (FieldInfo fieldInfo in fieldInfoArray) { // process TaskAttribute attributes TaskAttributeAttribute taskAttribute = (TaskAttributeAttribute) Attribute.GetCustomAttribute(fieldInfo, typeof(TaskAttributeAttribute)); if (taskAttribute != null) { // get value from xml file XmlNode node = taskNode.SelectSingleNode("@" + taskAttribute.Name); // check if its required if (node == null && taskAttribute.Required) { // TODO: add Location to exception throw new BuildException(String.Format("{0} is a required attribute.", taskAttribute.Name), Location); } if (node != null) { fieldInfo.SetValue(this, Convert.ChangeType(node.Value, fieldInfo.FieldType)); } } // process TaskFileSet attributes TaskFileSetAttribute fileSetAttribute = (TaskFileSetAttribute) Attribute.GetCustomAttribute(fieldInfo, typeof(TaskFileSetAttribute)); if (fileSetAttribute != null) { // have file set initialize itself FileSet fileSet = (FileSet) fieldInfo.GetValue(this); // set task fileset belongs to fileSet.Task = this; // load values from build file XmlNode fileSetNode = taskNode.SelectSingleNode(fileSetAttribute.Name); if (fileSetNode != null) { XmlNode baseDirectoryNode = fileSetNode.SelectSingleNode("@basedir"); if (baseDirectoryNode != null) { fileSet.BaseDirectory = baseDirectoryNode.Value; } foreach (XmlNode node in fileSetNode.SelectNodes("includes")) { string pathname = node.SelectSingleNode("@name").Value; fileSet.Includes.Add(pathname); } foreach (XmlNode node in fileSetNode.SelectNodes("excludes")) { fileSet.Excludes.Add(node.SelectSingleNode("@name").Value); } } } } currentType = currentType.BaseType; } } protected void AutoExpandAttributes() { // Go down the inheritance tree to find the private fields in the object. // We are looking for task attributes to initialize. Type currentType = GetType(); while (currentType != typeof(object)) { FieldInfo[] fieldInfoArray = currentType.GetFields(BindingFlags.NonPublic|BindingFlags.Instance); foreach (FieldInfo fieldInfo in fieldInfoArray) { // proces string parameters TaskAttributeAttribute taskAttribute = (TaskAttributeAttribute) Attribute.GetCustomAttribute(fieldInfo, typeof(TaskAttributeAttribute)); if (taskAttribute != null) { if (taskAttribute.ExpandText) { string value = (string) fieldInfo.GetValue(this); value = Project.ExpandText(value); fieldInfo.SetValue(this, value); } // if a field also has a validator attribute then ensure that value is correct ValidatorAttribute[] validators = (ValidatorAttribute[]) Attribute.GetCustomAttributes(fieldInfo, typeof(ValidatorAttribute)); foreach (ValidatorAttribute validator in validators) { string errorMessage = validator.Validate(fieldInfo.GetValue(this)); if (errorMessage != null) { throw new BuildException(String.Format("Error processing '{0}' attribute in <{1}> task: {2}", taskAttribute.Name, Name, errorMessage), Location); } } } } currentType = currentType.BaseType; } } public void Initialize(XmlNode taskNode) { Initialize(taskNode, null); } public void Initialize(XmlNode taskNode, Location location) { if (location != null) { _location = location; } AutoInitializeAttributes(taskNode); InitializeTask(taskNode); } public void Execute() { AutoExpandAttributes(); ExecuteTask(); } protected virtual void InitializeTask(XmlNode taskNode) { } protected abstract void ExecuteTask(); } } --- NEW FILE --- // NAnt - A .NET buil... [truncated message content] |