Skip to content

Commit be19d1f

Browse files
committed
GH-2225 use FileSystemGlobbing to resolve AsemblyInfo to be updated
1 parent d99dd95 commit be19d1f

File tree

6 files changed

+39
-10
lines changed

6 files changed

+39
-10
lines changed

src/GitVersionCore/Model/AssemblyInfo.cs renamed to src/GitVersionCore/Model/AssemblyInfoData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace GitVersion
44
{
5-
public class AssemblyInfo
5+
public class AssemblyInfoData
66
{
77
public bool ShouldUpdate;
88
public bool EnsureAssemblyInfo;

src/GitVersionCore/Model/GitVersionOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public GitVersionOptions()
2525
public string ProjectRootDirectory => projectRootDirectory.Value;
2626
public string DynamicGitRepositoryPath => dynamicGitRepositoryPath.Value;
2727

28-
public AssemblyInfo AssemblyInfo { get; } = new AssemblyInfo();
28+
public AssemblyInfoData AssemblyInfo { get; } = new AssemblyInfoData();
2929
public AuthenticationInfo Authentication { get; } = new AuthenticationInfo();
3030
public ConfigInfo ConfigInfo { get; } = new ConfigInfo();
3131
public RepositoryInfo RepositoryInfo { get; } = new RepositoryInfo();

src/GitVersionCore/VersionConverters/AssemblyInfo/AssemblyInfoFileUpdater.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@ public AssemblyInfoFileUpdater(ILog log, IFileSystem fileSystem)
4343

4444
public void Execute(VersionVariables variables, AssemblyInfoContext context)
4545
{
46-
var assemblyInfoFileNames = new HashSet<string>(context.AssemblyInfoFiles);
46+
var assemblyInfoFiles = GetAssemblyInfoFiles(context).ToList();
4747
log.Info("Updating assembly info files");
48-
49-
var assemblyInfoFiles = GetAssemblyInfoFiles(context.WorkingDirectory, assemblyInfoFileNames, context.EnsureAssemblyInfo).ToList();
5048
log.Info($"Found {assemblyInfoFiles.Count} files");
5149

5250
var assemblyVersion = variables.AssemblySemVer;
@@ -159,9 +157,13 @@ private string ReplaceOrInsertAfterLastAssemblyAttributeOrAppend(Regex replaceRe
159157
return inputString;
160158
}
161159

162-
private IEnumerable<FileInfo> GetAssemblyInfoFiles(string workingDirectory, ISet<string> assemblyInfoFileNames, bool ensureAssemblyInfo)
160+
private IEnumerable<FileInfo> GetAssemblyInfoFiles(AssemblyInfoContext context)
163161
{
164-
if (assemblyInfoFileNames != null && assemblyInfoFileNames.Any(x => !string.IsNullOrWhiteSpace(x)))
162+
var workingDirectory = context.WorkingDirectory;
163+
var ensureAssemblyInfo = context.EnsureAssemblyInfo;
164+
var assemblyInfoFileNames = new HashSet<string>(context.AssemblyInfoFiles);
165+
166+
if (assemblyInfoFileNames.Any(x => !string.IsNullOrWhiteSpace(x)))
165167
{
166168
foreach (var item in assemblyInfoFileNames)
167169
{

src/GitVersionExe/ArgumentParser.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,10 @@ private static void ParseUpdateAssemblyInfo(Arguments arguments, string value, s
440440
else if (!value.IsSwitchArgument())
441441
{
442442
arguments.UpdateAssemblyInfo = true;
443-
arguments.UpdateAssemblyInfoFileName.Add(value);
443+
if (value != null)
444+
{
445+
arguments.UpdateAssemblyInfoFileName.Add(value);
446+
}
444447
}
445448
else
446449
{

src/GitVersionExe/Arguments.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
35
using GitVersion.Logging;
46
using GitVersion.Model;
57
using GitVersion.Model.Configuration;
8+
using Microsoft.Extensions.FileSystemGlobbing;
9+
using Microsoft.Extensions.FileSystemGlobbing.Abstractions;
610

711
namespace GitVersion
812
{
@@ -52,15 +56,17 @@ public class Arguments
5256

5357
public GitVersionOptions ToOptions()
5458
{
59+
var workingDirectory = TargetPath.TrimEnd('/', '\\');
60+
5561
return new GitVersionOptions
5662
{
57-
WorkingDirectory = TargetPath.TrimEnd('/', '\\'),
63+
WorkingDirectory = workingDirectory,
5864

5965
AssemblyInfo =
6066
{
6167
ShouldUpdate = UpdateAssemblyInfo,
6268
EnsureAssemblyInfo = EnsureAssemblyInfo,
63-
Files = UpdateAssemblyInfoFileName,
69+
Files = ResolveFiles(workingDirectory).ToHashSet()
6470
},
6571

6672
Authentication =
@@ -114,5 +120,22 @@ public GitVersionOptions ToOptions()
114120
ExecArgs = ExecArgs,
115121
};
116122
}
123+
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)));
133+
134+
foreach (var result in results.Files)
135+
{
136+
yield return Path.GetFullPath(Path.Combine(workingDirectory, result.Path));
137+
}
138+
}
139+
}
117140
}
118141
}

src/GitVersionExe/GitVersionExe.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
<ItemGroup>
3131
<PackageReference Include="Microsoft.Extensions.Hosting" Version="$(PackageVersion_MicrosoftExtensions)" />
32+
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="$(PackageVersion_MicrosoftExtensions)" />
3233
</ItemGroup>
3334

3435
<ItemGroup>

0 commit comments

Comments
 (0)