Skip to content

Commit 2b6bca0

Browse files
committed
Refactor ProcessHelper and PathHelper classes
The ProcessHelper and PathHelper classes have been refactored to align with proper visibility levels and aliased "System.Environment.Newline" to "PathHelper.Newline". Their corresponding usages throughout the project have also been updated. Additionally, redundant code has been removed with this change.
1 parent 37e6daa commit 2b6bca0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+102
-289
lines changed

src/Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
<Using Include="System.Text.Json"/>
9999
<Using Include="System.Text.Json.Serialization"/>
100100
<Using Include="System.Xml"/>
101+
<Using Include="System.Environment" Alias="SysEnv"/>
101102
</ItemGroup>
102103

103104
<ItemGroup>

src/GitVersion.App.Tests/ArgumentParserTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void SetUp()
3030
public void EmptyMeansUseCurrentDirectory()
3131
{
3232
var arguments = this.argumentParser.ParseArguments("");
33-
arguments.TargetPath.ShouldBe(System.Environment.CurrentDirectory);
33+
arguments.TargetPath.ShouldBe(SysEnv.CurrentDirectory);
3434
arguments.LogFilePath.ShouldBe(null);
3535
arguments.IsHelp.ShouldBe(false);
3636
}
@@ -48,7 +48,7 @@ public void SingleMeansUseAsTargetDirectory()
4848
public void NoPathAndLogfileShouldUseCurrentDirectoryTargetDirectory()
4949
{
5050
var arguments = this.argumentParser.ParseArguments("-l logFilePath");
51-
arguments.TargetPath.ShouldBe(System.Environment.CurrentDirectory);
51+
arguments.TargetPath.ShouldBe(SysEnv.CurrentDirectory);
5252
arguments.LogFilePath.ShouldBe("logFilePath");
5353
arguments.IsHelp.ShouldBe(false);
5454
}

