Skip to content

Commit b46a086

Browse files
committed
added IGlobbingResolver class
1 parent be19d1f commit b46a086

File tree

5 files changed

+63
-31
lines changed

5 files changed

+63
-31
lines changed

src/GitVersionExe/ArgumentParser.cs

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ public class ArgumentParser : IArgumentParser
1616
private readonly IEnvironment environment;
1717
private readonly ICurrentBuildAgent buildAgent;
1818
private readonly IConsole console;
19+
private readonly IGlobbingResolver globbingResolver;
1920

20-
public ArgumentParser(IEnvironment environment, ICurrentBuildAgent buildAgent, IConsole console)
21+
public ArgumentParser(IEnvironment environment, ICurrentBuildAgent buildAgent, IConsole console, IGlobbingResolver globbingResolver)
2122
{
2223
this.environment = environment ?? throw new ArgumentNullException(nameof(environment));
2324
this.console = console ?? throw new ArgumentNullException(nameof(console));
25+
this.globbingResolver = globbingResolver ?? throw new ArgumentNullException(nameof(globbingResolver));
2426
this.buildAgent = buildAgent;
2527
}
2628

@@ -87,6 +89,8 @@ public Arguments ParseArguments(string[] commandLineArguments)
8789
? System.Environment.CurrentDirectory
8890
: firstArgument;
8991

92+
arguments.TargetPath = arguments.TargetPath.TrimEnd('/', '\\');
93+
arguments.UpdateAssemblyInfoFileName = ResolveFiles(arguments.TargetPath, arguments.UpdateAssemblyInfoFileName).ToHashSet();
9094
arguments.NoFetch = arguments.NoFetch || buildAgent != null && buildAgent.PreventFetch();
9195

9296
return arguments;
@@ -234,7 +238,6 @@ private void ParseArguments(Arguments arguments, NameValueCollection switchesAnd
234238
if (name.IsSwitch("showConfig"))
235239
{
236240
ParseShowConfig(value, arguments);
237-
238241
return;
239242
}
240243

@@ -311,6 +314,21 @@ private void ParseArguments(Arguments arguments, NameValueCollection switchesAnd
311314
throw new WarningException(couldNotParseMessage);
312315
}
313316

317+
private void AddAuthentication(Arguments arguments)
318+
{
319+
var username = environment.GetEnvironmentVariable("GITVERSION_REMOTE_USERNAME");
320+
if (!string.IsNullOrWhiteSpace(username))
321+
{
322+
arguments.Authentication.Username = username;
323+
}
324+
325+
var password = environment.GetEnvironmentVariable("GITVERSION_REMOTE_PASSWORD");
326+
if (!string.IsNullOrWhiteSpace(password))
327+
{
328+
arguments.Authentication.Username = password;
329+
}
330+
}
331+
314332
private static void ParseShowConfig(string value, Arguments arguments)
315333
{
316334
if (value.IsTrue())
@@ -456,18 +474,18 @@ private static void ParseUpdateAssemblyInfo(Arguments arguments, string value, s
456474
}
457475
}
458476

459-
private void AddAuthentication(Arguments arguments)
477+
private IEnumerable<string> ResolveFiles(string workingDirectory, ISet<string> assemblyInfoFiles)
460478
{
461-
var username = environment.GetEnvironmentVariable("GITVERSION_REMOTE_USERNAME");
462-
if (!string.IsNullOrWhiteSpace(username))
463-
{
464-
arguments.Authentication.Username = username;
465-
}
479+
if (assemblyInfoFiles == null) yield break;
466480

467-
var password = environment.GetEnvironmentVariable("GITVERSION_REMOTE_PASSWORD");
468-
if (!string.IsNullOrWhiteSpace(password))
481+
foreach (var file in assemblyInfoFiles)
469482
{
470-
arguments.Authentication.Username = password;
483+
var paths = globbingResolver.Resolve(workingDirectory, file);
484+
485+
foreach (var path in paths)
486+
{
487+
yield return Path.GetFullPath(Path.Combine(workingDirectory, path));
488+
}
471489
}
472490
}
473491

src/GitVersionExe/Arguments.cs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
53
using GitVersion.Logging;
64
using GitVersion.Model;
75
using GitVersion.Model.Configuration;
8-
using Microsoft.Extensions.FileSystemGlobbing;
9-
using Microsoft.Extensions.FileSystemGlobbing.Abstractions;
106

117
namespace GitVersion
128
{
@@ -66,7 +62,7 @@ public GitVersionOptions ToOptions()
6662
{
6763
ShouldUpdate = UpdateAssemblyInfo,
6864
EnsureAssemblyInfo = EnsureAssemblyInfo,
69-
Files = ResolveFiles(workingDirectory).ToHashSet()
65+
Files = UpdateAssemblyInfoFileName
7066
},
7167

7268
Authentication =
@@ -121,21 +117,6 @@ public GitVersionOptions ToOptions()
121117
};
122118
}
123119

124-
private IEnumerable<string> ResolveFiles(string workingDirectory)
125-
{
126-
if (UpdateAssemblyInfoFileName == null) yield break;
127-
var matcher = new Matcher(StringComparison.OrdinalIgnoreCase);
128-
129-
foreach (var file in UpdateAssemblyInfoFileName)
130-
{
131-
matcher.AddInclude(file);
132-
var results = matcher.Execute(new DirectoryInfoWrapper(new DirectoryInfo(workingDirectory)));
133120

134-
foreach (var result in results.Files)
135-
{
136-
yield return Path.GetFullPath(Path.Combine(workingDirectory, result.Path));
137-
}
138-
}
139-
}
140121
}
141122
}

src/GitVersionExe/GitVersionExeModule.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ public class GitVersionExeModule : IGitVersionModule
77
public void RegisterTypes(IServiceCollection services)
88
{
99
services.AddSingleton<IArgumentParser, ArgumentParser>();
10+
services.AddSingleton<IGlobbingResolver, GlobbingResolver>();
11+
1012
services.AddSingleton<IHelpWriter, HelpWriter>();
1113
services.AddSingleton<IVersionWriter, VersionWriter>();
1214
services.AddSingleton<IGitVersionExecutor, GitVersionExecutor>();

src/GitVersionExe/GlobbingResolver.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using Microsoft.Extensions.FileSystemGlobbing;
6+
using Microsoft.Extensions.FileSystemGlobbing.Abstractions;
7+
8+
namespace GitVersion
9+
{
10+
public class GlobbingResolver : IGlobbingResolver
11+
{
12+
private Matcher matcher = new Matcher(StringComparison.OrdinalIgnoreCase);
13+
14+
public IEnumerable<string> Resolve(string workingDirectory, string pattern)
15+
{
16+
matcher.AddInclude(pattern);
17+
return matcher.Execute(GetDirectoryInfoWrapper(workingDirectory)).Files.Select(file => file.Path);
18+
}
19+
20+
protected virtual DirectoryInfoBase GetDirectoryInfoWrapper(string workingDirectory) => new DirectoryInfoWrapper(new DirectoryInfo(workingDirectory));
21+
}
22+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Collections.Generic;
2+
3+
namespace GitVersion
4+
{
5+
public interface IGlobbingResolver
6+
{
7+
public IEnumerable<string> Resolve(string workingDirectory, string pattern);
8+
}
9+
}

0 commit comments

Comments
 (0)