Skip to content

NuGetUtils update #1645

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

Closed
wants to merge 12 commits into from
Closed
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
6 changes: 2 additions & 4 deletions src/GitVersionTask.Tests/GetVersionTaskTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Linq;
using System.Linq;
using GitVersion;
using GitVersionTask;
using Microsoft.Build.Framework;
using NUnit.Framework;
using Shouldly;

Expand All @@ -11,9 +10,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
1 change: 0 additions & 1 deletion src/GitVersionTask.Tests/GitVersionTask.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<PackageReference Include="NUnit" Version="3.11.0"></PackageReference>
<packagereference Include="NUnit3TestAdapter" Version="3.13.0"></packagereference>
<PackageReference Include="Shouldly" Version="3.0.2"></PackageReference>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.0.461" />
</ItemGroup>
<ItemGroup>
<Content Include="Approved\**\*.txt" />
Expand Down
24 changes: 11 additions & 13 deletions src/GitVersionTask.Tests/InvalidFileCheckerTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.IO;
using GitVersion;
using GitVersionTask.Tests.Mocks;
using Microsoft.Build.Framework;
using NUnit.Framework;

[TestFixture]
Expand Down Expand Up @@ -41,7 +39,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 +55,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 +73,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 +90,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 +109,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 +127,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 +143,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 +161,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 +178,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 +196,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 +213,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.

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

public class GenerateGitVersionInformation : GitVersionTaskBase
public static class GenerateGitVersionInformation
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stazz, why the change to static class here?

Copy link
Contributor

@stazz stazz May 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is that the class has no state on its own anymore (instead, the Input and Output inner classes are used), so no instances of it will be created either.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Thanks for the explanation.

{
[Required]
public string ProjectFile { get; set; }
public static Output Execute(
Input input
)
{
if ( !input.ValidateInput() )
{
throw new Exception( "Invalid input." );
}

[Required]
public string IntermediateOutputPath { get; set; }
var logger = new TaskLogger();
Logger.SetLoggers( logger.LogInfo, logger.LogInfo, logger.LogWarning, s => logger.LogError( s ) );

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

[Output]
public string GitVersionInformationFilePath { get; set; }
Output output = null;
try
{
output = InnerExecute(input );
}
catch (WarningException errorException)
{
logger.LogWarning(errorException.Message);
output = new Output();
}
catch (Exception exception)
{
logger.LogError("Error occurred: " + exception);
throw;
}
finally
{
Logger.Reset();
}

protected override void InnerExecute()
return output;
}

private static Output InnerExecute( Input input )
{
if (GetVersionVariables(out var versionVariables)) return;
var execute = GitVersionTaskBase.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.GetWorkingDirectoryAndFileNameAndExtension(
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);
public sealed class Input
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stazz, why isn't any form of inheritance used across the different Input classes (and Output classes, for that matter)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simply forgot to do that. I'll fix this on Sunday.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

{
public string SolutionDirectory { get; set; }

var generator = new GitVersionInformationGenerator(fileName, workingDirectory, versionVariables, new FileSystem());
generator.Generate();
public string ProjectFile { get; set; }

public string IntermediateOutputPath { get; set; }

public string Language { get; set; }

public bool NoFetch { get; set; }
}

private static Boolean ValidateInput( this Input input )
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stazz, why isn't this method placed inside the Input class itself?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No particular reason. I guess the validity input depends a bit on a context (which I admit in this case is exactly one). Can move it as instance method of Input class on Sunday.

{
return input != null
&& !String.IsNullOrEmpty( input.SolutionDirectory )
&& !String.IsNullOrEmpty(input.ProjectFile)
// && !String.IsNullOrEmpty(input.IntermediateOutputPath) // This was marked as [Required] but it InnerExecute still seems to allow it to be null... ?
&& !String.IsNullOrEmpty(input.Language)
;
}

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