Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4a9fa96
Add Microsoft.Extensions.DependencyInjection
arturcic Oct 17, 2019
ff811ea
Add Microsoft.Extensions.Hosting
arturcic Oct 17, 2019
83d002a
Register types in each module
arturcic Oct 20, 2019
8895c6c
refactored ExecCommand and ExecuteCore
arturcic Oct 21, 2019
f3ac0e9
replaced BuildServerList with BuildServerResolver
arturcic Oct 21, 2019
26480d7
moved initialization to CoreModule
arturcic Oct 21, 2019
923f91d
applied code review changes
arturcic Oct 22, 2019
dd892d5
using c#8 using declarations
arturcic Oct 22, 2019
dbac722
code cleanup for GitVersionComputer & GitPrepare
arturcic Oct 22, 2019
df2f486
code cleanup for GitPrepare
arturcic Oct 22, 2019
d7d0dc5
moved the semanticversion classes to folder, made IGitVersionCache DI
arturcic Oct 22, 2019
ec1639e
applied code review changes
arturcic Oct 23, 2019
fb2566f
moving to DI GitVersionFinder, VariableProvider and MetaDataCalculator
arturcic Oct 23, 2019
8e0c12d
moving to DI ConfigurationProvider, GitPreparer
arturcic Oct 23, 2019
d040f41
made GitversionTask DI aware
arturcic Oct 23, 2019
ce1e815
migrate to DI IBaseVersionCalculator
arturcic Oct 23, 2019
9dcce02
migrate to DI NextVersionCalculator
arturcic Oct 23, 2019
901cccc
code cleanup
arturcic Oct 23, 2019
5958435
applied code review changes
arturcic Oct 24, 2019
82a8e33
made GitversionTask DI aware, added GitVersionTaskExecutor
arturcic Oct 24, 2019
433a597
ConfigurationProvider cleanup
arturcic Oct 24, 2019
d572cc7
moving to DI MainlineVersionCalculator
arturcic Oct 24, 2019
dff4e62
using c#8 switch expressions
arturcic Oct 24, 2019
b394a93
moving to DI ConfigInit
arturcic Oct 24, 2019
b243b4d
ConfigInitSteps, made constructor with the same parameters
arturcic Oct 24, 2019
cd1afb1
moving to DI ConfigInit (2), added IConfigInitStepFactory
arturcic Oct 24, 2019
a22fb34
added "?? throw new ArgumentNullException(nameof({field}))" to the i…
arturcic Oct 24, 2019
405cdb3
fix GitPrepare injection
arturcic Oct 24, 2019
ba517dd
moved ConfigInit registration from CoreModule
arturcic Oct 24, 2019
70cb999
introduced ConfigFileLocatorFactory
arturcic Oct 24, 2019
98eebe6
adjusted field names, removed underscore
arturcic Oct 25, 2019
2684c41
code review adjustments
arturcic Oct 25, 2019
7ef3499
code review adjustments
arturcic Oct 25, 2019
02074ed
Moved the `GitVersionTask` and `GitVersionTask.MsBuild` under `GitVer…
arturcic Oct 25, 2019
83ed431
+semver: minor code review adjustments
arturcic Oct 25, 2019
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
Prev Previous commit
Next Next commit
applied code review changes
  • Loading branch information
arturcic committed Oct 23, 2019
commit 923f91df216cd60e1f86d133757d1ea01fbc915e
4 changes: 2 additions & 2 deletions src/GitVersionCore.Tests/DynamicRepositoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public void FindsVersionInDynamicRepo(string name, string url, string targetBran
var log = new NullLog();
var configFileLocator = new DefaultConfigFileLocator(testFileSystem, log);

var executeCore = new ExecuteCore(testFileSystem, log, configFileLocator, new BuildServerResolver(null, log));
var executeCore = new GitVersionComputer(testFileSystem, log, configFileLocator, new BuildServerResolver(null, log));

var versionVariables = executeCore.ExecuteGitVersion(arguments);
var versionVariables = executeCore.ComputeVersionVariables(arguments);

Assert.AreEqual(expectedFullSemVer, versionVariables.FullSemVer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace GitVersionCore.Tests
{
[TestFixture]
[Parallelizable(ParallelScope.None)]
public class ExecuteCoreTests : TestBase
public class GitVersionExecutorTests : TestBase
{
private IFileSystem fileSystem;
private IEnvironment environment;
Expand All @@ -40,7 +40,7 @@ public void SetUp()
[Test]
public void CacheKeySameAfterReNormalizing()
{
var versionAndBranchFinder = new ExecuteCore(fileSystem, log, configFileLocator, buildServerResolver);
var versionAndBranchFinder = new GitVersionComputer(fileSystem, log, configFileLocator, buildServerResolver);

RepositoryScope(versionAndBranchFinder, (fixture, vv) =>
{
Expand All @@ -62,7 +62,7 @@ public void CacheKeySameAfterReNormalizing()
[Description("LibGit2Sharp fails here when running under Mono")]
public void CacheKeyForWorktree()
{
var versionAndBranchFinder = new ExecuteCore(fileSystem, log, configFileLocator, buildServerResolver);
var versionAndBranchFinder = new GitVersionComputer(fileSystem, log, configFileLocator, buildServerResolver);

RepositoryScope(versionAndBranchFinder, (fixture, vv) =>
{
Expand Down Expand Up @@ -128,12 +128,12 @@ public void CacheFileExistsOnDisk()
var logAppender = new TestLogAppender(Action);
log = new Log(logAppender);

var versionAndBranchFinder = new ExecuteCore(fileSystem, log, configFileLocator, buildServerResolver);
var versionAndBranchFinder = new GitVersionComputer(fileSystem, log, configFileLocator, buildServerResolver);

RepositoryScope(versionAndBranchFinder, (fixture, vv) =>
{
fileSystem.WriteAllText(vv.FileName, versionCacheFileContent);
vv = versionAndBranchFinder.ExecuteGitVersion(new Arguments { TargetPath = fixture.RepositoryPath });
vv = versionAndBranchFinder.ComputeVersionVariables(new Arguments { TargetPath = fixture.RepositoryPath });
vv.AssemblySemVer.ShouldBe("4.10.3.0");
});

Expand Down Expand Up @@ -177,7 +177,7 @@ public void CacheFileExistsOnDiskWhenOverrideConfigIsSpecifiedVersionShouldBeDyn
CommitDate: 2015-11-10
";

var versionAndBranchFinder = new ExecuteCore(fileSystem, log, configFileLocator, buildServerResolver);
var versionAndBranchFinder = new GitVersionComputer(fileSystem, log, configFileLocator, buildServerResolver);

RepositoryScope(versionAndBranchFinder, (fixture, vv) =>
{
Expand All @@ -188,7 +188,7 @@ public void CacheFileExistsOnDiskWhenOverrideConfigIsSpecifiedVersionShouldBeDyn

var cacheDirectoryTimestamp = fileSystem.GetLastDirectoryWrite(cacheDirectory);

vv = versionAndBranchFinder.ExecuteGitVersion(new Arguments { TargetPath = fixture.RepositoryPath , OverrideConfig = new Config { TagPrefix = "prefix" } });
vv = versionAndBranchFinder.ComputeVersionVariables(new Arguments { TargetPath = fixture.RepositoryPath , OverrideConfig = new Config { TagPrefix = "prefix" } });

vv.AssemblySemVer.ShouldBe("0.1.0.0");

Expand All @@ -208,7 +208,7 @@ public void CacheFileIsMissing()
var logAppender = new TestLogAppender(Action);
log = new Log(logAppender);

var executeCore = new ExecuteCore(fileSystem, log, configFileLocator, buildServerResolver);
var executeCore = new GitVersionComputer(fileSystem, log, configFileLocator, buildServerResolver);

RepositoryScope(executeCore);
var logsMessages = stringBuilder.ToString();
Expand Down Expand Up @@ -252,19 +252,19 @@ public void ConfigChangeInvalidatesCache()
CommitDate: 2015-11-10
";

var versionAndBranchFinder = new ExecuteCore(fileSystem, log, configFileLocator, buildServerResolver);
var versionAndBranchFinder = new GitVersionComputer(fileSystem, log, configFileLocator, buildServerResolver);

RepositoryScope(versionAndBranchFinder, (fixture, vv) =>
{
fileSystem.WriteAllText(vv.FileName, versionCacheFileContent);
var arguments = new Arguments { TargetPath = fixture.RepositoryPath };
vv = versionAndBranchFinder.ExecuteGitVersion(arguments);
vv = versionAndBranchFinder.ComputeVersionVariables(arguments);
vv.AssemblySemVer.ShouldBe("4.10.3.0");

var configPath = Path.Combine(fixture.RepositoryPath, "GitVersionConfig.yaml");
fileSystem.WriteAllText(configPath, "next-version: 5.0");

vv = versionAndBranchFinder.ExecuteGitVersion(arguments);
vv = versionAndBranchFinder.ComputeVersionVariables(arguments);
vv.AssemblySemVer.ShouldBe("5.0.0.0");
});
}
Expand Down Expand Up @@ -305,18 +305,18 @@ public void NoCacheBypassesCache()
CommitDate: 2015-11-10
";

var versionAndBranchFinder = new ExecuteCore(fileSystem, log, configFileLocator, buildServerResolver);
var versionAndBranchFinder = new GitVersionComputer(fileSystem, log, configFileLocator, buildServerResolver);

RepositoryScope(versionAndBranchFinder, (fixture, vv) =>
{
var arguments = new Arguments { TargetPath = fixture.RepositoryPath };

fileSystem.WriteAllText(vv.FileName, versionCacheFileContent);
vv = versionAndBranchFinder.ExecuteGitVersion(arguments);
vv = versionAndBranchFinder.ComputeVersionVariables(arguments);
vv.AssemblySemVer.ShouldBe("4.10.3.0");

arguments.NoCache = true;
vv = versionAndBranchFinder.ExecuteGitVersion(arguments);
vv = versionAndBranchFinder.ComputeVersionVariables(arguments);
vv.AssemblySemVer.ShouldBe("0.1.0.0");
});
}
Expand All @@ -325,13 +325,13 @@ public void NoCacheBypassesCache()
[Test]
public void WorkingDirectoryWithoutGit()
{
var versionAndBranchFinder = new ExecuteCore(fileSystem, log, configFileLocator, buildServerResolver);
var versionAndBranchFinder = new GitVersionComputer(fileSystem, log, configFileLocator, buildServerResolver);

RepositoryScope(versionAndBranchFinder, (fixture, vv) =>
{
var arguments = new Arguments { TargetPath = Environment.SystemDirectory };

var exception = Assert.Throws<DirectoryNotFoundException>(() => versionAndBranchFinder.ExecuteGitVersion(arguments));
var exception = Assert.Throws<DirectoryNotFoundException>(() => versionAndBranchFinder.ComputeVersionVariables(arguments));
exception.Message.ShouldContain("Can't find the .git directory in");
});
}
Expand All @@ -341,7 +341,7 @@ public void WorkingDirectoryWithoutGit()
[Description("LibGit2Sharp fails when running under Mono")]
public void GetProjectRootDirectory_WorkingDirectoryWithWorktree()
{
var versionAndBranchFinder = new ExecuteCore(fileSystem, log, configFileLocator, buildServerResolver);
var versionAndBranchFinder = new GitVersionComputer(fileSystem, log, configFileLocator, buildServerResolver);

RepositoryScope(versionAndBranchFinder, (fixture, vv) =>
{
Expand All @@ -366,7 +366,7 @@ public void GetProjectRootDirectory_WorkingDirectoryWithWorktree()
[Test]
public void GetProjectRootDirectory_NoWorktree()
{
var versionAndBranchFinder = new ExecuteCore(fileSystem, log, configFileLocator, buildServerResolver);
var versionAndBranchFinder = new GitVersionComputer(fileSystem, log, configFileLocator, buildServerResolver);

RepositoryScope(versionAndBranchFinder, (fixture, vv) =>
{
Expand All @@ -380,7 +380,7 @@ public void GetProjectRootDirectory_NoWorktree()
[Test]
public void DynamicRepositoriesShouldNotErrorWithFailedToFindGitDirectory()
{
var versionAndBranchFinder = new ExecuteCore(fileSystem, log, configFileLocator, buildServerResolver);
var versionAndBranchFinder = new GitVersionComputer(fileSystem, log, configFileLocator, buildServerResolver);

RepositoryScope(versionAndBranchFinder, (fixture, vv) =>
{
Expand All @@ -391,14 +391,14 @@ public void DynamicRepositoriesShouldNotErrorWithFailedToFindGitDirectory()
TargetBranch = "refs/head/master"
};

versionAndBranchFinder.ExecuteGitVersion(arguments);
versionAndBranchFinder.ComputeVersionVariables(arguments);
});
}

[Test]
public void GetDotGitDirectory_NoWorktree()
{
var versionAndBranchFinder = new ExecuteCore(fileSystem, log, configFileLocator, buildServerResolver);
var versionAndBranchFinder = new GitVersionComputer(fileSystem, log, configFileLocator, buildServerResolver);

RepositoryScope(versionAndBranchFinder, (fixture, vv) =>
{
Expand All @@ -414,7 +414,7 @@ public void GetDotGitDirectory_NoWorktree()
[Description("LibGit2Sharp fails when running under Mono")]
public void GetDotGitDirectory_Worktree()
{
var versionAndBranchFinder = new ExecuteCore(fileSystem, log, configFileLocator, buildServerResolver);
var versionAndBranchFinder = new GitVersionComputer(fileSystem, log, configFileLocator, buildServerResolver);

RepositoryScope(versionAndBranchFinder, (fixture, vv) =>
{
Expand All @@ -438,7 +438,7 @@ public void GetDotGitDirectory_Worktree()
});
}

private void RepositoryScope(ExecuteCore executeCore, Action<EmptyRepositoryFixture, VersionVariables> fixtureAction = null)
private void RepositoryScope(GitVersionComputer gitVersionComputer, Action<EmptyRepositoryFixture, VersionVariables> fixtureAction = null)
{
// Make sure GitVersion doesn't trigger build server mode when we are running the tests
environment.SetEnvironmentVariable(AppVeyor.EnvironmentVariableName, null);
Expand All @@ -449,7 +449,7 @@ private void RepositoryScope(ExecuteCore executeCore, Action<EmptyRepositoryFixt
using var fixture = new EmptyRepositoryFixture();
var arguments = new Arguments { TargetPath = fixture.RepositoryPath };
fixture.Repository.MakeACommit();
var vv = executeCore.ExecuteGitVersion(arguments);
var vv = gitVersionComputer.ComputeVersionVariables(arguments);

vv.AssemblySemVer.ShouldBe("0.1.0.0");
vv.FileName.ShouldNotBeNullOrEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

namespace GitVersion
{
public class ExecuteCore : IExecuteCore
public class GitVersionComputer : IGitVersionComputer
{
private readonly IFileSystem fileSystem;
private readonly ILog log;
private readonly IConfigFileLocator configFileLocator;
private readonly IBuildServerResolver buildServerResolver;
private readonly GitVersionCache gitVersionCache;

public ExecuteCore(IFileSystem fileSystem, ILog log, IConfigFileLocator configFileLocator, IBuildServerResolver buildServerResolver)
public GitVersionComputer(IFileSystem fileSystem, ILog log, IConfigFileLocator configFileLocator, IBuildServerResolver buildServerResolver)
{
this.fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
this.log = log;
Expand All @@ -25,9 +25,9 @@ public ExecuteCore(IFileSystem fileSystem, ILog log, IConfigFileLocator configFi
gitVersionCache = new GitVersionCache(fileSystem, log);
}

public VersionVariables ExecuteGitVersion(Arguments arguments)
public VersionVariables ComputeVersionVariables(Arguments arguments)
{
return ExecuteGitVersion(
return ComputeVersionVariables(
arguments.TargetUrl, arguments.DynamicRepositoryLocation, arguments.Authentication,
arguments.TargetBranch, arguments.NoFetch, arguments.TargetPath,
arguments.CommitId, arguments.OverrideConfig, arguments.NoCache, arguments.NoNormalize);
Expand All @@ -37,7 +37,7 @@ public bool TryGetVersion(string directory, out VersionVariables versionVariable
{
try
{
versionVariables = ExecuteGitVersion(null, null, null, null, noFetch, directory, null);
versionVariables = ComputeVersionVariables(null, null, null, null, noFetch, directory, null);
return true;
}
catch (Exception ex)
Expand All @@ -48,7 +48,7 @@ public bool TryGetVersion(string directory, out VersionVariables versionVariable
}
}

private VersionVariables ExecuteGitVersion(string targetUrl, string dynamicRepositoryLocation, Authentication authentication, string targetBranch, bool noFetch, string workingDirectory, string commitId, Config overrideConfig = null, bool noCache = false, bool noNormalize = false)
private VersionVariables ComputeVersionVariables(string targetUrl, string dynamicRepositoryLocation, Authentication authentication, string targetBranch, bool noFetch, string workingDirectory, string commitId, Config overrideConfig = null, bool noCache = false, bool noNormalize = false)
{
// Normalize if we are running on build server
var buildServer = buildServerResolver.GetCurrentBuildServer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

namespace GitVersion
{
public class CoreModule : IModule
public class GitVersionModule : IModule
{
public void RegisterTypes(IServiceCollection services)
{
services.AddSingleton<IFileSystem, FileSystem>();
services.AddSingleton<IEnvironment, Environment>();
services.AddSingleton<ILog, Log>();

services.AddSingleton<IExecuteCore, ExecuteCore>();
services.AddSingleton<IGitVersionComputer, GitVersionComputer>();

services.AddSingleton<IBuildServerResolver, BuildServerResolver>();
services.AddSingleton(GetConfigFileLocator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace GitVersion
{
public interface IExecuteCore
public interface IGitVersionComputer
{
VersionVariables ExecuteGitVersion(Arguments arguments);
VersionVariables ComputeVersionVariables(Arguments arguments);
bool TryGetVersion(string directory, out VersionVariables versionVariables, bool noFetch);
}
}
10 changes: 5 additions & 5 deletions src/GitVersionExe/ExecCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ public class ExecCommand : IExecCommand
private readonly IFileSystem fileSystem;
private readonly IBuildServerResolver buildServerResolver;
private readonly ILog log;
private readonly IExecuteCore executeCore;
private readonly IGitVersionComputer gitVersionComputer;
private readonly Arguments arguments;
public static readonly string BuildTool = GetMsBuildToolPath();

public ExecCommand(IFileSystem fileSystem, IBuildServerResolver buildServerResolver, ILog log, IExecuteCore executeCore, IOptions<Arguments> arguments)
public ExecCommand(IFileSystem fileSystem, IBuildServerResolver buildServerResolver, ILog log, IGitVersionComputer gitVersionComputer, IOptions<Arguments> arguments)
{
this.fileSystem = fileSystem;
this.buildServerResolver = buildServerResolver;
this.log = log;
this.executeCore = executeCore;
this.gitVersionComputer = gitVersionComputer;
this.arguments = arguments.Value;
}

public void Execute()
public void Compute()
{
log.Info($"Running on {(runningOnUnix ? "Unix" : "Windows")}.");

var variables = executeCore.ExecuteGitVersion(arguments);
var variables = gitVersionComputer.ComputeVersionVariables(arguments);

switch (arguments.Output)
{
Expand Down
8 changes: 4 additions & 4 deletions src/GitVersionExe/GitVersionApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ namespace GitVersion
internal class GitVersionApp : IHostedService
{
private readonly IHostApplicationLifetime applicationLifetime;
private readonly IGitVersionRunner gitVersionRunner;
private readonly IGitVersionExecutor gitVersionExecutor;
private readonly Arguments arguments;

public GitVersionApp(IHostApplicationLifetime applicationLifetime, IGitVersionRunner gitVersionRunner, ILog log, IOptions<Arguments> options)
public GitVersionApp(IHostApplicationLifetime applicationLifetime, IGitVersionExecutor gitVersionExecutor, ILog log, IOptions<Arguments> options)
{
this.arguments = options.Value;
this.applicationLifetime = applicationLifetime;
this.gitVersionRunner = gitVersionRunner;
this.gitVersionExecutor = gitVersionExecutor;

log.Verbosity = arguments.Verbosity;
}
public Task StartAsync(CancellationToken cancellationToken)
{
try
{
gitVersionRunner.Run(arguments);
gitVersionExecutor.Run(arguments);
}
catch (Exception exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

namespace GitVersion
{
public class Module : IModule
public class GitVersionExeModule : IModule
{
public void RegisterTypes(IServiceCollection services)
{
services.AddSingleton<IArgumentParser, ArgumentParser>();
services.AddSingleton<IHelpWriter, HelpWriter>();
services.AddSingleton<IVersionWriter, VersionWriter>();
services.AddSingleton<IGitVersionRunner, GitVersionRunner>();
services.AddSingleton<IGitVersionExecutor, GitVersionExecutor>();

services.AddTransient<IExecCommand, ExecCommand>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace GitVersion
{
public class GitVersionRunner : IGitVersionRunner
public class GitVersionExecutor : IGitVersionExecutor
{
private readonly IFileSystem fileSystem;
private readonly ILog log;
Expand All @@ -19,7 +19,7 @@ public class GitVersionRunner : IGitVersionRunner
private readonly IExecCommand execCommand;
private readonly IVersionWriter versionWriter;

public GitVersionRunner(IFileSystem fileSystem, ILog log, IConfigFileLocator configFileLocator, IVersionWriter versionWriter, IHelpWriter helpWriter, IExecCommand execCommand)
public GitVersionExecutor(IFileSystem fileSystem, ILog log, IConfigFileLocator configFileLocator, IVersionWriter versionWriter, IHelpWriter helpWriter, IExecCommand execCommand)
{
this.fileSystem = fileSystem;
this.log = log;
Expand Down Expand Up @@ -105,7 +105,7 @@ private int VerifyArgumentsAndRun(Arguments arguments)
return 0;
}

execCommand.Execute();
execCommand.Compute();
}
catch (WarningException exception)
{
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersionExe/IExecCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ namespace GitVersion
{
public interface IExecCommand
{
void Execute();
void Compute();
}
}
Loading