-
Notifications
You must be signed in to change notification settings - Fork 663
LibGit2Sharp update to 0.26.0 #1659
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
Closed
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0fb4cac
libgit2sharp update
arturcic ccd343d
code cleanup for GitVersionTask
arturcic afb4805
remove UtilPack dependency for GitVersionTask
arturcic 2058982
split GitVersionTask in 2 projects, one with tasks another with imple…
arturcic ad3dfb5
updated to the msbuild props and targets
arturcic 425e488
rename GitVersionTask to GitVersion.MsBuild
arturcic ac27ceb
updates to build scripts
arturcic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
code cleanup for GitVersionTask
- Loading branch information
commit ccd343d3ee9c1e2633b225c524577927464b685d
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,72 +1,13 @@ | ||
| namespace GitVersionTask | ||
| { | ||
| using System; | ||
| using GitVersion; | ||
| using GitVersion.Helpers; | ||
|
|
||
| using Microsoft.Build.Framework; | ||
| using Microsoft.Build.Utilities; | ||
|
|
||
| public abstract class GitVersionTaskBase : Task | ||
| { | ||
| protected GitVersionTaskBase() | ||
| { | ||
| var fileSystem = new FileSystem(); | ||
| ExecuteCore = new ExecuteCore(fileSystem); | ||
| GitVersion.Logger.SetLoggers(LogDebug, LogInfo, LogWarning, s => LogError(s)); | ||
| } | ||
|
|
||
| public override bool Execute() | ||
| { | ||
| try | ||
| { | ||
| InnerExecute(); | ||
| return true; | ||
| } | ||
| catch (WarningException errorException) | ||
| { | ||
| LogWarning(errorException.Message); | ||
| return true; | ||
| } | ||
| catch (Exception exception) | ||
| { | ||
| LogError("Error occurred: " + exception); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| protected abstract void InnerExecute(); | ||
|
|
||
| protected ExecuteCore ExecuteCore { get; } | ||
|
|
||
| [Required] | ||
| public string SolutionDirectory { get; set; } | ||
|
|
||
| public bool NoFetch { get; set; } | ||
|
|
||
| public void LogDebug(string message) | ||
| { | ||
| BuildEngine.LogMessageEvent(new BuildMessageEventArgs(message, string.Empty, "GitVersionTask", MessageImportance.Low)); | ||
| } | ||
|
|
||
| public void LogWarning(string message) | ||
| { | ||
| BuildEngine.LogWarningEvent(new BuildWarningEventArgs(string.Empty, string.Empty, null, 0, 0, 0, 0, message, string.Empty, "GitVersionTask")); | ||
| } | ||
|
|
||
| public void LogInfo(string message) | ||
| { | ||
| BuildEngine.LogMessageEvent(new BuildMessageEventArgs(message, string.Empty, "GitVersionTask", MessageImportance.Normal)); | ||
| } | ||
|
|
||
| public void LogError(string message, string file = null) | ||
| { | ||
| BuildEngine.LogErrorEvent(new BuildErrorEventArgs(string.Empty, string.Empty, file, 0, 0, 0, 0, message, string.Empty, "GitVersionTask")); | ||
| } | ||
|
|
||
| protected bool GetVersionVariables(out VersionVariables versionVariables) | ||
| { | ||
| return !ExecuteCore.TryGetVersion(SolutionDirectory, out versionVariables, NoFetch, new Authentication()); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| namespace GitVersionTask | ||
| { | ||
| using System; | ||
| using System.IO; | ||
| using GitVersion; | ||
| using GitVersion.Helpers; | ||
| using Microsoft.Build.Framework; | ||
|
|
||
| public static class GitVersionTasks | ||
| { | ||
| public static ExecuteCore ExecuteCore { get; } | ||
|
|
||
| static GitVersionTasks() | ||
| { | ||
| var fileSystem = new FileSystem(); | ||
| ExecuteCore = new ExecuteCore(fileSystem); | ||
| } | ||
|
|
||
| public static bool GetVersion(GetVersion task) | ||
| { | ||
| return Execute(task, t => | ||
| { | ||
| if (!GetVersionVariables(task, out var versionVariables)) return; | ||
|
|
||
| var thisType = typeof(GetVersion); | ||
| foreach (var variable in versionVariables) | ||
| { | ||
| thisType.GetProperty(variable.Key)?.SetValue(task, variable.Value, null); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| public static bool GenerateGitVersionInformation(GenerateGitVersionInformation task) | ||
| { | ||
| return Execute(task, t => | ||
| { | ||
| if (!GetVersionVariables(task, out var versionVariables)) return; | ||
|
|
||
| var fileExtension = GetFileExtension(task.Language); | ||
| var fileName = $"GitVersionInformation.g.{fileExtension}"; | ||
|
|
||
| if (task.IntermediateOutputPath == null) | ||
| { | ||
| fileName = $"GitVersionInformation_{Path.GetFileNameWithoutExtension(task.ProjectFile)}_{Path.GetRandomFileName()}.g.{fileExtension}"; | ||
| } | ||
|
|
||
| var workingDirectory = task.IntermediateOutputPath ?? TempFileTracker.TempPath; | ||
|
|
||
| task.GitVersionInformationFilePath = Path.Combine(workingDirectory, fileName); | ||
|
|
||
| var generator = new GitVersionInformationGenerator(fileName, workingDirectory, versionVariables, new FileSystem()); | ||
| generator.Generate(); | ||
| }); | ||
| } | ||
|
|
||
| public static bool UpdateAssemblyInfo(UpdateAssemblyInfo task) | ||
| { | ||
| return Execute(task, t => | ||
| { | ||
| TempFileTracker.DeleteTempFiles(); | ||
| InvalidFileChecker.CheckForInvalidFiles(task.CompileFiles, task.ProjectFile); | ||
|
|
||
| if (!GetVersionVariables(task, out var versionVariables)) return; | ||
|
|
||
| var fileExtension = GetFileExtension(task.Language); | ||
| var assemblyInfoFileName = $"GitVersionTaskAssemblyInfo.g.{fileExtension}"; | ||
|
|
||
| if (task.IntermediateOutputPath == null) | ||
| { | ||
| assemblyInfoFileName = $"AssemblyInfo_{Path.GetFileNameWithoutExtension(task.ProjectFile)}_{Path.GetRandomFileName()}.g.{fileExtension}"; | ||
| } | ||
|
|
||
| var workingDirectory = task.IntermediateOutputPath ?? TempFileTracker.TempPath; | ||
|
|
||
| task.AssemblyInfoTempFilePath = Path.Combine(workingDirectory, assemblyInfoFileName); | ||
|
|
||
| using (var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(assemblyInfoFileName, workingDirectory, versionVariables, new FileSystem(), true)) | ||
| { | ||
| assemblyInfoFileUpdater.Update(); | ||
| assemblyInfoFileUpdater.CommitChanges(); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| public static bool WriteVersionInfoToBuildLog(WriteVersionInfoToBuildLog task) | ||
| { | ||
| return Execute(task, t => | ||
| { | ||
| if (!GetVersionVariables(task, out var versionVariables)) return; | ||
| var log = task.Log; | ||
|
|
||
| foreach (var buildServer in BuildServerList.GetApplicableBuildServers()) | ||
| { | ||
| log.LogMessage($"Executing GenerateSetVersionMessage for '{buildServer.GetType().Name}'."); | ||
| log.LogMessage(buildServer.GenerateSetVersionMessage(versionVariables)); | ||
| log.LogMessage($"Executing GenerateBuildLogOutput for '{buildServer.GetType().Name}'."); | ||
| foreach (var buildParameter in BuildOutputFormatter.GenerateBuildLogOutput(buildServer, versionVariables)) | ||
| { | ||
| log.LogMessage(buildParameter); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| private static bool Execute<T>(T task, Action<T> action) | ||
| where T : GitVersionTaskBase | ||
| { | ||
| void LogDebug(string message) => task.Log.LogMessage(MessageImportance.Low, message); | ||
| void LogInfo(string message) => task.Log.LogMessage(MessageImportance.Normal, message); | ||
| void LogWarning(string message) => task.Log.LogWarning(message); | ||
| void LogError(string message) => task.Log.LogError(message); | ||
|
|
||
| Logger.SetLoggers(LogDebug, LogInfo, LogWarning, LogError); | ||
| var log = task.Log; | ||
| try | ||
| { | ||
| action(task); | ||
| } | ||
| catch (WarningException errorException) | ||
| { | ||
| log.LogWarningFromException(errorException); | ||
| return true; | ||
| } | ||
| catch (Exception exception) | ||
| { | ||
| log.LogErrorFromException(exception); | ||
| return false; | ||
| } | ||
|
|
||
| return !log.HasLoggedErrors; | ||
| } | ||
|
|
||
| private static bool GetVersionVariables(GitVersionTaskBase task, out VersionVariables versionVariables) | ||
| => ExecuteCore.TryGetVersion(task.SolutionDirectory, out versionVariables, task.NoFetch, new Authentication()); | ||
|
|
||
| private static string GetFileExtension(string language) | ||
| { | ||
| switch(language) | ||
| { | ||
| case "C#": | ||
| return "cs"; | ||
|
|
||
| case "F#": | ||
| return "fs"; | ||
|
|
||
| case "VB": | ||
| return "vb"; | ||
|
|
||
| default: | ||
| throw new Exception($"Unknown language detected: '{language}'"); | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.