Skip to content

Commit 4ae945a

Browse files
authored
Merge pull request #1677 from stazz/stazz/NuGetUtilsUpdate2
Migrating from UtilPack to NuGetUtils, take two
2 parents 406bebd + b1c206f commit 4ae945a

21 files changed

+427
-385
lines changed

src/GitVersionTask.Tests/GetVersionTaskTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Linq;
1+
using System.Linq;
22
using GitVersion;
33
using GitVersionTask;
44
using Microsoft.Build.Framework;
@@ -11,9 +11,8 @@ public class GetVersionTaskTests : TestBase
1111
[Test]
1212
public void OutputsShouldMatchVariableProvider()
1313
{
14-
var taskProperties = typeof(GetVersion)
14+
var taskProperties = typeof(GetVersion.Output)
1515
.GetProperties()
16-
.Where(p => p.GetCustomAttributes(typeof(OutputAttribute), false).Any())
1716
.Select(p => p.Name);
1817

1918
var variablesProperties = VersionVariables.AvailableVariables;

src/GitVersionTask.Tests/InvalidFileCheckerTests.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.IO;
33
using GitVersion;
4-
using GitVersionTask.Tests.Mocks;
54
using Microsoft.Build.Framework;
65
using NUnit.Framework;
76

@@ -41,7 +40,7 @@ public void VerifyIgnoreNonAssemblyInfoFile()
4140
");
4241
}
4342

44-
InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "SomeOtherFile.cs" } }, projectFile);
43+
InvalidFileChecker.CheckForInvalidFiles(new[] { "SomeOtherFile.cs" }, projectFile);
4544
}
4645

4746
[Test]
@@ -57,7 +56,7 @@ public void VerifyAttributeFoundCSharp([Values("AssemblyVersion", "AssemblyFileV
5756
", attribute);
5857
}
5958

60-
var ex = Assert.Throws<WarningException>(() => InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile), attribute);
59+
var ex = Assert.Throws<WarningException>(() => InvalidFileChecker.CheckForInvalidFiles(new[] { "AssemblyInfo.cs" }, projectFile), attribute);
6160
Assert.That(ex.Message, Is.EqualTo("File contains assembly version attributes which conflict with the attributes generated by GitVersion AssemblyInfo.cs"));
6261
}
6362

@@ -75,7 +74,7 @@ public void VerifyUnformattedAttributeFoundCSharp([Values("AssemblyVersion", "As
7574
", attribute);
7675
}
7776

78-
var ex = Assert.Throws<WarningException>(() => InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile), attribute);
77+
var ex = Assert.Throws<WarningException>(() => InvalidFileChecker.CheckForInvalidFiles(new[] { "AssemblyInfo.cs" }, projectFile), attribute);
7978
Assert.That(ex.Message, Is.EqualTo("File contains assembly version attributes which conflict with the attributes generated by GitVersion AssemblyInfo.cs"));
8079
}
8180

@@ -92,7 +91,7 @@ public void VerifyCommentWorksCSharp([Values("AssemblyVersion", "AssemblyFileVer
9291
", attribute);
9392
}
9493

95-
InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile);
94+
InvalidFileChecker.CheckForInvalidFiles(new[] { "AssemblyInfo.cs" }, projectFile);
9695
}
9796

9897
[Test]
@@ -111,7 +110,7 @@ public class Temp
111110
", attribute);
112111
}
113112

114-
InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile);
113+
InvalidFileChecker.CheckForInvalidFiles(new[] { "AssemblyInfo.cs" }, projectFile);
115114
}
116115

117116
[Test]
@@ -129,7 +128,7 @@ public class {0}
129128
", attribute);
130129
}
131130

132-
InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile);
131+
InvalidFileChecker.CheckForInvalidFiles(new[] { "AssemblyInfo.cs" }, projectFile);
133132
}
134133

135134
[Test]
@@ -145,7 +144,7 @@ Imports System.Reflection
145144
", attribute);
146145
}
147146

148-
var ex = Assert.Throws<WarningException>(() => InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile), attribute);
147+
var ex = Assert.Throws<WarningException>(() => InvalidFileChecker.CheckForInvalidFiles(new[] { "AssemblyInfo.vb" }, projectFile), attribute);
149148
Assert.That(ex.Message, Is.EqualTo("File contains assembly version attributes which conflict with the attributes generated by GitVersion AssemblyInfo.vb"));
150149
}
151150

@@ -163,7 +162,7 @@ Imports System.Reflection
163162
", attribute);
164163
}
165164

