Skip to content

Commit 79f13a3

Browse files
committed
replace Path.* usage with PathHelper.*
1 parent 5ab6336 commit 79f13a3

File tree

26 files changed

+81
-60
lines changed

26 files changed

+81
-60
lines changed

src/GitVersion.App.Tests/ArgumentParserTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public void UpdateAssemblyInfoWithFilename()
289289
var arguments = this.argumentParser.ParseArguments($"-targetpath {repo.RepositoryPath} -updateAssemblyInfo CommonAssemblyInfo.cs");
290290
arguments.UpdateAssemblyInfo.ShouldBe(true);
291291
arguments.UpdateAssemblyInfoFileName.Count.ShouldBe(1);
292-
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => Path.GetFileName(x).Equals("CommonAssemblyInfo.cs"));
292+
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => PathHelper.GetFileName(x).Equals("CommonAssemblyInfo.cs"));
293293
}
294294

295295
[Test]
@@ -306,8 +306,8 @@ public void UpdateAssemblyInfoWithMultipleFilenames()
306306
var arguments = this.argumentParser.ParseArguments($"-targetpath {repo.RepositoryPath} -updateAssemblyInfo CommonAssemblyInfo.cs VersionAssemblyInfo.cs");
307307
arguments.UpdateAssemblyInfo.ShouldBe(true);
308308
arguments.UpdateAssemblyInfoFileName.Count.ShouldBe(2);
309-
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => Path.GetFileName(x).Equals("CommonAssemblyInfo.cs"));
310-
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => Path.GetFileName(x).Equals("VersionAssemblyInfo.cs"));
309+
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => PathHelper.GetFileName(x).Equals("CommonAssemblyInfo.cs"));
310+
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => PathHelper.GetFileName(x).Equals("VersionAssemblyInfo.cs"));
311311
}
312312

313313
[Test]
@@ -324,8 +324,8 @@ public void UpdateProjectFilesWithMultipleFilenames()
324324
var arguments = this.argumentParser.ParseArguments($"-targetpath {repo.RepositoryPath} -updateProjectFiles CommonAssemblyInfo.csproj VersionAssemblyInfo.csproj");
325325
arguments.UpdateProjectFiles.ShouldBe(true);
326326
arguments.UpdateAssemblyInfoFileName.Count.ShouldBe(2);
327-
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => Path.GetFileName(x).Equals("CommonAssemblyInfo.csproj"));
328-
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => Path.GetFileName(x).Equals("VersionAssemblyInfo.csproj"));
327+
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => PathHelper.GetFileName(x).Equals("CommonAssemblyInfo.csproj"));
328+
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => PathHelper.GetFileName(x).Equals("VersionAssemblyInfo.csproj"));
329329
}
330330

331331
[Test]
@@ -348,9 +348,9 @@ public void UpdateAssemblyInfoWithMultipleFilenamesMatchingGlobbing()
348348
var arguments = this.argumentParser.ParseArguments($"-targetpath {repo.RepositoryPath} -updateAssemblyInfo **/*AssemblyInfo.cs");
349349
arguments.UpdateAssemblyInfo.ShouldBe(true);
350350
arguments.UpdateAssemblyInfoFileName.Count.ShouldBe(3);
351-
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => Path.GetFileName(x).Equals("CommonAssemblyInfo.cs"));
352-
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => Path.GetFileName(x).Equals("VersionAssemblyInfo.cs"));
353-
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => Path.GetFileName(x).Equals("LocalAssemblyInfo.cs"));
351+
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => PathHelper.GetFileName(x).Equals("CommonAssemblyInfo.cs"));
352+
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => PathHelper.GetFileName(x).Equals("VersionAssemblyInfo.cs"));
353+
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => PathHelper.GetFileName(x).Equals("LocalAssemblyInfo.cs"));
354354
}
355355

356356
[Test]
@@ -367,7 +367,7 @@ public void UpdateAssemblyInfoWithRelativeFilename()
367367
var arguments = this.argumentParser.ParseArguments($"-targetpath {targetPath} -updateAssemblyInfo ..\\..\\CommonAssemblyInfo.cs");
368368
arguments.UpdateAssemblyInfo.ShouldBe(true);
369369
arguments.UpdateAssemblyInfoFileName.Count.ShouldBe(1);
370-
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => Path.GetFileName(x).Equals("CommonAssemblyInfo.cs"));
370+
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => PathHelper.GetFileName(x).Equals("CommonAssemblyInfo.cs"));
371371
}
372372

373373
[Test]

