Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
arturcic committed Mar 25, 2020
1 parent 65db5a4 commit 255afd9
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 49 deletions.
11 changes: 7 additions & 4 deletions src/GitVersionCore/Core/GitVersionTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,25 @@ public class GitVersionTool : IGitVersionTool

private readonly IBuildServer buildServer;

public GitVersionTool(ILog log, IGitVersionCache gitVersionCache, INextVersionCalculator nextVersionCalculator, IVariableProvider variableProvider,
IGitVersionCacheKeyFactory cacheKeyFactory, IBuildServerResolver buildServerResolver,
public GitVersionTool(ILog log, INextVersionCalculator nextVersionCalculator, IVariableProvider variableProvider,
IGitVersionCache gitVersionCache, IGitVersionCacheKeyFactory cacheKeyFactory, IBuildServerResolver buildServerResolver,
IWixVersionFileUpdater wixVersionFileUpdater, IGitVersionInformationGenerator gitVersionInformationGenerator, IAssemblyInfoFileUpdater assemblyInfoFileUpdater,
IOptions<Arguments> options, IOptions<GitVersionContext> versionContext)
{
this.log = log ?? throw new ArgumentNullException(nameof(log));
this.gitVersionCache = gitVersionCache ?? throw new ArgumentNullException(nameof(gitVersionCache));

this.nextVersionCalculator = nextVersionCalculator ?? throw new ArgumentNullException(nameof(nextVersionCalculator));
this.variableProvider = variableProvider ?? throw new ArgumentNullException(nameof(variableProvider));
this.options = options ?? throw new ArgumentNullException(nameof(options));

this.cacheKeyFactory = cacheKeyFactory ?? throw new ArgumentNullException(nameof(cacheKeyFactory));
this.gitVersionCache = gitVersionCache ?? throw new ArgumentNullException(nameof(gitVersionCache));

this.wixVersionFileUpdater = wixVersionFileUpdater ?? throw new ArgumentNullException(nameof(wixVersionFileUpdater));
this.gitVersionInformationGenerator = gitVersionInformationGenerator ?? throw new ArgumentNullException(nameof(gitVersionInformationGenerator));
this.assemblyInfoFileUpdater = assemblyInfoFileUpdater ?? throw new ArgumentNullException(nameof(gitVersionInformationGenerator));

this.options = options ?? throw new ArgumentNullException(nameof(options));

context = versionContext.Value;
buildServer = buildServerResolver.Resolve();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@

namespace GitVersion.Extensions.GitVersionInformationResources
{
public interface IGitVersionInformationGenerator
{
void Generate(VersionVariables variables, FileWriteInfo writeInfo);
}

public class GitVersionInformationGenerator : IGitVersionInformationGenerator
{
private readonly IFileSystem fileSystem;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using GitVersion.OutputVariables;

namespace GitVersion.Extensions.GitVersionInformationResources
{
public interface IGitVersionInformationGenerator
{
void Generate(VersionVariables variables, FileWriteInfo writeInfo);
}
}
10 changes: 10 additions & 0 deletions src/GitVersionCore/Extensions/IWixVersionFileUpdater.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using GitVersion.OutputVariables;

namespace GitVersion.Extensions
{
public interface IWixVersionFileUpdater : IDisposable
{
string Update(VersionVariables variables, string workingDirectory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@

namespace GitVersion.Extensions.VersionAssemblyInfoResources
{
public interface IAssemblyInfoFileUpdater : IDisposable
{
void Update(VersionVariables variables, bool ensureAssemblyInfo, string workingDirectory, params string[] assemblyInfo);
void CommitChanges();
}

public class AssemblyInfoFileUpdater : IAssemblyInfoFileUpdater
{
private readonly List<Action> restoreBackupTasks = new List<Action>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using GitVersion.OutputVariables;

namespace GitVersion.Extensions.VersionAssemblyInfoResources
{
public interface IAssemblyInfoFileUpdater : IDisposable
{
void Update(VersionVariables variables, bool ensureAssemblyInfo, string workingDirectory, params string[] assemblyInfo);
void CommitChanges();
}
}
5 changes: 0 additions & 5 deletions src/GitVersionCore/Extensions/WixVersionFileUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@

namespace GitVersion.Extensions
{
public interface IWixVersionFileUpdater : IDisposable
{
string Update(VersionVariables variables, string workingDirectory);
}

public class WixVersionFileUpdater : IWixVersionFileUpdater
{
private readonly IFileSystem fileSystem;
Expand Down
9 changes: 7 additions & 2 deletions src/GitVersionExe.Tests/ArgumentParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@
using GitVersion.Logging;
using GitVersion.Model;
using GitVersionCore.Tests.Helpers;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using Shouldly;
using Environment = System.Environment;

namespace GitVersionExe.Tests
{
[TestFixture]
public class ArgumentParserTests
public class ArgumentParserTests : TestBase
{
private IArgumentParser argumentParser;

[SetUp]
public void SetUp()
{
argumentParser = new ArgumentParser(new TestEnvironment());
var sp = ConfigureServices(services =>
{
services.AddSingleton<IArgumentParser, ArgumentParser>();
});
argumentParser = sp.GetService<IArgumentParser>();
}

[Test]
Expand Down
6 changes: 3 additions & 3 deletions src/GitVersionExe.Tests/ExecutionResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public ExecutionResults(int exitCode, string output, string logContents)
Log = logContents;
}

public int ExitCode { get; private set; }
public string Output { get; private set; }
public string Log { get; private set; }
public int ExitCode { get; }
public string Output { get; }
public string Log { get; }

public virtual VersionVariables OutputVariables
{
Expand Down
1 change: 1 addition & 0 deletions src/GitVersionExe.Tests/GitVersionExe.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<PackageReference Include="Mono.Cecil" Version="0.11.2"></PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GitVersionCore.Tests\GitVersionCore.Tests.csproj" />
<ProjectReference Include="..\GitVersionCore\GitVersionCore.csproj" />
<ProjectReference Include="..\GitVersionExe\GitVersionExe.csproj" />
</ItemGroup>
Expand Down
20 changes: 8 additions & 12 deletions src/GitVersionExe/ArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ namespace GitVersion
public class ArgumentParser : IArgumentParser
{
private readonly IEnvironment environment;
private readonly IBuildServerResolver buildServerResolver;

public ArgumentParser(IEnvironment environment)
public ArgumentParser(IEnvironment environment, IBuildServerResolver buildServerResolver)
{
this.environment = environment ?? throw new ArgumentNullException(nameof(environment));
this.buildServerResolver = buildServerResolver ?? throw new ArgumentNullException(nameof(buildServerResolver));
}

public Arguments ParseArguments(string commandLineArguments)
Expand Down Expand Up @@ -158,7 +160,6 @@ public Arguments ParseArguments(string[] commandLineArguments)
continue;
}


if (name.IsSwitch("execargs"))
{
EnsureArgumentValueCount(values);
Expand Down Expand Up @@ -186,7 +187,6 @@ public Arguments ParseArguments(string[] commandLineArguments)
continue;
}


if (name.IsSwitch("diag"))
{
if (value == null || value.IsTrue())
Expand Down Expand Up @@ -305,18 +305,11 @@ public Arguments ParseArguments(string[] commandLineArguments)

if (name.IsSwitch("ensureassemblyinfo"))
{
if (value.IsTrue())
{
arguments.EnsureAssemblyInfo = true;
}
else if (value.IsFalse())
arguments.EnsureAssemblyInfo = true;
if (value.IsFalse())
{
arguments.EnsureAssemblyInfo = false;
}
else
{
arguments.EnsureAssemblyInfo = true;
}

if (arguments.UpdateAssemblyInfoFileName.Count > 1 && arguments.EnsureAssemblyInfo)
{
Expand Down Expand Up @@ -428,6 +421,9 @@ public Arguments ParseArguments(string[] commandLineArguments)
: firstArgument;
}

var buildServer = buildServerResolver.Resolve();
arguments.NoFetch = arguments.NoFetch || buildServer != null && buildServer.PreventFetch();

return arguments;
}

Expand Down
1 change: 0 additions & 1 deletion src/GitVersionExe/ExecCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace GitVersion
{
public class ExecCommand : IExecCommand
{

private readonly ILog log;
private readonly IOptions<Arguments> options;

Expand Down
17 changes: 6 additions & 11 deletions src/GitVersionExe/GitVersionExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,16 @@ public class GitVersionExecutor : IGitVersionExecutor
private readonly IHelpWriter helpWriter;
private readonly IExecCommand execCommand;
private readonly IConfigProvider configProvider;
private readonly IBuildServerResolver buildServerResolver;
private readonly IGitVersionTool gitVersionTool;
private readonly IVersionWriter versionWriter;

public GitVersionExecutor(ILog log, IConfigFileLocator configFileLocator, IConfigProvider configProvider,
IBuildServerResolver buildServerResolver, IGitVersionTool gitVersionTool,
public GitVersionExecutor(ILog log, IConfigFileLocator configFileLocator, IConfigProvider configProvider, IGitVersionTool gitVersionTool,
IVersionWriter versionWriter, IHelpWriter helpWriter, IExecCommand execCommand)
{
this.log = log ?? throw new ArgumentNullException(nameof(log));
this.configFileLocator = configFileLocator ?? throw new ArgumentNullException(nameof(configFileLocator));
this.configProvider = configProvider ?? throw new ArgumentNullException(nameof(configFileLocator));

this.buildServerResolver = buildServerResolver ?? throw new ArgumentNullException(nameof(buildServerResolver));
this.gitVersionTool = gitVersionTool ?? throw new ArgumentNullException(nameof(gitVersionTool));

this.versionWriter = versionWriter ?? throw new ArgumentNullException(nameof(versionWriter));
Expand All @@ -38,7 +35,10 @@ public GitVersionExecutor(ILog log, IConfigFileLocator configFileLocator, IConfi

public int Execute(Arguments arguments)
{
var exitCode = VerifyArgumentsAndRun(arguments);
if (!HandleNonMainCommand(arguments, out var exitCode))
{
exitCode = RunGitVersionTool(arguments);
}

if (exitCode != 0)
{
Expand All @@ -49,12 +49,10 @@ public int Execute(Arguments arguments)
return exitCode;
}

private int VerifyArgumentsAndRun(Arguments arguments)
private int RunGitVersionTool(Arguments arguments)
{
try
{
if (HandleNonMainCommand(arguments, out var exitCode)) return exitCode;

var variables = gitVersionTool.CalculateVersionVariables();

gitVersionTool.OutputVariables(variables, Console.WriteLine);
Expand Down Expand Up @@ -132,9 +130,6 @@ private bool HandleNonMainCommand(Arguments arguments, out int exitCode)
arguments.Output.Add(OutputType.BuildServer);
}

var buildServer = buildServerResolver.Resolve();
arguments.NoFetch = arguments.NoFetch || buildServer != null && buildServer.PreventFetch();

ConfigureLogging(arguments, log);

if (arguments.Diag)
Expand Down

0 comments on commit 255afd9

Please sign in to comment.