// NAnt - A .NET build tool // Copyright (C) 2001-2003 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 // // Clayton Harbour (claytonharbour@sporadicism.com) using System; using System.Globalization; using System.IO; using ICSharpCode.SharpCvsLib.Util; using NAnt.Core.Attributes; using NAnt.Core.Types; using NAnt.Core.Util; namespace NAnt.SourceControl.Tasks { /// /// Updates a CVS module in a local working directory. /// /// /// Update nant. /// /// /// ]]> /// /// /// /// /// Update your NAnt revision named your_favorite_revision_here in /// the folder c:\src\nant\replacement_for_module_directory_name. /// /// /// /// /// /// /// /// ]]> /// /// [TaskName("cvs-update")] public class UpdateTask : AbstractCvsTask { #region Internal Static Fields /// /// The command being executed. /// internal const string CvsCommandName = "update"; #endregion Internal Static Fields #region Public Instance Constructors /// /// Initializes a new instance of the /// class. /// /// /// Sets the build directory and prune empty directory properties to /// . /// public UpdateTask() { BuildDirs = true; PruneEmpty = true; } #endregion Public Instance Constructors #region Public Instance Properties /// /// If . new directories will be created on the local /// sandbox. The default is . /// [TaskAttribute("builddirs", Required=false)] [BooleanValidator()] public bool BuildDirs { get { return ((Option)CommandOptions["builddirs"]).IfDefined; } set { SetCommandOption("builddirs", "-d", value); } } /// /// If empty directories copied down from the /// remote repository will be removed from the local sandbox. /// The default is . /// [TaskAttribute("pruneempty", Required=false)] [BooleanValidator()] public bool PruneEmpty { get { return ((Option)CommandOptions["pruneempty"]).IfDefined; } set { SetCommandOption("pruneempty", "-P", value); } } /// /// If the local copy of the file will be /// overwritten with the copy from the remote repository. The default /// is . /// [TaskAttribute("overwritelocal", Required=false)] [BooleanValidator()] public bool OverwriteLocal { get { return ((Option)CommandOptions["overwritelocal"]).IfDefined; } set { SetCommandOption("overwritelocal", "-C", value); } } /// /// Specifies if the command should be executed recursively. The /// default is . /// /// /// The -R option is on by default in cvs. /// [TaskAttribute("recursive", Required=false)] [BooleanValidator()] public bool Recursive { get { Option option = (Option) CommandOptions["recursive"]; if (option == null || option.Value == "-R") { return true; } return false; } set { if (value) { // update should be executed recursive SetCommandOption("recursive", "-R", true); } else { // update should be executed locally (not recursive) SetCommandOption("recursive", "-l", true); } } } /// /// Specify the revision to update the file to. This corresponds to the /// "sticky-tag" of the file. /// [TaskAttribute("revision", Required=false)] [StringValidator(AllowEmpty=true, Expression=@"^[A-Za-z0-9][A-Za-z0-9._\-]*$")] public string Revision { get { if (CommandOptions.ContainsKey("revision")) { return ((Option)CommandOptions["revision"]).Value; } return null; } set { if (StringUtils.IsNullOrEmpty(value)) { CommandOptions.Remove("revision"); } else { SetCommandOption("revision", string.Format(CultureInfo.InvariantCulture, "-r {0}", value), true); } } } /// /// Sticky tag or revision to update the local file to. /// /// /// A valid cvs tag. /// [TaskAttribute("sticky-tag", Required=false)] public string StickyTag { get { return Revision; } set { Revision = value; } } /// /// Specify the revision date to update to. The version of the file that /// existed at the date specified is retrieved. /// /// /// A valid date time value, which is then converted to a format that /// cvs can parse. /// [TaskAttribute("date", Required=false)] [DateTimeValidator()] public DateTime Date { get { return Convert.ToDateTime(((Option)CommandOptions["date"]).Value); } set { SetCommandOption("date", String.Format(CultureInfo.InvariantCulture,"-D \"{0}\"", DateParser.GetCvsDateString(value)), true); } } #endregion #region Override implementation of AbstractCvsTask /// /// Specify if the module is needed for this cvs command. It is /// only needed if there is no module information on the local file /// system. /// protected override bool IsModuleNeeded { get {return false;} } /// /// The name of the cvs command that is going to be executed. /// public override string CommandName { get {return CvsCommandName;} } #endregion Override implementation of AbstractCvsTask } }