diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2010-12-23 13:09:32 -0800 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2010-12-23 13:09:32 -0800 |
commit | 45775797c5f50dc56370c75c3244ea0e83ab4832 (patch) | |
tree | 92b067e463370751e7c35ad626062b9d641842fc /src/DotNetOpenAuth.BuildTasks/AddFilesTo7Zip.cs | |
parent | 5c38b4c0564f75a845678005c474df2073113ce7 (diff) | |
parent | 1b87e9b8d74afe71b70d842ee435523e7f1aad46 (diff) | |
download | DotNetOpenAuth-45775797c5f50dc56370c75c3244ea0e83ab4832.zip DotNetOpenAuth-45775797c5f50dc56370c75c3244ea0e83ab4832.tar.gz DotNetOpenAuth-45775797c5f50dc56370c75c3244ea0e83ab4832.tar.bz2 |
Merge branch 'v3.4' into oauth2
Conflicts:
samples/OAuthServiceProvider/Code/DatabaseTokenManager.cs
samples/OAuthServiceProvider/Code/OAuthToken.cs
src/DotNetOpenAuth/Messaging/MessagingStrings.resx
Diffstat (limited to 'src/DotNetOpenAuth.BuildTasks/AddFilesTo7Zip.cs')
-rw-r--r-- | src/DotNetOpenAuth.BuildTasks/AddFilesTo7Zip.cs | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.BuildTasks/AddFilesTo7Zip.cs b/src/DotNetOpenAuth.BuildTasks/AddFilesTo7Zip.cs new file mode 100644 index 0000000..8bf3e16 --- /dev/null +++ b/src/DotNetOpenAuth.BuildTasks/AddFilesTo7Zip.cs @@ -0,0 +1,105 @@ +//----------------------------------------------------------------------- +// <copyright file="AddFilesTo7Zip.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.BuildTasks { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using Microsoft.Build.Utilities; + using Microsoft.Build.Framework; + + public class AddFilesTo7Zip : ToolTask { + /// <summary> + /// Initializes a new instance of the <see cref="AddFilesTo7Zip"/> class. + /// </summary> + public AddFilesTo7Zip() { + this.YieldDuringToolExecution = true; + } + + [Required] + public ITaskItem ZipFileName { get; set; } + + [Required] + public ITaskItem[] Files { get; set; } + + public string WorkingDirectory { get; set; } + + /// <summary> + /// Gets the name of the tool. + /// </summary> + /// <value> + /// The name of the tool. + /// </value> + protected override string ToolName { + get { return "7za.exe"; } + } + + /// <summary> + /// Generates the full path to tool. + /// </summary> + protected override string GenerateFullPathToTool() { + return this.ToolPath; + } + + protected override string GenerateCommandLineCommands() { + var args = new CommandLineBuilder(); + + args.AppendSwitch("a"); + args.AppendSwitch("--"); + + args.AppendFileNameIfNotNull(this.ZipFileName); + + return args.ToString(); + } + + /// <summary> + /// Gets the response file switch. + /// </summary> + /// <param name="responseFilePath">The response file path.</param> + protected override string GetResponseFileSwitch(string responseFilePath) { + return "@" + responseFilePath; + } + + /// <summary> + /// Gets the response file encoding. + /// </summary> + /// <value> + /// The response file encoding. + /// </value> + protected override Encoding ResponseFileEncoding { + get { return Encoding.UTF8; } + } + + /// <summary> + /// Generates the response file commands. + /// </summary> + protected override string GenerateResponseFileCommands() { + var args = new CommandLineBuilder(); + args.AppendFileNamesIfNotNull(this.Files.Select(GetWorkingDirectoryRelativePath).ToArray(), Environment.NewLine); + return args.ToString(); + } + + /// <summary> + /// Gets the working directory. + /// </summary> + protected override string GetWorkingDirectory() { + if (!String.IsNullOrEmpty(this.WorkingDirectory)) { + return this.WorkingDirectory; + } else { + return base.GetWorkingDirectory(); + } + } + + private string GetWorkingDirectoryRelativePath(ITaskItem taskItem) { + if (taskItem.ItemSpec.StartsWith(this.WorkingDirectory, StringComparison.OrdinalIgnoreCase)) { + return taskItem.ItemSpec.Substring(this.WorkingDirectory.Length); + } else { + return taskItem.ItemSpec; + } + } + } +} |