Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrating from UtilPack to NuGetUtils, take two #1677

Merged
merged 11 commits into from
May 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/GitVersionTask.Tests/GetVersionTaskTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using GitVersion;
using GitVersionTask;
using Microsoft.Build.Framework;
Expand All @@ -11,9 +11,8 @@ public class GetVersionTaskTests : TestBase
[Test]
public void OutputsShouldMatchVariableProvider()
{
var taskProperties = typeof(GetVersion)
var taskProperties = typeof(GetVersion.Output)
.GetProperties()
.Where(p => p.GetCustomAttributes(typeof(OutputAttribute), false).Any())
.Select(p => p.Name);

var variablesProperties = VersionVariables.AvailableVariables;
Expand Down
23 changes: 11 additions & 12 deletions src/GitVersionTask.Tests/InvalidFileCheckerTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.IO;
using GitVersion;
using GitVersionTask.Tests.Mocks;
using Microsoft.Build.Framework;
using NUnit.Framework;

Expand Down Expand Up @@ -41,7 +40,7 @@ public void VerifyIgnoreNonAssemblyInfoFile()
");
}

InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "SomeOtherFile.cs" } }, projectFile);
InvalidFileChecker.CheckForInvalidFiles(new[] { "SomeOtherFile.cs" }, projectFile);
}

[Test]
Expand All @@ -57,7 +56,7 @@ public void VerifyAttributeFoundCSharp([Values("AssemblyVersion", "AssemblyFileV
", attribute);
}

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

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

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

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

InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile);
InvalidFileChecker.CheckForInvalidFiles(new[] { "AssemblyInfo.cs" }, projectFile);
}

[Test]
Expand All @@ -111,7 +110,7 @@ public class Temp
", attribute);
}

InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile);
InvalidFileChecker.CheckForInvalidFiles(new[] { "AssemblyInfo.cs" }, projectFile);
}

[Test]
Expand All @@ -129,7 +128,7 @@ public class {0}
", attribute);
}

InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile);
InvalidFileChecker.CheckForInvalidFiles(new[] { "AssemblyInfo.cs" }, projectFile);
}

[Test]
Expand All @@ -145,7 +144,7 @@ Imports System.Reflection
", attribute);
}

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

Expand All @@ -163,7 +162,7 @@ Imports System.Reflection
", attribute);
}

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

Expand All @@ -180,7 +179,7 @@ Imports System.Reflection
", attribute);
}

InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile);
InvalidFileChecker.CheckForInvalidFiles(new[] { "AssemblyInfo.vb" }, projectFile);
}

[Test]
Expand All @@ -198,7 +197,7 @@ End Class
", attribute);
}

InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile);
InvalidFileChecker.CheckForInvalidFiles(new[] { "AssemblyInfo.vb" }, projectFile);
}

[Test]
Expand All @@ -215,6 +214,6 @@ End Class
", attribute);
}

InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile);
InvalidFileChecker.CheckForInvalidFiles(new[] { "AssemblyInfo.vb" }, projectFile);
}
}
45 changes: 0 additions & 45 deletions src/GitVersionTask.Tests/Mocks/MockBuildEngine.cs

This file was deleted.

40 changes: 0 additions & 40 deletions src/GitVersionTask.Tests/Mocks/MockTaskItem.cs

This file was deleted.

58 changes: 34 additions & 24 deletions src/GitVersionTask/GenerateGitVersionInformation.cs
Original file line number Diff line number Diff line change
@@ -1,42 +1,52 @@
namespace GitVersionTask
{
using System;
using System.IO;
using GitVersion;
using GitVersion.Helpers;
using Microsoft.Build.Framework;

public class GenerateGitVersionInformation : GitVersionTaskBase
public static class GenerateGitVersionInformation
{
[Required]
public string ProjectFile { get; set; }

[Required]
public string IntermediateOutputPath { get; set; }

[Required]
public string Language { get; set; }

[Output]
public string GitVersionInformationFilePath { get; set; }
// This method is entrypoint for the task declared in .props file
public static Output Execute(Input input)
{
return GitVersionTaskCommonFunctionality.ExecuteGitVersionTask(input, InnerExecute);
}

protected override void InnerExecute()
private static Output InnerExecute(Input input, TaskLogger logger)
{
if (GetVersionVariables(out var versionVariables)) return;
var execute = GitVersionTaskCommonFunctionality.CreateExecuteCore();
if (!execute.TryGetVersion(input.SolutionDirectory, out var versionVariables, input.NoFetch, new Authentication()))
{
return null;
}

var fileExtension = TaskUtils.GetFileExtension(Language);
var fileName = $"GitVersionInformation.g.{fileExtension}";
var fileWriteInfo = input.IntermediateOutputPath.GetFileWriteInfo(
input.Language,
input.ProjectFile,
(pf, ext) => $"GitVersionInformation.g.{ext}",
(pf, ext) => $"GitVersionInformation_{Path.GetFileNameWithoutExtension(pf)}_{Path.GetRandomFileName()}.g.{ext}"
);

if (IntermediateOutputPath == null)
var output = new Output()
{
fileName = $"GitVersionInformation_{Path.GetFileNameWithoutExtension(ProjectFile)}_{Path.GetRandomFileName()}.g.{fileExtension}";
}
GitVersionInformationFilePath = Path.Combine(fileWriteInfo.WorkingDirectory, fileWriteInfo.FileName)
};
var generator = new GitVersionInformationGenerator(fileWriteInfo.FileName, fileWriteInfo.WorkingDirectory, versionVariables, new FileSystem());
generator.Generate();

var workingDirectory = IntermediateOutputPath ?? TempFileTracker.TempPath;
return output;
}

GitVersionInformationFilePath = Path.Combine(workingDirectory, fileName);

var generator = new GitVersionInformationGenerator(fileName, workingDirectory, versionVariables, new FileSystem());
generator.Generate();
public sealed class Input : InputWithCommonAdditionalProperties
{
}

public sealed class Output
{
public string GitVersionInformationFilePath { get; set; }
}

}
}
Loading