166-
var ex = Assert.Throws<WarningException>(() => InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile), attribute);
165+
var ex = Assert.Throws<WarningException>(() => InvalidFileChecker.CheckForInvalidFiles(new[] { "AssemblyInfo.vb" }, projectFile), attribute);
167166
Assert.That(ex.Message, Is.EqualTo("File contains assembly version attributes which conflict with the attributes generated by GitVersion AssemblyInfo.vb"));
168167
}
169168

@@ -180,7 +179,7 @@ Imports System.Reflection
180179
", attribute);
181180
}
182181

183-
InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile);
182+
InvalidFileChecker.CheckForInvalidFiles(new[] { "AssemblyInfo.vb" }, projectFile);
184183
}
185184

186185
[Test]
@@ -198,7 +197,7 @@ End Class
198197
", attribute);
199198
}
200199

201-
InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile);
200+
InvalidFileChecker.CheckForInvalidFiles(new[] { "AssemblyInfo.vb" }, projectFile);
202201
}
203202

204203
[Test]
@@ -215,6 +214,6 @@ End Class
215214
", attribute);
216215
}
217216

218-
InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile);
217+
InvalidFileChecker.CheckForInvalidFiles(new[] { "AssemblyInfo.vb" }, projectFile);
219218
}
220219
}

src/GitVersionTask.Tests/Mocks/MockBuildEngine.cs

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/GitVersionTask.Tests/Mocks/MockTaskItem.cs

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,52 @@
11
namespace GitVersionTask
22
{
3+
using System;
34
using System.IO;
45
using GitVersion;
56
using GitVersion.Helpers;
6-
using Microsoft.Build.Framework;
77

8-
public class GenerateGitVersionInformation : GitVersionTaskBase
8+
public static class GenerateGitVersionInformation
99
{
10-
[Required]
11-
public string ProjectFile { get; set; }
12-
13-
[Required]
14-
public string IntermediateOutputPath { get; set; }
15-
16-
[Required]
17-
public string Language { get; set; }
18-
19-
[Output]
20-
public string GitVersionInformationFilePath { get; set; }
10+
// This method is entrypoint for the task declared in .props file
11+
public static Output Execute(Input input)
12+
{
13+
return GitVersionTaskCommonFunctionality.ExecuteGitVersionTask(input, InnerExecute);
14+
}
2115

22-
protected override void InnerExecute()
16+
private static Output InnerExecute(Input input, TaskLogger logger)
2317
{
24-
if (GetVersionVariables(out var versionVariables)) return;
18+
var execute = GitVersionTaskCommonFunctionality.CreateExecuteCore();
19+
if (!execute.TryGetVersion(input.SolutionDirectory, out var versionVariables, input.NoFetch, new Authentication()))
20+
{
21+
return null;
22+
}
2523

26-
var fileExtension = TaskUtils.GetFileExtension(Language);
27-
var fileName = $"GitVersionInformation.g.{fileExtension}";
24+
var fileWriteInfo = input.IntermediateOutputPath.GetFileWriteInfo(
25+
input.Language,
26+
input.ProjectFile,
27+
(pf, ext) => $"GitVersionInformation.g.{ext}",
28+
(pf, ext) => $"GitVersionInformation_{Path.GetFileNameWithoutExtension(pf)}_{Path.GetRandomFileName()}.g.{ext}"
29+
);
2830

29-
if (IntermediateOutputPath == null)
31+
var output = new Output()
3032
{
31-
fileName = $"GitVersionInformation_{Path.GetFileNameWithoutExtension(ProjectFile)}_{Path.GetRandomFileName()}.g.{fileExtension}";
32-
}
33+
GitVersionInformationFilePath = Path.Combine(fileWriteInfo.WorkingDirectory, fileWriteInfo.FileName)
34+
};
35+
var generator = new GitVersionInformationGenerator(fileWriteInfo.FileName, fileWriteInfo.WorkingDirectory, versionVariables, new FileSystem());
36+
generator.Generate();
3337

34-
var workingDirectory = IntermediateOutputPath ?? TempFileTracker.TempPath;
38+
return output;
39+
}
3540

36-
GitVersionInformationFilePath = Path.Combine(workingDirectory, fileName);
3741

38-
var generator = new GitVersionInformationGenerator(fileName, workingDirectory, versionVariables, new FileSystem());
39-
generator.Generate();
42+
public sealed class Input : InputWithCommonAdditionalProperties
43+
{
4044
}
45+
46+
public sealed class Output
47+
{
48+
public string GitVersionInformationFilePath { get; set; }
49+
}
50+
4151
}
4252
}

0 commit comments

Comments
 (0)