#region CPL License /* Nuclex.NAnt.Tasks Copyright (C) 2009 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library 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 IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #endregion using System; using System.Collections.Generic; using System.IO; using System.Text; using Microsoft.Win32; using NAnt.Core; using NAnt.Core.Attributes; namespace Nuclex.NAnt.Tasks { /// Commits changes to a working copy into a subversion repository [TaskName("subversion-commit")] public class SubversionCommitTask : Task { /// Initializes a new subversion commit task public SubversionCommitTask() { this.fromDirectory = new DirectoryInfo("."); } /// Directory from which the working copy will be committed [TaskAttribute("fromdir"), StringValidator(AllowEmpty = false)] public DirectoryInfo FromDirectory { get { return this.fromDirectory; } set { this.fromDirectory = value; } } /// Message describing the changes being committed [TaskAttribute("message")] public string Message { get { return this.message; } set { this.message = value; } } /// Name of the user with which to access the subversion repository [TaskAttribute("username")] public string UserName { get { return this.userName; } set { this.userName = value; } } /// Password by which to log in to the subversion repository [TaskAttribute("password")] public string Password { get { return this.password; } set { this.password = value; } } /// Executes the task protected override void ExecuteTask() { this.Log( Level.Info, "Committing '{0}'.", this.fromDirectory.FullName ); StringBuilder commandLineBuilder = new StringBuilder(256); commandLineBuilder.AppendFormat("commit"); if(this.userName != null) { commandLineBuilder.AppendFormat(" --username {0}", this.userName); } if(this.password != null) { commandLineBuilder.AppendFormat(" --password {0}", this.password); } if(this.message != null) { commandLineBuilder.AppendFormat(" --message \"{0}\"", this.message); } commandLineBuilder.AppendFormat( " --no-auth-cache --non-interactive --trust-server-cert {0}", this.fromDirectory.FullName ); try { Subversion.Run(this.fromDirectory.FullName, commandLineBuilder.ToString()); } catch(InvalidOperationException exception) { throw new BuildException( "Error during Subversion commit operation: " + exception.Message, this.Location ); } } /// Directory to extract to private DirectoryInfo fromDirectory; /// User name by which to log in to the subversion repository private string userName; /// Password to use for logging in to the subversion repository private string password; /// The commit message in which the changes are described private string message; } } // namespace Nuclex.NAnt.Tasks