src/GitVersion.App/ArgumentParser.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ private void ValidateConfigurationFile(Arguments arguments)
107107
{
108108
if (arguments.ConfigurationFile.IsNullOrWhiteSpace()) return;
109109

110-
if (Path.IsPathRooted(arguments.ConfigurationFile))
110+
if (PathHelper.IsPathRooted(arguments.ConfigurationFile))
111111
{
112112
if (!this.fileSystem.File.Exists(arguments.ConfigurationFile)) throw new WarningException($"Could not find config file at '{arguments.ConfigurationFile}'");
113-
arguments.ConfigurationFile = Path.GetFullPath(arguments.ConfigurationFile);
113+
arguments.ConfigurationFile = PathHelper.GetFullPath(arguments.ConfigurationFile);
114114
}
115115
else
116116
{
117-
var configFilePath = Path.GetFullPath(PathHelper.Combine(arguments.TargetPath, arguments.ConfigurationFile));
117+
var configFilePath = PathHelper.GetFullPath(PathHelper.Combine(arguments.TargetPath, arguments.ConfigurationFile));
118118
if (!this.fileSystem.File.Exists(configFilePath)) throw new WarningException($"Could not find config file at '{configFilePath}'");
119119
arguments.ConfigurationFile = configFilePath;
120120
}
@@ -156,7 +156,7 @@ private IEnumerable<string> ResolveFiles(string workingDirectory, ISet<string>?
156156

157157
foreach (var path in paths)
158158
{
159-
yield return Path.GetFullPath(PathHelper.Combine(workingDirectory, path));
159+
yield return PathHelper.GetFullPath(PathHelper.Combine(workingDirectory, path));
160160
}
161161
}
162162
}
@@ -182,7 +182,7 @@ private void ParseTargetPath(Arguments arguments, string? name, IReadOnlyList<st
182182
{
183183
if (name?.StartsWith('/') == true)
184184
{
185-
if (Path.DirectorySeparatorChar == '/' && name.IsValidPath())
185+
if (PathHelper.DirectorySeparatorChar == '/' && name.IsValidPath())
186186
{
187187
arguments.TargetPath = name;
188188
return;

src/GitVersion.App/ArgumentParserExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static bool ArgumentRequiresValue(this string argument, int argumentIndex
7474
var argumentMightRequireValue = !booleanArguments.Contains(argument[1..], StringComparer.OrdinalIgnoreCase);
7575

7676
// If this is the first argument that might be a target path, the argument starts with slash, and we're on an OS that supports paths with slashes, the argument does not require a value.
77-
if (argumentMightRequireValue && argumentIndex == 0 && argument.StartsWith('/') && Path.DirectorySeparatorChar == '/' && argument.IsValidPath())
77+
if (argumentMightRequireValue && argumentIndex == 0 && argument.StartsWith('/') && PathHelper.DirectorySeparatorChar == '/' && argument.IsValidPath())
7878
return false;
7979

8080
return argumentMightRequireValue;

src/GitVersion.App/FileAppender.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public FileAppender(IFileSystem fileSystem, string filePath)
1515
this.fileSystem = fileSystem.NotNull();
1616
this.filePath = filePath;
1717

18-
var logFile = this.fileSystem.FileInfo.New(Path.GetFullPath(filePath));
18+
var logFile = this.fileSystem.FileInfo.New(PathHelper.GetFullPath(filePath));
1919

2020
logFile.Directory?.Create();
2121
if (logFile.Exists) return;

src/GitVersion.App/GitVersionExecutor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public int Execute(GitVersionOptions gitVersionOptions)
5656
private int RunGitVersionTool(GitVersionOptions gitVersionOptions)
5757
{
5858
this.gitRepository.DiscoverRepository(gitVersionOptions.WorkingDirectory);
59-
var mutexName = this.repositoryInfo.DotGitDirectory?.Replace(Path.DirectorySeparatorChar.ToString(), "") ?? string.Empty;
59+
var mutexName = this.repositoryInfo.DotGitDirectory?.Replace(PathHelper.DirectorySeparatorChar.ToString(), "") ?? string.Empty;
6060
using var mutex = new Mutex(true, $@"Global\gitversion{mutexName}", out var acquired);
6161

6262
try

src/GitVersion.BuildAgents.Tests/Agents/BitBucketPipelinesTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void GetCurrentBranchShouldHandlePullRequests()
120120
[Test]
121121
public void WriteAllVariablesToTheTextWriter()
122122
{
123-
var assemblyLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
123+
var assemblyLocation = PathHelper.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
124124
assemblyLocation.ShouldNotBeNull();
125125
var propertyFile = PathHelper.Combine(assemblyLocation, "gitversion.properties");
126126
var ps1File = PathHelper.Combine(assemblyLocation, "gitversion.ps1");

src/GitVersion.BuildAgents.Tests/Agents/CodeBuildTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void PicksUpBranchNameFromEnvironmentFromWebHook()
5555
[Test]
5656
public void WriteAllVariablesToTheTextWriter()
5757
{
58-
var assemblyLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
58+
var assemblyLocation = PathHelper.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
5959
assemblyLocation.ShouldNotBeNull();
6060
var f = PathHelper.Combine(assemblyLocation, "codebuild_this_file_should_be_deleted.properties");
6161

src/GitVersion.BuildAgents.Tests/Agents/GitHubActionsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public void SetUp()
2323
this.environment.SetEnvironmentVariable(GitHubActions.EnvironmentVariableName, "true");
2424
this.environment.SetEnvironmentVariable("GITHUB_REF_TYPE", "branch");
2525

26-
this.githubSetEnvironmentTempFilePath = Path.GetTempFileName();
26+
this.githubSetEnvironmentTempFilePath = PathHelper.GetTempFileName();
2727
this.environment.SetEnvironmentVariable(GitHubActions.GitHubSetEnvTempFileEnvironmentVariableName, this.githubSetEnvironmentTempFilePath);
2828
}
2929

src/GitVersion.BuildAgents.Tests/Agents/GitLabCiTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void GetCurrentBranchShouldHandlePullRequests(string branchName, string e
9595
[Test]
9696
public void WriteAllVariablesToTheTextWriter()
9797
{
98-
var assemblyLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
98+
var assemblyLocation = PathHelper.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
9999
assemblyLocation.ShouldNotBeNull();
100100
var f = PathHelper.Combine(assemblyLocation, "jenkins_this_file_should_be_deleted.properties");
101101

src/GitVersion.BuildAgents.Tests/Agents/JenkinsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public void GenerateMessageTest()
111111
[Test]
112112
public void WriteAllVariablesToTheTextWriter()
113113
{
114-
var assemblyLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
114+
var assemblyLocation = PathHelper.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
115115
assemblyLocation.ShouldNotBeNull();
116116
var f = PathHelper.Combine(assemblyLocation, "gitlab_this_file_should_be_deleted.properties");
117117

0 commit comments

Comments
 (0)