From ca3a38021ad0175226a3ab78b13db95b755d44c6 Mon Sep 17 00:00:00 2001 From: "paul.welter" Date: Wed, 11 Jun 2014 14:28:12 -0500 Subject: [PATCH] - add ConsoleOut to GitClient --- Source/GlobalAssemblyInfo.cs | 6 ++-- .../Git/GitClientTest.cs | 33 +++++++++++++++++++ .../MSBuild.Community.Tasks.Tests.csproj | 1 + .../MSBuild.Community.Tasks/Git/GitClient.cs | 32 +++++++++++++++--- 4 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 Source/MSBuild.Community.Tasks.Tests/Git/GitClientTest.cs diff --git a/Source/GlobalAssemblyInfo.cs b/Source/GlobalAssemblyInfo.cs index 28e967b6..cc7396d4 100644 --- a/Source/GlobalAssemblyInfo.cs +++ b/Source/GlobalAssemblyInfo.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.18408 +// Runtime Version:4.0.30319.18444 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -11,7 +11,7 @@ [assembly: System.Reflection.AssemblyCompany("https://github.com/loresoft/msbuildtasks/")] [assembly: System.Reflection.AssemblyProduct("MSBuild.Community.Tasks")] [assembly: System.Reflection.AssemblyCopyright("Copyright © 2014 MSBuild Community Tasks Project")] -[assembly: System.Reflection.AssemblyConfiguration("Commit 38413f3")] +[assembly: System.Reflection.AssemblyConfiguration("Commit 837efe9")] [assembly: System.Runtime.InteropServices.ComVisible(false)] [assembly: System.CLSCompliant(false)] [assembly: System.Reflection.AssemblyVersion("1.4.0.0")] @@ -28,7 +28,7 @@ internal sealed partial class ThisAssembly { internal const string AssemblyCopyright = "Copyright © 2014 MSBuild Community Tasks Project"; - internal const string AssemblyConfiguration = "Commit 38413f3"; + internal const string AssemblyConfiguration = "Commit 837efe9"; internal const string AssemblyVersion = "1.4.0.0"; diff --git a/Source/MSBuild.Community.Tasks.Tests/Git/GitClientTest.cs b/Source/MSBuild.Community.Tasks.Tests/Git/GitClientTest.cs new file mode 100644 index 00000000..d5e9c758 --- /dev/null +++ b/Source/MSBuild.Community.Tasks.Tests/Git/GitClientTest.cs @@ -0,0 +1,33 @@ +using System; +using System.IO; +using MSBuild.Community.Tasks.Git; +using NUnit.Framework; + +namespace MSBuild.Community.Tasks.Tests.Git +{ + [TestFixture] + public class GitClientTest + { + [Test] + public void Execute() + { + var task = new GitClient(); + task.BuildEngine = new MockBuild(); + task.ToolPath = @"C:\Program Files (x86)\Git\bin"; + + + string prjRootPath = TaskUtility.GetProjectRootDirectory(true); + task.LocalPath = Path.Combine(prjRootPath, @"Source"); + + task.Command = "symbolic-ref"; + task.Arguments = "HEAD"; + + bool result = task.Execute(); + + Assert.IsTrue(result, "Execute Failed"); + + Assert.IsTrue(task.ConsoleOutput.Length > 0); + } + + } +} \ No newline at end of file diff --git a/Source/MSBuild.Community.Tasks.Tests/MSBuild.Community.Tasks.Tests.csproj b/Source/MSBuild.Community.Tasks.Tests/MSBuild.Community.Tasks.Tests.csproj index b04e1fd7..8d673a8a 100644 --- a/Source/MSBuild.Community.Tasks.Tests/MSBuild.Community.Tasks.Tests.csproj +++ b/Source/MSBuild.Community.Tasks.Tests/MSBuild.Community.Tasks.Tests.csproj @@ -70,6 +70,7 @@ + diff --git a/Source/MSBuild.Community.Tasks/Git/GitClient.cs b/Source/MSBuild.Community.Tasks/Git/GitClient.cs index 2d3490ce..d6ecfe01 100644 --- a/Source/MSBuild.Community.Tasks/Git/GitClient.cs +++ b/Source/MSBuild.Community.Tasks/Git/GitClient.cs @@ -43,12 +43,13 @@ namespace MSBuild.Community.Tasks.Git public class GitClient : ToolTask { private string _initialToolPath; - + private readonly List _consoleOut; /// /// Default constructor. Creates a new GitClient task. /// public GitClient() { + _consoleOut = new List(); _initialToolPath = ToolPath; } @@ -62,12 +63,21 @@ public GitClient() /// public string Arguments { get; set; } - /// /// Gets or sets the local or working path for git command. /// public string LocalPath { get; set; } - + + /// + /// Gets command console output messages. + /// + [Output] + public ITaskItem[] ConsoleOutput + { + get { return _consoleOut.ToArray(); } + set { } + } + private string FindToolPath(string toolName) { string toolPath = @@ -170,7 +180,7 @@ protected override string ToolName { get { return ToolPathUtil.MakeToolName("git"); } } - + /// /// Indicates whether all task paratmeters are valid. /// @@ -200,5 +210,19 @@ protected override string GetWorkingDirectory() return LocalPath; } + + /// + /// Parses a single line of text to identify any errors or warnings in canonical format. + /// + /// A single line of text for the method to parse. + /// A value of that indicates the importance level with which to log the message. + protected override void LogEventsFromTextOutput(string singleLine, MessageImportance messageImportance) + { + base.LogEventsFromTextOutput(singleLine, messageImportance); + + var messageItem = new TaskItem(singleLine); + _consoleOut.Add(messageItem); + } + } }