Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NugetAdd, GitCommit and GitTag tasks. #273

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions Source/MSBuild.Community.Tasks/Git/GitCommit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace MSBuild.Community.Tasks.Git
{
/// <summary>
/// A task for git commit.
/// </summary>
public class GitCommit : GitClient
{
/// <summary>
/// Initializes a new instance of the <see cref="GitCommit"/> class.
/// </summary>
public GitCommit()
{
Command = "commit";
}

/// <summary>
/// Gets or sets the commit message.
/// </summary>
[Required]
public string Message { get; set; }

/// <summary>
/// Whether or not to add modified and deleted files to the commit
/// </summary>
public bool AddModifiedFiles { get; set; }

/// <summary>
/// Generates the arguments.
/// </summary>
/// <param name="builder">The builder.</param>
protected override void GenerateArguments(CommandLineBuilder builder)
{
base.GenerateArguments(builder);

if (AddModifiedFiles)
{
builder.AppendSwitch("-a");
}

builder.AppendSwitchIfNotNull("-m", Message);
}
}
}
69 changes: 69 additions & 0 deletions Source/MSBuild.Community.Tasks/Git/GitTag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace MSBuild.Community.Tasks.Git
{
/// <summary>
/// A task for git commit.
/// </summary>
public class GitTag : GitClient
{
/// <summary>
/// Initializes a new instance of the <see cref="GitTag"/> class.
/// </summary>
public GitTag()
{
Command = "tag";
}

/// <summary>
/// Gets or sets the tag label.
/// </summary>
[Required]
public string Label { get; set; }

/// <summary>
/// Commit hash to add the tag to. If empty, tag HEAD.
/// </summary>
public string CommitHash { get; set; }

/// <summary>
/// For annotated tags, gets or sets the tag message.
/// </summary>
public string Message { get; set; }

/// <summary>
/// Whether or not to add modified files to the commit
/// </summary>
public bool Annotated { get; set; }

/// <summary>
/// Generates the arguments.
/// </summary>
/// <param name="builder">The builder.</param>
protected override void GenerateArguments(CommandLineBuilder builder)
{
base.GenerateArguments(builder);

if (Annotated)
{
builder.AppendSwitch("-a");
builder.AppendSwitch(Label);

if (!string.IsNullOrWhiteSpace(Message))
{
builder.AppendSwitchIfNotNull("-m", Message);
}
}
else
{
builder.AppendSwitch(Label);
}

if (!string.IsNullOrWhiteSpace(CommitHash))
{
builder.AppendTextUnquoted("\"" + CommitHash + "\"");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@
<UsingTask AssemblyFile="$(MSBuildCommunityTasksLib)" TaskName="MSBuild.Community.Tasks.Net.HttpRequest" />

<UsingTask AssemblyFile="$(MSBuildCommunityTasksLib)" TaskName="MSBuild.Community.Tasks.NuGet.NuGetInstall" />
<UsingTask AssemblyFile="$(MSBuildCommunityTasksLib)" TaskName="MSBuild.Community.Tasks.NuGet.NuGetUpdate" />
<UsingTask AssemblyFile="$(MSBuildCommunityTasksLib)" TaskName="MSBuild.Community.Tasks.NuGet.NuGetPack" />
<UsingTask AssemblyFile="$(MSBuildCommunityTasksLib)" TaskName="MSBuild.Community.Tasks.NuGet.NuGetPush" />
<UsingTask AssemblyFile="$(MSBuildCommunityTasksLib)" TaskName="MSBuild.Community.Tasks.NuGet.NuGetAdd" />
<UsingTask AssemblyFile="$(MSBuildCommunityTasksLib)" TaskName="MSBuild.Community.Tasks.NuGet.NuGetRestore" />

<UsingTask AssemblyFile="$(MSBuildCommunityTasksLib)" TaskName="MSBuild.Community.Tasks.Git.GitClient" />
Expand All @@ -147,6 +149,8 @@
<UsingTask AssemblyFile="$(MSBuildCommunityTasksLib)" TaskName="MSBuild.Community.Tasks.Git.GitPendingChanges" />
<UsingTask AssemblyFile="$(MSBuildCommunityTasksLib)" TaskName="MSBuild.Community.Tasks.Git.GitCommits" />
<UsingTask AssemblyFile="$(MSBuildCommunityTasksLib)" TaskName="MSBuild.Community.Tasks.Git.GitCommitDate" />
<UsingTask AssemblyFile="$(MSBuildCommunityTasksLib)" TaskName="MSBuild.Community.Tasks.Git.GitCommit" />
<UsingTask AssemblyFile="$(MSBuildCommunityTasksLib)" TaskName="MSBuild.Community.Tasks.Git.GitTag" />

<UsingTask AssemblyFile="$(MSBuildCommunityTasksLib)" TaskName="MSBuild.Community.Tasks.InnoSetup" />
<UsingTask AssemblyFile="$(MSBuildCommunityTasksLib)" TaskName="MSBuild.Community.Tasks.Checksum" />
Expand Down
3 changes: 3 additions & 0 deletions Source/MSBuild.Community.Tasks/MSBuild.Community.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@
</Compile>
<Compile Include="Fusion\InstallReference.cs" />
<Compile Include="Fusion\NativeMethods.cs" />
<Compile Include="Git\GitTag.cs" />
<Compile Include="Git\GitCommitDate.cs" />
<Compile Include="Git\GitCommit.cs" />
<Compile Include="Git\GitDescribe.cs" />
<Compile Include="Git\GitBranch.cs" />
<Compile Include="Git\GitClient.cs" />
Expand All @@ -135,6 +137,7 @@
<Compile Include="NuGet\NuGetDelete.cs" />
<Compile Include="NuGet\NuGetInstall.cs" />
<Compile Include="NuGet\NuGetPack.cs" />
<Compile Include="NuGet\NuGetAdd.cs" />
<Compile Include="NuGet\NuGetPush.cs" />
<Compile Include="NuGet\NuGetRestore.cs" />
<Compile Include="NuGet\NuGetUpdate.cs" />
Expand Down
107 changes: 107 additions & 0 deletions Source/MSBuild.Community.Tasks/NuGet/NuGetAdd.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#region Copyright � 2011 Paul Welter. All rights reserved.
/*
Copyright � 2005 Paul Welter. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;



namespace MSBuild.Community.Tasks.NuGet
{
/// <summary>
/// Adds a package to the server and optionally publishes it.
/// </summary>
public class NuGetAdd : NuGetBase
{
/// <summary>
/// The path to the package to push the package to the server.
/// </summary>
[Required]
public ITaskItem File { get; set; }

/// <summary>
/// The API key to use for push to the server.
/// </summary>
public string APIKey { get; set; }

/// <summary>
/// The NuGet configuation file. If not specified, file %AppData%\NuGet\NuGet.config is used as configuration file.
/// </summary>
public string ConfigFile { get; set; }

/// <summary>
/// Specifies the server folder or UNC path.
/// </summary>
public string Source { get; set; }

/// <summary>
/// Specifies if the package should be created and uploaded to the server but not published to the server. False by default.
/// </summary>
/// <value>
/// <c>true</c> if create only; otherwise, <c>false</c>.
/// </value>
public bool CreateOnly { get; set; }

/// <summary>
/// Display this amount of details in the output: normal, quiet, detailed.
/// </summary>
public string Verbosity { get; set; }

/// <summary>
/// (v3.5) Forces NuGet to run using an invariant, English-based culture.
/// </summary>
/// <remarks>
/// Only available starting in version 3.5.
/// </remarks>
public bool ForceEnglishOutput { get; set; }

/// <summary>
/// Returns a string value containing the command line arguments to pass directly to the executable file.
/// </summary>
/// <returns>
/// A string value containing the command line arguments to pass directly to the executable file.
/// </returns>
protected override string GenerateCommandLineCommands()
{
var builder = new CommandLineBuilder();
builder.AppendSwitch("add");
builder.AppendFileNameIfNotNull(File);
builder.AppendFileNameIfNotNull(APIKey);
builder.AppendSwitchIfNotNull("-Source ", Source);
builder.AppendSwitchIfNotNull("-Verbosity ", Verbosity);
builder.AppendSwitchIfNotNull("-ConfigFile ", ConfigFile);
if (CreateOnly)
builder.AppendSwitch("-CreateOnly");
if (ForceEnglishOutput)
builder.AppendSwitch("-ForceEnglishOutput");

return builder.ToString();
}
}
}