src/GitVersion.App.Tests/ExecCmdLineArgumentTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void CheckBuildServerVerbosityConsole(string verbosityArg, string expecte
4949
[Test]
5050
public void WorkingDirectoryWithoutGitFolderFailsWithInformativeMessage()
5151
{
52-
var result = GitVersionHelper.ExecuteIn(System.Environment.SystemDirectory, null, false);
52+
var result = GitVersionHelper.ExecuteIn(SysEnv.SystemDirectory, null, false);
5353

5454
result.ExitCode.ShouldNotBe(0);
5555
result.Output.ShouldContain("Cannot find the .git directory");
@@ -69,7 +69,7 @@ public void WorkingDirectoryWithoutCommitsFailsWithInformativeMessage()
6969
[Test]
7070
public void WorkingDirectoryDoesNotExistFailsWithInformativeMessage()
7171
{
72-
var workingDirectory = PathHelper.Combine(ExecutableHelper.GetCurrentDirectory(), Guid.NewGuid().ToString("N"));
72+
var workingDirectory = PathHelper.Combine(PathHelper.GetCurrentDirectory(), Guid.NewGuid().ToString("N"));
7373
var executable = ExecutableHelper.GetDotNetExecutable();
7474

7575
var output = new StringBuilder();
@@ -81,7 +81,7 @@ public void WorkingDirectoryDoesNotExistFailsWithInformativeMessage()
8181
null,
8282
executable,
8383
args,
84-
ExecutableHelper.GetCurrentDirectory());
84+
PathHelper.GetCurrentDirectory());
8585

8686
exitCode.ShouldNotBe(0);
8787
var outputString = output.ToString();

src/GitVersion.App.Tests/Helpers/ProgramFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public async Task<ProgramFixtureResult> Run(params string[] args)
6767

6868
return new ProgramFixtureResult
6969
{
70-
ExitCode = System.Environment.ExitCode,
70+
ExitCode = SysEnv.ExitCode,
7171
Output = this.output.Value,
7272
Log = this.logger.Value
7373
};

src/GitVersion.App.Tests/PullRequestInBuildAgentTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using GitVersion.Agents;
22
using GitVersion.Core.Tests.Helpers;
33
using GitVersion.Extensions;
4+
using GitVersion.Helpers;
45
using GitVersion.Output;
56
using LibGit2Sharp;
67

@@ -142,7 +143,7 @@ public async Task VerifyBitBucketPipelinesPullRequest(string pullRequestRef)
142143
private static async Task VerifyPullRequestVersionIsCalculatedProperly(string pullRequestRef, Dictionary<string, string> env)
143144
{
144145
using var fixture = new EmptyRepositoryFixture("main");
145-
var remoteRepositoryPath = ExecutableHelper.GetTempPath();
146+
var remoteRepositoryPath = PathHelper.GetTempPath();
146147
RepositoryFixtureBase.Init(remoteRepositoryPath, "main");
147148
using (var remoteRepository = new Repository(remoteRepositoryPath))
148149
{

src/GitVersion.App.Tests/TagCheckoutInBuildAgentTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using GitVersion.Agents;
22
using GitVersion.Core.Tests.Helpers;
3+
using GitVersion.Helpers;
34
using LibGit2Sharp;
45

56
namespace GitVersion.App.Tests;
@@ -34,7 +35,7 @@ public async Task VerifyTagCheckoutOnGitHubActions()
3435
private static async Task VerifyTagCheckoutVersionIsCalculatedProperly(Dictionary<string, string> env)
3536
{
3637
using var fixture = new EmptyRepositoryFixture("main");
37-
var remoteRepositoryPath = ExecutableHelper.GetTempPath();
38+
var remoteRepositoryPath = PathHelper.GetTempPath();
3839
RepositoryFixtureBase.Init(remoteRepositoryPath, "main");
3940
using (var remoteRepository = new Repository(remoteRepositoryPath))
4041
{

src/GitVersion.App/ArgumentParser.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public Arguments ParseArguments(string[] commandLineArguments)
3636
{
3737
var args = new Arguments
3838
{
39-
TargetPath = System.Environment.CurrentDirectory
39+
TargetPath = SysEnv.CurrentDirectory
4040
};
4141

4242
args.Output.Add(OutputType.Json);
@@ -54,7 +54,7 @@ public Arguments ParseArguments(string[] commandLineArguments)
5454
{
5555
return new Arguments
5656
{
57-
TargetPath = System.Environment.CurrentDirectory,
57+
TargetPath = SysEnv.CurrentDirectory,
5858
Init = true
5959
};
6060
}
@@ -99,7 +99,7 @@ public Arguments ParseArguments(string[] commandLineArguments)
9999
// If the first argument is a switch, it should already have been consumed in the above loop,
100100
// or else a WarningException should have been thrown and we wouldn't end up here.
101101
arguments.TargetPath ??= firstArgumentIsSwitch
102-
? System.Environment.CurrentDirectory
102+
? SysEnv.CurrentDirectory
103103
: firstArgument;
104104

105105
arguments.TargetPath = arguments.TargetPath.TrimEnd('/', '\\');
@@ -388,7 +388,7 @@ private static void ParseShowVariable(Arguments arguments, string? value, string
388388

389389
if (versionVariable == null)
390390
{
391-
var message = $"{name} requires a valid version variable. Available variables are:{System.Environment.NewLine}" +
391+
var message = $"{name} requires a valid version variable. Available variables are:{PathHelper.NewLine}" +
392392
string.Join(", ", availableVariables.Select(x => string.Concat("'", x, "'")));
393393
throw new WarningException(message);
394394
}

src/GitVersion.App/GitVersionApp.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ public Task StartAsync(CancellationToken cancellationToken)
2525
{
2626
var gitVersionOptions = this.options.Value;
2727
this.log.Verbosity = gitVersionOptions.Verbosity;
28-
System.Environment.ExitCode = this.gitVersionExecutor.Execute(gitVersionOptions);
28+
SysEnv.ExitCode = this.gitVersionExecutor.Execute(gitVersionOptions);
2929
}
3030
catch (Exception exception)
3131
{
3232
Console.Error.WriteLine(exception.Message);
33-
System.Environment.ExitCode = 1;
33+
SysEnv.ExitCode = 1;
3434
}
3535

3636
this.applicationLifetime.StopApplication();

src/GitVersion.App/GitVersionExecutor.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using GitVersion.Configuration;
22
using GitVersion.Extensions;
3+
using GitVersion.Helpers;
34
using GitVersion.Logging;
45

56
namespace GitVersion;
@@ -72,13 +73,13 @@ private int RunGitVersionTool(GitVersionOptions gitVersionOptions)
7273
}
7374
catch (WarningException exception)
7475
{
75-
var error = $"An error occurred:{System.Environment.NewLine}{exception.Message}";
76+
var error = $"An error occurred:{PathHelper.NewLine}{exception.Message}";
7677
this.log.Warning(error);
7778
return 1;
7879
}
7980
catch (Exception exception)
8081
{
81-
var error = $"An unexpected error occurred:{System.Environment.NewLine}{exception}";
82+
var error = $"An unexpected error occurred:{PathHelper.NewLine}{exception}";
8283
this.log.Error(error);
8384

8485
this.log.Info("Attempting to show the current git graph (please include in issue): ");

src/GitVersion.App/HelpWriter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using GitVersion.Extensions;
2+
using GitVersion.Helpers;
23
using GitVersion.Logging;
34

45
namespace GitVersion;
@@ -23,8 +24,7 @@ public void WriteTo(Action<string> writeAction)
2324
this.versionWriter.WriteTo(assembly, v => version = v);
2425

2526
var args = ArgumentList();
26-
var nl = System.Environment.NewLine;
27-
var message = "GitVersion " + version + nl + nl + args;
27+
var message = $"GitVersion {version}{PathHelper.NewLine}{PathHelper.NewLine}{args}";
2828

2929
writeAction(message);
3030
}

0 commit comments

Comments
 (0)