#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 {
/// Checks out a working copy from a subversion repository
[TaskName("subversion-checkout")]
public class SubversionCheckoutTask : Task {
/// Initializes a new subversion checkout task
public SubversionCheckoutTask() {
this.toDirectory = new DirectoryInfo(".");
}
/// URL of the subversion repository
[TaskAttribute("url"), StringValidator(AllowEmpty = false)]
public string Url {
get { return this.url; }
set { this.url = value; }
}
/// Directory into which the working copy will be checked out
[TaskAttribute("todir"), StringValidator(AllowEmpty = false)]
public DirectoryInfo ToDirectory {
get { return this.toDirectory; }
set { this.toDirectory = 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; }
}
/// Password by which to log in to the subversion repository
[TaskAttribute("revision")]
public string Revision {
get { return this.revision; }
set { this.revision = value; }
}
/// Executes the task
protected override void ExecuteTask() {
this.Log(
Level.Info,
"Checking out '{0}' to '{1}'.",
this.url,
this.toDirectory.FullName
);
StringBuilder commandLineBuilder = new StringBuilder(256);
commandLineBuilder.AppendFormat("checkout {0}", this.url);
if(this.revision != null) {
commandLineBuilder.AppendFormat(" --revision {0}", this.revision);
}
if(this.userName != null) {
commandLineBuilder.AppendFormat(" --username {0}", this.userName);
}
if(this.password != null) {
commandLineBuilder.AppendFormat(" --password {0}", this.password);
}
commandLineBuilder.AppendFormat(
" --no-auth-cache --non-interactive --trust-server-cert {0}",
this.toDirectory.FullName
);
try {
Subversion.Run(".", commandLineBuilder.ToString());
}
catch(InvalidOperationException exception) {
throw new BuildException(
"Error during Subversion checkout operation: " + exception.Message,
this.Location
);
}
}
/// URL of the subversion repository
private string url;
/// Directory to extract to
private DirectoryInfo toDirectory;
/// Revision number, date or name to check out
private string revision;
/// 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;
}
} // namespace Nuclex.NAnt.Tasks