Skip to content

Commit b84d0ef

Browse files
committed
Remove dependency on Arguments
1 parent 724f2fa commit b84d0ef

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

src/GitVersionCore/VersionAssemblyInfoResources/AssemblyInfoFileUpdate.cs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,26 @@ class AssemblyInfoFileUpdate : IDisposable
1414
List<Action> restoreBackupTasks = new List<Action>();
1515
List<Action> cleanupBackupTasks = new List<Action>();
1616

17-
public AssemblyInfoFileUpdate(Arguments args, string workingDirectory, VersionVariables variables, IFileSystem fileSystem)
17+
ISet<string> updateAssemblyInfoFileName;
18+
string workingDirectory;
19+
VersionVariables variables;
20+
IFileSystem fileSystem;
21+
bool ensureAssemblyInfo;
22+
23+
public AssemblyInfoFileUpdate(ISet<string> updateAssemblyInfoFileName, string workingDirectory, VersionVariables variables, IFileSystem fileSystem, bool ensureAssemblyInfo)
1824
{
19-
if (!args.UpdateAssemblyInfo) return;
25+
this.updateAssemblyInfoFileName = updateAssemblyInfoFileName;
26+
this.workingDirectory = workingDirectory;
27+
this.variables = variables;
28+
this.fileSystem = fileSystem;
29+
this.ensureAssemblyInfo = ensureAssemblyInfo;
30+
}
2031

21-
if (args.Output != OutputType.Json)
22-
Logger.WriteInfo("Updating assembly info files");
32+
public void Update()
33+
{
34+
Logger.WriteInfo("Updating assembly info files");
2335

24-
var assemblyInfoFiles = GetAssemblyInfoFiles(workingDirectory, args, fileSystem).ToList();
36+
var assemblyInfoFiles = GetAssemblyInfoFiles(workingDirectory, updateAssemblyInfoFileName, fileSystem, ensureAssemblyInfo).ToList();
2537
Logger.WriteInfo($"Found {assemblyInfoFiles.Count} files");
2638

2739
var assemblyVersion = variables.AssemblySemVer;
@@ -90,15 +102,15 @@ static string ReplaceOrAppend(Regex replaceRegex, string inputString, string rep
90102
}
91103

92104

93-
static IEnumerable<FileInfo> GetAssemblyInfoFiles(string workingDirectory, Arguments args, IFileSystem fileSystem)
105+
static IEnumerable<FileInfo> GetAssemblyInfoFiles(string workingDirectory, ISet<string> updateAssemblyInfoFileName, IFileSystem fileSystem, bool ensureAssemblyInfo)
94106
{
95-
if (args.UpdateAssemblyInfoFileName != null && args.UpdateAssemblyInfoFileName.Any(x => !string.IsNullOrWhiteSpace(x)))
107+
if (updateAssemblyInfoFileName != null && updateAssemblyInfoFileName.Any(x => !string.IsNullOrWhiteSpace(x)))
96108
{
97-
foreach (var item in args.UpdateAssemblyInfoFileName)
109+
foreach (var item in updateAssemblyInfoFileName)
98110
{
99111
var fullPath = Path.Combine(workingDirectory, item);
100112

101-
if (EnsureVersionAssemblyInfoFile(args, fileSystem, fullPath))
113+
if (EnsureVersionAssemblyInfoFile(ensureAssemblyInfo, fileSystem, fullPath, updateAssemblyInfoFileName))
102114
{
103115
yield return new FileInfo(fullPath);
104116
}
@@ -116,11 +128,11 @@ static IEnumerable<FileInfo> GetAssemblyInfoFiles(string workingDirectory, Argum
116128
}
117129
}
118130

119-
static bool EnsureVersionAssemblyInfoFile(Arguments arguments, IFileSystem fileSystem, string fullPath)
131+
static bool EnsureVersionAssemblyInfoFile(bool ensureAssemblyInfo, IFileSystem fileSystem, string fullPath, ISet<string> updateAssemblyInfoFileName)
120132
{
121133
if (fileSystem.Exists(fullPath)) return true;
122134

123-
if (!arguments.EnsureAssemblyInfo) return false;
135+
if (!ensureAssemblyInfo) return false;
124136

125137
var assemblyInfoSource = AssemblyVersionInfoTemplates.GetAssemblyInfoTemplateFor(fullPath);
126138
if (!string.IsNullOrWhiteSpace(assemblyInfoSource))
@@ -133,7 +145,7 @@ static bool EnsureVersionAssemblyInfoFile(Arguments arguments, IFileSystem fileS
133145
fileSystem.WriteAllText(fullPath, assemblyInfoSource);
134146
return true;
135147
}
136-
Logger.WriteWarning($"No version assembly info template available to create source file '{arguments.UpdateAssemblyInfoFileName}'");
148+
Logger.WriteWarning($"No version assembly info template available to create source file '{updateAssemblyInfoFileName}'");
137149
return false;
138150
}
139151

src/GitVersionExe/SpecifiedArgumentRunner.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,18 @@ public static void Run(Arguments arguments, IFileSystem fileSystem)
5656
}
5757
}
5858

59-
using (var assemblyInfoUpdate = new AssemblyInfoFileUpdate(arguments, targetPath, variables, fileSystem))
59+
using (var assemblyInfoUpdater = new AssemblyInfoFileUpdate(arguments.UpdateAssemblyInfoFileName, targetPath, variables, fileSystem, arguments.EnsureAssemblyInfo))
6060
{
61+
if (arguments.UpdateAssemblyInfo)
62+
{
63+
assemblyInfoUpdater.Update();
64+
}
65+
6166
var execRun = RunExecCommandIfNeeded(arguments, targetPath, variables);
6267
var msbuildRun = RunMsBuildIfNeeded(arguments, targetPath, variables);
6368
if (!execRun && !msbuildRun)
6469
{
65-
assemblyInfoUpdate.DoNotRestoreAssemblyInfo();
70+
assemblyInfoUpdater.DoNotRestoreAssemblyInfo();
6671
//TODO Put warning back
6772
//if (!context.CurrentBuildServer.IsRunningInBuildAgent())
6873
//{

0 commit comments

Comments
 (0)