From fd45b4363e8654f60ea1f108037ee400ecbdeaf7 Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Wed, 22 Apr 2020 21:32:26 +0300 Subject: [PATCH] GH-2225 use FileSystemGlobbing to resolve AsemblyInfo to be updated --- .../{AssemblyInfo.cs => AssemblyInfoData.cs} | 2 +- src/GitVersionCore/Model/GitVersionOptions.cs | 2 +- src/GitVersionExe/ArgumentParser.cs | 5 +++- src/GitVersionExe/Arguments.cs | 27 +++++++++++++++++-- src/GitVersionExe/GitVersionExe.csproj | 1 + 5 files changed, 32 insertions(+), 5 deletions(-) rename src/GitVersionCore/Model/{AssemblyInfo.cs => AssemblyInfoData.cs} (85%) diff --git a/src/GitVersionCore/Model/AssemblyInfo.cs b/src/GitVersionCore/Model/AssemblyInfoData.cs similarity index 85% rename from src/GitVersionCore/Model/AssemblyInfo.cs rename to src/GitVersionCore/Model/AssemblyInfoData.cs index f32470ec5f..ec886c0fa8 100644 --- a/src/GitVersionCore/Model/AssemblyInfo.cs +++ b/src/GitVersionCore/Model/AssemblyInfoData.cs @@ -2,7 +2,7 @@ namespace GitVersion { - public class AssemblyInfo + public class AssemblyInfoData { public bool ShouldUpdate; public bool EnsureAssemblyInfo; diff --git a/src/GitVersionCore/Model/GitVersionOptions.cs b/src/GitVersionCore/Model/GitVersionOptions.cs index aa9bf12ab3..4e616b3101 100644 --- a/src/GitVersionCore/Model/GitVersionOptions.cs +++ b/src/GitVersionCore/Model/GitVersionOptions.cs @@ -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(); diff --git a/src/GitVersionExe/ArgumentParser.cs b/src/GitVersionExe/ArgumentParser.cs index 8bb3e1c1e7..11e27209a0 100644 --- a/src/GitVersionExe/ArgumentParser.cs +++ b/src/GitVersionExe/ArgumentParser.cs @@ -445,7 +445,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 { diff --git a/src/GitVersionExe/Arguments.cs b/src/GitVersionExe/Arguments.cs index a2b8cc5e2d..4d476e76be 100644 --- a/src/GitVersionExe/Arguments.cs +++ b/src/GitVersionExe/Arguments.cs @@ -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 { @@ -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 = @@ -114,5 +120,22 @@ public GitVersionOptions ToOptions() ExecArgs = ExecArgs, }; } + + private IEnumerable 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)); + } + } + } } } diff --git a/src/GitVersionExe/GitVersionExe.csproj b/src/GitVersionExe/GitVersionExe.csproj index 899980aa74..7424ee3d7d 100644 --- a/src/GitVersionExe/GitVersionExe.csproj +++ b/src/GitVersionExe/GitVersionExe.csproj @@ -29,6 +29,7 @@ +