-
Notifications
You must be signed in to change notification settings - Fork 655
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
NuGetUtils update #1645
Changes from all commits
66c1435
9c1fc6c
7a077a5
9c74cd7
e4ebb13
956ae14
2ae8f1a
91650a0
42f30a8
6b607fa
1b8ae10
1a09bc3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
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 | ||
{ | ||
[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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @stazz, why isn't any form of inheritance used across the different There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I simply forgot to do that. I'll fix this on Sunday. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @stazz, why isn't this method placed inside the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
{ | ||
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; } | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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
andOutput
inner classes are used), so no instances of it will be created either.There was a problem hiding this comment.
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.