Skip to content

Added /exec and /proj arguments #112

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

Merged
merged 3 commits into from
Mar 28, 2014
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
*.vspscc
.builds
*.dotCover
*.orig

## If you have NuGet Package Restore enabled, uncomment this
packages/
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

5 changes: 5 additions & 0 deletions GitVersion.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitVersionTask", "GitVersionTask\GitVersionTask.csproj", "{F7AC0E71-3E9A-4F6D-B986-E004825A48E1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AcceptanceTests", "AcceptanceTests\AcceptanceTests.csproj", "{BF905F84-382C-440D-92F5-C61108626D8D}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3EFFC5D6-88D0-49D9-BB53-E1B7EB49DD45}"
ProjectSection(SolutionItems) = preProject
LICENSE = LICENSE
README.md = README.md
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need these as solution items?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly so readme is easily accessed so it gets updated when things are changed. Happy to revert though

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah that is fine. was just curious

EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
24 changes: 24 additions & 0 deletions GitVersion/ArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,30 @@ public static Arguments ParseArguments(List<string> commandLineArguments)
continue;
}

if (IsSwitch("exec", name))
{
arguments.Exec = value;
continue;
}

if (IsSwitch("execargs", name))
{
arguments.ExecArgs = value;
continue;
}

if (IsSwitch("proj", name))
{
arguments.Proj = value;
continue;
}

if (IsSwitch("projargs", name))
{
arguments.ProjArgs = value;
continue;
}

if ((IsSwitch("v", name)) && VersionParts.Contains(value.ToLower()))
{
arguments.VersionPart = value.ToLower();
Expand Down
5 changes: 5 additions & 0 deletions GitVersion/Arguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,10 @@ public Arguments()
public string VersionPart;

public OutputType Output;

public string Proj;
public string ProjArgs;
public string Exec;
public string ExecArgs;
}
}
1 change: 1 addition & 0 deletions GitVersion/GitVersion.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<Compile Include="HelpWriter.cs" />
<Compile Include="GitFlow\ReleaseInformation.cs" />
<Compile Include="GitFlow\ReleaseInformationCalculator.cs" />
<Compile Include="ProcessHelper.cs" />
<Compile Include="ReleaseDate.cs" />
<Compile Include="ReleaseDateFinder.cs" />
<Compile Include="SemanticVersionTag.cs" />
Expand Down
18 changes: 11 additions & 7 deletions GitVersion/HelpWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ public static void Write()

GitVersion [path] [/l logFilePath]

path The directory containing .git. If not defined current directory is used.
/url Url to remote git repository.
/b Name of the branch to use on the remote repository, must be used in combination with /url.
/u Username in case authentication is required.
/p Password in case authentication is required.
/output Determines the output to the console. Can be either 'json' or 'buildserver', will default to 'json'.
/l Path to logfile.
path The directory containing .git. If not defined current directory is used.
/url Url to remote git repository.
/b Name of the branch to use on the remote repository, must be used in combination with /url.
/u Username in case authentication is required.
/p Password in case authentication is required.
/output Determines the output to the console. Can be either 'json' or 'buildserver', will default to 'json'.
/l Path to logfile.
/exec Executes target executable making GitVersion variables available as environmental variables
/execargs Arguments for the executable specified by /exec
/proj Build a msbuild file, GitVersion variables will be passed as msbuild properties
/projargs Additional arguments to pass to msbuild
";
Console.Write(message);
}
Expand Down
112 changes: 112 additions & 0 deletions GitVersion/ProcessHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
namespace GitVersion
{
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;

static class ProcessHelper
{
private static volatile object _lockObject = new object();

// http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/f6069441-4ab1-4299-ad6a-b8bb9ed36be3
public static Process Start(ProcessStartInfo startInfo)
{
Process process;

lock (_lockObject)
{
using (new ChangeErrorMode(ErrorModes.FailCriticalErrors | ErrorModes.NoGpFaultErrorBox))
{
process = Process.Start(startInfo);
process.PriorityClass = ProcessPriorityClass.Idle;
}
}

return process;
}

// http://csharptest.net/532/using-processstart-to-capture-console-output/
public static int Run(Action<string> output, Action<string> errorOutput, TextReader input, string exe, string args, string workingDirectory)
{
if (String.IsNullOrEmpty(exe))
throw new FileNotFoundException();
if (output == null)
throw new ArgumentNullException("output");

var psi = new ProcessStartInfo
{
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardOutput = true,
RedirectStandardInput = true,
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
ErrorDialog = false,
WorkingDirectory = workingDirectory ?? Environment.CurrentDirectory,
FileName = exe,
Arguments = args
};

using (var process = Process.Start(psi))
using (var mreOut = new ManualResetEvent(false))
using (var mreErr = new ManualResetEvent(false))
{
process.EnableRaisingEvents = true;
process.OutputDataReceived += (o, e) =>
{
// ReSharper disable once AccessToDisposedClosure
if (e.Data == null)
mreOut.Set();
else
output(e.Data);
};
process.BeginOutputReadLine();
process.ErrorDataReceived += (o, e) =>
{
// ReSharper disable once AccessToDisposedClosure
if (e.Data == null)
mreErr.Set();
else
errorOutput(e.Data);
};
process.BeginErrorReadLine();

string line;
while (input != null && null != (line = input.ReadLine()))
process.StandardInput.WriteLine(line);

process.StandardInput.Close();
process.WaitForExit();

mreOut.WaitOne();
mreErr.WaitOne();

return process.ExitCode;
}
}

[Flags]
enum ErrorModes
{
FailCriticalErrors = 0x1,
NoGpFaultErrorBox = 0x2
}

struct ChangeErrorMode : IDisposable
{
private readonly int _oldMode;

public ChangeErrorMode(ErrorModes mode)
{
_oldMode = SetErrorMode((int)mode);
}

void IDisposable.Dispose() { SetErrorMode(_oldMode); }

[DllImport("kernel32.dll")]
private static extern int SetErrorMode(int newMode);
}
}
}
Loading