Skip to content

Commit e4c239a

Browse files
stazzasbjornu
authored andcommitted
First modifications for changing from UtilPack.NuGet.MSBuild to NuGetUtils.MSBuild.Exec.
1 parent 3547037 commit e4c239a

13 files changed

+355
-315
lines changed

src/GitVersionTask.Tests/GitVersionTask.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
<PackageReference Include="NUnit" Version="3.11.0"></PackageReference>
1818
<packagereference Include="NUnit3TestAdapter" Version="3.13.0"></packagereference>
1919
<PackageReference Include="Shouldly" Version="3.0.2"></PackageReference>
20-
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.9.20" />
2120
</ItemGroup>
2221
<ItemGroup>
2322
<Content Include="Approved\**\*.txt" />

src/GitVersionTask/BuildLogger.cs

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

src/GitVersionTask/GenerateGitVersionInformation.cs

Lines changed: 54 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,98 +4,96 @@ namespace GitVersionTask
44
using System.IO;
55
using GitVersion;
66
using GitVersion.Helpers;
7-
using Microsoft.Build.Framework;
87

9-
public class GenerateGitVersionInformation : GitVersionTaskBase
8+
public static class GenerateGitVersionInformation
109
{
11-
TaskLogger logger;
12-
13-
public GenerateGitVersionInformation()
10+
public static Output Execute(
11+
Input input
12+
)
1413
{
15-
logger = new TaskLogger(this);
16-
Logger.SetLoggers(this.LogDebug, this.LogInfo, this.LogWarning, s => this.LogError(s));
17-
}
18-
19-
[Required]
20-
public string SolutionDirectory { get; set; }
21-
22-
[Required]
23-
public string ProjectFile { get; set; }
24-
25-
[Required]
26-
public string IntermediateOutputPath { get; set; }
27-
28-
[Required]
29-
public string Language { get; set; }
14+
if ( !input.ValidateInput() )
15+
{
16+
throw new Exception( "Invalid input." );
17+
}
3018

31-
[Output]
32-
public string GitVersionInformationFilePath { get; set; }
19+
var logger = new TaskLogger();
20+
Logger.SetLoggers( logger.LogInfo, logger.LogInfo, logger.LogWarning, s => logger.LogError( s ) );
3321

34-
public bool NoFetch { get; set; }
3522

36-
public override bool Execute()
37-
{
23+
Output output = null;
3824
try
3925
{
40-
InnerExecute();
41-
return true;
26+
output = InnerExecute(input );
4227
}
4328
catch (WarningException errorException)
4429
{
4530
logger.LogWarning(errorException.Message);
46-
return true;
31+
output = new Output();
4732
}
4833
catch (Exception exception)
4934
{
5035
logger.LogError("Error occurred: " + exception);
51-
return false;
36+
throw;
5237
}
5338
finally
5439
{
5540
Logger.Reset();
5641
}
42+
43+
return output;
5744
}
5845

59-
void InnerExecute()
46+
private static Output InnerExecute( Input input )
6047
{
61-
VersionVariables versionVariables;
62-
if (!ExecuteCore.TryGetVersion(SolutionDirectory, out versionVariables, NoFetch, new Authentication()))
48+
var execute = GitVersionTaskBase.CreateExecuteCore();
49+
if (!execute.TryGetVersion(input.SolutionDirectory, out var versionVariables, input.NoFetch, new Authentication()))
6350
{
64-
return;
51+
return null;
6552
}
6653

67-
var fileExtension = GetFileExtension();
68-
var fileName = $"GitVersionInformation.g.{fileExtension}";
54+
var fileWriteInfo = input.IntermediateOutputPath.GetWorkingDirectoryAndFileNameAndExtension(
55+
input.Language,
56+
input.ProjectFile,
57+
( pf, ext ) => $"GitVersionInformation.g.{ext}",
58+
( pf, ext ) => $"GitVersionInformation_{Path.GetFileNameWithoutExtension( pf )}_{Path.GetRandomFileName()}.g.{ext}"
59+
);
6960

70-
if (IntermediateOutputPath == null)
61+
var output = new Output()
7162
{
72-
fileName = $"GitVersionInformation_{Path.GetFileNameWithoutExtension(ProjectFile)}_{Path.GetRandomFileName()}.g.{fileExtension}";
73-
}
74-
75-
var workingDirectory = IntermediateOutputPath ?? TempFileTracker.TempPath;
76-
77-
GitVersionInformationFilePath = Path.Combine(workingDirectory, fileName);
78-
79-
var generator = new GitVersionInformationGenerator(fileName, workingDirectory, versionVariables, new FileSystem());
63+
GitVersionInformationFilePath = Path.Combine( fileWriteInfo.WorkingDirectory, fileWriteInfo.FileName )
64+
};
65+
var generator = new GitVersionInformationGenerator( fileWriteInfo.FileName, fileWriteInfo.WorkingDirectory, versionVariables, new FileSystem());
8066
generator.Generate();
67+
68+
return output;
8169
}
8270

83-
string GetFileExtension()
71+
public sealed class Input
8472
{
85-
switch (Language)
86-
{
87-
case "C#":
88-
return "cs";
73+
public string SolutionDirectory { get; set; }
8974

90-
case "F#":
91-
return "fs";
75+
public string ProjectFile { get; set; }
9276

93-
case "VB":
94-
return "vb";
77+
public string IntermediateOutputPath { get; set; }
9578

96-
default:
97-
throw new Exception($"Unknown language detected: '{Language}'");
98-
}
79+
public string Language { get; set; }
80+
81+
public bool NoFetch { get; set; }
82+
}
83+
84+
private static Boolean ValidateInput( this Input input )
85+
{
86+
return input != null
87+
&& !String.IsNullOrEmpty( input.SolutionDirectory )
88+
&& !String.IsNullOrEmpty(input.ProjectFile)
89+
// && !String.IsNullOrEmpty(input.IntermediateOutputPath) // This was marked as [Required] but it InnerExecute still seems to allow it to be null... ?
90+
&& !String.IsNullOrEmpty(input.Language)
91+
;
92+
}
93+
94+
public sealed class Output
95+
{
96+
public string GitVersionInformationFilePath { get; set; }
9997
}
10098
}
10199
}

0 commit comments

Comments
 (0)