Skip to content

Commit

Permalink
GitToolsGH-2225 use FileSystemGlobbing to resolve AsemblyInfo to be u…
Browse files Browse the repository at this point in the history
…pdated
  • Loading branch information
arturcic committed Apr 30, 2020
1 parent d99dd95 commit 9a4fc90
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace GitVersion
{
public class AssemblyInfo
public class AssemblyInfoData
{
public bool ShouldUpdate;
public bool EnsureAssemblyInfo;
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersionCore/Model/GitVersionOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public GitVersionOptions()
public string ProjectRootDirectory => projectRootDirectory.Value;
public string DynamicGitRepositoryPath => dynamicGitRepositoryPath.Value;

public AssemblyInfo AssemblyInfo { get; } = new AssemblyInfo();
public AssemblyInfoData AssemblyInfo { get; } = new AssemblyInfoData();
public AuthenticationInfo Authentication { get; } = new AuthenticationInfo();
public ConfigInfo ConfigInfo { get; } = new ConfigInfo();
public RepositoryInfo RepositoryInfo { get; } = new RepositoryInfo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ public AssemblyInfoFileUpdater(ILog log, IFileSystem fileSystem)

public void Execute(VersionVariables variables, AssemblyInfoContext context)
{
var assemblyInfoFileNames = new HashSet<string>(context.AssemblyInfoFiles);
var assemblyInfoFiles = GetAssemblyInfoFiles(context).ToList();
log.Info("Updating assembly info files");

var assemblyInfoFiles = GetAssemblyInfoFiles(context.WorkingDirectory, assemblyInfoFileNames, context.EnsureAssemblyInfo).ToList();
log.Info($"Found {assemblyInfoFiles.Count} files");

var assemblyVersion = variables.AssemblySemVer;
Expand Down Expand Up @@ -159,9 +157,13 @@ private string ReplaceOrInsertAfterLastAssemblyAttributeOrAppend(Regex replaceRe
return inputString;
}

private IEnumerable<FileInfo> GetAssemblyInfoFiles(string workingDirectory, ISet<string> assemblyInfoFileNames, bool ensureAssemblyInfo)
private IEnumerable<FileInfo> GetAssemblyInfoFiles(AssemblyInfoContext context)
{
if (assemblyInfoFileNames != null && assemblyInfoFileNames.Any(x => !string.IsNullOrWhiteSpace(x)))
var workingDirectory = context.WorkingDirectory;
var ensureAssemblyInfo = context.EnsureAssemblyInfo;
var assemblyInfoFileNames = new HashSet<string>(context.AssemblyInfoFiles);

if (assemblyInfoFileNames.Any(x => !string.IsNullOrWhiteSpace(x)))
{
foreach (var item in assemblyInfoFileNames)
{
Expand Down
5 changes: 4 additions & 1 deletion src/GitVersionExe/ArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,10 @@ private static void ParseUpdateAssemblyInfo(Arguments arguments, string value, s
else if (!value.IsSwitchArgument())
{
arguments.UpdateAssemblyInfo = true;
arguments.UpdateAssemblyInfoFileName.Add(value);
if (value != null)
{
arguments.UpdateAssemblyInfoFileName.Add(value);
}
}
else
{
Expand Down
27 changes: 25 additions & 2 deletions src/GitVersionExe/Arguments.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using GitVersion.Logging;
using GitVersion.Model;
using GitVersion.Model.Configuration;
using Microsoft.Extensions.FileSystemGlobbing;
using Microsoft.Extensions.FileSystemGlobbing.Abstractions;

namespace GitVersion
{
Expand Down Expand Up @@ -52,15 +56,17 @@ public class Arguments

public GitVersionOptions ToOptions()
{
var workingDirectory = TargetPath.TrimEnd('/', '\\');

return new GitVersionOptions
{
WorkingDirectory = TargetPath.TrimEnd('/', '\\'),
WorkingDirectory = workingDirectory,

AssemblyInfo =
{
ShouldUpdate = UpdateAssemblyInfo,
EnsureAssemblyInfo = EnsureAssemblyInfo,
Files = UpdateAssemblyInfoFileName,
Files = ResolveFiles(workingDirectory).ToHashSet()
},

Authentication =
Expand Down Expand Up @@ -114,5 +120,22 @@ public GitVersionOptions ToOptions()
ExecArgs = ExecArgs,
};
}

private IEnumerable<string> ResolveFiles(string workingDirectory)
{
if (UpdateAssemblyInfoFileName == null) yield break;
var matcher = new Matcher(StringComparison.OrdinalIgnoreCase);

foreach (var file in UpdateAssemblyInfoFileName)
{
matcher.AddInclude(file);
var results = matcher.Execute(new DirectoryInfoWrapper(new DirectoryInfo(workingDirectory)));

foreach (var result in results.Files)
{
yield return Path.GetFullPath(Path.Combine(workingDirectory, result.Path));
}
}
}
}
}
1 change: 1 addition & 0 deletions src/GitVersionExe/GitVersionExe.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="$(PackageVersion_MicrosoftExtensions)" />
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="$(PackageVersion_MicrosoftExtensions)" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 9a4fc90

Please sign in to comment.