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 23, 2020
1 parent 49b07e7 commit fd45b43
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 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
5 changes: 4 additions & 1 deletion src/GitVersionExe/ArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
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 fd45b43

Please sign in to comment.